aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2011-04-22 13:15:23 -0400
committerWey-Yi Guy <wey-yi.w.guy@intel.com>2011-04-22 13:18:48 -0400
commitca7966c88e44233fac113579071a6f55e00ef5ac (patch)
treec80674f6237d48ea56b677bc6b409c54afeb9f08 /drivers
parente74fe2330a5a721610b2b69652d2ec2ebbd302e0 (diff)
iwlagn: implement synchronous firmware load
The current firmware loading mechanism in iwlwifi is very hard to follow, and thus hard to maintain. To make it easier, make the firmware loading synchronous. For now, as a side effect, this removes a number of retry possibilities we had. It isn't typical for this to fail, but if it does happen we restart from scratch which this also makes easier to do should it be necessary. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-ucode.c240
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c190
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.h13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c50
8 files changed, 246 insertions, 274 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index a29e2e267ee4..8216e5ca918b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -483,8 +483,6 @@ void iwlagn_rx_handler_setup(struct iwl_priv *priv)
483 /* init calibration handlers */ 483 /* init calibration handlers */
484 priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] = 484 priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
485 iwlagn_rx_calib_result; 485 iwlagn_rx_calib_result;
486 priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
487 iwlagn_rx_calib_complete;
488 priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx; 486 priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
489 487
490 /* set up notification wait support */ 488 /* set up notification wait support */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
index 5c30f6b19a7f..56dc7712aa70 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
@@ -161,8 +161,8 @@ static int iwlagn_load_section(struct iwl_priv *priv, const char *name,
161} 161}
162 162
163static int iwlagn_load_given_ucode(struct iwl_priv *priv, 163static int iwlagn_load_given_ucode(struct iwl_priv *priv,
164 struct fw_desc *inst_image, 164 struct fw_desc *inst_image,
165 struct fw_desc *data_image) 165 struct fw_desc *data_image)
166{ 166{
167 int ret = 0; 167 int ret = 0;
168 168
@@ -175,33 +175,6 @@ static int iwlagn_load_given_ucode(struct iwl_priv *priv,
175 IWLAGN_RTC_DATA_LOWER_BOUND); 175 IWLAGN_RTC_DATA_LOWER_BOUND);
176} 176}
177 177
178int iwlagn_load_ucode(struct iwl_priv *priv)
179{
180 int ret = 0;
181
182 /* check whether init ucode should be loaded, or rather runtime ucode */
183 if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
184 IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n");
185 ret = iwlagn_load_given_ucode(priv,
186 &priv->ucode_init, &priv->ucode_init_data);
187 if (!ret) {
188 IWL_DEBUG_INFO(priv, "Init ucode load complete.\n");
189 priv->ucode_type = UCODE_INIT;
190 }
191 } else {
192 IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. "
193 "Loading runtime ucode...\n");
194 ret = iwlagn_load_given_ucode(priv,
195 &priv->ucode_code, &priv->ucode_data);
196 if (!ret) {
197 IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n");
198 priv->ucode_type = UCODE_RT;
199 }
200 }
201
202 return ret;
203}
204
205/* 178/*
206 * Calibration 179 * Calibration
207 */ 180 */
@@ -297,33 +270,9 @@ void iwlagn_rx_calib_result(struct iwl_priv *priv,
297 iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len); 270 iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
298} 271}
299 272
300void iwlagn_rx_calib_complete(struct iwl_priv *priv, 273static int iwlagn_init_alive_start(struct iwl_priv *priv)
301 struct iwl_rx_mem_buffer *rxb)
302{ 274{
303 IWL_DEBUG_INFO(priv, "Init. calibration is completed, restarting fw.\n"); 275 int ret;
304 queue_work(priv->workqueue, &priv->restart);
305}
306
307void iwlagn_init_alive_start(struct iwl_priv *priv)
308{
309 int ret = 0;
310
311 /* initialize uCode was loaded... verify inst image.
312 * This is a paranoid check, because we would not have gotten the
313 * "initialize" alive if code weren't properly loaded. */
314 if (iwl_verify_ucode(priv, &priv->ucode_init)) {
315 /* Runtime instruction load was bad;
316 * take it all the way back down so we can try again */
317 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
318 goto restart;
319 }
320
321 ret = iwlagn_alive_notify(priv);
322 if (ret) {
323 IWL_WARN(priv,
324 "Could not complete ALIVE transition: %d\n", ret);
325 goto restart;
326 }
327 276
328 if (priv->cfg->bt_params && 277 if (priv->cfg->bt_params &&
329 priv->cfg->bt_params->advanced_bt_coexist) { 278 priv->cfg->bt_params->advanced_bt_coexist) {
@@ -333,24 +282,25 @@ void iwlagn_init_alive_start(struct iwl_priv *priv)
333 * no need to close the envlope since we are going 282 * no need to close the envlope since we are going
334 * to load the runtime uCode later. 283 * to load the runtime uCode later.
335 */ 284 */
336 iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, 285 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
337 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 286 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
287 if (ret)
288 return ret;
338 289
339 } 290 }
340 iwlagn_send_calib_cfg(priv); 291
292 ret = iwlagn_send_calib_cfg(priv);
293 if (ret)
294 return ret;
341 295
342 /** 296 /**
343 * temperature offset calibration is only needed for runtime ucode, 297 * temperature offset calibration is only needed for runtime ucode,
344 * so prepare the value now. 298 * so prepare the value now.
345 */ 299 */
346 if (priv->cfg->need_temp_offset_calib) 300 if (priv->cfg->need_temp_offset_calib)
347 iwlagn_set_temperature_offset_calib(priv); 301 return iwlagn_set_temperature_offset_calib(priv);
348
349 return;
350 302
351restart: 303 return 0;
352 /* real restart (first load init_ucode) */
353 queue_work(priv->workqueue, &priv->restart);
354} 304}
355 305
356static int iwlagn_send_wimax_coex(struct iwl_priv *priv) 306static int iwlagn_send_wimax_coex(struct iwl_priv *priv)
@@ -413,19 +363,22 @@ void iwlagn_send_prio_tbl(struct iwl_priv *priv)
413 IWL_ERR(priv, "failed to send BT prio tbl command\n"); 363 IWL_ERR(priv, "failed to send BT prio tbl command\n");
414} 364}
415 365
416void iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type) 366int iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type)
417{ 367{
418 struct iwl_bt_coex_prot_env_cmd env_cmd; 368 struct iwl_bt_coex_prot_env_cmd env_cmd;
369 int ret;
419 370
420 env_cmd.action = action; 371 env_cmd.action = action;
421 env_cmd.type = type; 372 env_cmd.type = type;
422 if (iwl_send_cmd_pdu(priv, REPLY_BT_COEX_PROT_ENV, 373 ret = iwl_send_cmd_pdu(priv, REPLY_BT_COEX_PROT_ENV,
423 sizeof(env_cmd), &env_cmd)) 374 sizeof(env_cmd), &env_cmd);
375 if (ret)
424 IWL_ERR(priv, "failed to send BT env command\n"); 376 IWL_ERR(priv, "failed to send BT env command\n");
377 return ret;
425} 378}
426 379
427 380
428int iwlagn_alive_notify(struct iwl_priv *priv) 381static int iwlagn_alive_notify(struct iwl_priv *priv)
429{ 382{
430 const struct queue_to_fifo_ac *queue_to_fifo; 383 const struct queue_to_fifo_ac *queue_to_fifo;
431 struct iwl_rxon_context *ctx; 384 struct iwl_rxon_context *ctx;
@@ -604,7 +557,7 @@ static void iwl_print_mismatch_inst(struct iwl_priv *priv,
604 * iwl_verify_ucode - determine which instruction image is in SRAM, 557 * iwl_verify_ucode - determine which instruction image is in SRAM,
605 * and verify its contents 558 * and verify its contents
606 */ 559 */
607int iwl_verify_ucode(struct iwl_priv *priv, struct fw_desc *fw_desc) 560static int iwl_verify_ucode(struct iwl_priv *priv, struct fw_desc *fw_desc)
608{ 561{
609 if (!iwlcore_verify_inst_sparse(priv, fw_desc)) { 562 if (!iwlcore_verify_inst_sparse(priv, fw_desc)) {
610 IWL_DEBUG_INFO(priv, "uCode is good in inst SRAM\n"); 563 IWL_DEBUG_INFO(priv, "uCode is good in inst SRAM\n");
@@ -616,3 +569,154 @@ int iwl_verify_ucode(struct iwl_priv *priv, struct fw_desc *fw_desc)
616 iwl_print_mismatch_inst(priv, fw_desc); 569 iwl_print_mismatch_inst(priv, fw_desc);
617 return -EIO; 570 return -EIO;
618} 571}
572
573struct iwlagn_alive_data {
574 bool valid;
575 u8 subtype;
576};
577
578static void iwlagn_alive_fn(struct iwl_priv *priv,
579 struct iwl_rx_packet *pkt,
580 void *data)
581{
582 struct iwlagn_alive_data *alive_data = data;
583 struct iwl_alive_resp *palive;
584
585 palive = &pkt->u.alive_frame;
586
587 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
588 "0x%01X 0x%01X\n",
589 palive->is_valid, palive->ver_type,
590 palive->ver_subtype);
591
592 priv->device_pointers.error_event_table =
593 le32_to_cpu(palive->error_event_table_ptr);
594 priv->device_pointers.log_event_table =
595 le32_to_cpu(palive->log_event_table_ptr);
596
597 alive_data->subtype = palive->ver_subtype;
598 alive_data->valid = palive->is_valid == UCODE_VALID_OK;
599}
600
601#define UCODE_ALIVE_TIMEOUT HZ
602#define UCODE_CALIB_TIMEOUT (2*HZ)
603
604int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
605 struct fw_desc *inst_image,
606 struct fw_desc *data_image,
607 int subtype, int alternate_subtype)
608{
609 struct iwl_notification_wait alive_wait;
610 struct iwlagn_alive_data alive_data;
611 int ret;
612 enum iwlagn_ucode_subtype old_type;
613
614 ret = iwlagn_start_device(priv);
615 if (ret)
616 return ret;
617
618 iwlagn_init_notification_wait(priv, &alive_wait, REPLY_ALIVE,
619 iwlagn_alive_fn, &alive_data);
620
621 old_type = priv->ucode_type;
622 priv->ucode_type = subtype;
623
624 ret = iwlagn_load_given_ucode(priv, inst_image, data_image);
625 if (ret) {
626 priv->ucode_type = old_type;
627 iwlagn_remove_notification(priv, &alive_wait);
628 return ret;
629 }
630
631 /* Remove all resets to allow NIC to operate */
632 iwl_write32(priv, CSR_RESET, 0);
633
634 /*
635 * Some things may run in the background now, but we
636 * just wait for the ALIVE notification here.
637 */
638 ret = iwlagn_wait_notification(priv, &alive_wait, UCODE_ALIVE_TIMEOUT);
639 if (ret) {
640 priv->ucode_type = old_type;
641 return ret;
642 }
643
644 if (!alive_data.valid) {
645 IWL_ERR(priv, "Loaded ucode is not valid!\n");
646 priv->ucode_type = old_type;
647 return -EIO;
648 }
649
650 if (alive_data.subtype != subtype &&
651 alive_data.subtype != alternate_subtype) {
652 IWL_ERR(priv,
653 "Loaded ucode is not expected type (got %d, expected %d)!\n",
654 alive_data.subtype, subtype);
655 priv->ucode_type = old_type;
656 return -EIO;
657 }
658
659 ret = iwl_verify_ucode(priv, inst_image);
660 if (ret) {
661 priv->ucode_type = old_type;
662 return ret;
663 }
664
665 /* delay a bit to give rfkill time to run */
666 msleep(5);
667
668 ret = iwlagn_alive_notify(priv);
669 if (ret) {
670 IWL_WARN(priv,
671 "Could not complete ALIVE transition: %d\n", ret);
672 priv->ucode_type = old_type;
673 return ret;
674 }
675
676 return 0;
677}
678
679int iwlagn_run_init_ucode(struct iwl_priv *priv)
680{
681 struct iwl_notification_wait calib_wait;
682 int ret;
683
684 lockdep_assert_held(&priv->mutex);
685
686 /* No init ucode required? Curious, but maybe ok */
687 if (!priv->ucode_init.len)
688 return 0;
689
690 if (priv->ucode_type != UCODE_SUBTYPE_NONE_LOADED)
691 return 0;
692
693 iwlagn_init_notification_wait(priv, &calib_wait,
694 CALIBRATION_COMPLETE_NOTIFICATION,
695 NULL, NULL);
696
697 /* Will also start the device */
698 ret = iwlagn_load_ucode_wait_alive(priv, &priv->ucode_init,
699 &priv->ucode_init_data,
700 UCODE_SUBTYPE_INIT, -1);
701 if (ret)
702 goto error;
703
704 ret = iwlagn_init_alive_start(priv);
705 if (ret)
706 goto error;
707
708 /*
709 * Some things may run in the background now, but we
710 * just wait for the calibration complete notification.
711 */
712 ret = iwlagn_wait_notification(priv, &calib_wait, UCODE_CALIB_TIMEOUT);
713
714 goto out;
715
716 error:
717 iwlagn_remove_notification(priv, &calib_wait);
718 out:
719 /* Whatever happened, stop the device */
720 iwlagn_stop_device(priv);
721 return ret;
722}
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index a9204db377a8..12cd5e0352bc 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -1181,12 +1181,6 @@ static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
1181 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); 1181 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1182} 1182}
1183 1183
1184static void iwl_nic_start(struct iwl_priv *priv)
1185{
1186 /* Remove all resets to allow NIC to operate */
1187 iwl_write32(priv, CSR_RESET, 0);
1188}
1189
1190struct iwlagn_ucode_capabilities { 1184struct iwlagn_ucode_capabilities {
1191 u32 max_probe_length; 1185 u32 max_probe_length;
1192 u32 standard_phy_calibration_size; 1186 u32 standard_phy_calibration_size;
@@ -1873,7 +1867,7 @@ void iwl_dump_nic_error_log(struct iwl_priv *priv)
1873 struct iwl_error_event_table table; 1867 struct iwl_error_event_table table;
1874 1868
1875 base = priv->device_pointers.error_event_table; 1869 base = priv->device_pointers.error_event_table;
1876 if (priv->ucode_type == UCODE_INIT) { 1870 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
1877 if (!base) 1871 if (!base)
1878 base = priv->_agn.init_errlog_ptr; 1872 base = priv->_agn.init_errlog_ptr;
1879 } else { 1873 } else {
@@ -1884,7 +1878,9 @@ void iwl_dump_nic_error_log(struct iwl_priv *priv)
1884 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { 1878 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1885 IWL_ERR(priv, 1879 IWL_ERR(priv,
1886 "Not valid error log pointer 0x%08X for %s uCode\n", 1880 "Not valid error log pointer 0x%08X for %s uCode\n",
1887 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT"); 1881 base,
1882 (priv->ucode_type == UCODE_SUBTYPE_INIT)
1883 ? "Init" : "RT");
1888 return; 1884 return;
1889 } 1885 }
1890 1886
@@ -1944,7 +1940,7 @@ static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1944 return pos; 1940 return pos;
1945 1941
1946 base = priv->device_pointers.log_event_table; 1942 base = priv->device_pointers.log_event_table;
1947 if (priv->ucode_type == UCODE_INIT) { 1943 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
1948 if (!base) 1944 if (!base)
1949 base = priv->_agn.init_evtlog_ptr; 1945 base = priv->_agn.init_evtlog_ptr;
1950 } else { 1946 } else {
@@ -2057,7 +2053,7 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
2057 size_t bufsz = 0; 2053 size_t bufsz = 0;
2058 2054
2059 base = priv->device_pointers.log_event_table; 2055 base = priv->device_pointers.log_event_table;
2060 if (priv->ucode_type == UCODE_INIT) { 2056 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
2061 logsize = priv->_agn.init_evtlog_size; 2057 logsize = priv->_agn.init_evtlog_size;
2062 if (!base) 2058 if (!base)
2063 base = priv->_agn.init_evtlog_ptr; 2059 base = priv->_agn.init_evtlog_ptr;
@@ -2070,7 +2066,9 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
2070 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { 2066 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
2071 IWL_ERR(priv, 2067 IWL_ERR(priv,
2072 "Invalid event log pointer 0x%08X for %s uCode\n", 2068 "Invalid event log pointer 0x%08X for %s uCode\n",
2073 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT"); 2069 base,
2070 (priv->ucode_type == UCODE_SUBTYPE_INIT)
2071 ? "Init" : "RT");
2074 return -EINVAL; 2072 return -EINVAL;
2075 } 2073 }
2076 2074
@@ -2217,30 +2215,14 @@ static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
2217 * from protocol/runtime uCode (initialization uCode's 2215 * from protocol/runtime uCode (initialization uCode's
2218 * Alive gets handled by iwl_init_alive_start()). 2216 * Alive gets handled by iwl_init_alive_start()).
2219 */ 2217 */
2220static void iwl_alive_start(struct iwl_priv *priv) 2218static int iwl_alive_start(struct iwl_priv *priv)
2221{ 2219{
2222 int ret = 0; 2220 int ret = 0;
2223 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 2221 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2224 2222
2225 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); 2223 iwl_reset_ict(priv);
2226
2227 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2228 * This is a paranoid check, because we would not have gotten the
2229 * "runtime" alive if code weren't properly loaded. */
2230 if (iwl_verify_ucode(priv, &priv->ucode_code)) {
2231 /* Runtime instruction load was bad;
2232 * take it all the way back down so we can try again */
2233 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
2234 goto restart;
2235 }
2236
2237 ret = iwlagn_alive_notify(priv);
2238 if (ret) {
2239 IWL_WARN(priv,
2240 "Could not complete ALIVE transition [ntf]: %d\n", ret);
2241 goto restart;
2242 }
2243 2224
2225 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
2244 2226
2245 /* After the ALIVE response, we can send host commands to the uCode */ 2227 /* After the ALIVE response, we can send host commands to the uCode */
2246 set_bit(STATUS_ALIVE, &priv->status); 2228 set_bit(STATUS_ALIVE, &priv->status);
@@ -2249,7 +2231,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
2249 iwl_setup_watchdog(priv); 2231 iwl_setup_watchdog(priv);
2250 2232
2251 if (iwl_is_rfkill(priv)) 2233 if (iwl_is_rfkill(priv))
2252 return; 2234 return -ERFKILL;
2253 2235
2254 /* download priority table before any calibration request */ 2236 /* download priority table before any calibration request */
2255 if (priv->cfg->bt_params && 2237 if (priv->cfg->bt_params &&
@@ -2263,10 +2245,14 @@ static void iwl_alive_start(struct iwl_priv *priv)
2263 iwlagn_send_prio_tbl(priv); 2245 iwlagn_send_prio_tbl(priv);
2264 2246
2265 /* FIXME: w/a to force change uCode BT state machine */ 2247 /* FIXME: w/a to force change uCode BT state machine */
2266 iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, 2248 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
2267 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 2249 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2268 iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE, 2250 if (ret)
2269 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 2251 return ret;
2252 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
2253 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2254 if (ret)
2255 return ret;
2270 } 2256 }
2271 if (priv->hw_params.calib_rt_cfg) 2257 if (priv->hw_params.calib_rt_cfg)
2272 iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg); 2258 iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
@@ -2308,22 +2294,16 @@ static void iwl_alive_start(struct iwl_priv *priv)
2308 set_bit(STATUS_READY, &priv->status); 2294 set_bit(STATUS_READY, &priv->status);
2309 2295
2310 /* Configure the adapter for unassociated operation */ 2296 /* Configure the adapter for unassociated operation */
2311 iwlcore_commit_rxon(priv, ctx); 2297 ret = iwlcore_commit_rxon(priv, ctx);
2298 if (ret)
2299 return ret;
2312 2300
2313 /* At this point, the NIC is initialized and operational */ 2301 /* At this point, the NIC is initialized and operational */
2314 iwl_rf_kill_ct_config(priv); 2302 iwl_rf_kill_ct_config(priv);
2315 2303
2316 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n"); 2304 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
2317 wake_up_interruptible(&priv->wait_command_queue);
2318
2319 iwl_power_update_mode(priv, true);
2320 IWL_DEBUG_INFO(priv, "Updated power mode\n");
2321
2322 2305
2323 return; 2306 return iwl_power_update_mode(priv, true);
2324
2325 restart:
2326 queue_work(priv->workqueue, &priv->restart);
2327} 2307}
2328 2308
2329static void iwl_cancel_deferred_work(struct iwl_priv *priv); 2309static void iwl_cancel_deferred_work(struct iwl_priv *priv);
@@ -2446,9 +2426,10 @@ int iwl_prepare_card_hw(struct iwl_priv *priv)
2446static int __iwl_up(struct iwl_priv *priv) 2426static int __iwl_up(struct iwl_priv *priv)
2447{ 2427{
2448 struct iwl_rxon_context *ctx; 2428 struct iwl_rxon_context *ctx;
2449 int i;
2450 int ret; 2429 int ret;
2451 2430
2431 lockdep_assert_held(&priv->mutex);
2432
2452 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { 2433 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2453 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); 2434 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
2454 return -EIO; 2435 return -EIO;
@@ -2462,39 +2443,34 @@ static int __iwl_up(struct iwl_priv *priv)
2462 } 2443 }
2463 } 2444 }
2464 2445
2465 ret = iwlagn_start_device(priv); 2446 ret = iwlagn_run_init_ucode(priv);
2466 if (ret) 2447 if (ret) {
2467 return ret; 2448 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
2468 2449 goto error;
2469 for (i = 0; i < MAX_HW_RESTARTS; i++) { 2450 }
2470
2471 /* load bootstrap state machine,
2472 * load bootstrap program into processor's memory,
2473 * prepare to load the "initialize" uCode */
2474 ret = iwlagn_load_ucode(priv);
2475
2476 if (ret) {
2477 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2478 ret);
2479 continue;
2480 }
2481
2482 /* start card; "initialize" will load runtime ucode */
2483 iwl_nic_start(priv);
2484
2485 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
2486 2451
2487 return 0; 2452 ret = iwlagn_load_ucode_wait_alive(priv,
2453 &priv->ucode_code,
2454 &priv->ucode_data,
2455 UCODE_SUBTYPE_REGULAR,
2456 UCODE_SUBTYPE_REGULAR_NEW);
2457 if (ret) {
2458 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
2459 goto error;
2488 } 2460 }
2489 2461
2462 ret = iwl_alive_start(priv);
2463 if (ret)
2464 goto error;
2465 return 0;
2466
2467 error:
2490 set_bit(STATUS_EXIT_PENDING, &priv->status); 2468 set_bit(STATUS_EXIT_PENDING, &priv->status);
2491 __iwl_down(priv); 2469 __iwl_down(priv);
2492 clear_bit(STATUS_EXIT_PENDING, &priv->status); 2470 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2493 2471
2494 /* tried to restart and config the device for as long as our 2472 IWL_ERR(priv, "Unable to initialize device.\n");
2495 * patience could withstand */ 2473 return ret;
2496 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
2497 return -EIO;
2498} 2474}
2499 2475
2500 2476
@@ -2504,39 +2480,6 @@ static int __iwl_up(struct iwl_priv *priv)
2504 * 2480 *
2505 *****************************************************************************/ 2481 *****************************************************************************/
2506 2482
2507static void iwl_bg_init_alive_start(struct work_struct *data)
2508{
2509 struct iwl_priv *priv =
2510 container_of(data, struct iwl_priv, init_alive_start.work);
2511
2512 mutex_lock(&priv->mutex);
2513
2514 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2515 mutex_unlock(&priv->mutex);
2516 return;
2517 }
2518
2519 iwlagn_init_alive_start(priv);
2520 mutex_unlock(&priv->mutex);
2521}
2522
2523static void iwl_bg_alive_start(struct work_struct *data)
2524{
2525 struct iwl_priv *priv =
2526 container_of(data, struct iwl_priv, alive_start.work);
2527
2528 mutex_lock(&priv->mutex);
2529 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2530 goto unlock;
2531
2532 /* enable dram interrupt */
2533 iwl_reset_ict(priv);
2534
2535 iwl_alive_start(priv);
2536unlock:
2537 mutex_unlock(&priv->mutex);
2538}
2539
2540static void iwl_bg_run_time_calib_work(struct work_struct *work) 2483static void iwl_bg_run_time_calib_work(struct work_struct *work)
2541{ 2484{
2542 struct iwl_priv *priv = container_of(work, struct iwl_priv, 2485 struct iwl_priv *priv = container_of(work, struct iwl_priv,
@@ -2602,14 +2545,7 @@ static void iwl_bg_restart(struct work_struct *data)
2602 iwl_cancel_deferred_work(priv); 2545 iwl_cancel_deferred_work(priv);
2603 ieee80211_restart_hw(priv->hw); 2546 ieee80211_restart_hw(priv->hw);
2604 } else { 2547 } else {
2605 iwl_down(priv); 2548 WARN_ON(1);
2606
2607 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2608 return;
2609
2610 mutex_lock(&priv->mutex);
2611 __iwl_up(priv);
2612 mutex_unlock(&priv->mutex);
2613 } 2549 }
2614} 2550}
2615 2551
@@ -2720,8 +2656,6 @@ unlock:
2720 * 2656 *
2721 *****************************************************************************/ 2657 *****************************************************************************/
2722 2658
2723#define UCODE_READY_TIMEOUT (4 * HZ)
2724
2725/* 2659/*
2726 * Not a mac80211 entry point function, but it fits in with all the 2660 * Not a mac80211 entry point function, but it fits in with all the
2727 * other mac80211 functions grouped here. 2661 * other mac80211 functions grouped here.
@@ -2814,31 +2748,17 @@ static int iwlagn_mac_start(struct ieee80211_hw *hw)
2814 mutex_lock(&priv->mutex); 2748 mutex_lock(&priv->mutex);
2815 ret = __iwl_up(priv); 2749 ret = __iwl_up(priv);
2816 mutex_unlock(&priv->mutex); 2750 mutex_unlock(&priv->mutex);
2817
2818 if (ret) 2751 if (ret)
2819 return ret; 2752 return ret;
2820 2753
2821 if (iwl_is_rfkill(priv))
2822 goto out;
2823
2824 IWL_DEBUG_INFO(priv, "Start UP work done.\n"); 2754 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
2825 2755
2826 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from 2756 /* Now we should be done, and the READY bit should be set. */
2827 * mac80211 will not be run successfully. */ 2757 if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
2828 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 2758 ret = -EIO;
2829 test_bit(STATUS_READY, &priv->status),
2830 UCODE_READY_TIMEOUT);
2831 if (!ret) {
2832 if (!test_bit(STATUS_READY, &priv->status)) {
2833 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
2834 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2835 return -ETIMEDOUT;
2836 }
2837 }
2838 2759
2839 iwlagn_led_enable(priv); 2760 iwlagn_led_enable(priv);
2840 2761
2841out:
2842 priv->is_open = 1; 2762 priv->is_open = 1;
2843 IWL_DEBUG_MAC80211(priv, "leave\n"); 2763 IWL_DEBUG_MAC80211(priv, "leave\n");
2844 return 0; 2764 return 0;
@@ -3425,8 +3345,6 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
3425 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush); 3345 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
3426 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency); 3346 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
3427 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config); 3347 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
3428 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3429 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
3430 INIT_DELAYED_WORK(&priv->_agn.hw_roc_work, iwlagn_bg_roc_done); 3348 INIT_DELAYED_WORK(&priv->_agn.hw_roc_work, iwlagn_bg_roc_done);
3431 3349
3432 iwl_setup_scan_deferred_work(priv); 3350 iwl_setup_scan_deferred_work(priv);
@@ -3455,8 +3373,6 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
3455 if (priv->cfg->ops->lib->cancel_deferred_work) 3373 if (priv->cfg->ops->lib->cancel_deferred_work)
3456 priv->cfg->ops->lib->cancel_deferred_work(priv); 3374 priv->cfg->ops->lib->cancel_deferred_work(priv);
3457 3375
3458 cancel_delayed_work_sync(&priv->init_alive_start);
3459 cancel_delayed_work(&priv->alive_start);
3460 cancel_work_sync(&priv->run_time_calib_work); 3376 cancel_work_sync(&priv->run_time_calib_work);
3461 cancel_work_sync(&priv->beacon_update); 3377 cancel_work_sync(&priv->beacon_update);
3462 3378
@@ -3691,6 +3607,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3691 priv = hw->priv; 3607 priv = hw->priv;
3692 /* At this point both hw and priv are allocated. */ 3608 /* At this point both hw and priv are allocated. */
3693 3609
3610 priv->ucode_type = UCODE_SUBTYPE_NONE_LOADED;
3611
3694 /* 3612 /*
3695 * The default context is always valid, 3613 * The default context is always valid,
3696 * more may be discovered when firmware 3614 * more may be discovered when firmware
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.h b/drivers/net/wireless/iwlwifi/iwl-agn.h
index ba90aa474777..cf05f87ec80e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.h
@@ -158,16 +158,15 @@ void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
158 u32 changes); 158 u32 changes);
159 159
160/* uCode */ 160/* uCode */
161int iwlagn_load_ucode(struct iwl_priv *priv);
162void iwlagn_rx_calib_result(struct iwl_priv *priv, 161void iwlagn_rx_calib_result(struct iwl_priv *priv,
163 struct iwl_rx_mem_buffer *rxb); 162 struct iwl_rx_mem_buffer *rxb);
164void iwlagn_rx_calib_complete(struct iwl_priv *priv, 163int iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
165 struct iwl_rx_mem_buffer *rxb);
166void iwlagn_init_alive_start(struct iwl_priv *priv);
167int iwlagn_alive_notify(struct iwl_priv *priv);
168int iwl_verify_ucode(struct iwl_priv *priv, struct fw_desc *fw_desc);
169void iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
170void iwlagn_send_prio_tbl(struct iwl_priv *priv); 164void iwlagn_send_prio_tbl(struct iwl_priv *priv);
165int iwlagn_run_init_ucode(struct iwl_priv *priv);
166int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
167 struct fw_desc *inst_image,
168 struct fw_desc *data_image,
169 int subtype, int alternate_subtype);
171 170
172/* lib */ 171/* lib */
173void iwl_check_abort_status(struct iwl_priv *priv, 172void iwl_check_abort_status(struct iwl_priv *priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 7aea7b34f36c..e125896c8096 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -386,7 +386,18 @@ struct iwl_tx_ant_config_cmd {
386 *****************************************************************************/ 386 *****************************************************************************/
387 387
388#define UCODE_VALID_OK cpu_to_le32(0x1) 388#define UCODE_VALID_OK cpu_to_le32(0x1)
389#define INITIALIZE_SUBTYPE (9) 389
390enum iwlagn_ucode_subtype {
391 UCODE_SUBTYPE_REGULAR = 0,
392 UCODE_SUBTYPE_REGULAR_NEW = 1,
393 UCODE_SUBTYPE_INIT = 9,
394
395 /*
396 * Not a valid subtype, the ucode has just a u8, so
397 * we can use something > 0xff for this value.
398 */
399 UCODE_SUBTYPE_NONE_LOADED = 0x100,
400};
390 401
391/** 402/**
392 * REPLY_ALIVE = 0x1 (response only, not a command) 403 * REPLY_ALIVE = 0x1 (response only, not a command)
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index c272204fccff..2b606889b64b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -226,7 +226,7 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file,
226 /* default is to dump the entire data segment */ 226 /* default is to dump the entire data segment */
227 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) { 227 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
228 priv->dbgfs_sram_offset = 0x800000; 228 priv->dbgfs_sram_offset = 0x800000;
229 if (priv->ucode_type == UCODE_INIT) 229 if (priv->ucode_type == UCODE_SUBTYPE_INIT)
230 priv->dbgfs_sram_len = priv->ucode_init_data.len; 230 priv->dbgfs_sram_len = priv->ucode_init_data.len;
231 else 231 else
232 priv->dbgfs_sram_len = priv->ucode_data.len; 232 priv->dbgfs_sram_len = priv->ucode_data.len;
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 03452925bae3..414968c6b7cf 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -794,12 +794,6 @@ struct iwl_calib_result {
794 size_t buf_len; 794 size_t buf_len;
795}; 795};
796 796
797enum ucode_type {
798 UCODE_NONE = 0,
799 UCODE_INIT,
800 UCODE_RT
801};
802
803/* Sensitivity calib data */ 797/* Sensitivity calib data */
804struct iwl_sensitivity_data { 798struct iwl_sensitivity_data {
805 u32 auto_corr_ofdm; 799 u32 auto_corr_ofdm;
@@ -1276,7 +1270,7 @@ struct iwl_priv {
1276 struct fw_desc ucode_data; /* runtime data original */ 1270 struct fw_desc ucode_data; /* runtime data original */
1277 struct fw_desc ucode_init; /* initialization inst */ 1271 struct fw_desc ucode_init; /* initialization inst */
1278 struct fw_desc ucode_init_data; /* initialization data */ 1272 struct fw_desc ucode_init_data; /* initialization data */
1279 enum ucode_type ucode_type; 1273 enum iwlagn_ucode_subtype ucode_type;
1280 u8 ucode_write_complete; /* the image write is complete */ 1274 u8 ucode_write_complete; /* the image write is complete */
1281 char firmware_name[25]; 1275 char firmware_name[25];
1282 1276
@@ -1474,8 +1468,6 @@ struct iwl_priv {
1474 1468
1475 struct tasklet_struct irq_tasklet; 1469 struct tasklet_struct irq_tasklet;
1476 1470
1477 struct delayed_work init_alive_start;
1478 struct delayed_work alive_start;
1479 struct delayed_work scan_check; 1471 struct delayed_work scan_check;
1480 1472
1481 /* TX Power */ 1473 /* TX Power */
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index b49819ca2cd6..aca9a1d40080 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -225,55 +225,6 @@ err_bd:
225 * 225 *
226 ******************************************************************************/ 226 ******************************************************************************/
227 227
228static void iwl_rx_reply_alive(struct iwl_priv *priv,
229 struct iwl_rx_mem_buffer *rxb)
230{
231 struct iwl_rx_packet *pkt = rxb_addr(rxb);
232 struct iwl_alive_resp *palive;
233 struct delayed_work *pwork;
234
235 palive = &pkt->u.alive_frame;
236
237 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
238 "0x%01X 0x%01X\n",
239 palive->is_valid, palive->ver_type,
240 palive->ver_subtype);
241
242 priv->device_pointers.log_event_table =
243 le32_to_cpu(palive->log_event_table_ptr);
244 priv->device_pointers.error_event_table =
245 le32_to_cpu(palive->error_event_table_ptr);
246
247 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
248 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
249 pwork = &priv->init_alive_start;
250 } else {
251 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
252 pwork = &priv->alive_start;
253 }
254
255 /* We delay the ALIVE response by 5ms to
256 * give the HW RF Kill time to activate... */
257 if (palive->is_valid == UCODE_VALID_OK)
258 queue_delayed_work(priv->workqueue, pwork,
259 msecs_to_jiffies(5));
260 else {
261 IWL_WARN(priv, "%s uCode did not respond OK.\n",
262 (palive->ver_subtype == INITIALIZE_SUBTYPE) ?
263 "init" : "runtime");
264 /*
265 * If fail to load init uCode,
266 * let's try to load the init uCode again.
267 * We should not get into this situation, but if it
268 * does happen, we should not move on and loading "runtime"
269 * without proper calibrate the device.
270 */
271 if (palive->ver_subtype == INITIALIZE_SUBTYPE)
272 priv->ucode_type = UCODE_NONE;
273 queue_work(priv->workqueue, &priv->restart);
274 }
275}
276
277static void iwl_rx_reply_error(struct iwl_priv *priv, 228static void iwl_rx_reply_error(struct iwl_priv *priv,
278 struct iwl_rx_mem_buffer *rxb) 229 struct iwl_rx_mem_buffer *rxb)
279{ 230{
@@ -1125,7 +1076,6 @@ void iwl_setup_rx_handlers(struct iwl_priv *priv)
1125 1076
1126 handlers = priv->rx_handlers; 1077 handlers = priv->rx_handlers;
1127 1078
1128 handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
1129 handlers[REPLY_ERROR] = iwl_rx_reply_error; 1079 handlers[REPLY_ERROR] = iwl_rx_reply_error;
1130 handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; 1080 handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
1131 handlers[SPECTRUM_MEASURE_NOTIFICATION] = iwl_rx_spectrum_measure_notif; 1081 handlers[SPECTRUM_MEASURE_NOTIFICATION] = iwl_rx_spectrum_measure_notif;