struct NCR5380_hostdata *hostdata =
                container_of(work, struct NCR5380_hostdata, main_task);
        struct Scsi_Host *instance = hostdata->host;
-       struct scsi_cmnd *cmd;
        int done;
 
        do {
                done = 1;
 
                spin_lock_irq(&hostdata->lock);
-               while (!hostdata->connected &&
-                      (cmd = dequeue_next_cmd(instance))) {
+               while (!hostdata->connected && !hostdata->selecting) {
+                       struct scsi_cmnd *cmd = dequeue_next_cmd(instance);
+
+                       if (!cmd)
+                               break;
 
                        dsprintk(NDEBUG_MAIN, instance, "main: dequeued %p\n", cmd);
 
                         * entire unit.
                         */
 
-                       cmd = NCR5380_select(instance, cmd);
-                       if (!cmd) {
+                       if (!NCR5380_select(instance, cmd)) {
                                dsprintk(NDEBUG_MAIN, instance, "main: select complete\n");
                        } else {
                                dsprintk(NDEBUG_MAIN | NDEBUG_QUEUES, instance,
                /* Reselection interrupt */
                goto out;
        }
+       if (!hostdata->selecting) {
+               /* Command was aborted */
+               NCR5380_write(MODE_REG, MR_BASE);
+               goto out;
+       }
        if (err < 0) {
                NCR5380_write(MODE_REG, MR_BASE);
                shost_printk(KERN_ERR, instance,
 
        struct NCR5380_hostdata *hostdata =
                container_of(work, struct NCR5380_hostdata, main_task);
        struct Scsi_Host *instance = hostdata->host;
-       struct scsi_cmnd *cmd;
        int done;
 
        /*
                done = 1;
 
                spin_lock_irq(&hostdata->lock);
-               while (!hostdata->connected &&
-                      (cmd = dequeue_next_cmd(instance))) {
+               while (!hostdata->connected && !hostdata->selecting) {
+                       struct scsi_cmnd *cmd = dequeue_next_cmd(instance);
+
+                       if (!cmd)
+                               break;
 
                        dsprintk(NDEBUG_MAIN, instance, "main: dequeued %p\n", cmd);
 
 #ifdef SUPPORT_TAGS
                        cmd_get_tag(cmd, cmd->cmnd[0] != REQUEST_SENSE);
 #endif
-                       cmd = NCR5380_select(instance, cmd);
-                       if (!cmd) {
+                       if (!NCR5380_select(instance, cmd)) {
                                dsprintk(NDEBUG_MAIN, instance, "main: select complete\n");
                                maybe_release_dma_irq(instance);
                        } else {
                /* Reselection interrupt */
                goto out;
        }
+       if (!hostdata->selecting) {
+               /* Command was aborted */
+               NCR5380_write(MODE_REG, MR_BASE);
+               goto out;
+       }
        if (err < 0) {
                NCR5380_write(MODE_REG, MR_BASE);
                shost_printk(KERN_ERR, instance,