I/OAT: Rename the source file
[safe/jmp/linux-2.6] / drivers / scsi / scsi_error.c
index ff82ccf..d29f846 100644 (file)
 #include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/string.h>
-#include <linux/slab.h>
 #include <linux/kernel.h>
+#include <linux/freezer.h>
 #include <linux/kthread.h>
 #include <linux/interrupt.h>
 #include <linux/blkdev.h>
 #include <linux/delay.h>
+#include <linux/scatterlist.h>
 
 #include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_dbg.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_eh.h>
+#include <scsi/scsi_transport.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>
-#include <scsi/scsi_request.h>
 
 #include "scsi_priv.h"
 #include "scsi_logging.h"
+#include "scsi_transport_api.h"
 
 #define SENSE_TIMEOUT          (10*HZ)
-#define START_UNIT_TIMEOUT     (30*HZ)
 
 /*
  * These should *probably* be handled by the host itself.
@@ -57,6 +59,28 @@ void scsi_eh_wakeup(struct Scsi_Host *shost)
 }
 
 /**
+ * scsi_schedule_eh - schedule EH for SCSI host
+ * @shost:     SCSI host to invoke error handling on.
+ *
+ * Schedule SCSI EH without scmd.
+ **/
+void scsi_schedule_eh(struct Scsi_Host *shost)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(shost->host_lock, flags);
+
+       if (scsi_host_set_state(shost, SHOST_RECOVERY) == 0 ||
+           scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY) == 0) {
+               shost->host_eh_scheduled++;
+               scsi_eh_wakeup(shost);
+       }
+
+       spin_unlock_irqrestore(shost->host_lock, flags);
+}
+EXPORT_SYMBOL_GPL(scsi_schedule_eh);
+
+/**
  * scsi_eh_scmd_add - add scsi cmd to error handling.
  * @scmd:      scmd to run eh on.
  * @eh_flag:   optional SCSI_EH flag.
@@ -161,18 +185,23 @@ int scsi_delete_timer(struct scsi_cmnd *scmd)
  **/
 void scsi_times_out(struct scsi_cmnd *scmd)
 {
+       enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *);
+
        scsi_log_completion(scmd, TIMEOUT_ERROR);
 
-       if (scmd->device->host->hostt->eh_timed_out)
-               switch (scmd->device->host->hostt->eh_timed_out(scmd)) {
+       if (scmd->device->host->transportt->eh_timed_out)
+               eh_timed_out = scmd->device->host->transportt->eh_timed_out;
+       else if (scmd->device->host->hostt->eh_timed_out)
+               eh_timed_out = scmd->device->host->hostt->eh_timed_out;
+       else
+               eh_timed_out = NULL;
+
+       if (eh_timed_out)
+               switch (eh_timed_out(scmd)) {
                case EH_HANDLED:
                        __scsi_done(scmd);
                        return;
                case EH_RESET_TIMER:
-                       /* This allows a single retry even of a command
-                        * with allowed == 0 */
-                       if (scmd->retries++ > scmd->allowed)
-                               break;
                        scsi_add_timer(scmd, scmd->timeout_per_command,
                                       scsi_times_out);
                        return;
@@ -340,6 +369,11 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
                return SUCCESS;
 
        case MEDIUM_ERROR:
+               if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */
+                   sshdr.asc == 0x13 || /* AMNF DATA FIELD */
+                   sshdr.asc == 0x14) { /* RECORD NOT FOUND */
+                       return SUCCESS;
+               }
                return NEEDS_RETRY;
 
        case HARDWARE_ERROR:
@@ -434,28 +468,250 @@ static void scsi_eh_done(struct scsi_cmnd *scmd)
 }
 
 /**
- * scsi_send_eh_cmnd  - send a cmd to a device as part of error recovery.
- * @scmd:      SCSI Cmd to send.
- * @timeout:   Timeout for cmd.
+ * scsi_try_host_reset - ask host adapter to reset itself
+ * @scmd:      SCSI cmd to send hsot reset.
+ **/
+static int scsi_try_host_reset(struct scsi_cmnd *scmd)
+{
+       unsigned long flags;
+       int rtn;
+
+       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
+                                         __FUNCTION__));
+
+       if (!scmd->device->host->hostt->eh_host_reset_handler)
+               return FAILED;
+
+       rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
+
+       if (rtn == SUCCESS) {
+               if (!scmd->device->host->hostt->skip_settle_delay)
+                       ssleep(HOST_RESET_SETTLE_TIME);
+               spin_lock_irqsave(scmd->device->host->host_lock, flags);
+               scsi_report_bus_reset(scmd->device->host,
+                                     scmd_channel(scmd));
+               spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
+       }
+
+       return rtn;
+}
+
+/**
+ * scsi_try_bus_reset - ask host to perform a bus reset
+ * @scmd:      SCSI cmd to send bus reset.
+ **/
+static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
+{
+       unsigned long flags;
+       int rtn;
+
+       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
+                                         __FUNCTION__));
+
+       if (!scmd->device->host->hostt->eh_bus_reset_handler)
+               return FAILED;
+
+       rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
+
+       if (rtn == SUCCESS) {
+               if (!scmd->device->host->hostt->skip_settle_delay)
+                       ssleep(BUS_RESET_SETTLE_TIME);
+               spin_lock_irqsave(scmd->device->host->host_lock, flags);
+               scsi_report_bus_reset(scmd->device->host,
+                                     scmd_channel(scmd));
+               spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
+       }
+
+       return rtn;
+}
+
+/**
+ * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
+ * @scmd:      SCSI cmd used to send BDR
+ *
+ * Notes:
+ *    There is no timeout for this operation.  if this operation is
+ *    unreliable for a given host, then the host itself needs to put a
+ *    timer on it, and set the host back to a consistent state prior to
+ *    returning.
+ **/
+static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
+{
+       int rtn;
+
+       if (!scmd->device->host->hostt->eh_device_reset_handler)
+               return FAILED;
+
+       rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
+       if (rtn == SUCCESS) {
+               scmd->device->was_reset = 1;
+               scmd->device->expecting_cc_ua = 1;
+       }
+
+       return rtn;
+}
+
+static int __scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
+{
+       if (!scmd->device->host->hostt->eh_abort_handler)
+               return FAILED;
+
+       return scmd->device->host->hostt->eh_abort_handler(scmd);
+}
+
+/**
+ * scsi_try_to_abort_cmd - Ask host to abort a running command.
+ * @scmd:      SCSI cmd to abort from Lower Level.
+ *
+ * Notes:
+ *    This function will not return until the user's completion function
+ *    has been called.  there is no timeout on this operation.  if the
+ *    author of the low-level driver wishes this operation to be timed,
+ *    they can provide this facility themselves.  helper functions in
+ *    scsi_error.c can be supplied to make this easier to do.
+ **/
+static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
+{
+       /*
+        * scsi_done was called just after the command timed out and before
+        * we had a chance to process it. (db)
+        */
+       if (scmd->serial_number == 0)
+               return SUCCESS;
+       return __scsi_try_to_abort_cmd(scmd);
+}
+
+static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
+{
+       if (__scsi_try_to_abort_cmd(scmd) != SUCCESS)
+               if (scsi_try_bus_device_reset(scmd) != SUCCESS)
+                       if (scsi_try_bus_reset(scmd) != SUCCESS)
+                               scsi_try_host_reset(scmd);
+}
+
+/**
+ * scsi_eh_prep_cmnd  - Save a scsi command info as part of error recory
+ * @scmd:       SCSI command structure to hijack
+ * @ses:        structure to save restore information
+ * @cmnd:       CDB to send. Can be NULL if no new cmnd is needed
+ * @cmnd_size:  size in bytes of @cmnd
+ * @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored)
+ *
+ * This function is used to save a scsi command information before re-execution
+ * as part of the error recovery process.  If @sense_bytes is 0 the command
+ * sent must be one that does not transfer any data.  If @sense_bytes != 0
+ * @cmnd is ignored and this functions sets up a REQUEST_SENSE command
+ * and cmnd buffers to read @sense_bytes into @scmd->sense_buffer.
+ **/
+void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
+                       unsigned char *cmnd, int cmnd_size, unsigned sense_bytes)
+{
+       struct scsi_device *sdev = scmd->device;
+
+       /*
+        * We need saved copies of a number of fields - this is because
+        * error handling may need to overwrite these with different values
+        * to run different commands, and once error handling is complete,
+        * we will need to restore these values prior to running the actual
+        * command.
+        */
+       ses->cmd_len = scmd->cmd_len;
+       memcpy(ses->cmnd, scmd->cmnd, sizeof(scmd->cmnd));
+       ses->data_direction = scmd->sc_data_direction;
+       ses->bufflen = scmd->request_bufflen;
+       ses->buffer = scmd->request_buffer;
+       ses->use_sg = scmd->use_sg;
+       ses->resid = scmd->resid;
+       ses->result = scmd->result;
+
+       if (sense_bytes) {
+               scmd->request_bufflen = min_t(unsigned,
+                                      sizeof(scmd->sense_buffer), sense_bytes);
+               sg_init_one(&ses->sense_sgl, scmd->sense_buffer,
+                                                      scmd->request_bufflen);
+               scmd->request_buffer = &ses->sense_sgl;
+               scmd->sc_data_direction = DMA_FROM_DEVICE;
+               scmd->use_sg = 1;
+               memset(scmd->cmnd, 0, sizeof(scmd->cmnd));
+               scmd->cmnd[0] = REQUEST_SENSE;
+               scmd->cmnd[4] = scmd->request_bufflen;
+               scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
+       } else {
+               scmd->request_buffer = NULL;
+               scmd->request_bufflen = 0;
+               scmd->sc_data_direction = DMA_NONE;
+               scmd->use_sg = 0;
+               if (cmnd) {
+                       memset(scmd->cmnd, 0, sizeof(scmd->cmnd));
+                       memcpy(scmd->cmnd, cmnd, cmnd_size);
+                       scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
+               }
+       }
+
+       scmd->underflow = 0;
+
+       if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN)
+               scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
+                       (sdev->lun << 5 & 0xe0);
+
+       /*
+        * Zero the sense buffer.  The scsi spec mandates that any
+        * untransferred sense data should be interpreted as being zero.
+        */
+       memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
+}
+EXPORT_SYMBOL(scsi_eh_prep_cmnd);
+
+/**
+ * scsi_eh_restore_cmnd  - Restore a scsi command info as part of error recory
+ * @scmd:       SCSI command structure to restore
+ * @ses:        saved information from a coresponding call to scsi_prep_eh_cmnd
+ *
+ * Undo any damage done by above scsi_prep_eh_cmnd().
+ **/
+void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses)
+{
+       /*
+        * Restore original data
+        */
+       scmd->cmd_len = ses->cmd_len;
+       memcpy(scmd->cmnd, ses->cmnd, sizeof(scmd->cmnd));
+       scmd->sc_data_direction = ses->data_direction;
+       scmd->request_bufflen = ses->bufflen;
+       scmd->request_buffer = ses->buffer;
+       scmd->use_sg = ses->use_sg;
+       scmd->resid = ses->resid;
+       scmd->result = ses->result;
+}
+EXPORT_SYMBOL(scsi_eh_restore_cmnd);
+
+/**
+ * scsi_send_eh_cmnd  - submit a scsi command as part of error recory
+ * @scmd:       SCSI command structure to hijack
+ * @cmnd:       CDB to send
+ * @cmnd_size:  size in bytes of @cmnd
+ * @timeout:    timeout for this request
+ * @sense_bytes: size of sense data to copy or 0
+ *
+ * This function is used to send a scsi command down to a target device
+ * as part of the error recovery process. See also scsi_eh_prep_cmnd() above.
  *
  * Return value:
  *    SUCCESS or FAILED or NEEDS_RETRY
  **/
-static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
+static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
+                            int cmnd_size, int timeout, unsigned sense_bytes)
 {
        struct scsi_device *sdev = scmd->device;
        struct Scsi_Host *shost = sdev->host;
-       DECLARE_COMPLETION(done);
+       DECLARE_COMPLETION_ONSTACK(done);
        unsigned long timeleft;
        unsigned long flags;
+       struct scsi_eh_save ses;
        int rtn;
 
-       if (sdev->scsi_level <= SCSI_2)
-               scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
-                       (sdev->lun << 5 & 0xe0);
-
+       scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes);
        shost->eh_action = &done;
-       scmd->request->rq_status = RQ_SCSI_BUSY;
 
        spin_lock_irqsave(shost->host_lock, flags);
        scsi_log_send(scmd);
@@ -464,7 +720,6 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
 
        timeleft = wait_for_completion_timeout(&done, timeout);
 
-       scmd->request->rq_status = RQ_SCSI_DONE;
        shost->eh_action = NULL;
 
        scsi_log_completion(scmd, SUCCESS);
@@ -495,16 +750,11 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
                        break;
                }
        } else {
-               /*
-                * FIXME(eric) - we are not tracking whether we could
-                * abort a timed out command or not.  not sure how
-                * we should treat them differently anyways.
-                */
-               if (shost->hostt->eh_abort_handler)
-                       shost->hostt->eh_abort_handler(scmd);
+               scsi_abort_eh_cmnd(scmd);
                rtn = FAILED;
        }
 
+       scsi_eh_restore_cmnd(scmd, &ses);
        return rtn;
 }
 
@@ -519,57 +769,7 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
  **/
 static int scsi_request_sense(struct scsi_cmnd *scmd)
 {
-       static unsigned char generic_sense[6] =
-       {REQUEST_SENSE, 0, 0, 0, 252, 0};
-       unsigned char *scsi_result;
-       int saved_result;
-       int rtn;
-
-       memcpy(scmd->cmnd, generic_sense, sizeof(generic_sense));
-
-       scsi_result = kmalloc(252, GFP_ATOMIC | ((scmd->device->host->hostt->unchecked_isa_dma) ? __GFP_DMA : 0));
-
-
-       if (unlikely(!scsi_result)) {
-               printk(KERN_ERR "%s: cannot allocate scsi_result.\n",
-                      __FUNCTION__);
-               return FAILED;
-       }
-
-       /*
-        * zero the sense buffer.  some host adapters automatically always
-        * request sense, so it is not a good idea that
-        * scmd->request_buffer and scmd->sense_buffer point to the same
-        * address (db).  0 is not a valid sense code. 
-        */
-       memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
-       memset(scsi_result, 0, 252);
-
-       saved_result = scmd->result;
-       scmd->request_buffer = scsi_result;
-       scmd->request_bufflen = 252;
-       scmd->use_sg = 0;
-       scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
-       scmd->sc_data_direction = DMA_FROM_DEVICE;
-       scmd->underflow = 0;
-
-       rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
-
-       /* last chance to have valid sense data */
-       if(!SCSI_SENSE_VALID(scmd)) {
-               memcpy(scmd->sense_buffer, scmd->request_buffer,
-                      sizeof(scmd->sense_buffer));
-       }
-
-       kfree(scsi_result);
-
-       /*
-        * when we eventually call scsi_finish, we really wish to complete
-        * the original request, so let's restore the original data. (db)
-        */
-       scsi_setup_cmd_retry(scmd);
-       scmd->result = saved_result;
-       return rtn;
+       return scsi_send_eh_cmnd(scmd, NULL, 0, SENSE_TIMEOUT, ~0);
 }
 
 /**
@@ -584,19 +784,13 @@ static int scsi_request_sense(struct scsi_cmnd *scmd)
  *    keep a list of pending commands for final completion, and once we
  *    are ready to leave error handling we handle completion for real.
  **/
-static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
-                              struct list_head *done_q)
+void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
 {
        scmd->device->host->host_failed--;
        scmd->eh_eflags = 0;
-
-       /*
-        * set this back so that the upper level can correctly free up
-        * things.
-        */
-       scsi_setup_cmd_retry(scmd);
        list_move_tail(&scmd->eh_entry, done_q);
 }
+EXPORT_SYMBOL(scsi_eh_finish_cmd);
 
 /**
  * scsi_eh_get_sense - Get device sense data.
@@ -618,8 +812,8 @@ static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
  *    XXX: Long term this code should go away, but that needs an audit of
  *         all LLDDs first.
  **/
-static int scsi_eh_get_sense(struct list_head *work_q,
-                            struct list_head *done_q)
+int scsi_eh_get_sense(struct list_head *work_q,
+                     struct list_head *done_q)
 {
        struct scsi_cmnd *scmd, *next;
        int rtn;
@@ -661,31 +855,7 @@ static int scsi_eh_get_sense(struct list_head *work_q,
 
        return list_empty(work_q);
 }
-
-/**
- * scsi_try_to_abort_cmd - Ask host to abort a running command.
- * @scmd:      SCSI cmd to abort from Lower Level.
- *
- * Notes:
- *    This function will not return until the user's completion function
- *    has been called.  there is no timeout on this operation.  if the
- *    author of the low-level driver wishes this operation to be timed,
- *    they can provide this facility themselves.  helper functions in
- *    scsi_error.c can be supplied to make this easier to do.
- **/
-static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
-{
-       if (!scmd->device->host->hostt->eh_abort_handler)
-               return FAILED;
-
-       /*
-        * scsi_done was called just after the command timed out and before
-        * we had a chance to process it. (db)
-        */
-       if (scmd->serial_number == 0)
-               return SUCCESS;
-       return scmd->device->host->hostt->eh_abort_handler(scmd);
-}
+EXPORT_SYMBOL_GPL(scsi_eh_get_sense);
 
 /**
  * scsi_eh_tur - Send TUR to device.
@@ -698,47 +868,23 @@ static int scsi_eh_tur(struct scsi_cmnd *scmd)
 {
        static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
        int retry_cnt = 1, rtn;
-       int saved_result;
 
 retry_tur:
-       memcpy(scmd->cmnd, tur_command, sizeof(tur_command));
-
-       /*
-        * zero the sense buffer.  the scsi spec mandates that any
-        * untransferred sense data should be interpreted as being zero.
-        */
-       memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
-
-       saved_result = scmd->result;
-       scmd->request_buffer = NULL;
-       scmd->request_bufflen = 0;
-       scmd->use_sg = 0;
-       scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
-       scmd->underflow = 0;
-       scmd->sc_data_direction = DMA_NONE;
-
-       rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
+       rtn = scsi_send_eh_cmnd(scmd, tur_command, 6, SENSE_TIMEOUT, 0);
 
-       /*
-        * when we eventually call scsi_finish, we really wish to complete
-        * the original request, so let's restore the original data. (db)
-        */
-       scsi_setup_cmd_retry(scmd);
-       scmd->result = saved_result;
-
-       /*
-        * hey, we are done.  let's look to see what happened.
-        */
        SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
                __FUNCTION__, scmd, rtn));
-       if (rtn == SUCCESS)
-               return 0;
-       else if (rtn == NEEDS_RETRY) {
+
+       switch (rtn) {
+       case NEEDS_RETRY:
                if (retry_cnt--)
                        goto retry_tur;
+               /*FALLTHRU*/
+       case SUCCESS:
                return 0;
+       default:
+               return 1;
        }
-       return 1;
 }
 
 /**
@@ -785,32 +931,6 @@ static int scsi_eh_abort_cmds(struct list_head *work_q,
 }
 
 /**
- * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
- * @scmd:      SCSI cmd used to send BDR       
- *
- * Notes:
- *    There is no timeout for this operation.  if this operation is
- *    unreliable for a given host, then the host itself needs to put a
- *    timer on it, and set the host back to a consistent state prior to
- *    returning.
- **/
-static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
-{
-       int rtn;
-
-       if (!scmd->device->host->hostt->eh_device_reset_handler)
-               return FAILED;
-
-       rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
-       if (rtn == SUCCESS) {
-               scmd->device->was_reset = 1;
-               scmd->device->expecting_cc_ua = 1;
-       }
-
-       return rtn;
-}
-
-/**
  * scsi_eh_try_stu - Send START_UNIT to device.
  * @scmd:      Scsi cmd to send START_UNIT
  *
@@ -820,44 +940,18 @@ static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
 static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
 {
        static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0};
-       int rtn;
-       int saved_result;
-
-       if (!scmd->device->allow_restart)
-               return 1;
-
-       memcpy(scmd->cmnd, stu_command, sizeof(stu_command));
 
-       /*
-        * zero the sense buffer.  the scsi spec mandates that any
-        * untransferred sense data should be interpreted as being zero.
-        */
-       memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
-
-       saved_result = scmd->result;
-       scmd->request_buffer = NULL;
-       scmd->request_bufflen = 0;
-       scmd->use_sg = 0;
-       scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
-       scmd->underflow = 0;
-       scmd->sc_data_direction = DMA_NONE;
+       if (scmd->device->allow_restart) {
+               int i, rtn = NEEDS_RETRY;
 
-       rtn = scsi_send_eh_cmnd(scmd, START_UNIT_TIMEOUT);
+               for (i = 0; rtn == NEEDS_RETRY && i < 2; i++)
+                       rtn = scsi_send_eh_cmnd(scmd, stu_command, 6,
+                                               scmd->device->timeout, 0);
 
-       /*
-        * when we eventually call scsi_finish, we really wish to complete
-        * the original request, so let's restore the original data. (db)
-        */
-       scsi_setup_cmd_retry(scmd);
-       scmd->result = saved_result;
+               if (rtn == SUCCESS)
+                       return 0;
+       }
 
-       /*
-        * hey, we are done.  let's look to see what happened.
-        */
-       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
-               __FUNCTION__, scmd, rtn));
-       if (rtn == SUCCESS)
-               return 0;
        return 1;
 }
 
@@ -969,64 +1063,6 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
 }
 
 /**
- * scsi_try_bus_reset - ask host to perform a bus reset
- * @scmd:      SCSI cmd to send bus reset.
- **/
-static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
-{
-       unsigned long flags;
-       int rtn;
-
-       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
-                                         __FUNCTION__));
-
-       if (!scmd->device->host->hostt->eh_bus_reset_handler)
-               return FAILED;
-
-       rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
-
-       if (rtn == SUCCESS) {
-               if (!scmd->device->host->hostt->skip_settle_delay)
-                       ssleep(BUS_RESET_SETTLE_TIME);
-               spin_lock_irqsave(scmd->device->host->host_lock, flags);
-               scsi_report_bus_reset(scmd->device->host,
-                                     scmd_channel(scmd));
-               spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
-       }
-
-       return rtn;
-}
-
-/**
- * scsi_try_host_reset - ask host adapter to reset itself
- * @scmd:      SCSI cmd to send hsot reset.
- **/
-static int scsi_try_host_reset(struct scsi_cmnd *scmd)
-{
-       unsigned long flags;
-       int rtn;
-
-       SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
-                                         __FUNCTION__));
-
-       if (!scmd->device->host->hostt->eh_host_reset_handler)
-               return FAILED;
-
-       rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
-
-       if (rtn == SUCCESS) {
-               if (!scmd->device->host->hostt->skip_settle_delay)
-                       ssleep(HOST_RESET_SETTLE_TIME);
-               spin_lock_irqsave(scmd->device->host->host_lock, flags);
-               scsi_report_bus_reset(scmd->device->host,
-                                     scmd_channel(scmd));
-               spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
-       }
-
-       return rtn;
-}
-
-/**
  * scsi_eh_bus_reset - send a bus reset 
  * @shost:     scsi host being recovered.
  * @eh_done_q: list_head for processed commands.
@@ -1130,9 +1166,8 @@ static void scsi_eh_offline_sdevs(struct list_head *work_q,
        struct scsi_cmnd *scmd, *next;
 
        list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
-               sdev_printk(KERN_INFO, scmd->device,
-                           "scsi: Device offlined - not"
-                           " ready after error recovery\n");
+               sdev_printk(KERN_INFO, scmd->device, "Device offlined - "
+                           "not ready after error recovery\n");
                scsi_device_set_state(scmd->device, SDEV_OFFLINE);
                if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD) {
                        /*
@@ -1409,9 +1444,9 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
  * @eh_done_q: list_head for processed commands.
  *
  **/
-static void scsi_eh_ready_devs(struct Scsi_Host *shost,
-                              struct list_head *work_q,
-                              struct list_head *done_q)
+void scsi_eh_ready_devs(struct Scsi_Host *shost,
+                       struct list_head *work_q,
+                       struct list_head *done_q)
 {
        if (!scsi_eh_stu(shost, work_q, done_q))
                if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
@@ -1419,13 +1454,14 @@ static void scsi_eh_ready_devs(struct Scsi_Host *shost,
                                if (!scsi_eh_host_reset(work_q, done_q))
                                        scsi_eh_offline_sdevs(work_q, done_q);
 }
+EXPORT_SYMBOL_GPL(scsi_eh_ready_devs);
 
 /**
  * scsi_eh_flush_done_q - finish processed commands or retry them.
  * @done_q:    list_head of processed commands.
  *
  **/
-static void scsi_eh_flush_done_q(struct list_head *done_q)
+void scsi_eh_flush_done_q(struct list_head *done_q)
 {
        struct scsi_cmnd *scmd, *next;
 
@@ -1454,6 +1490,7 @@ static void scsi_eh_flush_done_q(struct list_head *done_q)
                }
        }
 }
+EXPORT_SYMBOL(scsi_eh_flush_done_q);
 
 /**
  * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
@@ -1509,8 +1546,6 @@ int scsi_error_handler(void *data)
 {
        struct Scsi_Host *shost = data;
 
-       current->flags |= PF_NOFREEZE;
-
        /*
         * We use TASK_INTERRUPTIBLE so that the thread is not
         * counted against the load average as a running process.
@@ -1519,7 +1554,7 @@ int scsi_error_handler(void *data)
         */
        set_current_state(TASK_INTERRUPTIBLE);
        while (!kthread_should_stop()) {
-               if (shost->host_failed == 0 ||
+               if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) ||
                    shost->host_failed != shost->host_busy) {
                        SCSI_LOG_ERROR_RECOVERY(1,
                                printk("Error handler scsi_eh_%d sleeping\n",
@@ -1539,8 +1574,8 @@ int scsi_error_handler(void *data)
                 * what we need to do to get it up and online again (if we can).
                 * If we fail, we end up taking the thing offline.
                 */
-               if (shost->hostt->eh_strategy_handler) 
-                       shost->hostt->eh_strategy_handler(shost);
+               if (shost->transportt->eh_strategy_handler)
+                       shost->transportt->eh_strategy_handler(shost);
                else
                        scsi_unjam_host(shost);
 
@@ -1654,35 +1689,29 @@ int
 scsi_reset_provider(struct scsi_device *dev, int flag)
 {
        struct scsi_cmnd *scmd = scsi_get_command(dev, GFP_KERNEL);
+       struct Scsi_Host *shost = dev->host;
        struct request req;
+       unsigned long flags;
        int rtn;
 
        scmd->request = &req;
        memset(&scmd->eh_timeout, 0, sizeof(scmd->eh_timeout));
-       scmd->request->rq_status        = RQ_SCSI_BUSY;
 
        memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd));
     
        scmd->scsi_done         = scsi_reset_provider_done_command;
-       scmd->done                      = NULL;
-       scmd->buffer                    = NULL;
-       scmd->bufflen                   = 0;
        scmd->request_buffer            = NULL;
        scmd->request_bufflen           = 0;
 
        scmd->cmd_len                   = 0;
 
        scmd->sc_data_direction         = DMA_BIDIRECTIONAL;
-       scmd->sc_request                = NULL;
-       scmd->sc_magic                  = SCSI_CMND_MAGIC;
 
        init_timer(&scmd->eh_timeout);
 
-       /*
-        * Sometimes the command can get back into the timer chain,
-        * so use the pid as an identifier.
-        */
-       scmd->pid                       = 0;
+       spin_lock_irqsave(shost->host_lock, flags);
+       shost->tmf_in_progress = 1;
+       spin_unlock_irqrestore(shost->host_lock, flags);
 
        switch (flag) {
        case SCSI_TRY_RESET_DEVICE:
@@ -1702,6 +1731,22 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
                rtn = FAILED;
        }
 
+       spin_lock_irqsave(shost->host_lock, flags);
+       shost->tmf_in_progress = 0;
+       spin_unlock_irqrestore(shost->host_lock, flags);
+
+       /*
+        * be sure to wake up anyone who was sleeping or had their queue
+        * suspended while we performed the TMF.
+        */
+       SCSI_LOG_ERROR_RECOVERY(3,
+               printk("%s: waking up host to restart after TMF\n",
+               __FUNCTION__));
+
+       wake_up(&shost->host_wait);
+
+       scsi_run_host_queues(shost);
+
        scsi_next_command(scmd);
        return rtn;
 }
@@ -1771,14 +1816,6 @@ int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
 }
 EXPORT_SYMBOL(scsi_normalize_sense);
 
-int scsi_request_normalize_sense(struct scsi_request *sreq,
-                                struct scsi_sense_hdr *sshdr)
-{
-       return scsi_normalize_sense(sreq->sr_sense_buffer,
-                       sizeof(sreq->sr_sense_buffer), sshdr);
-}
-EXPORT_SYMBOL(scsi_request_normalize_sense);
-
 int scsi_command_normalize_sense(struct scsi_cmnd *cmd,
                                 struct scsi_sense_hdr *sshdr)
 {