ncr5380: Refactor command completion
authorFinn Thain <fthain@telegraphics.com.au>
Sun, 3 Jan 2016 05:05:59 +0000 (16:05 +1100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 7 Jan 2016 02:43:07 +0000 (21:43 -0500)
Implement a 'complete_cmd' function to complete commands. This is needed
by the following patch; the new function provides a site for the logic
needed to correctly handle REQUEST SENSE commands.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Tested-by: Ondrej Zary <linux@rainbow-software.org>
Tested-by: Michael Schmitz <schmitzmic@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/NCR5380.c
drivers/scsi/atari_NCR5380.c

index 6b861fd3fbb11bb0c084ef7472783e85972010df..08319164f0121613a1b1f3ca6cf12385717324a1 100644 (file)
@@ -725,6 +725,24 @@ static void NCR5380_exit(struct Scsi_Host *instance)
        destroy_workqueue(hostdata->work_q);
 }
 
+/**
+ * complete_cmd - finish processing a command and return it to the SCSI ML
+ * @instance: the host instance
+ * @cmd: command to complete
+ */
+
+static void complete_cmd(struct Scsi_Host *instance,
+                         struct scsi_cmnd *cmd)
+{
+       struct NCR5380_hostdata *hostdata = shost_priv(instance);
+
+       dsprintk(NDEBUG_QUEUES, instance, "complete_cmd: cmd %p\n", cmd);
+
+       hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
+
+       cmd->scsi_done(cmd);
+}
+
 /**
  * NCR5380_queue_command - queue a command
  * @instance: the relevant SCSI adapter
@@ -1171,7 +1189,7 @@ static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
                spin_lock_irq(&hostdata->lock);
                NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
                cmd->result = DID_BAD_TARGET << 16;
-               cmd->scsi_done(cmd);
+               complete_cmd(instance, cmd);
                NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
                dprintk(NDEBUG_SELECTION, "scsi%d : target did not respond within 250ms\n",
                        instance->host_no);
@@ -1759,7 +1777,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
                                sink = 1;
                                do_abort(instance);
                                cmd->result = DID_ERROR << 16;
-                               cmd->scsi_done(cmd);
+                               complete_cmd(instance, cmd);
                                return;
 #endif
                        case PHASE_DATAIN:
@@ -1804,7 +1822,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
                                                sink = 1;
                                                do_abort(instance);
                                                cmd->result = DID_ERROR << 16;
-                                               cmd->scsi_done(cmd);
+                                               complete_cmd(instance, cmd);
                                                /* XXX - need to source or sink data here, as appropriate */
                                        } else
                                                cmd->SCp.this_residual -= transfersize - len;
@@ -1834,7 +1852,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
                                                 cmd, scmd_id(cmd), cmd->device->lun);
 
                                        hostdata->connected = NULL;
-                                       hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xFF));
 
                                        /* 
                                         * I'm not sure what the correct thing to do here is : 
@@ -1870,8 +1887,9 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
                                                dsprintk(NDEBUG_AUTOSENSE | NDEBUG_QUEUES,
                                                         instance, "REQUEST SENSE cmd %p added to head of issue queue\n",
                                                         cmd);
+                                               hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xFF));
                                        } else {
-                                               cmd->scsi_done(cmd);
+                                               complete_cmd(instance, cmd);
                                        }
 
                                        /* 
@@ -2018,10 +2036,9 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
                                hostdata->last_message = msgout;
                                NCR5380_transfer_pio(instance, &phase, &len, &data);
                                if (msgout == ABORT) {
-                                       hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xFF));
                                        hostdata->connected = NULL;
                                        cmd->result = DID_ERROR << 16;
-                                       cmd->scsi_done(cmd);
+                                       complete_cmd(instance, cmd);
                                        NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
                                        return;
                                }
index 12b98cbe7b449695aa82e2b8a3e77d2ca5fea343..a1f9f390d7637d87ea4c3ad3e1d7be2124a2ff32 100644 (file)
@@ -764,6 +764,27 @@ static void NCR5380_exit(struct Scsi_Host *instance)
        destroy_workqueue(hostdata->work_q);
 }
 
+/**
+ * complete_cmd - finish processing a command and return it to the SCSI ML
+ * @instance: the host instance
+ * @cmd: command to complete
+ */
+
+static void complete_cmd(struct Scsi_Host *instance,
+                         struct scsi_cmnd *cmd)
+{
+       struct NCR5380_hostdata *hostdata = shost_priv(instance);
+
+       dsprintk(NDEBUG_QUEUES, instance, "complete_cmd: cmd %p\n", cmd);
+
+#ifdef SUPPORT_TAGS
+       cmd_free_tag(cmd);
+#else
+       hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
+#endif
+       cmd->scsi_done(cmd);
+}
+
 /**
  * NCR5380_queue_command - queue a command
  * @instance: the relevant SCSI adapter
@@ -1352,10 +1373,7 @@ static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
                spin_lock_irq(&hostdata->lock);
                NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
                cmd->result = DID_BAD_TARGET << 16;
-#ifdef SUPPORT_TAGS
-               cmd_free_tag(cmd);
-#endif
-               cmd->scsi_done(cmd);
+               complete_cmd(instance, cmd);
                NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
                dprintk(NDEBUG_SELECTION, "scsi%d: target did not respond within 250ms\n", HOSTNO);
                return 0;
@@ -1866,7 +1884,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                sink = 1;
                                do_abort(instance);
                                cmd->result = DID_ERROR << 16;
-                               cmd->scsi_done(cmd);
+                               complete_cmd(instance, cmd);
                                return;
 #endif
                        case PHASE_DATAIN:
@@ -1926,7 +1944,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                                sink = 1;
                                                do_abort(instance);
                                                cmd->result = DID_ERROR << 16;
-                                               cmd->scsi_done(cmd);
+                                               complete_cmd(instance, cmd);
                                                /* XXX - need to source or sink data here, as appropriate */
                                        } else {
 #ifdef REAL_DMA
@@ -1982,8 +2000,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                                if (ta->queue_size > ta->nr_allocated)
                                                        ta->queue_size = ta->nr_allocated;
                                        }
-#else
-                                       hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
 #endif
 
                                        /*
@@ -2021,8 +2037,13 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                                dsprintk(NDEBUG_AUTOSENSE | NDEBUG_QUEUES,
                                                         instance, "REQUEST SENSE cmd %p added to head of issue queue\n",
                                                         cmd);
+#ifdef SUPPORT_TAGS
+                                               cmd_free_tag(cmd);
+#else
+                                               hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
+#endif
                                        } else {
-                                               cmd->scsi_done(cmd);
+                                               complete_cmd(instance, cmd);
                                        }
 
                                        /*
@@ -2193,15 +2214,10 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                hostdata->last_message = msgout;
                                NCR5380_transfer_pio(instance, &phase, &len, &data);
                                if (msgout == ABORT) {
-#ifdef SUPPORT_TAGS
-                                       cmd_free_tag(cmd);
-#else
-                                       hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
-#endif
                                        hostdata->connected = NULL;
                                        cmd->result = DID_ERROR << 16;
+                                       complete_cmd(instance, cmd);
                                        maybe_release_dma_irq(instance);
-                                       cmd->scsi_done(cmd);
                                        NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
                                        return;
                                }