iwlagn: centralize and fix ucode restart
authorJohannes Berg <johannes.berg@intel.com>
Tue, 5 Apr 2011 16:41:58 +0000 (09:41 -0700)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 7 Apr 2011 19:51:37 +0000 (15:51 -0400)
The ucode restart has to take into account a number
of things, like clearing the HCMD_ACTIVE and other
status bits, and waking up the wait_command_queue.
Currently, however, there are a number of places
that neither do that, nor actually set the FW error
bit that leads to proper restart handling, which
means that in those cases things will probably just
hang completely.

To clean this up, make all ucode restart go through
a single function, except for the cases where it's
called during firmware loading.

Also fix a bug in wimax coexist restart avoidance,
it needs to first clear the status bits (and it has
to clear the HCMD_ACTIVE one as well) and then wake
up anything waiting on wait_command_queue.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/iwlwifi/iwl-core.c
drivers/net/wireless/iwlwifi/iwl-core.h
drivers/net/wireless/iwlwifi/iwl-tx.c

index d778f52132cb5e21ac3b79f31a02abfad6f8f11d..64b28b01ad866c34267bab493f3a527da7facddd 100644 (file)
@@ -890,10 +890,8 @@ void iwl_print_rx_config_cmd(struct iwl_priv *priv,
        IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
 }
 #endif
-/**
- * iwl_irq_handle_error - called for HW or SW error interrupt from card
- */
-void iwl_irq_handle_error(struct iwl_priv *priv)
+
+void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
 {
        unsigned int reload_msec;
        unsigned long reload_jiffies;
@@ -904,18 +902,62 @@ void iwl_irq_handle_error(struct iwl_priv *priv)
        /* Cancel currently queued command. */
        clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
 
+       /* Keep the restart process from trying to send host
+        * commands by clearing the ready bit */
+       clear_bit(STATUS_READY, &priv->status);
+
+       wake_up_interruptible(&priv->wait_command_queue);
+
+       if (!ondemand) {
+               /*
+                * If firmware keep reloading, then it indicate something
+                * serious wrong and firmware having problem to recover
+                * from it. Instead of keep trying which will fill the syslog
+                * and hang the system, let's just stop it
+                */
+               reload_jiffies = jiffies;
+               reload_msec = jiffies_to_msecs((long) reload_jiffies -
+                                       (long) priv->reload_jiffies);
+               priv->reload_jiffies = reload_jiffies;
+               if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
+                       priv->reload_count++;
+                       if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
+                               IWL_ERR(priv, "BUG_ON, Stop restarting\n");
+                               return;
+                       }
+               } else
+                       priv->reload_count = 0;
+       }
+
+       if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
+               if (priv->cfg->mod_params->restart_fw) {
+                       IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
+                                 "Restarting adapter due to uCode error.\n");
+                       queue_work(priv->workqueue, &priv->restart);
+               } else
+                       IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
+                                 "Detected FW error, but not restarting\n");
+       }
+}
+
+/**
+ * iwl_irq_handle_error - called for HW or SW error interrupt from card
+ */
+void iwl_irq_handle_error(struct iwl_priv *priv)
+{
        /* W/A for WiFi/WiMAX coex and WiMAX own the RF */
        if (priv->cfg->internal_wimax_coex &&
            (!(iwl_read_prph(priv, APMG_CLK_CTRL_REG) &
                        APMS_CLK_VAL_MRB_FUNC_MODE) ||
             (iwl_read_prph(priv, APMG_PS_CTRL_REG) &
                        APMG_PS_CTRL_VAL_RESET_REQ))) {
-               wake_up_interruptible(&priv->wait_command_queue);
                /*
-                *Keep the restart process from trying to send host
-                * commands by clearing the INIT status bit
+                * Keep the restart process from trying to send host
+                * commands by clearing the ready bit.
                 */
                clear_bit(STATUS_READY, &priv->status);
+               clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
+               wake_up_interruptible(&priv->wait_command_queue);
                IWL_ERR(priv, "RF is used by WiMAX\n");
                return;
        }
@@ -935,38 +977,7 @@ void iwl_irq_handle_error(struct iwl_priv *priv)
                                        &priv->contexts[IWL_RXON_CTX_BSS]);
 #endif
 
-       wake_up_interruptible(&priv->wait_command_queue);
-
-       /* Keep the restart process from trying to send host
-        * commands by clearing the INIT status bit */
-       clear_bit(STATUS_READY, &priv->status);
-
-       /*
-        * If firmware keep reloading, then it indicate something
-        * serious wrong and firmware having problem to recover
-        * from it. Instead of keep trying which will fill the syslog
-        * and hang the system, let's just stop it
-        */
-       reload_jiffies = jiffies;
-       reload_msec = jiffies_to_msecs((long) reload_jiffies -
-                               (long) priv->reload_jiffies);
-       priv->reload_jiffies = reload_jiffies;
-       if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
-               priv->reload_count++;
-               if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
-                       IWL_ERR(priv, "BUG_ON, Stop restarting\n");
-                       return;
-               }
-       } else
-               priv->reload_count = 0;
-
-       if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
-               IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
-                         "Restarting adapter due to uCode error.\n");
-
-               if (priv->cfg->mod_params->restart_fw)
-                       queue_work(priv->workqueue, &priv->restart);
-       }
+       iwlagn_fw_error(priv, false);
 }
 
 static int iwl_apm_stop_master(struct iwl_priv *priv)
@@ -1755,15 +1766,7 @@ int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
                        break;
                }
                IWL_ERR(priv, "On demand firmware reload\n");
-               /* Set the FW error flag -- cleared on iwl_down */
-               set_bit(STATUS_FW_ERROR, &priv->status);
-               wake_up_interruptible(&priv->wait_command_queue);
-               /*
-                * Keep the restart process from trying to send host
-                * commands by clearing the INIT status bit
-                */
-               clear_bit(STATUS_READY, &priv->status);
-               queue_work(priv->workqueue, &priv->restart);
+               iwlagn_fw_error(priv, true);
                break;
        }
        return 0;
index 46c90b3cc30a53316175818b15ab01221fa123d7..8bc23468d82c0dc6f2b31f402bc66910c91a04cb 100644 (file)
@@ -729,4 +729,7 @@ static inline bool iwl_bt_statistics(struct iwl_priv *priv)
 extern bool bt_coex_active;
 extern bool bt_siso_mode;
 
+
+void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand);
+
 #endif /* __iwl_core_h__ */
index 39a4180ee854c16cf0791d1010e94549a101690f..fa81df22a10391c7838a1103d992f0f3c44f62b1 100644 (file)
@@ -474,7 +474,7 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
                }
                if (!is_ct_kill) {
                        IWL_ERR(priv, "Restarting adapter due to queue full\n");
-                       queue_work(priv->workqueue, &priv->restart);
+                       iwlagn_fw_error(priv, false);
                }
                return -ENOSPC;
        }
@@ -582,7 +582,7 @@ static void iwl_hcmd_queue_reclaim(struct iwl_priv *priv, int txq_id,
                if (nfreed++ > 0) {
                        IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", idx,
                                        q->write_ptr, q->read_ptr);
-                       queue_work(priv->workqueue, &priv->restart);
+                       iwlagn_fw_error(priv, false);
                }
 
        }