patch-2.1.103 linux/drivers/scsi/u14-34f.c

Next file: linux/drivers/scsi/u14-34f.h
Previous file: linux/drivers/scsi/sr_vendor.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.102/linux/drivers/scsi/u14-34f.c linux/drivers/scsi/u14-34f.c
@@ -1,6 +1,18 @@
 /*
  *      u14-34f.c - Low-level driver for UltraStor 14F/34F SCSI host adapters.
  *
+ *      18 May 1998 Rev. 4.31 for linux 2.0.33 and 2.1.102
+ *          Improved abort handling during the eh recovery process.
+ *
+ *      13 May 1998 Rev. 4.30 for linux 2.0.33 and 2.1.101
+ *          The driver is now fully SMP safe, including the
+ *          abort and reset routines.
+ *          Added command line options (eh:[y|n]) to choose between
+ *          new_eh_code and the old scsi code.
+ *          If linux verion >= 2.1.101 the default is eh:y, while the eh
+ *          option is ignored for previous releases and the old scsi code
+ *          is used.
+ *
  *      18 Apr 1998 Rev. 4.20 for linux 2.0.33 and 2.1.97
  *          Reworked interrupt handler.
  *
@@ -227,6 +239,8 @@
  *  After the optional list of detection probes, other possible command line
  *  options are:
  *
+ *  eh:y  use new scsi code (linux 2.2 only);
+ *  eh:n  use old scsi code;
  *  lc:y  enables linked commands;
  *  lc:n  disables linked commands;
  *  of:y  enables old firmware support;
@@ -234,13 +248,13 @@
  *  mq:xx set the max queue depth to the value xx (2 <= xx <= 8).
  *
  *  The default value is: "u14-34f=lc:n,of:n,mq:8". An example using the list
- *  of detection probes could be: "u14-34f=0x230,0x340,lc:y,of:n,mq:4".
+ *  of detection probes could be: "u14-34f=0x230,0x340,lc:y,of:n,mq:4,eh:n".
  *
  *  When loading as a module, parameters can be specified as well.
  *  The above example would be (use 1 in place of y and 0 in place of n):
  *
  *  modprobe u14-34f io_port=0x230,0x340 linked_comm=1 have_old_firmware=0 \
- *                max_queue_depth=4
+ *                max_queue_depth=4 use_new_eh_code=0
  *
  *  ----------------------------------------------------------------------------
  *  In this implementation, linked commands are designed to work with any DISK
@@ -295,6 +309,7 @@
 MODULE_PARM(have_old_firmware, "i");
 MODULE_PARM(link_statistics, "i");
 MODULE_PARM(max_queue_depth, "i");
+MODULE_PARM(use_new_eh_code, "i");
 MODULE_AUTHOR("Dario Ballabio");
 #endif
 
@@ -308,11 +323,6 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/byteorder.h>
-
-#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,95)
-#include <asm/spinlock.h>
-#endif
-
 #include <linux/proc_fs.h>
 #include <linux/blk.h>
 #include "scsi.h"
@@ -332,6 +342,34 @@
 #define __init
 #endif
 
+#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
+#include <asm/spinlock.h>
+#define IRQ_FLAGS
+#define IRQ_LOCK
+#define IRQ_LOCK_SAVE
+#define IRQ_UNLOCK
+#define IRQ_UNLOCK_RESTORE
+#define SPIN_FLAGS unsigned long spin_flags;
+#define SPIN_LOCK spin_lock_irq(&io_request_lock);
+#define SPIN_LOCK_SAVE spin_lock_irqsave(&io_request_lock, spin_flags);
+#define SPIN_UNLOCK spin_unlock_irq(&io_request_lock);
+#define SPIN_UNLOCK_RESTORE \
+                  spin_unlock_irqrestore(&io_request_lock, spin_flags);
+static int use_new_eh_code = TRUE;
+#else
+#define IRQ_FLAGS unsigned long irq_flags;
+#define IRQ_LOCK cli();
+#define IRQ_LOCK_SAVE do {save_flags(irq_flags); cli();} while (0);
+#define IRQ_UNLOCK sti();
+#define IRQ_UNLOCK_RESTORE do {restore_flags(irq_flags);} while (0);
+#define SPIN_FLAGS
+#define SPIN_LOCK
+#define SPIN_LOCK_SAVE
+#define SPIN_UNLOCK
+#define SPIN_UNLOCK_RESTORE
+static int use_new_eh_code = FALSE;
+#endif
+
 struct proc_dir_entry proc_scsi_u14_34f = {
     PROC_SCSI_U14_34F, 6, "u14_34f",
     S_IFDIR | S_IRUGO | S_IXUGO, 2
@@ -361,6 +399,8 @@
 #undef  DEBUG_DETECT
 #undef  DEBUG_INTERRUPT
 #undef  DEBUG_RESET
+#undef  DEBUG_GENERATE_ERRORS
+#undef  DEBUG_GENERATE_ABORTS
 
 #define MAX_ISA 3
 #define MAX_VESA 1
@@ -513,19 +553,19 @@
 static int setup_done = FALSE;
 static int link_statistics = 0;
 
-#if defined (HAVE_OLD_UX4F_FIRMWARE)
+#if defined(HAVE_OLD_UX4F_FIRMWARE)
 static int have_old_firmware = TRUE;
 #else
 static int have_old_firmware = FALSE;
 #endif
 
-#if defined (CONFIG_SCSI_U14_34F_LINKED_COMMANDS)
+#if defined(CONFIG_SCSI_U14_34F_LINKED_COMMANDS)
 static int linked_comm = TRUE;
 #else
 static int linked_comm = FALSE;
 #endif
 
-#if defined CONFIG_SCSI_U14_34F_MAX_TAGS
+#if defined(CONFIG_SCSI_U14_34F_MAX_TAGS)
 static int max_queue_depth = CONFIG_SCSI_U14_34F_MAX_TAGS;
 #else
 static int max_queue_depth = MAX_CMD_PER_LUN;
@@ -534,11 +574,9 @@
 static void select_queue_depths(struct Scsi_Host *host, Scsi_Device *devlist) {
    Scsi_Device *dev;
    int j, ntag = 0, nuntag = 0, tqd, utqd;
-   unsigned long flags;
-
-   save_flags(flags);
-   cli();
+   IRQ_FLAGS
 
+   IRQ_LOCK_SAVE
    j = ((struct hostdata *) host->hostdata)->board_number;
 
    for(dev = devlist; dev; dev = dev->next) {
@@ -586,7 +624,7 @@
              dev->queue_depth, link_suffix, tag_suffix);
       }
 
-   restore_flags(flags);
+   IRQ_UNLOCK_RESTORE
    return;
 }
 
@@ -629,8 +667,12 @@
    /* Issue OGM interrupt */
    outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
 
-   /* Wait a second.. */
-   { unsigned int msec = 1000; while (--msec) udelay(1000); }
+   SPIN_UNLOCK
+   IRQ_UNLOCK
+   time = jiffies;
+   while ((jiffies - time) < HZ && limit++ < 20000) udelay(100L);
+   IRQ_LOCK
+   SPIN_LOCK
 
    if (cpp->adapter_status || HD(j)->cp_stat[0] != FREE) {
       HD(j)->cp_stat[0] = FREE;
@@ -719,6 +761,14 @@
       return FALSE;
       }
 
+   if (have_old_firmware) tpnt->use_clustering = DISABLE_CLUSTERING;
+
+#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
+   tpnt->use_new_eh_code = use_new_eh_code;
+#else
+   use_new_eh_code = FALSE;
+#endif
+
    sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
 
    if (sh[j] == NULL) {
@@ -752,6 +802,9 @@
    }
 #endif
 
+   /* Probably a bogus host scsi id, set it to the dummy value */
+   if (sh[j]->this_id == 0) sh[j]->this_id = -1;
+
    /* If BIOS is disabled, force enable interrupts */
    if (sh[j]->base == 0) outb(CMD_ENA_INTR, sh[j]->io_port + REG_SYS_MASK);
 
@@ -779,9 +832,6 @@
       clear_dma_ff(dma_channel);
       set_dma_mode(dma_channel, DMA_MODE_CASCADE);
       enable_dma(dma_channel);
-
-      if (have_old_firmware) sh[j]->hostt->use_clustering = DISABLE_CLUSTERING;
-
       sh[j]->dma_channel = dma_channel;
       sprintf(BN(j), "U14F%d", j);
       bus_type = "ISA";
@@ -820,18 +870,23 @@
 
    if (max_queue_depth < MAX_CMD_PER_LUN) max_queue_depth = MAX_CMD_PER_LUN;
 
-   printk("%s: %s 0x%03lx, BIOS 0x%05x, IRQ %u, %s, SG %d, MB %d, of:%c, "\
-          "lc:%c, mq:%d.\n", BN(j), bus_type, (unsigned long)sh[j]->io_port,
-          (int)sh[j]->base, sh[j]->irq, dma_name, sh[j]->sg_tablesize,
-          sh[j]->can_queue, YESNO(have_old_firmware), YESNO(linked_comm),
-          max_queue_depth);
+   if (j == 0) {
+      printk("UltraStor 14F/34F: Copyright (C) 1994-1998 Dario Ballabio.\n");
+      printk("%s config options -> of:%c, lc:%c, mq:%d, eh:%c.\n",
+             driver_name, YESNO(have_old_firmware), YESNO(linked_comm),
+             max_queue_depth, YESNO(use_new_eh_code));
+      }
+
+   printk("%s: %s 0x%03lx, BIOS 0x%05x, IRQ %u, %s, SG %d, MB %d.\n",
+          BN(j), bus_type, (unsigned long)sh[j]->io_port, (int)sh[j]->base,
+          sh[j]->irq, dma_name, sh[j]->sg_tablesize, sh[j]->can_queue);
 
    if (sh[j]->max_id > 8 || sh[j]->max_lun > 8)
       printk("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n",
              BN(j), sh[j]->max_id, sh[j]->max_lun);
 
    for (i = 0; i <= sh[j]->max_channel; i++)
-      printk("%s: SCSI channel %u enabled, host target ID %u.\n",
+      printk("%s: SCSI channel %u enabled, host target ID %d.\n",
              BN(j), i, sh[j]->this_id);
 
    return TRUE;
@@ -862,6 +917,7 @@
       else if (!strncmp(cur, "of:", 3)) have_old_firmware = val;
       else if (!strncmp(cur, "mq:", 3))  max_queue_depth = val;
       else if (!strncmp(cur, "ls:", 3))  link_statistics = val;
+      else if (!strncmp(cur, "eh:", 3))  use_new_eh_code = val;
 
       if ((cur = strchr(cur, ','))) ++cur;
       }
@@ -870,14 +926,12 @@
 }
 
 __initfunc (int u14_34f_detect(Scsi_Host_Template *tpnt)) {
-   unsigned long flags;
    unsigned int j = 0, k;
+   IRQ_FLAGS
 
+   IRQ_LOCK_SAVE
    tpnt->proc_dir = &proc_scsi_u14_34f;
 
-   save_flags(flags);
-   cli();
-
 #if defined(MODULE)
    /* io_port could have been modified when loading as a module */
    if(io_port[0] != SKIP) {
@@ -895,11 +949,8 @@
       if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt)) j++;
       }
 
-   if (j > 0)
-      printk("UltraStor 14F/34F: Copyright (C) 1994-1998 Dario Ballabio.\n");
-
    num_boards = j;
-   restore_flags(flags);
+   IRQ_UNLOCK_RESTORE
    return j;
 }
 
@@ -920,8 +971,7 @@
    cpp->data_len = H2DEV(data_len);
 }
 
-int u14_34f_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
-   unsigned long flags;
+static inline int do_qcomm(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
    unsigned int i, j, k;
    struct mscp *cpp;
 
@@ -937,22 +987,12 @@
       0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5
       };
 
-   save_flags(flags);
-   cli();
    /* j is the board number */
    j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
 
-   if (!done) panic("%s: qcomm, pid %ld, null done.\n", BN(j), SCpnt->pid);
-
-   if (SCpnt->cmnd[0] == REQUEST_SENSE && SCpnt->sense_buffer[0]) {
-      SCpnt->result = DID_OK << 16;
-      SCpnt->host_scribble = NULL;
-      printk("%s: qcomm, target %d.%d:%d, pid %ld, request sense ignored.\n",
-             BN(j), SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid);
-      restore_flags(flags);
-      done(SCpnt);
-      return 0;
-      }
+   if (SCpnt->host_scribble)
+      panic("%s: qcomm, pid %ld, SCpnt %p already active.\n",
+            BN(j), SCpnt->pid, SCpnt);
 
    /* i is the mailbox number, look for the first free mailbox
       starting from last_cp_used */
@@ -969,19 +1009,7 @@
       }
 
    if (k == sh[j]->can_queue) {
-      printk("%s: qcomm, no free mailbox, resetting.\n", BN(j));
-
-      if (HD(j)->in_reset)
-         printk("%s: qcomm, already in reset.\n", BN(j));
-      else if (u14_34f_reset(SCpnt, SCSI_RESET_SUGGEST_BUS_RESET)
-               == SCSI_RESET_SUCCESS)
-         panic("%s: qcomm, SCSI_RESET_SUCCESS.\n", BN(j));
-
-      SCpnt->result = DID_BUS_BUSY << 16;
-      SCpnt->host_scribble = NULL;
-      printk("%s: qcomm, pid %ld, DID_BUS_BUSY, done.\n", BN(j), SCpnt->pid);
-      restore_flags(flags);
-      done(SCpnt);
+      printk("%s: qcomm, no free mailbox.\n", BN(j));
       return 1;
       }
 
@@ -1036,18 +1064,13 @@
                                      && TLDEV(SCpnt->device->type)) {
       HD(j)->cp_stat[i] = READY;
       flush_dev(SCpnt->device, SCpnt->request.sector, j, FALSE);
-      restore_flags(flags);
       return 0;
       }
 
    if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
-      SCpnt->result = DID_ERROR << 16;
       SCpnt->host_scribble = NULL;
-      printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy, DID_ERROR,"\
-             " done.\n", BN(j), SCpnt->channel, SCpnt->target, SCpnt->lun,
-             SCpnt->pid);
-      restore_flags(flags);
-      done(SCpnt);
+      printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy.\n",
+             BN(j), SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid);
       return 1;
       }
 
@@ -1058,23 +1081,29 @@
    outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
 
    HD(j)->cp_stat[i] = IN_USE;
-   restore_flags(flags);
    return 0;
 }
 
-int u14_34f_abort(Scsi_Cmnd *SCarg) {
-   unsigned long flags;
+int u14_34f_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
+   int rtn;
+   IRQ_FLAGS
+
+   IRQ_LOCK_SAVE
+   rtn = do_qcomm(SCpnt, done);
+   IRQ_UNLOCK_RESTORE
+   return rtn;
+}
+
+static inline int do_old_abort(Scsi_Cmnd *SCarg) {
    unsigned int i, j;
 
-   save_flags(flags);
-   cli();
    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
 
-   if (SCarg->host_scribble == NULL
-       || SCarg->serial_number != SCarg->serial_number_at_timeout) {
+   if (SCarg->host_scribble == NULL ||
+       (SCarg->serial_number_at_timeout &&
+       (SCarg->serial_number != SCarg->serial_number_at_timeout))) {
       printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
              BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
-      restore_flags(flags);
       return SCSI_ABORT_NOT_RUNNING;
       }
 
@@ -1087,13 +1116,11 @@
 
    if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
       printk("%s: abort, timeout error.\n", BN(j));
-      restore_flags(flags);
       return SCSI_ABORT_ERROR;
       }
 
    if (HD(j)->cp_stat[i] == FREE) {
       printk("%s: abort, mbox %d is free.\n", BN(j), i);
-      restore_flags(flags);
       return SCSI_ABORT_NOT_RUNNING;
       }
 
@@ -1107,19 +1134,16 @@
       if (inb(sh[j]->io_port + REG_SYS_INTR) & IRQ_ASSERTED)
          printk("%s: abort, mbox %d, interrupt pending.\n", BN(j), i);
 
-      restore_flags(flags);
       return SCSI_ABORT_SNOOZE;
       }
 
    if (HD(j)->cp_stat[i] == IN_RESET) {
       printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
-      restore_flags(flags);
       return SCSI_ABORT_ERROR;
       }
 
    if (HD(j)->cp_stat[i] == LOCKED) {
       printk("%s: abort, mbox %d is locked.\n", BN(j), i);
-      restore_flags(flags);
       return SCSI_ABORT_NOT_RUNNING;
       }
 
@@ -1130,45 +1154,128 @@
       printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
              BN(j), i, SCarg->pid);
       SCarg->scsi_done(SCarg);
-      restore_flags(flags);
       return SCSI_ABORT_SUCCESS;
       }
 
-   restore_flags(flags);
    panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
 }
 
-int u14_34f_reset(Scsi_Cmnd *SCarg, unsigned int reset_flags) {
-   unsigned long flags;
+int u14_34f_old_abort(Scsi_Cmnd *SCarg) {
+   int rtn;
+   IRQ_FLAGS
+
+   IRQ_LOCK_SAVE
+   rtn = do_old_abort(SCarg);
+   IRQ_UNLOCK_RESTORE
+   return rtn;
+}
+
+#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
+
+static inline int do_abort(Scsi_Cmnd *SCarg) {
+   unsigned int i, j;
+
+   j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
+
+   if (SCarg->host_scribble == NULL) {
+      printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n",
+             BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
+      return SUCCESS;
+      }
+
+   i = *(unsigned int *)SCarg->host_scribble;
+   printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n",
+          BN(j), i, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
+
+   if (i >= sh[j]->can_queue)
+      panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
+
+   if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
+      printk("%s: abort, timeout error.\n", BN(j));
+      return FAILED;
+      }
+
+   if (HD(j)->cp_stat[i] == FREE) {
+      printk("%s: abort, mbox %d is free.\n", BN(j), i);
+      return SUCCESS;
+      }
+
+   if (HD(j)->cp_stat[i] == IN_USE) {
+      printk("%s: abort, mbox %d is in use.\n", BN(j), i);
+
+      if (SCarg != HD(j)->cp[i].SCpnt)
+         panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
+               BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
+
+      if (inb(sh[j]->io_port + REG_SYS_INTR) & IRQ_ASSERTED)
+         printk("%s: abort, mbox %d, interrupt pending.\n", BN(j), i);
+
+      if (SCarg->eh_state == SCSI_STATE_TIMEOUT) {
+         SCarg->host_scribble = NULL;
+         HD(j)->cp_stat[i] = FREE;
+         printk("%s, abort, mbox %d, eh_state timeout, pid %ld.\n",
+                BN(j), i, SCarg->pid);
+         return SUCCESS;
+         }
+
+      return FAILED;
+      }
+
+   if (HD(j)->cp_stat[i] == IN_RESET) {
+      printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
+      return FAILED;
+      }
+
+   if (HD(j)->cp_stat[i] == LOCKED) {
+      printk("%s: abort, mbox %d is locked.\n", BN(j), i);
+      return SUCCESS;
+      }
+
+   if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
+      SCarg->result = DID_ABORT << 16;
+      SCarg->host_scribble = NULL;
+      HD(j)->cp_stat[i] = FREE;
+      printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n",
+             BN(j), i, SCarg->pid);
+      SCarg->scsi_done(SCarg);
+      return SUCCESS;
+      }
+
+   panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
+}
+
+int u14_34f_abort(Scsi_Cmnd *SCarg) {
+
+   return do_abort(SCarg);
+}
+
+#endif /* new_eh_code */
+
+static inline int do_old_reset(Scsi_Cmnd *SCarg) {
    unsigned int i, j, time, k, c, limit = 0;
    int arg_done = FALSE;
    Scsi_Cmnd *SCpnt;
 
-   save_flags(flags);
-   cli();
    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
-   printk("%s: reset, enter, target %d.%d:%d, pid %ld, reset_flags %u.\n",
-          BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid,
-          reset_flags);
+   printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n",
+          BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
 
    if (SCarg->host_scribble == NULL)
       printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
 
-   if (SCarg->serial_number != SCarg->serial_number_at_timeout) {
+   if (SCarg->serial_number_at_timeout &&
+       (SCarg->serial_number != SCarg->serial_number_at_timeout)) {
       printk("%s: reset, pid %ld, reset not running.\n", BN(j), SCarg->pid);
-      restore_flags(flags);
       return SCSI_RESET_NOT_RUNNING;
       }
 
    if (HD(j)->in_reset) {
       printk("%s: reset, exit, already in reset.\n", BN(j));
-      restore_flags(flags);
       return SCSI_RESET_ERROR;
       }
 
    if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
       printk("%s: reset, exit, timeout error.\n", BN(j));
-      restore_flags(flags);
       return SCSI_RESET_ERROR;
       }
 
@@ -1219,22 +1326,23 @@
 
    if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
       printk("%s: reset, cannot reset, timeout error.\n", BN(j));
-      restore_flags(flags);
       return SCSI_RESET_ERROR;
       }
 
    outb(CMD_RESET, sh[j]->io_port + REG_LCL_INTR);
    printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
 
-#if defined (DEBUG_RESET)
+#if defined(DEBUG_RESET)
    do_trace = TRUE;
 #endif
 
    HD(j)->in_reset = TRUE;
-
-   /* Wait 2 seconds ???!!! */
-   { unsigned int msec = 2*1000; while (--msec) udelay(1000); }
-
+   SPIN_UNLOCK
+   IRQ_UNLOCK
+   time = jiffies;
+   while ((jiffies - time) < (10 * HZ) && limit++ < 200000) udelay(100L);
+   IRQ_LOCK
+   SPIN_LOCK
    printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
 
    for (i = 0; i < sh[j]->can_queue; i++) {
@@ -1268,14 +1376,12 @@
          /* Any other mailbox has already been set free by interrupt */
          continue;
 
-      restore_flags(flags);
       SCpnt->scsi_done(SCpnt);
-      cli();
+      IRQ_LOCK
       }
 
    HD(j)->in_reset = FALSE;
    do_trace = FALSE;
-   restore_flags(flags);
 
    if (arg_done) {
       printk("%s: reset, exit, success.\n", BN(j));
@@ -1287,6 +1393,157 @@
       }
 }
 
+int u14_34f_old_reset(Scsi_Cmnd *SCarg, unsigned int reset_flags) {
+   int rtn;
+   IRQ_FLAGS
+
+   IRQ_LOCK_SAVE
+   rtn = do_old_reset(SCarg);
+   IRQ_UNLOCK_RESTORE
+   return rtn;
+}
+
+#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101)
+
+static inline int do_reset(Scsi_Cmnd *SCarg) {
+   unsigned int i, j, time, k, c, limit = 0;
+   int arg_done = FALSE;
+   Scsi_Cmnd *SCpnt;
+
+   j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
+   printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n",
+          BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid);
+
+   if (SCarg->host_scribble == NULL)
+      printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
+
+   if (HD(j)->in_reset) {
+      printk("%s: reset, exit, already in reset.\n", BN(j));
+      return FAILED;
+      }
+
+   if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
+      printk("%s: reset, exit, timeout error.\n", BN(j));
+      return FAILED;
+      }
+
+   HD(j)->retries = 0;
+
+   for (c = 0; c <= sh[j]->max_channel; c++)
+      for (k = 0; k < sh[j]->max_id; k++) {
+         HD(j)->target_redo[k][c] = TRUE;
+         HD(j)->target_to[k][c] = 0;
+         }
+
+   for (i = 0; i < sh[j]->can_queue; i++) {
+
+      if (HD(j)->cp_stat[i] == FREE) continue;
+
+      if (HD(j)->cp_stat[i] == LOCKED) {
+         HD(j)->cp_stat[i] = FREE;
+         printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
+         continue;
+         }
+
+      if (!(SCpnt = HD(j)->cp[i].SCpnt))
+         panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
+
+      if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) {
+         HD(j)->cp_stat[i] = ABORTING;
+         printk("%s: reset, mbox %d aborting, pid %ld.\n",
+                BN(j), i, SCpnt->pid);
+         }
+
+      else {
+         HD(j)->cp_stat[i] = IN_RESET;
+         printk("%s: reset, mbox %d in reset, pid %ld.\n",
+                BN(j), i, SCpnt->pid);
+         }
+
+      if (SCpnt->host_scribble == NULL)
+         panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
+
+      if (*(unsigned int *)SCpnt->host_scribble != i)
+         panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
+
+      if (SCpnt->scsi_done == NULL)
+         panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
+
+      if (SCpnt == SCarg) arg_done = TRUE;
+      }
+
+   if (wait_on_busy(sh[j]->io_port, MAXLOOP)) {
+      printk("%s: reset, cannot reset, timeout error.\n", BN(j));
+      return FAILED;
+      }
+
+   outb(CMD_RESET, sh[j]->io_port + REG_LCL_INTR);
+   printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
+
+#if defined(DEBUG_RESET)
+   do_trace = TRUE;
+#endif
+
+   HD(j)->in_reset = TRUE;
+   SPIN_UNLOCK
+   IRQ_UNLOCK
+   time = jiffies;
+   while ((jiffies - time) < (10 * HZ) && limit++ < 200000) udelay(100L);
+   IRQ_LOCK
+   SPIN_LOCK
+   printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
+
+   for (i = 0; i < sh[j]->can_queue; i++) {
+
+      if (HD(j)->cp_stat[i] == IN_RESET) {
+         SCpnt = HD(j)->cp[i].SCpnt;
+         SCpnt->result = DID_RESET << 16;
+         SCpnt->host_scribble = NULL;
+
+         /* This mailbox is still waiting for its interrupt */
+         HD(j)->cp_stat[i] = LOCKED;
+
+         printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
+                BN(j), i, SCpnt->pid);
+         }
+
+      else if (HD(j)->cp_stat[i] == ABORTING) {
+         SCpnt = HD(j)->cp[i].SCpnt;
+         SCpnt->result = DID_RESET << 16;
+         SCpnt->host_scribble = NULL;
+
+         /* This mailbox was never queued to the adapter */
+         HD(j)->cp_stat[i] = FREE;
+
+         printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n",
+                BN(j), i, SCpnt->pid);
+         }
+
+      else
+
+         /* Any other mailbox has already been set free by interrupt */
+         continue;
+
+      SCpnt->scsi_done(SCpnt);
+      IRQ_LOCK
+      }
+
+   HD(j)->in_reset = FALSE;
+   do_trace = FALSE;
+
+   if (arg_done) printk("%s: reset, exit, pid %ld done.\n", BN(j), SCarg->pid);
+   else          printk("%s: reset, exit.\n", BN(j));
+
+   return SUCCESS;
+}
+
+int u14_34f_reset(Scsi_Cmnd *SCarg) {
+
+   return do_reset(SCarg);
+}
+
+#endif /* new_eh_code */
+
 int u14_34f_biosparam(Disk *disk, kdev_t dev, int *dkinfo) {
    unsigned int j = 0;
    int size = disk->capacity;
@@ -1404,7 +1661,7 @@
       if (!rev && !s)    { sortcount++; readysorted += n_ready; }
       }
 
-#if defined (DEBUG_LINKED_COMMANDS)
+#if defined(DEBUG_LINKED_COMMANDS)
    if (link_statistics && (overlap || !(flushcount % link_statistics)))
       for (n = 0; n < n_ready; n++) {
          k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
@@ -1489,6 +1746,10 @@
    /* Clear interrupt pending flag */
    outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
 
+#if defined(DEBUG_GENERATE_ABORTS)
+   if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 500) < 3)) return;
+#endif
+
    /* Find the mailbox to be serviced on this board */
    i = cpp - HD(j)->cp;
 
@@ -1537,6 +1798,11 @@
 
    tstatus = status_byte(spp->target_status);
 
+#if defined(DEBUG_GENERATE_ERRORS)
+   if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 200) < 2))
+                                           spp->adapter_status = 0x01;
+#endif
+
    switch (spp->adapter_status) {
       case ASOK:     /* status OK */
 
@@ -1599,7 +1865,13 @@
 
          if (SCpnt->device->type != TYPE_TAPE
              && HD(j)->retries < MAX_INTERNAL_RETRIES) {
+
+#if defined(DID_SOFT_ERROR)
+            status = DID_SOFT_ERROR << 16;
+#else
             status = DID_BUS_BUSY << 16;
+#endif
+
             HD(j)->retries++;
             HD(j)->last_retried_pid = SCpnt->pid;
             }
@@ -1621,7 +1893,7 @@
 
    SCpnt->result = status | spp->target_status;
 
-#if defined (DEBUG_INTERRUPT)
+#if defined(DEBUG_INTERRUPT)
    if (SCpnt->result || do_trace)
 #else
    if ((spp->adapter_status != ASOK && HD(j)->iocount >  1000) ||
@@ -1647,31 +1919,25 @@
 }
 
 static void do_interrupt_handler(int irq, void *shap, struct pt_regs *regs) {
-
    unsigned int j;
+   IRQ_FLAGS
+   SPIN_FLAGS
 
    /* Check if the interrupt must be processed by this handler */
    if ((j = (unsigned int)((char *)shap - sha)) >= num_boards) return;
 
-#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,95)
-   {
-   unsigned long flags;
-   spin_lock_irqsave(&io_request_lock, flags);
+   SPIN_LOCK_SAVE
+   IRQ_LOCK_SAVE
    ihdlr(irq, j);
-   spin_unlock_irqrestore(&io_request_lock, flags);
-   }
-#else
-   ihdlr(irq, j);
-#endif
-
+   IRQ_UNLOCK_RESTORE
+   SPIN_UNLOCK_RESTORE
 }
 
 int u14_34f_release(struct Scsi_Host *shpnt) {
-   unsigned long flags;
    unsigned int i, j;
+   IRQ_FLAGS
 
-   save_flags(flags);
-   cli();
+   IRQ_LOCK_SAVE
 
    for (j = 0; sh[j] != NULL && sh[j] != shpnt; j++);
 
@@ -1687,7 +1953,7 @@
 
    release_region(sh[j]->io_port, sh[j]->n_io_port);
    scsi_unregister(sh[j]);
-   restore_flags(flags);
+   IRQ_UNLOCK_RESTORE
    return FALSE;
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov