a5b21895934717fa018527afc832aee5aca771a4
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-ucode.c
1 /******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
5 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32
33 #include "iwl-dev.h"
34 #include "iwl-core.h"
35 #include "iwl-io.h"
36 #include "iwl-agn-hw.h"
37 #include "iwl-agn.h"
38 #include "iwl-agn-calib.h"
39 #include "iwl-trans.h"
40 #include "iwl-fh.h"
41 #include "iwl-op-mode.h"
42
43 static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
44 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
45 0, COEX_UNASSOC_IDLE_FLAGS},
46 {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
47 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
48 {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
49 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
50 {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
51 0, COEX_CALIBRATION_FLAGS},
52 {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
53 0, COEX_PERIODIC_CALIBRATION_FLAGS},
54 {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
55 0, COEX_CONNECTION_ESTAB_FLAGS},
56 {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
57 0, COEX_ASSOCIATED_IDLE_FLAGS},
58 {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
59 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
60 {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
61 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
62 {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
63 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
64 {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
65 {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
66 {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
67 0, COEX_STAND_ALONE_DEBUG_FLAGS},
68 {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
69 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
70 {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
71 {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
72 };
73
74 /******************************************************************************
75 *
76 * uCode download functions
77 *
78 ******************************************************************************/
79
80 static inline const struct fw_img *
81 iwl_get_ucode_image(struct iwl_priv *priv, enum iwl_ucode_type ucode_type)
82 {
83 if (ucode_type >= IWL_UCODE_TYPE_MAX)
84 return NULL;
85
86 return &priv->fw->img[ucode_type];
87 }
88
89 /*
90 * Calibration
91 */
92 static int iwl_set_Xtal_calib(struct iwl_priv *priv)
93 {
94 struct iwl_calib_xtal_freq_cmd cmd;
95 __le16 *xtal_calib =
96 (__le16 *)iwl_eeprom_query_addr(priv->shrd, EEPROM_XTAL);
97
98 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD);
99 cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
100 cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]);
101 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
102 }
103
104 static int iwl_set_temperature_offset_calib(struct iwl_priv *priv)
105 {
106 struct iwl_calib_temperature_offset_cmd cmd;
107 __le16 *offset_calib =
108 (__le16 *)iwl_eeprom_query_addr(priv->shrd,
109 EEPROM_RAW_TEMPERATURE);
110
111 memset(&cmd, 0, sizeof(cmd));
112 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
113 memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
114 if (!(cmd.radio_sensor_offset))
115 cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
116
117 IWL_DEBUG_CALIB(priv, "Radio sensor offset: %d\n",
118 le16_to_cpu(cmd.radio_sensor_offset));
119 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
120 }
121
122 static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv)
123 {
124 struct iwl_calib_temperature_offset_v2_cmd cmd;
125 __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(priv->shrd,
126 EEPROM_KELVIN_TEMPERATURE);
127 __le16 *offset_calib_low =
128 (__le16 *)iwl_eeprom_query_addr(priv->shrd,
129 EEPROM_RAW_TEMPERATURE);
130 struct iwl_eeprom_calib_hdr *hdr;
131
132 memset(&cmd, 0, sizeof(cmd));
133 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
134 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv->shrd,
135 EEPROM_CALIB_ALL);
136 memcpy(&cmd.radio_sensor_offset_high, offset_calib_high,
137 sizeof(*offset_calib_high));
138 memcpy(&cmd.radio_sensor_offset_low, offset_calib_low,
139 sizeof(*offset_calib_low));
140 if (!(cmd.radio_sensor_offset_low)) {
141 IWL_DEBUG_CALIB(priv, "no info in EEPROM, use default\n");
142 cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET;
143 cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET;
144 }
145 memcpy(&cmd.burntVoltageRef, &hdr->voltage,
146 sizeof(hdr->voltage));
147
148 IWL_DEBUG_CALIB(priv, "Radio sensor offset high: %d\n",
149 le16_to_cpu(cmd.radio_sensor_offset_high));
150 IWL_DEBUG_CALIB(priv, "Radio sensor offset low: %d\n",
151 le16_to_cpu(cmd.radio_sensor_offset_low));
152 IWL_DEBUG_CALIB(priv, "Voltage Ref: %d\n",
153 le16_to_cpu(cmd.burntVoltageRef));
154
155 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
156 }
157
158 static int iwl_send_calib_cfg(struct iwl_priv *priv)
159 {
160 struct iwl_calib_cfg_cmd calib_cfg_cmd;
161 struct iwl_host_cmd cmd = {
162 .id = CALIBRATION_CFG_CMD,
163 .len = { sizeof(struct iwl_calib_cfg_cmd), },
164 .data = { &calib_cfg_cmd, },
165 };
166
167 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
168 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
169 calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
170 calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
171 calib_cfg_cmd.ucd_calib_cfg.flags =
172 IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK;
173
174 return iwl_dvm_send_cmd(priv, &cmd);
175 }
176
177 int iwl_init_alive_start(struct iwl_priv *priv)
178 {
179 int ret;
180
181 if (cfg(priv)->bt_params &&
182 cfg(priv)->bt_params->advanced_bt_coexist) {
183 /*
184 * Tell uCode we are ready to perform calibration
185 * need to perform this before any calibration
186 * no need to close the envlope since we are going
187 * to load the runtime uCode later.
188 */
189 ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
190 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
191 if (ret)
192 return ret;
193
194 }
195
196 ret = iwl_send_calib_cfg(priv);
197 if (ret)
198 return ret;
199
200 /**
201 * temperature offset calibration is only needed for runtime ucode,
202 * so prepare the value now.
203 */
204 if (cfg(priv)->need_temp_offset_calib) {
205 if (cfg(priv)->temp_offset_v2)
206 return iwl_set_temperature_offset_calib_v2(priv);
207 else
208 return iwl_set_temperature_offset_calib(priv);
209 }
210
211 return 0;
212 }
213
214 static int iwl_send_wimax_coex(struct iwl_priv *priv)
215 {
216 struct iwl_wimax_coex_cmd coex_cmd;
217
218 if (cfg(priv)->base_params->support_wimax_coexist) {
219 /* UnMask wake up src at associated sleep */
220 coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
221
222 /* UnMask wake up src at unassociated sleep */
223 coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
224 memcpy(coex_cmd.sta_prio, cu_priorities,
225 sizeof(struct iwl_wimax_coex_event_entry) *
226 COEX_NUM_OF_EVENTS);
227
228 /* enabling the coexistence feature */
229 coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
230
231 /* enabling the priorities tables */
232 coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
233 } else {
234 /* coexistence is disabled */
235 memset(&coex_cmd, 0, sizeof(coex_cmd));
236 }
237 return iwl_dvm_send_cmd_pdu(priv,
238 COEX_PRIORITY_TABLE_CMD, CMD_SYNC,
239 sizeof(coex_cmd), &coex_cmd);
240 }
241
242 static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
243 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
244 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
245 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
246 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
247 ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
248 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
249 ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
250 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
251 ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
252 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
253 ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
254 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
255 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
256 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
257 ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
258 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
259 ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
260 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
261 0, 0, 0, 0, 0, 0, 0
262 };
263
264 void iwl_send_prio_tbl(struct iwl_priv *priv)
265 {
266 struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd;
267
268 memcpy(prio_tbl_cmd.prio_tbl, iwl_bt_prio_tbl,
269 sizeof(iwl_bt_prio_tbl));
270 if (iwl_dvm_send_cmd_pdu(priv,
271 REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC,
272 sizeof(prio_tbl_cmd), &prio_tbl_cmd))
273 IWL_ERR(priv, "failed to send BT prio tbl command\n");
274 }
275
276 int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type)
277 {
278 struct iwl_bt_coex_prot_env_cmd env_cmd;
279 int ret;
280
281 env_cmd.action = action;
282 env_cmd.type = type;
283 ret = iwl_dvm_send_cmd_pdu(priv,
284 REPLY_BT_COEX_PROT_ENV, CMD_SYNC,
285 sizeof(env_cmd), &env_cmd);
286 if (ret)
287 IWL_ERR(priv, "failed to send BT env command\n");
288 return ret;
289 }
290
291
292 static int iwl_alive_notify(struct iwl_priv *priv)
293 {
294 int ret;
295
296 iwl_trans_fw_alive(trans(priv));
297
298 priv->passive_no_rx = false;
299 priv->transport_queue_stop = 0;
300
301 ret = iwl_send_wimax_coex(priv);
302 if (ret)
303 return ret;
304
305 if (!cfg(priv)->no_xtal_calib) {
306 ret = iwl_set_Xtal_calib(priv);
307 if (ret)
308 return ret;
309 }
310
311 return iwl_send_calib_results(priv);
312 }
313
314
315 /**
316 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
317 * using sample data 100 bytes apart. If these sample points are good,
318 * it's a pretty good bet that everything between them is good, too.
319 */
320 static int iwl_verify_sec_sparse(struct iwl_priv *priv,
321 const struct fw_desc *fw_desc)
322 {
323 __le32 *image = (__le32 *)fw_desc->v_addr;
324 u32 len = fw_desc->len;
325 u32 val;
326 u32 i;
327
328 IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len);
329
330 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
331 /* read data comes through single port, auto-incr addr */
332 /* NOTE: Use the debugless read so we don't flood kernel log
333 * if IWL_DL_IO is set */
334 iwl_write_direct32(trans(priv), HBUS_TARG_MEM_RADDR,
335 i + fw_desc->offset);
336 val = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
337 if (val != le32_to_cpu(*image))
338 return -EIO;
339 }
340
341 return 0;
342 }
343
344 static void iwl_print_mismatch_sec(struct iwl_priv *priv,
345 const struct fw_desc *fw_desc)
346 {
347 __le32 *image = (__le32 *)fw_desc->v_addr;
348 u32 len = fw_desc->len;
349 u32 val;
350 u32 offs;
351 int errors = 0;
352
353 IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len);
354
355 iwl_write_direct32(trans(priv), HBUS_TARG_MEM_RADDR,
356 fw_desc->offset);
357
358 for (offs = 0;
359 offs < len && errors < 20;
360 offs += sizeof(u32), image++) {
361 /* read data comes through single port, auto-incr addr */
362 val = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
363 if (val != le32_to_cpu(*image)) {
364 IWL_ERR(priv, "uCode INST section at "
365 "offset 0x%x, is 0x%x, s/b 0x%x\n",
366 offs, val, le32_to_cpu(*image));
367 errors++;
368 }
369 }
370 }
371
372 /**
373 * iwl_verify_ucode - determine which instruction image is in SRAM,
374 * and verify its contents
375 */
376 static int iwl_verify_ucode(struct iwl_priv *priv,
377 enum iwl_ucode_type ucode_type)
378 {
379 const struct fw_img *img = iwl_get_ucode_image(priv, ucode_type);
380
381 if (!img) {
382 IWL_ERR(priv, "Invalid ucode requested (%d)\n", ucode_type);
383 return -EINVAL;
384 }
385
386 if (!iwl_verify_sec_sparse(priv, &img->sec[IWL_UCODE_SECTION_INST])) {
387 IWL_DEBUG_FW(priv, "uCode is good in inst SRAM\n");
388 return 0;
389 }
390
391 IWL_ERR(priv, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n");
392
393 iwl_print_mismatch_sec(priv, &img->sec[IWL_UCODE_SECTION_INST]);
394 return -EIO;
395 }
396
397 struct iwl_alive_data {
398 bool valid;
399 u8 subtype;
400 };
401
402 static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
403 struct iwl_rx_packet *pkt, void *data)
404 {
405 struct iwl_priv *priv =
406 container_of(notif_wait, struct iwl_priv, notif_wait);
407 struct iwl_alive_data *alive_data = data;
408 struct iwl_alive_resp *palive;
409
410 palive = (void *)pkt->data;
411
412 IWL_DEBUG_FW(priv, "Alive ucode status 0x%08X revision "
413 "0x%01X 0x%01X\n",
414 palive->is_valid, palive->ver_type,
415 palive->ver_subtype);
416
417 priv->shrd->device_pointers.error_event_table =
418 le32_to_cpu(palive->error_event_table_ptr);
419 priv->shrd->device_pointers.log_event_table =
420 le32_to_cpu(palive->log_event_table_ptr);
421
422 alive_data->subtype = palive->ver_subtype;
423 alive_data->valid = palive->is_valid == UCODE_VALID_OK;
424
425 return true;
426 }
427
428 #define UCODE_ALIVE_TIMEOUT HZ
429 #define UCODE_CALIB_TIMEOUT (2*HZ)
430
431 int iwl_load_ucode_wait_alive(struct iwl_priv *priv,
432 enum iwl_ucode_type ucode_type)
433 {
434 struct iwl_notification_wait alive_wait;
435 struct iwl_alive_data alive_data;
436 const struct fw_img *fw;
437 int ret;
438 enum iwl_ucode_type old_type;
439 static const u8 alive_cmd[] = { REPLY_ALIVE };
440
441 old_type = priv->shrd->ucode_type;
442 priv->shrd->ucode_type = ucode_type;
443 fw = iwl_get_ucode_image(priv, ucode_type);
444
445 priv->ucode_loaded = false;
446
447 if (!fw)
448 return -EINVAL;
449
450 iwl_init_notification_wait(&priv->notif_wait, &alive_wait,
451 alive_cmd, ARRAY_SIZE(alive_cmd),
452 iwl_alive_fn, &alive_data);
453
454 ret = iwl_trans_start_fw(trans(priv), fw);
455 if (ret) {
456 priv->shrd->ucode_type = old_type;
457 iwl_remove_notification(&priv->notif_wait, &alive_wait);
458 return ret;
459 }
460
461 /*
462 * Some things may run in the background now, but we
463 * just wait for the ALIVE notification here.
464 */
465 ret = iwl_wait_notification(&priv->notif_wait, &alive_wait,
466 UCODE_ALIVE_TIMEOUT);
467 if (ret) {
468 priv->shrd->ucode_type = old_type;
469 return ret;
470 }
471
472 if (!alive_data.valid) {
473 IWL_ERR(priv, "Loaded ucode is not valid!\n");
474 priv->shrd->ucode_type = old_type;
475 return -EIO;
476 }
477
478 /*
479 * This step takes a long time (60-80ms!!) and
480 * WoWLAN image should be loaded quickly, so
481 * skip it for WoWLAN.
482 */
483 if (ucode_type != IWL_UCODE_WOWLAN) {
484 ret = iwl_verify_ucode(priv, ucode_type);
485 if (ret) {
486 priv->shrd->ucode_type = old_type;
487 return ret;
488 }
489
490 /* delay a bit to give rfkill time to run */
491 msleep(5);
492 }
493
494 ret = iwl_alive_notify(priv);
495 if (ret) {
496 IWL_WARN(priv,
497 "Could not complete ALIVE transition: %d\n", ret);
498 priv->shrd->ucode_type = old_type;
499 return ret;
500 }
501
502 priv->ucode_loaded = true;
503
504 return 0;
505 }
506
507 static bool iwlagn_wait_calib(struct iwl_notif_wait_data *notif_wait,
508 struct iwl_rx_packet *pkt, void *data)
509 {
510 struct iwl_priv *priv = data;
511 struct iwl_calib_hdr *hdr;
512 int len;
513
514 if (pkt->hdr.cmd != CALIBRATION_RES_NOTIFICATION) {
515 WARN_ON(pkt->hdr.cmd != CALIBRATION_COMPLETE_NOTIFICATION);
516 return true;
517 }
518
519 hdr = (struct iwl_calib_hdr *)pkt->data;
520 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
521
522 /* reduce the size by the length field itself */
523 len -= sizeof(__le32);
524
525 if (iwl_calib_set(priv, hdr, len))
526 IWL_ERR(priv, "Failed to record calibration data %d\n",
527 hdr->op_code);
528
529 return false;
530 }
531
532 int iwl_run_init_ucode(struct iwl_priv *priv)
533 {
534 struct iwl_notification_wait calib_wait;
535 static const u8 calib_complete[] = {
536 CALIBRATION_RES_NOTIFICATION,
537 CALIBRATION_COMPLETE_NOTIFICATION
538 };
539 int ret;
540
541 lockdep_assert_held(&priv->mutex);
542
543 /* No init ucode required? Curious, but maybe ok */
544 if (!priv->fw->img[IWL_UCODE_INIT].sec[0].len)
545 return 0;
546
547 if (priv->init_ucode_run)
548 return 0;
549
550 iwl_init_notification_wait(&priv->notif_wait, &calib_wait,
551 calib_complete, ARRAY_SIZE(calib_complete),
552 iwlagn_wait_calib, priv);
553
554 /* Will also start the device */
555 ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT);
556 if (ret)
557 goto error;
558
559 ret = iwl_init_alive_start(priv);
560 if (ret)
561 goto error;
562
563 /*
564 * Some things may run in the background now, but we
565 * just wait for the calibration complete notification.
566 */
567 ret = iwl_wait_notification(&priv->notif_wait, &calib_wait,
568 UCODE_CALIB_TIMEOUT);
569 if (!ret)
570 priv->init_ucode_run = true;
571
572 goto out;
573
574 error:
575 iwl_remove_notification(&priv->notif_wait, &calib_wait);
576 out:
577 /* Whatever happened, stop the device */
578 iwl_trans_stop_device(trans(priv));
579 priv->ucode_loaded = false;
580
581 return ret;
582 }
This page took 0.046386 seconds and 4 git commands to generate.