patch-2.2.0-pre7 linux/drivers/scsi/gdth.c

Next file: linux/drivers/scsi/gdth.h
Previous file: linux/drivers/scsi/atari_dma_emul.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.0-pre6/linux/drivers/scsi/gdth.c linux/drivers/scsi/gdth.c
@@ -2,7 +2,7 @@
  * GDT ISA/EISA/PCI Disk Array Controller driver for Linux              *
  *                                                                      *
  * gdth.c                                                               *
- * Copyright (C) 1995-97 ICP vortex Computersysteme GmbH, Achim Leubner *
+ * Copyright (C) 1995-98 ICP vortex Computersysteme GmbH, Achim Leubner *
  *                                                                      *
  * <achim@vortex.de>                                                    *
  *                                                                      *
@@ -20,27 +20,49 @@
  * along with this kernel; if not, write to the Free Software           *
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
  *                                                                      *
- * Tested with Linux 1.2.13, ..., 2.1.61                                *
+ * Tested with Linux 1.2.13, ..., 2.1.131                               *
  *                                                                      *
  * $Log: gdth.c,v $
- * Revision 1.3  1998/02/25 23:52:32  ecd
- * Final round of PCI device driver patches by Martin Mares.
+ * Revision 1.17  1998/12/17 15:58:11  achim
+ * Command line parameters implemented
+ * Changes for Alpha platforms
+ * PCI controller scan changed
+ * SMP support improved (spin_lock_irqsave(),...)
+ * New async. events, new scan/reserve commands included
  *
- * I could not verify each and every change to the drivers locally,
- * please consult linux/Documentation/pci.txt to understand changes
- * made in case patching should be necessary.
+ * Revision 1.16  1998/09/28 16:08:46  achim
+ * GDT_PCIMPR: DPMEM remapping, if required
+ * mdelay() added
  *
- * Revision 1.2  1997/11/12 23:58:51  davem
- * Merge to 2.1.63 to get the Ingo P5 bugfix.
- * I did not touch the sound changes at all, Alan
- * please look into that stuff as it is your
- * territory.
+ * Revision 1.15  1998/06/03 14:54:06  achim
+ * gdth_delay(), gdth_flush() implemented
+ * Bugfix: gdth_release() changed
+ *
+ * Revision 1.14  1998/05/22 10:01:17  achim
+ * mj: pcibios_strerror() removed
+ * Improved SMP support (if version >= 2.1.95)
+ * gdth_halt(): halt_called flag added (if version < 2.1)
+ *
+ * Revision 1.13  1998/04/16 09:14:57  achim
+ * Reserve drives (for raw service) implemented
+ * New error handling code enabled
+ * Get controller name from board_info() IOCTL
+ * Final round of PCI device driver patches by Martin Mares
+ *
+ * Revision 1.12  1998/03/03 09:32:37  achim
+ * Fibre channel controller support added
+ *
+ * Revision 1.11  1998/01/27 16:19:14  achim
+ * SA_SHIRQ added
+ * add_timer()/del_timer() instead of GDTH_TIMER
+ * scsi_add_timer()/scsi_del_timer() instead of SCSI_TIMER
+ * New error handling included
  *
  * Revision 1.10  1997/10/31 12:29:57  achim
  * Read heads/sectors from host drive
  *
  * Revision 1.9  1997/09/04 10:07:25  achim
- * IO-mapping with virt_to_bus(), readb(), writeb(), ...
+ * IO-mapping with virt_to_bus(), gdth_readb(), gdth_writeb(), ...
  * register_reboot_notifier() to get a notify on shutdown used
  *
  * Revision 1.8  1997/04/02 12:14:30  achim
@@ -72,9 +94,49 @@
  * Revision 1.1  1996/04/11 07:35:57  achim
  * Initial revision
  *
- *
- * $Id: gdth.c,v 1.4 1998/04/15 14:35:26 mj Exp $ 
  ************************************************************************/
+#ident "$Id: gdth.c,v 1.17 1998/12/17 15:58:11 achim Exp $" 
+
+/* All GDT Disk Array Controllers are fully supported by this driver.
+ * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the
+ * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete
+ * list of all controller types.
+ * 
+ * If you have one or more GDT3000/3020 EISA controllers with 
+ * controller BIOS disabled, you have to set the IRQ values with the 
+ * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are
+ * the IRQ values for the EISA controllers.
+ * 
+ * After the optional list of IRQ values, other possible 
+ * command line options are:
+ * disable:Y                    disable driver
+ * disable:N                    enable driver
+ * reserve_mode:0               reserve no drives for the raw service
+ * reserve_mode:1               reserve all not init., removable drives
+ * reserve_mode:2               reserve all not init. drives
+ * reserve_list:h,b,t,l,h,b,t,l,...     reserve particular drive(s) with 
+ *                              h- controller no., b- channel no., 
+ *                              t- target ID, l- LUN
+ * reverse_scan:Y               reverse scan order for PCI controllers         
+ * reverse_scan:N               scan PCI controllers like BIOS
+ * max_ids:x                    x - target ID count per channel (1..MAXID)
+ * rescan:Y                     rescan all channels/IDs 
+ * rescan:N                     use all devices found until now
+ *
+ * The default value is: "gdth=disable:N,reserve_mode:1,reverse_scan:N,
+ *                        max_ids:127,rescan:N".
+ * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y".
+ * 
+ * When loading the gdth driver as a module, the same options are available. 
+ * You can set the IRQs with "IRQ=...". However, the syntax to specify the
+ * options changes slightly. You must replace all ',' between options 
+ * with ' ' and all ':' with '=' and you must use 
+ * '1' in place of 'Y' and '0' in place of 'N'.
+ * 
+ * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0
+ *                         max_ids=127 rescan=0"
+ * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1".
+ */
 
 #ifdef MODULE
 #include <linux/module.h>
@@ -85,6 +147,7 @@
 #include <linux/types.h>
 #include <linux/pci.h>
 #include <linux/string.h>
+#include <linux/ctype.h>
 #include <linux/ioport.h>
 #include <linux/delay.h>
 #include <linux/sched.h>
@@ -101,7 +164,9 @@
 #include <asm/dma.h>
 #include <asm/system.h>
 #include <asm/io.h>
+#if LINUX_VERSION_CODE >= 0x02015F
 #include <asm/spinlock.h>
+#endif
 
 #if LINUX_VERSION_CODE >= 0x010300
 #include <linux/blk.h>
@@ -116,33 +181,34 @@
 
 #if LINUX_VERSION_CODE >= 0x010346
 static void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs);
-static void do_gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs);
 #else
 static void gdth_interrupt(int irq,struct pt_regs *regs);
 #endif
 static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp);
 static int gdth_async_event(int hanum,int service);
+static void gdth_log_event(gdth_evt_data *dvr);
 
 static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority);
 static void gdth_next(int hanum);
 static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b);
-static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp,unchar b);
-static gdth_evt_str *gdth_store_event(ushort source, ushort idx,
-                                      gdth_evt_data *evt);
-static int gdth_read_event(int handle, gdth_evt_str *estr);
-static void gdth_readapp_event(unchar application, gdth_evt_str *estr);
+static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp);
+static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
+                                      ushort idx, gdth_evt_data *evt);
+static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);
+static void gdth_readapp_event(gdth_ha_str *ha, unchar application, 
+                               gdth_evt_str *estr);
 static void gdth_clear_events(void);
 
 static void gdth_copy_internal_data(Scsi_Cmnd *scp,char *buffer,ushort count);
-static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp,
-                                   unchar b,ulong *flags);
+static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp);
 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive);
 
 static int gdth_search_eisa(ushort eisa_adr);
-static int gdth_search_isa(ulong bios_adr);
-static int gdth_search_pci(ushort device_id,ushort index,gdth_pci_str *pcistr);
+static int gdth_search_isa(ulong32 bios_adr);
+static int gdth_search_pci(gdth_pci_str *pcistr);
+static void gdth_sort_pci(gdth_pci_str *pcistr, int cnt);
 static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha);
-static int gdth_init_isa(ulong bios_adr,gdth_ha_str *ha);
+static int gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha);
 static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha);
 
 static void gdth_enable_int(int hanum);
@@ -150,38 +216,28 @@
 static int gdth_test_busy(int hanum);
 static int gdth_get_cmd_index(int hanum);
 static void gdth_release_event(int hanum);
-static int gdth_wait(int hanum,int index,ulong time);
-static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong p1,
-                             ulong p2,ulong p3);
+static int gdth_wait(int hanum,int index,ulong32 time);
+static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
+                             ulong32 p2,ulong32 p3);
 static int gdth_search_drives(int hanum);
 
 static void *gdth_mmap(ulong paddr, ulong size);
 static void gdth_munmap(void *addr);
 
 static const char *gdth_ctr_name(int hanum);
+
+static void gdth_flush(int hanum);
 #if LINUX_VERSION_CODE >= 0x020100
 static int gdth_halt(struct notifier_block *nb, ulong event, void *buf);
 #else
+static int halt_called = FALSE;
 void gdth_halt(void);
 #endif
 
 #ifdef DEBUG_GDTH
 static unchar   DebugState = DEBUG_GDTH;
 extern int sys_syslog(int,char*,int);
-#define LOGEN           sys_syslog(7,NULL,0);
-#define WAITSEC(a)      mdelay((a)*1000)
-
-#ifdef SLOWMOTION_GDTH
-#define SLOWM   WAITSEC(2)  
-#undef  INIT_RETRIES
-#undef  INIT_TIMEOUT
-#undef  POLL_TIMEOUT
-#define INIT_RETRIES    15
-#define INIT_TIMEOUT    150
-#define POLL_TIMEOUT    150
-#else
-#define SLOWM
-#endif
+#define LOGEN sys_syslog(7,NULL,0)
 
 #ifdef __SERIAL__
 #define MAX_SERBUF 160
@@ -245,14 +301,14 @@
     return i;
 }
 
-#define TRACE(a)    {if (DebugState==1) {ser_printk a; SLOWM}}
-#define TRACE2(a)   {if (DebugState==1 || DebugState==2) {ser_printk a; SLOWM}}
-#define TRACE3(a)   {if (DebugState!=0) {ser_printk a; SLOWM}}
+#define TRACE(a)    {if (DebugState==1) {ser_printk a;}}
+#define TRACE2(a)   {if (DebugState==1 || DebugState==2) {ser_printk a;}}
+#define TRACE3(a)   {if (DebugState!=0) {ser_printk a;}}
 
 #else /* !__SERIAL__ */
-#define TRACE(a)    {if (DebugState==1) {LOGEN;printk a; SLOWM}}
-#define TRACE2(a)   {if (DebugState==1 || DebugState==2) {LOGEN;printk a; SLOWM}}
-#define TRACE3(a)   {if (DebugState!=0) {LOGEN;printk a; SLOWM}}
+#define TRACE(a)    {if (DebugState==1) {LOGEN;printk a;}}
+#define TRACE2(a)   {if (DebugState==1 || DebugState==2) {LOGEN;printk a;}}
+#define TRACE3(a)   {if (DebugState!=0) {LOGEN;printk a;}}
 #endif
 
 #else /* !DEBUG */
@@ -262,70 +318,77 @@
 #endif
 
 #ifdef GDTH_STATISTICS
-static ulong max_rq=0, max_index=0, max_sg=0;
-static ulong act_ints=0, act_ios=0, act_stats=0, act_rq=0;
-#define GDTH_TIMER      31                      /* see linux/timer.h ! */
+static ulong32 max_rq=0, max_index=0, max_sg=0;
+static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0;
+static struct timer_list gdth_timer;
 #endif
 
 #define PTR2USHORT(a)   (ushort)(ulong)(a)
-#define JIFFYWAIT(a)    {ulong gdtjf;gdtjf=jiffies+(a);while(time_before(jiffies,gdtjf));}
 #define GDTOFFSOF(a,b)  (size_t)&(((a*)0)->b)   
 #define INDEX_OK(i,t)   ((i)<sizeof(t)/sizeof((t)[0]))
 
 #define NUMDATA(a)      ( (gdth_num_str  *)((a)->hostdata))
 #define HADATA(a)       (&((gdth_ext_str *)((a)->hostdata))->haext)
 #define CMDDATA(a)      (&((gdth_ext_str *)((a)->hostdata))->cmdext)
-#define DMADATA(a)      (&((gdth_ext_str *)((a)->hostdata))->dmaext)
 
 
 #if LINUX_VERSION_CODE < 0x010300
 static void *gdth_mmap(ulong paddr, ulong size) 
 {
     if (paddr >= high_memory)
-	return NULL; 
+        return NULL; 
     else
-	return (void *)paddr;
+        return (void *)paddr;
 }
 static void gdth_munmap(void *addr) 
 {
 }
-inline ulong virt_to_phys(volatile void *addr)
+inline ulong32 virt_to_phys(volatile void *addr)
 {
-    return (ulong)addr;
+    return (ulong32)addr;
 }
-inline void *phys_to_virt(ulong addr)
+inline void *phys_to_virt(ulong32 addr)
 {
     return (void *)addr;
 }
-#define virt_to_bus		virt_to_phys
-#define bus_to_virt		phys_to_virt
-#define readb(addr)		(*(volatile unchar *)(addr))
-#define readw(addr)		(*(volatile ushort *)(addr))
-#define readl(addr)		(*(volatile ulong *)(addr))
-#define writeb(b,addr)		(*(volatile unchar *)(addr) = (b))
-#define writew(b,addr)		(*(volatile ushort *)(addr) = (b))
-#define writel(b,addr)		(*(volatile ulong *)(addr) = (b))
-#define memset_io(a,b,c)	memset((void *)(a),(b),(c))
-#define memcpy_fromio(a,b,c)	memcpy((a),(void *)(b),(c))
-#define memcpy_toio(a,b,c)	memcpy((void *)(a),(b),(c))
+#define virt_to_bus             virt_to_phys
+#define bus_to_virt             phys_to_virt
+#define gdth_readb(addr)        (*(volatile unchar *)(addr))
+#define gdth_readw(addr)        (*(volatile ushort *)(addr))
+#define gdth_readl(addr)        (*(volatile ulong32 *)(addr))
+#define gdth_writeb(b,addr)     (*(volatile unchar *)(addr) = (b))
+#define gdth_writew(b,addr)     (*(volatile ushort *)(addr) = (b))
+#define gdth_writel(b,addr)     (*(volatile ulong32 *)(addr) = (b))
+#define memset_io(a,b,c)        memset((void *)(a),(b),(c))
+#define memcpy_fromio(a,b,c)    memcpy((a),(void *)(b),(c))
+#define memcpy_toio(a,b,c)      memcpy((void *)(a),(b),(c))
+
+#define PCI_SLOT(devfn)         ((devfn >> 3) & 0x1f)
 
 #elif LINUX_VERSION_CODE < 0x020100
 static int remapped = FALSE;
 static void *gdth_mmap(ulong paddr, ulong size) 
 {
     if ( paddr >= high_memory) {
-	remapped = TRUE;
-	return vremap(paddr, size);
+        remapped = TRUE;
+        return vremap(paddr, size);
     } else {
-	return (void *)paddr; 
+        return (void *)paddr; 
     }
 }
 static void gdth_munmap(void *addr) 
 {
     if (remapped)
-	vfree(addr);
+        vfree(addr);
     remapped = FALSE;
 }
+#define gdth_readb(addr)        readb((ulong)(addr))
+#define gdth_readw(addr)        readw((ulong)(addr))
+#define gdth_readl(addr)        (ulong32)readl((ulong)(addr))
+#define gdth_writeb(b,addr)     writeb((b),(ulong)(addr))
+#define gdth_writew(b,addr)     writew((b),(ulong)(addr))
+#define gdth_writel(b,addr)     writel((b),(ulong)(addr))
+
 #else
 static void *gdth_mmap(ulong paddr, ulong size) 
 { 
@@ -335,6 +398,12 @@
 {
     return iounmap(addr);
 }
+#define gdth_readb(addr)        readb((ulong)(addr))
+#define gdth_readw(addr)        readw((ulong)(addr))
+#define gdth_readl(addr)        (ulong32)readl((ulong)(addr))
+#define gdth_writeb(b,addr)     writeb((b),(ulong)(addr))
+#define gdth_writew(b,addr)     writew((b),(ulong)(addr))
+#define gdth_writel(b,addr)     writel((b),(ulong)(addr))
 #endif
 
 
@@ -345,19 +414,14 @@
 static int      wait_index,wait_hanum;                  /* gdth_wait() */
 static int      gdth_ctr_count  = 0;                    /* controller count */
 static int      gdth_ctr_vcount = 0;                    /* virt. ctr. count */
+static int      gdth_ctr_released = 0;                  /* gdth_release() */
 static struct Scsi_Host *gdth_ctr_tab[MAXHA];           /* controller table */
 static struct Scsi_Host *gdth_ctr_vtab[MAXHA*MAXBUS];   /* virt. ctr. table */
 static unchar   gdth_write_through = FALSE;             /* write through */
-static char *gdth_ioctl_tab[4][MAXHA];                  /* ioctl buffer */
 static gdth_evt_str ebuffer[MAX_EVENTS];                /* event buffer */
 static int elastidx;
 static int eoldidx;
 
-static struct {
-    Scsi_Cmnd   *cmnd;                          /* pending request */
-    ushort      service;                        /* service */
-} gdth_cmd_tab[GDTH_MAXCMDS][MAXHA];            /* table of pend. requests */
-
 #define DIN     1                               /* IN data direction */
 #define DOU     2                               /* OUT data direction */
 #define DNO     DIN                             /* no data transfer */
@@ -381,17 +445,34 @@
     DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN,DUN
 };
 
-/* LILO params: gdth=<IRQ>
- *
- * Where: <IRQ> is any of the valid IRQs for EISA controllers (10,11,12,14)
- * Sets the IRQ of the GDT3000/3020 EISA controller to this value,
- * if the IRQ can not automat. detect (controller BIOS disabled)
- * See gdth_init_eisa() 
- *
- * You can use the command line gdth=0 to disable the driver 
- */
-static unchar irqs[MAXHA] = {0xff};
-static unchar disable_gdth_scan = FALSE;
+/* __initfunc, __initdata macros */
+#if LINUX_VERSION_CODE >= 0x020126
+#include <linux/init.h>
+#else
+#define __initfunc(A) A
+#define __initdata
+#define __init
+#endif
+
+#if LINUX_VERSION_CODE >= 0x02015F
+#define GDTH_INIT_LOCK_HA(ha)           spin_lock_init(&(ha)->smp_lock)
+#define GDTH_LOCK_HA(ha,flags)          spin_lock_irqsave(&(ha)->smp_lock,flags)
+#define GDTH_UNLOCK_HA(ha,flags)        spin_unlock_irqrestore(&(ha)->smp_lock,flags)
+
+#define GDTH_LOCK_SCSI_DONE(flags)      spin_lock_irqsave(&io_request_lock,flags)
+#define GDTH_UNLOCK_SCSI_DONE(flags)    spin_unlock_irqrestore(&io_request_lock,flags)
+#define GDTH_LOCK_SCSI_DOCMD()          spin_lock_irq(&io_request_lock)
+#define GDTH_UNLOCK_SCSI_DOCMD()        spin_unlock_irq(&io_request_lock)
+#else
+#define GDTH_INIT_LOCK_HA(ha)           do {} while (0)
+#define GDTH_LOCK_HA(ha,flags)          do {save_flags(flags); cli();} while (0)
+#define GDTH_UNLOCK_HA(ha,flags)        do {restore_flags(flags);} while (0)
+
+#define GDTH_LOCK_SCSI_DONE(flags)      do {} while (0)
+#define GDTH_UNLOCK_SCSI_DONE(flags)    do {} while (0)
+#define GDTH_LOCK_SCSI_DOCMD()          do {} while (0)
+#define GDTH_UNLOCK_SCSI_DOCMD()        do {} while (0)
+#endif
 
 /* /proc support */
 #if LINUX_VERSION_CODE >= 0x010300
@@ -411,11 +492,63 @@
 };
 #endif
 
+
+/* LILO and modprobe/insmod parameters */
+/* IRQ list for GDT3000/3020 EISA controllers */
+static int irq[MAXHA] __initdata = 
+{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
+/* disable driver flag */
+static int disable __initdata = 0;
+/* reserve flag */
+static int reserve_mode __initdata = 1;                  
+/* reserve list */
+static int reserve_list[MAX_RES_ARGS] __initdata = 
+{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
+/* scan order for PCI controllers */
+static int reverse_scan __initdata = 0;
+/* max. IDs per channel */
+static int max_ids = MAXID;
+/* rescan all IDs */
+static int rescan = 0;
+
+#ifdef MODULE
+#if LINUX_VERSION_CODE >= 0x02011A
+/* parameters for modprobe/insmod */
+MODULE_PARM(irq, "i");
+MODULE_PARM(disable, "i");
+MODULE_PARM(reserve_mode, "i");
+MODULE_PARM(reserve_list, "4-" __MODULE_STRING(MAX_RES_ARGS) "i");
+MODULE_PARM(reverse_scan, "i");
+MODULE_PARM(max_ids, "i");
+MODULE_PARM(rescan, "i");
+MODULE_AUTHOR("Achim Leubner");
+#endif
+#endif
+
+
+static void gdth_delay(int milliseconds)
+{
+    if (milliseconds == 0) {
+        udelay(1);
+    } else {
+#if LINUX_VERSION_CODE >= 0x020168
+        mdelay(milliseconds);
+#else
+        int i;
+        for (i = 0; i < milliseconds; ++i) 
+            udelay(1000);
+#endif
+    }
+}
+
 /* controller search and initialization functions */
 
-static int gdth_search_eisa(ushort eisa_adr)
+__initfunc (static int gdth_search_eisa(ushort eisa_adr))
 {
-    ulong id;
+    ulong32 id;
     
     TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
     id = inl(eisa_adr+ID0REG);
@@ -431,99 +564,181 @@
 }
 
 
-static int gdth_search_isa(ulong bios_adr)
+__initfunc (static int gdth_search_isa(ulong32 bios_adr))
 {
     void *addr;
-    ulong id;
+    ulong32 id;
 
-    TRACE(("gdth_search_isa() bios adr. %lx\n",bios_adr));
-    if ((addr = gdth_mmap(bios_adr+BIOS_ID_OFFS, sizeof(ulong))) != NULL) {
-	id = readl(addr);
-	gdth_munmap(addr);
-	if (id == GDT2_ID)                          /* GDT2000 */
-	    return 1;
+    TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
+    if ((addr = gdth_mmap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
+        id = gdth_readl(addr);
+        gdth_munmap(addr);
+        if (id == GDT2_ID)                          /* GDT2000 */
+            return 1;
     }
     return 0;
 }
 
 
-static int gdth_search_pci(ushort device_id,ushort index,gdth_pci_str *pcistr)
+__initfunc (static int gdth_search_pci(gdth_pci_str *pcistr))
 {
+    ulong32 base0, base1, base2;
+    ushort device_id, cnt;
+#if LINUX_VERSION_CODE >= 0x2015C
+    struct pci_dev *pdev;
+#else
     int error;
-    ulong base0,base1,base2;
-
-    TRACE(("gdth_search_pci() device_id %d, index %d\n",
-                 device_id,index));
-
-    if (!pci_present())
-        return 0;
-
-    if (pcibios_find_device(PCI_VENDOR_ID_VORTEX,device_id,index,
-                             &pcistr->bus,&pcistr->device_fn))
-        return 0;
+    ushort idx;
+#endif
+    
+    TRACE(("gdth_search_pci()\n"));
 
-    /* GDT PCI controller found, now read resources from config space */
-#if LINUX_VERSION_CODE >= 0x20155
-    {
-	struct pci_dev *pdev = pci_find_slot(pcistr->bus, pcistr->device_fn);
-	base0 = pdev->base_address[0];
-	base1 = pdev->base_address[1];
-	base2 = pdev->base_address[2];
-	if ((error = pcibios_read_config_dword(pcistr->bus,pcistr->device_fn,
-                                           PCI_ROM_ADDRESS,
-                                           (int *) &pcistr->bios))) {
-		printk("GDT-PCI: error %d reading configuration space", error);
-		return -1;
-		}
-	pcistr->irq = pdev->irq;
-    }
-#else
+    cnt = 0;
+    for (device_id = 0; device_id <= PCI_DEVICE_ID_VORTEX_GDTMAXRP; 
+         ++device_id) {
+        if (device_id > PCI_DEVICE_ID_VORTEX_GDT6555 &&
+            device_id < PCI_DEVICE_ID_VORTEX_GDT6x17RP)
+            continue;
+#if LINUX_VERSION_CODE >= 0x2015C
+        pdev = NULL;
+        while ((pdev = pci_find_device(PCI_VENDOR_ID_VORTEX,device_id,pdev)) 
+               != NULL) {
+            if (cnt >= MAXHA)
+                return cnt;
+            /* GDT PCI controller found, resources are already in pdev */
+            pcistr[cnt].pdev = pdev;
+            pcistr[cnt].device_id = device_id;
+            pcistr[cnt].bus = pdev->bus->number;
+            pcistr[cnt].device_fn = pdev->devfn;
+            pcistr[cnt].irq = pdev->irq;
+            base0 = pdev->base_address[0];
+            base1 = pdev->base_address[1];
+            base2 = pdev->base_address[2];
+            if (device_id <= PCI_DEVICE_ID_VORTEX_GDT6000B ||   /* GDT6000/B */
+                device_id >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) {  /* MPR */
+                if ((base0 & PCI_BASE_ADDRESS_SPACE) != 
+                    PCI_BASE_ADDRESS_SPACE_MEMORY)
+                    continue;
+                pcistr[cnt].dpmem = base0 & PCI_BASE_ADDRESS_MEM_MASK;
+            } else {                                    /* GDT6110, GDT6120, .. */
+                if ((base0 & PCI_BASE_ADDRESS_SPACE) !=
+                    PCI_BASE_ADDRESS_SPACE_MEMORY ||
+                    (base2 & PCI_BASE_ADDRESS_SPACE) !=
+                    PCI_BASE_ADDRESS_SPACE_MEMORY ||
+                    (base1 & PCI_BASE_ADDRESS_SPACE) !=
+                    PCI_BASE_ADDRESS_SPACE_IO)
+                    continue;
+                pcistr[cnt].dpmem = base2 & PCI_BASE_ADDRESS_MEM_MASK;
+                pcistr[cnt].io_mm = base0 & PCI_BASE_ADDRESS_MEM_MASK;
+                pcistr[cnt].io    = base1 & PCI_BASE_ADDRESS_IO_MASK;
+            }
+            TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%x\n",
+                    pcistr[cnt].bus, PCI_SLOT(pcistr[cnt].device_fn), 
+                    pcistr[cnt].irq, pcistr[cnt].dpmem));
+            cnt++;
+        }       
+#else   
+        idx = 0;
+        while (!pcibios_find_device(PCI_VENDOR_ID_VORTEX,device_id,idx++,
+                                    &pcistr[cnt].bus,&pcistr[cnt].device_fn)) {
+            if (cnt >= MAXHA)
+                return cnt;
+            /* GDT PCI ctr. found, now read resources from config space */
 #if LINUX_VERSION_CODE >= 0x010300
 #define GDTH_BASEP      (int *)
 #else
 #define GDTH_BASEP
 #endif
-    if ((error = pcibios_read_config_dword(pcistr->bus,pcistr->device_fn,
-                                           PCI_BASE_ADDRESS_0,
-                                           GDTH_BASEP&base0)) ||
-        (error = pcibios_read_config_dword(pcistr->bus,pcistr->device_fn,
-                                           PCI_BASE_ADDRESS_1,
-                                           GDTH_BASEP&base1)) ||
-        (error = pcibios_read_config_dword(pcistr->bus,pcistr->device_fn,
-                                           PCI_BASE_ADDRESS_2,
-                                           GDTH_BASEP&base2)) ||
-        (error = pcibios_read_config_dword(pcistr->bus,pcistr->device_fn,
-                                           PCI_ROM_ADDRESS,
-                                           GDTH_BASEP&pcistr->bios)) ||
-        (error = pcibios_read_config_byte(pcistr->bus,pcistr->device_fn,
-                                          PCI_INTERRUPT_LINE,&pcistr->irq))) {
-        printk("GDT-PCI: error %d reading configuration space", error);
-        return -1;
-    }
+            if ((error = pcibios_read_config_dword(pcistr[cnt].bus,
+                                                   pcistr[cnt].device_fn,
+                                                   PCI_BASE_ADDRESS_0,
+                                                   GDTH_BASEP&base0)) ||
+                (error = pcibios_read_config_dword(pcistr[cnt].bus,
+                                                   pcistr[cnt].device_fn,
+                                                   PCI_BASE_ADDRESS_1,
+                                                   GDTH_BASEP&base1)) ||
+                (error = pcibios_read_config_dword(pcistr[cnt].bus,
+                                                   pcistr[cnt].device_fn,
+                                                   PCI_BASE_ADDRESS_2,
+                                                   GDTH_BASEP&base2)) ||
+                (error = pcibios_read_config_byte(pcistr[cnt].bus,
+                                                  pcistr[cnt].device_fn,
+                                                  PCI_INTERRUPT_LINE,
+                                                  &pcistr[cnt].irq))) {
+                printk("GDT-PCI: error %d reading configuration space", error);
+                continue;
+            }
+            pcistr[cnt].device_id = device_id;
+            if (device_id <= PCI_DEVICE_ID_VORTEX_GDT6000B ||   /* GDT6000/B */
+                device_id >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) {  /* MPR */
+                if ((base0 & PCI_BASE_ADDRESS_SPACE) !=
+                    PCI_BASE_ADDRESS_SPACE_MEMORY)
+                    continue;
+                pcistr[cnt].dpmem = base0 & PCI_BASE_ADDRESS_MEM_MASK;
+            } else {                                    /* GDT6110, GDT6120, .. */
+                if ((base0 & PCI_BASE_ADDRESS_SPACE) !=
+                    PCI_BASE_ADDRESS_SPACE_MEMORY ||
+                    (base2 & PCI_BASE_ADDRESS_SPACE) !=
+                    PCI_BASE_ADDRESS_SPACE_MEMORY ||
+                    (base1 & PCI_BASE_ADDRESS_SPACE) !=
+                    PCI_BASE_ADDRESS_SPACE_IO)
+                    continue;
+                pcistr[cnt].dpmem = base2 & PCI_BASE_ADDRESS_MEM_MASK;
+                pcistr[cnt].io_mm = base0 & PCI_BASE_ADDRESS_MEM_MASK;
+                pcistr[cnt].io    = base1 & PCI_BASE_ADDRESS_IO_MASK;
+            }
+            TRACE2(("Controller found at %d/%d, irq %d, dpmem 0x%x\n",
+                    pcistr[cnt].bus, PCI_SLOT(pcistr[cnt].device_fn), 
+                    pcistr[cnt].irq, pcistr[cnt].dpmem));
+            cnt++;
+        }
 #endif
+    }   
+    return cnt;
+}
 
-    pcistr->device_id = device_id;
-    if (device_id <= PCI_DEVICE_ID_VORTEX_GDT6000B ||   /* GDT6000 or GDT6000B */
-        device_id >= PCI_DEVICE_ID_VORTEX_GDT6x17RP) {  /* MPR */
-        if ((base0 & PCI_BASE_ADDRESS_SPACE)!=PCI_BASE_ADDRESS_SPACE_MEMORY)
-            return -1;
-        pcistr->dpmem = base0 & PCI_BASE_ADDRESS_MEM_MASK;
-    } else {                                    /* GDT6110, GDT6120, .. */
-        if ((base0 & PCI_BASE_ADDRESS_SPACE)!=PCI_BASE_ADDRESS_SPACE_MEMORY ||
-            (base2 & PCI_BASE_ADDRESS_SPACE)!=PCI_BASE_ADDRESS_SPACE_MEMORY ||
-            (base1 & PCI_BASE_ADDRESS_SPACE)!=PCI_BASE_ADDRESS_SPACE_IO)
-            return -1;
-        pcistr->dpmem = base2 & PCI_BASE_ADDRESS_MEM_MASK;
-        pcistr->io_mm = base0 & PCI_BASE_ADDRESS_MEM_MASK;
-        pcistr->io    = base1 & PCI_BASE_ADDRESS_IO_MASK;
-    }
-    return 1;
+
+__initfunc (static void gdth_sort_pci(gdth_pci_str *pcistr, int cnt))
+{    
+    gdth_pci_str temp;
+    int i, changed;
+    
+    TRACE(("gdth_sort_pci() cnt %d\n",cnt));
+    if (cnt == 0)
+        return;
+
+    do {
+        changed = FALSE;
+        for (i = 0; i < cnt-1; ++i) {
+            if (!reverse_scan) {
+                if ((pcistr[i].bus > pcistr[i+1].bus) ||
+                    (pcistr[i].bus == pcistr[i+1].bus &&
+                     PCI_SLOT(pcistr[i].device_fn) > 
+                     PCI_SLOT(pcistr[i+1].device_fn))) {
+                    temp = pcistr[i];
+                    pcistr[i] = pcistr[i+1];
+                    pcistr[i+1] = temp;
+                    changed = TRUE;
+                }
+            } else {
+                if ((pcistr[i].bus < pcistr[i+1].bus) ||
+                    (pcistr[i].bus == pcistr[i+1].bus &&
+                     PCI_SLOT(pcistr[i].device_fn) < 
+                     PCI_SLOT(pcistr[i+1].device_fn))) {
+                    temp = pcistr[i];
+                    pcistr[i] = pcistr[i+1];
+                    pcistr[i+1] = temp;
+                    changed = TRUE;
+                }
+            }
+        }
+    } while (changed);
 }
 
 
-static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
+__initfunc (static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha))
 {
-    ulong retries,id;
+    ulong32 retries,id;
     unchar prot_ver,eisacf,i,irq_found;
 
     TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
@@ -535,14 +750,14 @@
     
     outb(0xff,eisa_adr+LDOORREG);
     retries = INIT_RETRIES;
-    JIFFYWAIT(2);
+    gdth_delay(20);
     while (inb(eisa_adr+EDOORREG) != 0xff) {
         if (--retries == 0) {
             printk("GDT-EISA: Initialization error (DEINIT failed)\n");
             return 0;
         }
-        mdelay(1);
-        TRACE2(("wait for DEINIT: retries=%ld\n",retries));
+        gdth_delay(1);
+        TRACE2(("wait for DEINIT: retries=%d\n",retries));
     }
     prot_ver = inb(eisa_adr+MAILBOXREG);
     outb(0xff,eisa_adr+EDOORREG);
@@ -551,7 +766,7 @@
         return 0;
     }
     ha->bmic = eisa_adr;
-    ha->brd_phys = (ulong)eisa_adr >> 12;
+    ha->brd_phys = (ulong32)eisa_adr >> 12;
 
     outl(0,eisa_adr+MAILBOXREG);
     outl(0,eisa_adr+MAILBOXREG+4);
@@ -565,76 +780,82 @@
         outl(1,eisa_adr+MAILBOXREG+8);
         outb(0xfe,eisa_adr+LDOORREG);
         retries = INIT_RETRIES;
-        JIFFYWAIT(2);
+        gdth_delay(20);
         while (inb(eisa_adr+EDOORREG) != 0xfe) {
             if (--retries == 0) {
                 printk("GDT-EISA: Initialization error (get IRQ failed)\n");
                 return 0;
             }
-            mdelay(1);
+            gdth_delay(1);
         }
         ha->irq = inb(eisa_adr+MAILBOXREG);
         outb(0xff,eisa_adr+EDOORREG);
         TRACE2(("GDT3000/3020: IRQ=%d\n",ha->irq));
-	/* check the result */
-	if (ha->irq == 0) {
-	    TRACE2(("Unknown IRQ, check IRQ table from cmd line !\n"));
-	    for (i=0,irq_found=FALSE; i<MAXHA && irqs[i]!=0xff; ++i) {
-		if (irqs[i]!=0) {
-		    irq_found=TRUE;
-		    break;
-		}
-	    }
-	    if (irq_found) {
-		ha->irq = irqs[i];
-		irqs[i] = 0;
-		printk("GDT-EISA: Can not detect controller IRQ,\n");
-		printk("Use IRQ setting from command line (IRQ = %d)\n",
-		       ha->irq);
-	    } else {
-		printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
-		printk("the controller BIOS or use command line parameters\n");
-		return 0;
-	    }
-	}
+        /* check the result */
+        if (ha->irq == 0) {
+                TRACE2(("Unknown IRQ, use IRQ table from cmd line !\n"));
+                for (i = 0, irq_found = FALSE; 
+                     i < MAXHA && irq[i] != 0xff; ++i) {
+                if (irq[i]==10 || irq[i]==11 || irq[i]==12 || irq[i]==14) {
+                    irq_found = TRUE;
+                    break;
+                }
+                }
+            if (irq_found) {
+                ha->irq = irq[i];
+                irq[i] = 0;
+                printk("GDT-EISA: Can not detect controller IRQ,\n");
+                printk("Use IRQ setting from command line (IRQ = %d)\n",
+                       ha->irq);
+            } else {
+                printk("GDT-EISA: Initialization error (unknown IRQ), Enable\n");
+                printk("the controller BIOS or use command line parameters\n");
+                return 0;
+            }
+        }
     } else {
         eisacf = inb(eisa_adr+EISAREG) & 7;
         if (eisacf > 4)                         /* level triggered */
             eisacf -= 4;
         ha->irq = gdth_irq_tab[eisacf];
         ha->type = GDT_EISA;
-        ha->stype= id;
+        ha->stype = id;
     }
     return 1;
 }
 
        
-static int gdth_init_isa(ulong bios_adr,gdth_ha_str *ha)
+__initfunc (static int gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha))
 {
     register gdt2_dpram_str *dp2_ptr;
     int i;
     unchar irq_drq,prot_ver;
-    ulong retries;
+    ulong32 retries;
 
-    TRACE(("gdth_init_isa() bios adr. %lx\n",bios_adr));
+    TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
 
     ha->brd = gdth_mmap(bios_adr, sizeof(gdt2_dpram_str));
     if (ha->brd == NULL) {
-	printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
-	return 0;
+        printk("GDT-ISA: Initialization error (DPMEM remap error)\n");
+        return 0;
     }
     dp2_ptr = (gdt2_dpram_str *)ha->brd;
-    writeb(1, &dp2_ptr->io.memlock);			/* switch off write protection */
+    gdth_writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
     /* reset interface area */
     memset_io((char *)&dp2_ptr->u,0,sizeof(dp2_ptr->u));
+    if (gdth_readl(&dp2_ptr->u) != 0) {
+        printk("GDT-PCI: Initialization error (DPMEM write error)\n");
+        gdth_munmap(ha->brd);
+        return 0;
+    }
 
     /* disable board interrupts, read DRQ and IRQ */
-    writeb(0xff, &dp2_ptr->io.irqdel);
-    writeb(0x00, &dp2_ptr->io.irqen);
-    writeb(0x00, &dp2_ptr->u.ic.S_Status);
-    writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
+    gdth_writeb(0xff, &dp2_ptr->io.irqdel);
+    gdth_writeb(0x00, &dp2_ptr->io.irqen);
+    gdth_writeb(0x00, &dp2_ptr->u.ic.S_Status);
+    gdth_writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
 
-    irq_drq = readb(&dp2_ptr->io.rq);
+    irq_drq = gdth_readb(&dp2_ptr->io.rq);
     for (i=0; i<3; ++i) {
         if ((irq_drq & 1)==0)
             break;
@@ -642,7 +863,7 @@
     }
     ha->drq = gdth_drq_tab[i];
 
-    irq_drq = readb(&dp2_ptr->io.rq) >> 3;
+    irq_drq = gdth_readb(&dp2_ptr->io.rq) >> 3;
     for (i=1; i<5; ++i) {
         if ((irq_drq & 1)==0)
             break;
@@ -651,25 +872,25 @@
     ha->irq = gdth_irq_tab[i];
 
     /* deinitialize services */
-    writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
-    writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
-    writeb(0, &dp2_ptr->io.event);
+    gdth_writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
+    gdth_writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
+    gdth_writeb(0, &dp2_ptr->io.event);
     retries = INIT_RETRIES;
-    JIFFYWAIT(2);
-    while (readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
+    gdth_delay(20);
+    while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
         if (--retries == 0) {
             printk("GDT-ISA: Initialization error (DEINIT failed)\n");
-	    gdth_munmap(ha->brd);
+            gdth_munmap(ha->brd);
             return 0;
         }
-        mdelay(1);
+        gdth_delay(1);
     }
-    prot_ver = (unchar)readl(&dp2_ptr->u.ic.S_Info[0]);
-    writeb(0, &dp2_ptr->u.ic.Status);
-    writeb(0xff, &dp2_ptr->io.irqdel);
+    prot_ver = (unchar)gdth_readl(&dp2_ptr->u.ic.S_Info[0]);
+    gdth_writeb(0, &dp2_ptr->u.ic.Status);
+    gdth_writeb(0xff, &dp2_ptr->io.irqdel);
     if (prot_ver != PROTOCOL_VERSION) {
         printk("GDT-ISA: Illegal protocol version\n");
-	gdth_munmap(ha->brd);
+        gdth_munmap(ha->brd);
         return 0;
     }
 
@@ -679,83 +900,84 @@
     ha->brd_phys = bios_adr >> 4;
 
     /* special request to controller BIOS */
-    writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
-    writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
-    writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
-    writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
-    writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
-    writeb(0, &dp2_ptr->io.event);
+    gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
+    gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
+    gdth_writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
+    gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
+    gdth_writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
+    gdth_writeb(0, &dp2_ptr->io.event);
     retries = INIT_RETRIES;
-    JIFFYWAIT(2);
-    while (readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
+    gdth_delay(20);
+    while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
         if (--retries == 0) {
             printk("GDT-ISA: Initialization error\n");
-	    gdth_munmap(ha->brd);
+            gdth_munmap(ha->brd);
             return 0;
         }
-        mdelay(1);
+        gdth_delay(1);
     }
-    writeb(0, &dp2_ptr->u.ic.Status);
-    writeb(0xff, &dp2_ptr->io.irqdel);
+    gdth_writeb(0, &dp2_ptr->u.ic.Status);
+    gdth_writeb(0xff, &dp2_ptr->io.irqdel);
     return 1;
 }
 
 
-static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
+__initfunc (static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha))
 {
     register gdt6_dpram_str *dp6_ptr;
     register gdt6c_dpram_str *dp6c_ptr;
     register gdt6m_dpram_str *dp6m_ptr;
-    ulong retries;
+    ulong32 retries;
     unchar prot_ver;
+    int i, found = FALSE;
 
     TRACE(("gdth_init_pci()\n"));
 
     ha->brd_phys = (pcistr->bus << 8) | (pcistr->device_fn & 0xf8);
-    ha->stype    = (ulong)pcistr->device_id;
+    ha->stype    = (ulong32)pcistr->device_id;
     ha->irq      = pcistr->irq;
     
-    if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6000B) {   /* GDT6000 or GDT6000B */
+    if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6000B) {  /* GDT6000/B */
         TRACE2(("init_pci() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
-	ha->brd = gdth_mmap(pcistr->dpmem, sizeof(gdt6_dpram_str));
-	if (ha->brd == NULL) {
-	    printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
-	    return 0;
-	}
+        ha->brd = gdth_mmap(pcistr->dpmem, sizeof(gdt6_dpram_str));
+        if (ha->brd == NULL) {
+            printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
+            return 0;
+        }
         dp6_ptr = (gdt6_dpram_str *)ha->brd;
         /* reset interface area */
         memset_io((char *)&dp6_ptr->u,0,sizeof(dp6_ptr->u));
-        if (readl(&dp6_ptr->u) != 0) {
+        if (gdth_readl(&dp6_ptr->u) != 0) {
             printk("GDT-PCI: Initialization error (DPMEM write error)\n");
-	    gdth_munmap(ha->brd);
+            gdth_munmap(ha->brd);
             return 0;
         }
         
         /* disable board interrupts, deinit services */
-        writeb(0xff, &dp6_ptr->io.irqdel);
-        writeb(0x00, &dp6_ptr->io.irqen);;
-        writeb(0x00, &dp6_ptr->u.ic.S_Status);
-        writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
-
-        writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
-        writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
-        writeb(0, &dp6_ptr->io.event);
+        gdth_writeb(0xff, &dp6_ptr->io.irqdel);
+        gdth_writeb(0x00, &dp6_ptr->io.irqen);;
+        gdth_writeb(0x00, &dp6_ptr->u.ic.S_Status);
+        gdth_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
+
+        gdth_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
+        gdth_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
+        gdth_writeb(0, &dp6_ptr->io.event);
         retries = INIT_RETRIES;
-        JIFFYWAIT(2);
-        while (readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
+        gdth_delay(20);
+        while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
-		gdth_munmap(ha->brd);
+                gdth_munmap(ha->brd);
                 return 0;
             }
-            mdelay(1);
+            gdth_delay(1);
         }
-        prot_ver = (unchar)readl(&dp6_ptr->u.ic.S_Info[0]);
-        writeb(0, &dp6_ptr->u.ic.S_Status);
-        writeb(0xff, &dp6_ptr->io.irqdel);
+        prot_ver = (unchar)gdth_readl(&dp6_ptr->u.ic.S_Info[0]);
+        gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
+        gdth_writeb(0xff, &dp6_ptr->io.irqdel);
         if (prot_ver != PROTOCOL_VERSION) {
             printk("GDT-PCI: Illegal protocol version\n");
-	    gdth_munmap(ha->brd);
+            gdth_munmap(ha->brd);
             return 0;
         }
 
@@ -763,41 +985,41 @@
         ha->ic_all_size = sizeof(dp6_ptr->u);
         
         /* special command to controller BIOS */
-        writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
-        writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
-        writel(0x01, &dp6_ptr->u.ic.S_Info[2]);
-        writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
-        writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
-        writeb(0, &dp6_ptr->io.event);
+        gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
+        gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
+        gdth_writel(0x01, &dp6_ptr->u.ic.S_Info[2]);
+        gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
+        gdth_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
+        gdth_writeb(0, &dp6_ptr->io.event);
         retries = INIT_RETRIES;
-        JIFFYWAIT(2);
-        while (readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
+        gdth_delay(20);
+        while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error\n");
-		gdth_munmap(ha->brd);
+                gdth_munmap(ha->brd);
                 return 0;
             }
-            mdelay(1);
+            gdth_delay(1);
         }
-        writeb(0, &dp6_ptr->u.ic.S_Status);
-        writeb(0xff, &dp6_ptr->io.irqdel);
+        gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
+        gdth_writeb(0xff, &dp6_ptr->io.irqdel);
 
-    } else if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, GDT6120, .. */
-	ha->plx = (gdt6c_plx_regs *)pcistr->io;
-	TRACE2(("init_pci_new() dpmem %lx io %lx irq %d\n",
-		pcistr->dpmem,(ulong)ha->plx,ha->irq));
-	ha->brd = gdth_mmap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
-	if (ha->brd == NULL) {
-	    printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
-	    gdth_munmap(ha->brd);
-	    return 0;
-	}
+    } else if (ha->stype <= PCI_DEVICE_ID_VORTEX_GDT6555) { /* GDT6110, ... */
+        ha->plx = (gdt6c_plx_regs *)pcistr->io;
+        TRACE2(("init_pci_new() dpmem %lx irq %d\n",
+            pcistr->dpmem,ha->irq));
+        ha->brd = gdth_mmap(pcistr->dpmem, sizeof(gdt6c_dpram_str));
+        if (ha->brd == NULL) {
+            printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
+            gdth_munmap(ha->brd);
+            return 0;
+        }
         dp6c_ptr = (gdt6c_dpram_str *)ha->brd;
         /* reset interface area */
         memset_io((char *)&dp6c_ptr->u,0,sizeof(dp6c_ptr->u));
-        if (readl(&dp6c_ptr->u) != 0) {
+        if (gdth_readl(&dp6c_ptr->u) != 0) {
             printk("GDT-PCI: Initialization error (DPMEM write error)\n");
-	    gdth_munmap(ha->brd);
+            gdth_munmap(ha->brd);
             return 0;
         }
         
@@ -805,29 +1027,29 @@
         outb(0x00,PTR2USHORT(&ha->plx->control1));
         outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
         
-        writeb(0x00, &dp6c_ptr->u.ic.S_Status);
-        writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
+        gdth_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
+        gdth_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
 
-        writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
-        writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
+        gdth_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
+        gdth_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
 
         outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
 
         retries = INIT_RETRIES;
-        JIFFYWAIT(2);
-        while (readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
+        gdth_delay(20);
+        while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
-		gdth_munmap(ha->brd);
+                gdth_munmap(ha->brd);
                 return 0;
             }
-            mdelay(1);
+            gdth_delay(1);
         }
-        prot_ver = (unchar)readl(&dp6c_ptr->u.ic.S_Info[0]);
-        writeb(0, &dp6c_ptr->u.ic.Status);
+        prot_ver = (unchar)gdth_readl(&dp6c_ptr->u.ic.S_Info[0]);
+        gdth_writeb(0, &dp6c_ptr->u.ic.Status);
         if (prot_ver != PROTOCOL_VERSION) {
             printk("GDT-PCI: Illegal protocol version\n");
-	    gdth_munmap(ha->brd);
+            gdth_munmap(ha->brd);
             return 0;
         }
 
@@ -835,68 +1057,106 @@
         ha->ic_all_size = sizeof(dp6c_ptr->u);
 
         /* special command to controller BIOS */
-        writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
-        writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
-        writel(0x01, &dp6c_ptr->u.ic.S_Info[2]);
-        writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
-        writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
+        gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
+        gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
+        gdth_writel(0x01, &dp6c_ptr->u.ic.S_Info[2]);
+        gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
+        gdth_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
         
         outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
 
         retries = INIT_RETRIES;
-        JIFFYWAIT(2);
-        while (readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
+        gdth_delay(20);
+        while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error\n");
-		gdth_munmap(ha->brd);
+                gdth_munmap(ha->brd);
                 return 0;
             }
-            mdelay(1);
+            gdth_delay(1);
         }
-        writeb(0, &dp6c_ptr->u.ic.S_Status);
+        gdth_writeb(0, &dp6c_ptr->u.ic.S_Status);
 
     } else {                                            /* MPR */
-	TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
-	ha->brd = gdth_mmap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
-	if (ha->brd == NULL) {
-	    printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
-	    return 0;
-	}
+        TRACE2(("init_pci_mpr() dpmem %lx irq %d\n",pcistr->dpmem,ha->irq));
+        ha->brd = gdth_mmap(pcistr->dpmem, sizeof(gdt6m_dpram_str));
+        if (ha->brd == NULL) {
+            printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
+            return 0;
+        }
 
+        /* check and reset interface area */
         dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
-        /* reset interface area */
-        memset_io((char *)&dp6m_ptr->u,0,sizeof(dp6m_ptr->u));
-        if (readl(&dp6m_ptr->u) != 0) {
-            printk("GDT-PCI: Initialization error (DPMEM write error)\n");
-	    gdth_munmap(ha->brd);
-            return 0;
+        gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
+        if (gdth_readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
+            printk("GDT-PCI: Cannot access DPMEM at 0x%x (shadowed?)\n", 
+                   (int)pcistr->dpmem);
+            found = FALSE;
+            for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
+                gdth_munmap(ha->brd);
+                ha->brd = gdth_mmap(i, sizeof(ushort)); 
+                if (ha->brd == NULL) {
+                    printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
+                    return 0;
+                }
+                if (gdth_readw(ha->brd) != 0xffff) {
+                    TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
+                    continue;
+                }
+                gdth_munmap(ha->brd);
+#if LINUX_VERSION_CODE >= 0x2015C
+                pci_write_config_dword(pcistr->pdev, 
+                                       PCI_BASE_ADDRESS_0, i);
+#else
+                pcibios_write_config_dword(pcistr->bus, pcistr->device_fn,
+                                           PCI_BASE_ADDRESS_0, i);
+#endif
+                ha->brd = gdth_mmap(i, sizeof(gdt6m_dpram_str)); 
+                if (ha->brd == NULL) {
+                    printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
+                    return 0;
+                }
+                dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
+                gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
+                if (gdth_readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
+                    printk("GDT-PCI: Use free address at 0x%x\n", i);
+                    found = TRUE;
+                    break;
+                }
+            }   
+            if (!found) {
+                printk("GDT-PCI: No free address found!\n");
+                gdth_munmap(ha->brd);
+                return 0;
+            }
         }
+        memset_io((char *)&dp6m_ptr->u,0,sizeof(dp6m_ptr->u));
         
         /* disable board interrupts, deinit services */
-        writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
-	       &dp6m_ptr->i960r.edoor_en_reg);
-        writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
-        writeb(0x00, &dp6m_ptr->u.ic.S_Status);
-        writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
-
-        writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
-        writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
-        writeb(1, &dp6m_ptr->i960r.ldoor_reg);
+        gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
+                    &dp6m_ptr->i960r.edoor_en_reg);
+        gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
+        gdth_writeb(0x00, &dp6m_ptr->u.ic.S_Status);
+        gdth_writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
+
+        gdth_writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
+        gdth_writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
+        gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
         retries = INIT_RETRIES;
-        JIFFYWAIT(2);
-        while (readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
+        gdth_delay(20);
+        while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
-		gdth_munmap(ha->brd);
+                gdth_munmap(ha->brd);
                 return 0;
             }
-            mdelay(1);
+            gdth_delay(1);
         }
-        prot_ver = (unchar)readl(&dp6m_ptr->u.ic.S_Info[0]);
-        writeb(0, &dp6m_ptr->u.ic.S_Status);
+        prot_ver = (unchar)gdth_readl(&dp6m_ptr->u.ic.S_Info[0]);
+        gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
         if (prot_ver != PROTOCOL_VERSION) {
             printk("GDT-PCI: Illegal protocol version\n");
-	    gdth_munmap(ha->brd);
+            gdth_munmap(ha->brd);
             return 0;
         }
 
@@ -904,23 +1164,23 @@
         ha->ic_all_size = sizeof(dp6m_ptr->u);
         
         /* special command to controller BIOS */
-        writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
-        writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
-        writel(0x01, &dp6m_ptr->u.ic.S_Info[2]);
-        writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
-        writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
-        writeb(1, &dp6m_ptr->i960r.ldoor_reg);
+        gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
+        gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
+        gdth_writel(0x01, &dp6m_ptr->u.ic.S_Info[2]);
+        gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
+        gdth_writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
+        gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
         retries = INIT_RETRIES;
-        JIFFYWAIT(2);
-        while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
+        gdth_delay(20);
+        while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error\n");
-		gdth_munmap(ha->brd);
+                gdth_munmap(ha->brd);
                 return 0;
             }
-            mdelay(1);
+            gdth_delay(1);
         }
-        writeb(0, &dp6m_ptr->u.ic.S_Status);
+        gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
     }
 
     return 1;
@@ -929,7 +1189,7 @@
 
 /* controller protocol functions */
 
-static void gdth_enable_int(int hanum)
+__initfunc (static void gdth_enable_int(int hanum))
 {
     gdth_ha_str *ha;
     ulong flags;
@@ -939,9 +1199,7 @@
 
     TRACE(("gdth_enable_int() hanum %d\n",hanum));
     ha = HADATA(gdth_ctr_tab[hanum]);
-
-    save_flags(flags);
-    cli();
+    GDTH_LOCK_HA(ha, flags);
 
     if (ha->type == GDT_EISA) {
         outb(0xff, ha->bmic + EDOORREG);
@@ -949,24 +1207,24 @@
         outb(0x01, ha->bmic + EINTENABREG);
     } else if (ha->type == GDT_ISA) {
         dp2_ptr = (gdt2_dpram_str *)ha->brd;
-        writeb(1, &dp2_ptr->io.irqdel);
-        writeb(0, &dp2_ptr->u.ic.Cmd_Index);
-        writeb(1, &dp2_ptr->io.irqen);
+        gdth_writeb(1, &dp2_ptr->io.irqdel);
+        gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);
+        gdth_writeb(1, &dp2_ptr->io.irqen);
     } else if (ha->type == GDT_PCI) {
         dp6_ptr = (gdt6_dpram_str *)ha->brd;
-        writeb(1, &dp6_ptr->io.irqdel);
-        writeb(0, &dp6_ptr->u.ic.Cmd_Index);
-        writeb(1, &dp6_ptr->io.irqen);
+        gdth_writeb(1, &dp6_ptr->io.irqdel);
+        gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);
+        gdth_writeb(1, &dp6_ptr->io.irqen);
     } else if (ha->type == GDT_PCINEW) {
         outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
         outb(0x03, PTR2USHORT(&ha->plx->control1));
     } else if (ha->type == GDT_PCIMPR) {
         dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
-        writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
-        writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
-	       &dp6m_ptr->i960r.edoor_en_reg);
+        gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
+        gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
+                    &dp6m_ptr->i960r.edoor_en_reg);
     }
-    restore_flags(flags);
+    GDTH_UNLOCK_HA(ha, flags);
 }
 
 
@@ -976,7 +1234,7 @@
     int i;
 
     TRACE(("gdth_get_status() irq %d ctr_count %d\n",
-                 irq,gdth_ctr_count));
+           irq,gdth_ctr_count));
     
     *pIStatus = 0;
     for (i=0; i<gdth_ctr_count; ++i) {
@@ -986,13 +1244,16 @@
         if (ha->type == GDT_EISA)
             *pIStatus = inb((ushort)ha->bmic + EDOORREG);
         else if (ha->type == GDT_ISA)
-            *pIStatus = readb(&((gdt2_dpram_str *)ha->brd)->u.ic.Cmd_Index);
+            *pIStatus =
+                gdth_readb(&((gdt2_dpram_str *)ha->brd)->u.ic.Cmd_Index);
         else if (ha->type == GDT_PCI)
-            *pIStatus = readb(&((gdt6_dpram_str *)ha->brd)->u.ic.Cmd_Index);
+            *pIStatus =
+                gdth_readb(&((gdt6_dpram_str *)ha->brd)->u.ic.Cmd_Index);
         else if (ha->type == GDT_PCINEW) 
             *pIStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
         else if (ha->type == GDT_PCIMPR)
-            *pIStatus = readb(&((gdt6m_dpram_str *)ha->brd)->i960r.edoor_reg);
+            *pIStatus =
+                gdth_readb(&((gdt6m_dpram_str *)ha->brd)->i960r.edoor_reg);
    
         if (*pIStatus)                                  
             return i;                           /* board found */
@@ -1012,13 +1273,14 @@
     if (ha->type == GDT_EISA)
         gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
     else if (ha->type == GDT_ISA)
-        gdtsema0 = (int)readb(&((gdt2_dpram_str *)ha->brd)->u.ic.Sema0);
+        gdtsema0 = (int)gdth_readb(&((gdt2_dpram_str *)ha->brd)->u.ic.Sema0);
     else if (ha->type == GDT_PCI)
-        gdtsema0 = (int)readb(&((gdt6_dpram_str *)ha->brd)->u.ic.Sema0);
+        gdtsema0 = (int)gdth_readb(&((gdt6_dpram_str *)ha->brd)->u.ic.Sema0);
     else if (ha->type == GDT_PCINEW) 
         gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
     else if (ha->type == GDT_PCIMPR)
-        gdtsema0 = (int)readb(&((gdt6m_dpram_str *)ha->brd)->i960r.sema0_reg);
+        gdtsema0 = 
+            (int)gdth_readb(&((gdt6m_dpram_str *)ha->brd)->i960r.sema0_reg);
 
     return (gdtsema0 & 1);
 }
@@ -1033,10 +1295,10 @@
 
     ha = HADATA(gdth_ctr_tab[hanum]);
     for (i=0; i<GDTH_MAXCMDS; ++i) {
-        if (gdth_cmd_tab[i][hanum].cmnd == UNUSED_CMND) {
-            gdth_cmd_tab[i][hanum].cmnd = ha->pccb->RequestBuffer;
-            gdth_cmd_tab[i][hanum].service = ha->pccb->Service;
-            ha->pccb->CommandIndex = (ulong)i+2;
+        if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
+            ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
+            ha->cmd_tab[i].service = ha->pccb->Service;
+            ha->pccb->CommandIndex = (ulong32)i+2;
             return (i+2);
         }
     }
@@ -1051,17 +1313,17 @@
     TRACE(("gdth_set_sema0() hanum %d\n",hanum));
 
     ha = HADATA(gdth_ctr_tab[hanum]);
-    if (ha->type == GDT_EISA)
+    if (ha->type == GDT_EISA) {
         outb(1, ha->bmic + SEMA0REG);
-    else if (ha->type == GDT_ISA)
-        writeb(1, &((gdt2_dpram_str *)ha->brd)->u.ic.Sema0);
-    else if (ha->type == GDT_PCI)
-        writeb(1, &((gdt6_dpram_str *)ha->brd)->u.ic.Sema0);
-    else if (ha->type == GDT_PCINEW)  
+    } else if (ha->type == GDT_ISA) {
+        gdth_writeb(1, &((gdt2_dpram_str *)ha->brd)->u.ic.Sema0);
+    } else if (ha->type == GDT_PCI) {
+        gdth_writeb(1, &((gdt6_dpram_str *)ha->brd)->u.ic.Sema0);
+    } else if (ha->type == GDT_PCINEW) { 
         outb(1, PTR2USHORT(&ha->plx->sema0_reg));
-    else if (ha->type == GDT_PCIMPR)
-        writeb(1, &((gdt6m_dpram_str *)ha->brd)->i960r.sema0_reg);
-    
+    } else if (ha->type == GDT_PCIMPR) {
+        gdth_writeb(1, &((gdt6m_dpram_str *)ha->brd)->i960r.sema0_reg);
+    }
 }
 
 
@@ -1096,31 +1358,31 @@
     /* set offset and service, copy command to DPMEM */
     if (ha->type == GDT_ISA) {
         dp2_ptr = (gdt2_dpram_str *)ha->brd;
-        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
-	       &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
-        writew((ushort)cmd_ptr->Service, 
-	       &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
-	memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
+        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+                    &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
+        gdth_writew((ushort)cmd_ptr->Service, 
+                    &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
+        memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     } else if (ha->type == GDT_PCI) {
         dp6_ptr = (gdt6_dpram_str *)ha->brd;
-        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
-	       &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
-        writew((ushort)cmd_ptr->Service, 
-	       &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
+        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+                    &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
+        gdth_writew((ushort)cmd_ptr->Service, 
+                    &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
         memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     } else if (ha->type == GDT_PCINEW) {
         dp6c_ptr = (gdt6c_dpram_str *)ha->brd;
-        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
-	       &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
-	writew((ushort)cmd_ptr->Service, 
-	       &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
-	memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
+        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+                    &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
+        gdth_writew((ushort)cmd_ptr->Service, 
+                    &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
+        memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     } else if (ha->type == GDT_PCIMPR) {
         dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
-        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
-	       &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
-        writew((ushort)cmd_ptr->Service, 
-	       &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
+        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+                    &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
+        gdth_writew((ushort)cmd_ptr->Service, 
+                    &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
         memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     }
 }
@@ -1130,21 +1392,23 @@
 {
     register gdth_ha_str *ha;
 
+    TRACE(("gdth_release_event() hanum %d\n",hanum));
+    ha = HADATA(gdth_ctr_tab[hanum]);
+
 #ifdef GDTH_STATISTICS
-    ulong i,j;
-    for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
-        if (gdth_cmd_tab[j][hanum].cmnd != UNUSED_CMND)
-            ++i;
-    }
-    if (max_index < i) {
-        max_index = i;
-        TRACE3(("GDT: max_index = %d\n",(ushort)i));
+    {
+        ulong32 i,j;
+        for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
+            if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
+                ++i;
+        }
+        if (max_index < i) {
+            max_index = i;
+            TRACE3(("GDT: max_index = %d\n",(ushort)i));
+        }
     }
 #endif
 
-    TRACE(("gdth_release_event() hanum %d\n",hanum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
-
     if (ha->pccb->OpCode == GDT_INIT)
         ha->pccb->Service |= 0x80;
 
@@ -1152,23 +1416,24 @@
         outb(ha->pccb->Service, ha->bmic + LDOORREG);
         if (ha->pccb->OpCode == GDT_INIT)               /* store DMA buffer */
             outl((ulong)ha->pccb, ha->bmic + MAILBOXREG);
-    } else if (ha->type == GDT_ISA)
-        writeb(0, &((gdt2_dpram_str *)ha->brd)->io.event);
-    else if (ha->type == GDT_PCI)
-        writeb(0, &((gdt6_dpram_str *)ha->brd)->io.event);
-    else if (ha->type == GDT_PCINEW) 
+    } else if (ha->type == GDT_ISA) {
+        gdth_writeb(0, &((gdt2_dpram_str *)ha->brd)->io.event);
+    } else if (ha->type == GDT_PCI) {
+        gdth_writeb(0, &((gdt6_dpram_str *)ha->brd)->io.event);
+    } else if (ha->type == GDT_PCINEW) { 
         outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
-    else if (ha->type == GDT_PCIMPR)
-        writeb(1, &((gdt6m_dpram_str *)ha->brd)->i960r.ldoor_reg);
+    } else if (ha->type == GDT_PCIMPR) {
+        gdth_writeb(1, &((gdt6m_dpram_str *)ha->brd)->i960r.ldoor_reg);
+    }
 }
 
     
-static int gdth_wait(int hanum,int index,ulong time)
+static int gdth_wait(int hanum,int index,ulong32 time)
 {
     gdth_ha_str *ha;
     int answer_found = FALSE;
 
-    TRACE(("gdth_wait() hanum %d index %d time %ld\n",hanum,index,time));
+    TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum,index,time));
 
     ha = HADATA(gdth_ctr_tab[hanum]);
     if (index == 0)
@@ -1177,7 +1442,7 @@
     gdth_from_wait = TRUE;
     do {
 #if LINUX_VERSION_CODE >= 0x010346
-        gdth_interrupt((int)ha->irq,NULL,NULL);
+        gdth_interrupt((int)ha->irq,ha,NULL);
 #else
         gdth_interrupt((int)ha->irq,NULL);
 #endif
@@ -1185,19 +1450,19 @@
             answer_found = TRUE;
             break;
         }
-        mdelay(1);
+        gdth_delay(1);
     } while (--time);
     gdth_from_wait = FALSE;
     
     while (gdth_test_busy(hanum))
-        udelay(1);
+        gdth_delay(0);
 
     return (answer_found);
 }
 
 
-static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong p1,
-                             ulong p2,ulong p3)
+static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
+                             ulong32 p2,ulong32 p3)
 {
     register gdth_ha_str *ha;
     register gdth_cmd_str *cmd_ptr;
@@ -1234,21 +1499,21 @@
             cmd_ptr->u.raw.direction  = p1;
             cmd_ptr->u.raw.bus        = (unchar)p2;
             cmd_ptr->u.raw.target     = (unchar)p3;
-            cmd_ptr->u.raw.lun        = 0;
+            cmd_ptr->u.raw.lun        = (unchar)(p3 >> 8);
         }
         ha->cmd_len          = sizeof(gdth_cmd_str);
         ha->cmd_offs_dpmem   = 0;
         ha->cmd_cnt          = 0;
         gdth_copy_command(hanum);
         gdth_release_event(hanum);
-        JIFFYWAIT(2);
+        gdth_delay(20);
         if (!gdth_wait(hanum,index,INIT_TIMEOUT)) {
             printk("GDT: Initialization error (timeout service %d)\n",service);
             return 0;
         }
         if (ha->status != S_BSY || --retries == 0)
             break;
-        mdelay(1);   
+        gdth_delay(1);   
     }   
     
     return (ha->status != S_OK ? 0:1);
@@ -1257,14 +1522,14 @@
 
 /* search for devices */
 
-static int gdth_search_drives(int hanum)
+__initfunc (static int gdth_search_drives(int hanum))
 {
     register gdth_ha_str *ha;
-    ushort cdev_cnt,i;
-    unchar b,t,pos_found;
-    ulong drv_cyls, drv_hds, drv_secs;
-    ulong bus_no;
+    ushort cdev_cnt, i;
+    ulong32 drv_cyls, drv_hds, drv_secs;
+    ulong32 bus_no;
     gdth_getch_str *chn;
+    gdth_iochan_str *ioc;
     
     TRACE(("gdth_search_drives() hanum %d\n",hanum));
     ha = HADATA(gdth_ctr_tab[hanum]);
@@ -1292,45 +1557,76 @@
 
     /* initialize cache service after mountall */
     if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_INIT,LINUX_OS,0,0)) {
-	printk("GDT: Initialization error cache service (code %d)\n",
-	       ha->status);
-	return 0;
+        printk("GDT: Initialization error cache service (code %d)\n",
+               ha->status);
+        return 0;
     }
     TRACE2(("gdth_search_drives() CACHES. init. after mountall\n"));
     cdev_cnt = (ushort)ha->info;
 
-    /* detect number of SCSI buses */
-    chn = (gdth_getch_str *)DMADATA(gdth_ctr_tab[hanum]);
-    for (bus_no=0; bus_no<MAXBUS; ++bus_no) {
-	chn->channel_no = bus_no;
-	if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
-			       SCSI_CHAN_CNT | L_CTRL_PATTERN,
-			       IO_CHANNEL | INVALID_CHANNEL,
-			       sizeof(gdth_getch_str))) {
-	    if (bus_no == 0) {
-		printk("GDT: Error detecting SCSI channel count (0x%x)\n",
-		       ha->status);
-		return 0;
-	    }
-	    break;
-	}
-	if (chn->siop_id < MAXID)
-	    ha->id[bus_no][chn->siop_id].type = SIOP_DTYP;
-    }       
-    ha->bus_cnt = (unchar)bus_no;
-    TRACE2(("gdth_search_drives() %d SCSI channels\n",ha->bus_cnt));
+    /* detect number of buses - try new IOCTL */
+    ioc = (gdth_iochan_str *)ha->pscratch;
+    ioc->version        = 0xffffffff;
+    ioc->list_entries   = MAXBUS;
+    ioc->first_chan     = 0;
+    ioc->last_chan      = MAXBUS-1;
+    ioc->list_offset    = GDTOFFSOF(gdth_iochan_str, list[0]);
+    if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,GET_IOCHAN_DESC,
+                          INVALID_CHANNEL,sizeof(gdth_iochan_str))) {
+        TRACE2(("GET_IOCHAN_DESC supported!\n"));
+        ha->bus_cnt = ioc->chan_count;
+        for (bus_no = 0; bus_no < ha->bus_cnt; ++bus_no) {
+            if (ioc->list[bus_no].proc_id < MAXID)
+                ha->bus_id[bus_no] = ioc->list[bus_no].proc_id;
+            else
+                ha->bus_id[bus_no] = 0xff;
+        }
+    } else {
+        /* old method */
+        chn = (gdth_getch_str *)ha->pscratch;
+        for (bus_no = 0; bus_no < MAXBUS; ++bus_no) {
+            chn->channel_no = bus_no;
+            if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,
+                                   SCSI_CHAN_CNT | L_CTRL_PATTERN,
+                                   IO_CHANNEL | INVALID_CHANNEL,
+                                   sizeof(gdth_getch_str))) {
+                if (bus_no == 0) {
+                    printk("GDT: Error detecting channel count (0x%x)\n",
+                           ha->status);
+                    return 0;
+                }
+                break;
+            }
+            if (chn->siop_id < MAXID)
+                ha->bus_id[bus_no] = chn->siop_id;
+            else
+                ha->bus_id[bus_no] = 0xff;
+        }       
+        ha->bus_cnt = (unchar)bus_no;
+    }
+    TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
 
     /* read cache configuration */
     if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,CACHE_INFO,
-			   INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
-	printk("GDT: Initialization error cache service (code %d)\n",
-	       ha->status);
-	return 0;
-    }
-    ha->cpar = ((gdth_cinfo_str *)DMADATA(gdth_ctr_tab[hanum]))->cpar;
-    TRACE2(("gdth_search_drives() cinfo: vs %lx sta %d str %d dw %d b %d\n",
-	    ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
-	    ha->cpar.write_back,ha->cpar.block_size));
+                           INVALID_CHANNEL,sizeof(gdth_cinfo_str))) {
+        printk("GDT: Initialization error cache service (code %d)\n",
+               ha->status);
+        return 0;
+    }
+    ha->cpar = ((gdth_cinfo_str *)ha->pscratch)->cpar;
+    TRACE2(("gdth_search_drives() cinfo: vs %x sta %d str %d dw %d b %d\n",
+            ha->cpar.version,ha->cpar.state,ha->cpar.strategy,
+            ha->cpar.write_back,ha->cpar.block_size));
+
+    /* read board info, fill ctr_name[] */
+    if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_IOCTL,BOARD_INFO,
+                          INVALID_CHANNEL,sizeof(gdth_binfo_str))) {
+        TRACE2(("BOARD_INFO supported!\n"));
+        strcpy(ha->ctr_name, ((gdth_binfo_str *)ha->pscratch)->type_string);
+    } else {
+        strcpy(ha->ctr_name, gdth_ctr_name(hanum));
+    }
+    TRACE2(("Controller name: %s\n",ha->ctr_name));
 
     /* initialize raw service */
     if (!gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_INIT,0,0,0)) {
@@ -1345,10 +1641,9 @@
     if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_SET_FEAT,SCATTER_GATHER,
                           0,0)) {
         TRACE2(("gdth_search_drives(): set features RAWSERVICE OK\n"));
-        if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_GET_FEAT,0,0,0))
-        {
-            TRACE2(("gdth_search_dr(): get feat RAWSERVICE %ld\n",
-                          ha->info));
+        if (gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_GET_FEAT,0,0,0)) {
+            TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
+                    ha->info));
             ha->raw_feat = (ushort)ha->info;
         }
     } 
@@ -1358,20 +1653,31 @@
                           SCATTER_GATHER,0)) {
         TRACE2(("gdth_search_drives(): set features CACHESERVICE OK\n"));
         if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_GET_FEAT,0,0,0)) {
-            TRACE2(("gdth_search_dr(): get feat CACHESERV. %ld\n",
-                          ha->info));
+            TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
+                    ha->info));
             ha->cache_feat = (ushort)ha->info;
         }
     }
 
-    /* scanning for raw devices */
-    for (b=0; b<ha->bus_cnt; ++b) {
-        for (t=0; t<MAXID; ++t) {
-            TRACE(("gdth_search_drives() rawd. bus %d id %d\n",b,t));
-            if (ha->id[b][t].type != SIOP_DTYP && 
-                gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_INFO,0,b,t)) {
-                ha->id[b][t].type = RAW_DTYP;
-            }
+    /* reserve drives for raw service */
+    if (reserve_mode != 0) {
+        gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE_ALL,
+                          reserve_mode == 1 ? 1 : 3, 0, 0);
+        TRACE2(("gdth_search_drives(): RESERVE_ALL code %d\n", 
+                ha->status));
+    }
+    for (i = 0; i < MAX_RES_ARGS; i += 4) {
+        if (reserve_list[i] == hanum && reserve_list[i+1] < ha->bus_cnt && 
+            reserve_list[i+2] < ha->tid_cnt && reserve_list[i+3] < MAXLUN) {
+            TRACE2(("gdth_search_drives(): reserve ha %d bus %d id %d lun %d\n",
+                    reserve_list[i], reserve_list[i+1],
+                    reserve_list[i+2], reserve_list[i+3]));
+            if (!gdth_internal_cmd(hanum,SCSIRAWSERVICE,GDT_RESERVE,0,
+                                   reserve_list[i+1], reserve_list[i+2] | 
+                                   (reserve_list[i+3] << 8))) {
+                printk("GDT: Error raw service (RESERVE, code %d)\n",
+                       ha->status);
+             }
         }
     }
 
@@ -1379,63 +1685,49 @@
     for (i=0; i<cdev_cnt && i<MAX_HDRIVES; ++i) {
         TRACE(("gdth_search_drives() cachedev. %d\n",i));
         if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_INFO,i,0,0)) {
-            /* dynamic relation between host drive number and Bus/ID */
-            /* search free position */
-            pos_found = FALSE;
-            for (b=0,t=0; b<ha->bus_cnt; ++b) {
-                for (t=0; t<MAXID; ++t) {
-                    if (ha->id[b][t].type == EMPTY_DTYP) {
-                        pos_found = TRUE;
-                        break;
-                    }
-                }
-                if (pos_found)
-                    break;
-            }
-            TRACE(("gdth_search_dr() drive %d free pos at bus/id %d/%d\n",
-                         i,b,t));
+            /* static relation between host drive number and Bus/ID */
+            TRACE(("gdth_search_dr() drive %d mapped to bus/id %d/%d\n",
+                   i,ha->bus_cnt,i));
 
-            ha->id[b][t].type      = CACHE_DTYP;
-            ha->id[b][t].devtype   = 0;
-            ha->id[b][t].size      = ha->info;
-            ha->id[b][t].hostdrive = i;
+            ha->hdr[i].present = TRUE;
+            ha->hdr[i].size = ha->info;
 
             /* evaluate mapping (sectors per head, heads per cylinder) */
-	    ha->id[b][t].size &= ~SECS32;
-	    if (ha->info2 == 0) {
-		drv_cyls = ha->id[b][t].size /HEADS/SECS;
-		if (drv_cyls <= MAXCYLS) {
-		    drv_hds = HEADS;
-		    drv_secs= SECS;
-		} else {                            /* too high for 64*32 */
-		    drv_cyls = ha->id[b][t].size /MEDHEADS/MEDSECS;
-		    if (drv_cyls <= MAXCYLS) {
-			drv_hds = MEDHEADS;
-			drv_secs= MEDSECS;
-		    } else {                        /* too high for 127*63 */
-			drv_cyls = ha->id[b][t].size /BIGHEADS/BIGSECS;
-			drv_hds = BIGHEADS;
-			drv_secs= BIGSECS;
-		    }
-		}
+            ha->hdr[i].size &= ~SECS32;
+            if (ha->info2 == 0) {
+                drv_cyls = ha->hdr[i].size /HEADS/SECS;
+                if (drv_cyls <= MAXCYLS) {
+                    drv_hds = HEADS;
+                    drv_secs= SECS;
+                } else {                            /* too high for 64*32 */
+                    drv_cyls = ha->hdr[i].size /MEDHEADS/MEDSECS;
+                    if (drv_cyls <= MAXCYLS) {
+                        drv_hds = MEDHEADS;
+                        drv_secs= MEDSECS;
+                    } else {                        /* too high for 127*63 */
+                        drv_cyls = ha->hdr[i].size /BIGHEADS/BIGSECS;
+                        drv_hds = BIGHEADS;
+                        drv_secs= BIGSECS;
+                    }
+                }
             } else {
-		drv_hds = ha->info2 & 0xff;
-		drv_secs = (ha->info2 >> 8) & 0xff;
-		drv_cyls = ha->id[b][t].size /drv_hds/drv_secs;
-	    }
-            ha->id[b][t].heads = (unchar)drv_hds;
-            ha->id[b][t].secs  = (unchar)drv_secs;
+                drv_hds = ha->info2 & 0xff;
+                drv_secs = (ha->info2 >> 8) & 0xff;
+                drv_cyls = ha->hdr[i].size /drv_hds/drv_secs;
+            }
+            ha->hdr[i].heads = (unchar)drv_hds;
+            ha->hdr[i].secs  = (unchar)drv_secs;
             /* round size */
-            ha->id[b][t].size  = drv_cyls * drv_hds * drv_secs;
-            TRACE2(("gdth_search_dr() cdr. %d size %ld hds %ld scs %ld\n",
-                   i,ha->id[b][t].size,drv_hds,drv_secs));
+            ha->hdr[i].size  = drv_cyls * drv_hds * drv_secs;
+            TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
+                   i,ha->hdr[i].size,drv_hds,drv_secs));
             
             /* get informations about device */
             if (gdth_internal_cmd(hanum,CACHESERVICE,GDT_DEVTYPE,i,
                                   0,0)) {
-                TRACE(("gdth_search_dr() cache drive %d devtype %ld\n",
+                TRACE(("gdth_search_dr() cache drive %d devtype %d\n",
                        i,ha->info));
-                ha->id[b][t].devtype = (ushort)ha->info;
+                ha->hdr[i].devtype = (ushort)ha->info;
             }
         }
     }
@@ -1456,12 +1748,11 @@
     unchar b, t;
 
     TRACE(("gdth_putq() priority %d\n",priority));
-    save_flags(flags);
-    cli();
-
     ha = HADATA(gdth_ctr_tab[hanum]);
+    GDTH_LOCK_HA(ha, flags);
+
     scp->SCp.this_residual = (int)priority;
-    gdth_update_timeout(scp, scp->timeout * 6);
+    gdth_update_timeout(hanum, scp, scp->timeout_per_command * 6);
 #if LINUX_VERSION_CODE >= 0x020000
     b = scp->channel;
 #else
@@ -1469,9 +1760,12 @@
 #endif
     t = scp->target;
 #if LINUX_VERSION_CODE >= 0x010300
-    if (priority >= DEFAULT_PRI && ha->id[b][t].lock) {
-        TRACE2(("gdth_putq(): locked IO -> update_timeout()\n"));
-        scp->SCp.buffers_residual = gdth_update_timeout(scp, 0);
+    if (priority >= DEFAULT_PRI) {
+        if ((b < ha->bus_cnt && ha->raw[b].lock) ||
+            (b == ha->bus_cnt && ha->hdr[t].lock)) {
+            TRACE2(("gdth_putq(): locked IO -> update_timeout()\n"));
+            scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
+        }
     }
 #endif
 
@@ -1489,7 +1783,7 @@
         pscp->SCp.ptr = (char *)scp;
         scp->SCp.ptr  = (char *)nscp;
     }
-    restore_flags(flags);
+    GDTH_UNLOCK_HA(ha, flags);
 
 #ifdef GDTH_STATISTICS
     flags = 0;
@@ -1507,18 +1801,18 @@
     register gdth_ha_str *ha;
     register Scsi_Cmnd *pscp;
     register Scsi_Cmnd *nscp;
-    unchar b, t, next_cmd, firsttime;
-    ushort hdrive;
+    unchar b, t, firsttime;
+    unchar this_cmd, next_cmd;
     ulong flags;
     int cmd_index;
 
     TRACE(("gdth_next() hanum %d\n",hanum));
-    save_flags(flags);
-    cli();
-
     ha = HADATA(gdth_ctr_tab[hanum]);
+    GDTH_LOCK_HA(ha, flags);
+
     ha->cmd_cnt = ha->cmd_offs_dpmem = 0;
-    next_cmd = firsttime = TRUE;
+    this_cmd = firsttime = TRUE;
+    next_cmd = gdth_polling ? FALSE:TRUE;
     cmd_index = 0;
 
     for (nscp = pscp = ha->req_first; nscp; nscp = (Scsi_Cmnd *)nscp->SCp.ptr) {
@@ -1530,105 +1824,173 @@
         b = NUMDATA(nscp->host)->busnum;
 #endif
         t = nscp->target;
-        if (nscp->SCp.this_residual < DEFAULT_PRI || !ha->id[b][t].lock) {
+        if (nscp->SCp.this_residual >= DEFAULT_PRI) {
+            if ((b < ha->bus_cnt && ha->raw[b].lock) ||
+                (b == ha->bus_cnt && ha->hdr[t].lock)) 
+                continue;
+        }
 
-            if (firsttime) {
-                if (gdth_test_busy(hanum)) {        /* controller busy ? */
-                    TRACE(("gdth_next() controller %d busy !\n",hanum));
-                    if (!gdth_polling) {
-                        restore_flags(flags);
-                        return;
+        if (firsttime) {
+            if (gdth_test_busy(hanum)) {        /* controller busy ? */
+                TRACE(("gdth_next() controller %d busy !\n",hanum));
+                if (!gdth_polling) {
+                    GDTH_UNLOCK_HA(ha, flags);
+                    return;
+                }
+                while (gdth_test_busy(hanum))
+                    gdth_delay(1);
+            }   
+            firsttime = FALSE;
+        }
+
+        if (nscp->SCp.phase == -1) {
+            nscp->SCp.phase = SCSIRAWSERVICE;           /* default: raw svc. */ 
+            if (nscp->cmnd[0] == TEST_UNIT_READY) {
+                TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %d\n",
+                        nscp->channel, nscp->target, nscp->lun));
+                /* TEST_UNIT_READY -> set scan mode */
+                if ((ha->scan_mode & 0x0f) == 0) {
+                    if (nscp->channel == 0 && nscp->target == 0 &&
+                        nscp->lun == 0) {
+                        ha->scan_mode |= 1;
+                        TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
+                    }
+                } else if ((ha->scan_mode & 0x0f) == 1) {
+                    if (nscp->channel == 0 && 
+                        ((nscp->target == 0 && nscp->lun == 1) ||
+                         (nscp->target == 1 && nscp->lun == 0))) {
+                        nscp->SCp.Status = GDT_SCAN_START;
+                        nscp->SCp.phase |= ((ha->scan_mode & 0x10 ? 1:0) << 8);
+                        ha->scan_mode = 0x12;
+                        TRACE2(("Scan mode: 0x%x (SCAN_START)\n", 
+                                ha->scan_mode));
+                    } else {
+                        ha->scan_mode &= 0x10;
+                        TRACE2(("Scan mode: 0x%x\n", ha->scan_mode));
+                    }                   
+                } else if (ha->scan_mode == 0x12) {
+                    if (b == ha->bus_cnt) {
+                        nscp->SCp.Status = GDT_SCAN_END;
+                        ha->scan_mode &= 0x10;
+                        TRACE2(("Scan mode: 0x%x (SCAN_END)\n", 
+                                ha->scan_mode));
                     }
-                    while (gdth_test_busy(hanum))
-                        mdelay(1);
                 }
-                firsttime = FALSE;
             }
+        }
+
+        if (nscp->SCp.Status != -1) {
+            if ((nscp->SCp.phase & 0xff) == SCSIRAWSERVICE) {
+                cmd_index=gdth_fill_raw_cmd(hanum,nscp,b);
+                next_cmd = FALSE;
+            }
+        } else
 
 #if LINUX_VERSION_CODE >= 0x010300
-            if (nscp->done == gdth_scsi_done) {
-                if (!(cmd_index=gdth_special_cmd(hanum,nscp,b)))
-                    next_cmd = FALSE;
-            } else
-#endif
-            if (ha->id[b][t].type != CACHE_DTYP) {
-                if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,b)))
-                    next_cmd = FALSE;
-            } else {
-                hdrive = ha->id[b][t].hostdrive;
-                switch (nscp->cmnd[0]) {
-                  case TEST_UNIT_READY:
-                  case INQUIRY:
-                  case REQUEST_SENSE:
-                  case READ_CAPACITY:
-                  case VERIFY:
-                  case START_STOP:
-                  case MODE_SENSE:
-                    TRACE2(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
-                        nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
-                        nscp->cmnd[4],nscp->cmnd[5]));
-                        gdth_internal_cache_cmd(hanum,nscp,b,&flags);
-                    break;
+        if (nscp->done == gdth_scsi_done) {
+            if (!(cmd_index=gdth_special_cmd(hanum,nscp)))
+                this_cmd = FALSE;
+            next_cmd = FALSE;
+        } else
+#endif
+        if (b < ha->bus_cnt) {
+            if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,b))) {
+                this_cmd = FALSE;
+            }
+        } else if (!ha->hdr[nscp->target].present || nscp->lun != 0) {
+            TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNORE\n",
+                    nscp->cmnd[0], b, nscp->target, nscp->lun));
+            nscp->result = DID_BAD_TARGET << 16;
+            GDTH_UNLOCK_HA(ha,flags);
+            /* io_request_lock already active ! */      
+            nscp->scsi_done(nscp);
+            GDTH_LOCK_HA(ha,flags);
+        } else {
+            switch (nscp->cmnd[0]) {
+              case TEST_UNIT_READY:
+              case INQUIRY:
+              case REQUEST_SENSE:
+              case READ_CAPACITY:
+              case VERIFY:
+              case START_STOP:
+              case MODE_SENSE:
+                TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
+                       nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
+                       nscp->cmnd[4],nscp->cmnd[5]));
+                if (gdth_internal_cache_cmd(hanum,nscp)) {
+                    GDTH_UNLOCK_HA(ha,flags);
+                    /* io_request_lock already active ! */      
+                    nscp->scsi_done(nscp);
+                    GDTH_LOCK_HA(ha,flags);
+                }
+                break;
 
-                  case ALLOW_MEDIUM_REMOVAL:
-                    TRACE2(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
-                        nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
-                        nscp->cmnd[4],nscp->cmnd[5]));
-                    if ( (nscp->cmnd[4]&1) && !(ha->id[b][t].devtype&1) ) {
-                        TRACE2(("Prevent r. nonremov. drive->do nothing\n"));
-                        nscp->result = DID_OK << 16;
-                        restore_flags( flags );
+              case ALLOW_MEDIUM_REMOVAL:
+                TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
+                       nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
+                       nscp->cmnd[4],nscp->cmnd[5]));
+                if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
+                    TRACE(("Prevent r. nonremov. drive->do nothing\n"));
+                    nscp->result = DID_OK << 16;
+                    if (!nscp->SCp.have_data_in)
+                        nscp->SCp.have_data_in++;
+                    else {
+                        GDTH_UNLOCK_HA(ha,flags);
+                        /* io_request_lock already active ! */      
                         nscp->scsi_done(nscp);
-                        save_flags( flags );
-                        cli();
-                    } else {
-                        nscp->cmnd[3] = (ha->id[b][t].devtype&1) ? 1:0;
-                        TRACE2(("Prevent/allow r. %d rem. drive %d\n",
-                            nscp->cmnd[4],nscp->cmnd[3]));
-                        if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,hdrive)))
-                            next_cmd = FALSE;
+                        GDTH_LOCK_HA(ha,flags);
                     }
-                    break;
-
-                  case READ_6:
-                  case WRITE_6:
-                  case READ_10:
-                  case WRITE_10:
-                    if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,hdrive)))
-                        next_cmd = FALSE;
-                    break;
+                } else {
+                    nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
+                    TRACE(("Prevent/allow r. %d rem. drive %d\n",
+                           nscp->cmnd[4],nscp->cmnd[3]));
+                    if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
+                        this_cmd = FALSE;
+                }
+                break;
+                
+              case READ_6:
+              case WRITE_6:
+              case READ_10:
+              case WRITE_10:
+                if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
+                    this_cmd = FALSE;
+                break;
 
-                  default:
-                    TRACE2(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
+              default:
+                TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknown\n",nscp->cmnd[0],
                         nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
                         nscp->cmnd[4],nscp->cmnd[5]));
-                    printk("GDT: Unknown SCSI command 0x%x to cache service !\n",
+                printk("GDT: Unknown SCSI command 0x%x to cache service !\n",
                        nscp->cmnd[0]);
-                    nscp->result = DID_ABORT << 16;
-                    restore_flags( flags );
-                    nscp->scsi_done( nscp );
-                    save_flags( flags );
-                    cli();
-                    break;
+                nscp->result = DID_ABORT << 16;
+                if (!nscp->SCp.have_data_in)
+                    nscp->SCp.have_data_in++;
+                else {
+                    GDTH_UNLOCK_HA(ha,flags);
+                    /* io_request_lock already active ! */  
+                    nscp->scsi_done(nscp);
+                    GDTH_LOCK_HA(ha,flags);
                 }
-            }
-
-            if (!next_cmd)
-                break;
-            if (nscp == ha->req_first)
-                ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
-            else
-                pscp->SCp.ptr = nscp->SCp.ptr;
-            if (gdth_polling)
                 break;
+            }
         }
+
+        if (!this_cmd)
+            break;
+        if (nscp == ha->req_first)
+            ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
+        else
+            pscp->SCp.ptr = nscp->SCp.ptr;
+        if (!next_cmd)
+            break;
     }
 
     if (ha->cmd_cnt > 0) {
         gdth_release_event(hanum);
     }
 
-    restore_flags(flags);
+    GDTH_UNLOCK_HA(ha, flags);
 
     if (gdth_polling && ha->cmd_cnt > 0) {
         if (!gdth_wait(hanum,cmd_index,POLL_TIMEOUT))
@@ -1664,11 +2026,9 @@
     }
 }
 
-static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp,
-                                   unchar b,ulong *flags)
+static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
 {
     register gdth_ha_str *ha;
-    ushort hdrive;
     unchar t;
     gdth_inq_data inq;
     gdth_rdcap_data rdc;
@@ -1677,77 +2037,73 @@
 
     ha = HADATA(gdth_ctr_tab[hanum]);
     t  = scp->target;
-    hdrive = ha->id[b][t].hostdrive;
     TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
-                 scp->cmnd[0],hdrive));
-
-    if (scp->lun !=0)
-        scp->result = DID_BAD_TARGET << 16;
-    else {
-        switch (scp->cmnd[0]) {
-          case TEST_UNIT_READY:
-          case VERIFY:
-          case START_STOP:
-            TRACE2(("Test/Verify/Start hdrive %d\n",hdrive));
-            break;
-
-          case INQUIRY:
-            TRACE2(("Inquiry hdrive %d devtype %d\n",
-                          hdrive,ha->id[b][t].devtype));
-            inq.type_qual = (ha->id[b][t].devtype&4) ? TYPE_ROM:TYPE_DISK;
-            /* you can here set all disks to removable, if you want to do
-               a flush using the ALLOW_MEDIUM_REMOVAL command */
-            inq.modif_rmb = ha->id[b][t].devtype&1 ? 0x80:0x00;
-            inq.version   = 2;
-            inq.resp_aenc = 2;
-            inq.add_length= 32;
-            strcpy(inq.vendor,"ICP    ");
-            sprintf(inq.product,"Host Drive  #%02d",hdrive);
-            strcpy(inq.revision,"   ");
-            gdth_copy_internal_data(scp,(char*)&inq,sizeof(gdth_inq_data));
-            break;
-
-          case REQUEST_SENSE:
-            TRACE2(("Request sense hdrive %d\n",hdrive));
-            sd.errorcode = 0x70;
-            sd.segno     = 0x00;
-            sd.key       = NO_SENSE;
-            sd.info      = 0;
-            sd.add_length= 0;
-            gdth_copy_internal_data(scp,(char*)&sd,sizeof(gdth_sense_data));
-            break;
-
-          case MODE_SENSE:
-            TRACE2(("Mode sense hdrive %d\n",hdrive));
-            memset((char*)&mpd,0,sizeof(gdth_modep_data));
-            mpd.hd.data_length = sizeof(gdth_modep_data);
-            mpd.hd.dev_par     = (ha->id[b][t].devtype&2) ? 0x80:0;
-            mpd.hd.bd_length   = sizeof(mpd.bd);
-            mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
-            mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
-            mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
-            gdth_copy_internal_data(scp,(char*)&mpd,sizeof(gdth_modep_data));
-            break;
-
-          case READ_CAPACITY:
-            TRACE2(("Read capacity hdrive %d\n",hdrive));
-            rdc.last_block_no = ntohl(ha->id[b][t].size-1);
-            rdc.block_length  = ntohl(SECTOR_SIZE);
-            gdth_copy_internal_data(scp,(char*)&rdc,sizeof(gdth_rdcap_data));
-            break;
+           scp->cmnd[0],t));
 
-          default:
-            TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
-            break;
-        }
-        scp->result = DID_OK << 16;
+    switch (scp->cmnd[0]) {
+      case TEST_UNIT_READY:
+      case VERIFY:
+      case START_STOP:
+        TRACE2(("Test/Verify/Start hdrive %d\n",t));
+        break;
+
+      case INQUIRY:
+        TRACE2(("Inquiry hdrive %d devtype %d\n",
+                t,ha->hdr[t].devtype));
+        inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
+        /* you can here set all disks to removable, if you want to do
+           a flush using the ALLOW_MEDIUM_REMOVAL command */
+        inq.modif_rmb = ha->hdr[t].devtype&1 ? 0x80:0x00;
+        inq.version   = 2;
+        inq.resp_aenc = 2;
+        inq.add_length= 32;
+        strcpy(inq.vendor,"ICP    ");
+        sprintf(inq.product,"Host Drive  #%02d",t);
+        strcpy(inq.revision,"   ");
+        gdth_copy_internal_data(scp,(char*)&inq,sizeof(gdth_inq_data));
+        break;
+
+      case REQUEST_SENSE:
+        TRACE2(("Request sense hdrive %d\n",t));
+        sd.errorcode = 0x70;
+        sd.segno     = 0x00;
+        sd.key       = NO_SENSE;
+        sd.info      = 0;
+        sd.add_length= 0;
+        gdth_copy_internal_data(scp,(char*)&sd,sizeof(gdth_sense_data));
+        break;
+
+      case MODE_SENSE:
+        TRACE2(("Mode sense hdrive %d\n",t));
+        memset((char*)&mpd,0,sizeof(gdth_modep_data));
+        mpd.hd.data_length = sizeof(gdth_modep_data);
+        mpd.hd.dev_par     = (ha->hdr[t].devtype&2) ? 0x80:0;
+        mpd.hd.bd_length   = sizeof(mpd.bd);
+        mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
+        mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
+        mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
+        gdth_copy_internal_data(scp,(char*)&mpd,sizeof(gdth_modep_data));
+        break;
+
+      case READ_CAPACITY:
+        TRACE2(("Read capacity hdrive %d\n",t));
+        rdc.last_block_no = ntohl(ha->hdr[t].size-1);
+        rdc.block_length  = ntohl(SECTOR_SIZE);
+        gdth_copy_internal_data(scp,(char*)&rdc,sizeof(gdth_rdcap_data));
+        break;
+
+      default:
+        TRACE2(("Internal cache cmd 0x%x unknown\n",scp->cmnd[0]));
+        break;
     }
+    scp->result = DID_OK << 16;
 
-    restore_flags(*flags);
-    scp->scsi_done(scp);
-    save_flags(*flags);
-    cli();
-    return 1;
+    if (!scp->SCp.have_data_in)
+        scp->SCp.have_data_in++;
+    else 
+        return 1;
+
+    return 0;
 }
     
 static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
@@ -1804,25 +2160,26 @@
         cmdp->u.cache.sg_canz = 0;
     } else {
         if (scp->cmd_len != 6) {
-            cmdp->u.cache.BlockNo = ntohl(*(ulong*)&scp->cmnd[2]);
-            cmdp->u.cache.BlockCnt= (ulong)ntohs(*(ushort*)&scp->cmnd[7]);
+            cmdp->u.cache.BlockNo = ntohl(*(ulong32*)&scp->cmnd[2]);
+            cmdp->u.cache.BlockCnt= (ulong32)ntohs(*(ushort*)&scp->cmnd[7]);
         } else {
-            cmdp->u.cache.BlockNo = ntohl(*(ulong*)&scp->cmnd[0]) & 0x001fffffUL;
+            cmdp->u.cache.BlockNo = 
+                ntohl(*(ulong32*)&scp->cmnd[0]) & 0x001fffffUL;
             cmdp->u.cache.BlockCnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
         }
 
         if (scp->use_sg) {
-            cmdp->u.cache.DestAddr= -1UL;
+            cmdp->u.cache.DestAddr= 0xffffffff;
             sl = (struct scatterlist *)scp->request_buffer;
             for (i=0; i<scp->use_sg; ++i,++sl) {
                 cmdp->u.cache.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
-                cmdp->u.cache.sg_lst[i].sg_len = (ulong)sl->length;
+                cmdp->u.cache.sg_lst[i].sg_len = (ulong32)sl->length;
             }
-            cmdp->u.cache.sg_canz = (ulong)i;
+            cmdp->u.cache.sg_canz = (ulong32)i;
 
 #ifdef GDTH_STATISTICS
-            if (max_sg < (ulong)i) {
-                max_sg = (ulong)i;
+            if (max_sg < (ulong32)i) {
+                max_sg = (ulong32)i;
                 TRACE3(("GDT: max_sg = %d\n",i));
             }
 #endif
@@ -1830,9 +2187,10 @@
                 cmdp->u.cache.sg_lst[i].sg_len = 0;
         } else {
             if (ha->cache_feat & SCATTER_GATHER) {
-                cmdp->u.cache.DestAddr = -1UL;
+                cmdp->u.cache.DestAddr = 0xffffffff;
                 cmdp->u.cache.sg_canz = 1;
-                cmdp->u.cache.sg_lst[0].sg_ptr = virt_to_bus(scp->request_buffer);
+                cmdp->u.cache.sg_lst[0].sg_ptr = 
+                    virt_to_bus(scp->request_buffer);
                 cmdp->u.cache.sg_lst[0].sg_len = scp->request_bufflen;
                 cmdp->u.cache.sg_lst[1].sg_len = 0;
             } else {
@@ -1841,12 +2199,12 @@
             }
         }
     }
-    TRACE(("cache cmd: addr. %lx sganz %lx sgptr0 %lx sglen0 %lx\n",
-                  cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
-                  cmdp->u.cache.sg_lst[0].sg_ptr,
-                  cmdp->u.cache.sg_lst[0].sg_len));
-    TRACE(("cache cmd: cmd %d blockno. %ld, blockcnt %ld\n",
-                  cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
+    TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
+           cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
+           cmdp->u.cache.sg_lst[0].sg_ptr,
+           cmdp->u.cache.sg_lst[0].sg_len));
+    TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
+           cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
 
     /* evaluate command size, check space */
     ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
@@ -1858,7 +2216,7 @@
         if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
             ha->ic_all_size) {
             TRACE2(("gdth_fill_cache() DPMEM overflow\n"));
-            gdth_cmd_tab[cmd_index-2][hanum].cmnd = UNUSED_CMND;
+            ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
             return 0;
         }
     }
@@ -1882,7 +2240,7 @@
     l = scp->lun;
     cmdp = ha->pccb;
     TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %d\n",
-                 scp->cmnd[0],b,t,l));
+           scp->cmnd[0],b,t,l));
 
     if (ha->type==GDT_EISA && ha->cmd_cnt>0) 
         return 0;
@@ -1899,61 +2257,73 @@
         gdth_set_sema0(hanum);
 
     /* fill command */  
-    cmdp->OpCode           = GDT_WRITE;         /* always */
-    cmdp->BoardNode        = LOCALBOARD;
-    cmdp->u.raw.reserved   = 0;
-    cmdp->u.raw.mdisc_time = 0;
-    cmdp->u.raw.mcon_time  = 0;
-    cmdp->u.raw.clen       = scp->cmd_len;
-    cmdp->u.raw.target     = t;
-    cmdp->u.raw.lun        = l;
-    cmdp->u.raw.bus        = b;
-    cmdp->u.raw.priority   = 0;
-    cmdp->u.raw.link_p     = NULL;
-    cmdp->u.raw.sdlen      = scp->request_bufflen;
-    cmdp->u.raw.sense_len  = 16;
-    cmdp->u.raw.sense_data = virt_to_bus(scp->sense_buffer);
-    cmdp->u.raw.direction  = 
-        gdth_direction_tab[scp->cmnd[0]]==DOU ? DATA_OUT : DATA_IN;
-    memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
+    if (scp->SCp.Status != -1) {
+        cmdp->OpCode           = scp->SCp.Status;       /* special raw cmd. */
+        cmdp->BoardNode        = LOCALBOARD;
+        cmdp->u.raw.direction  = (scp->SCp.phase >> 8);
+        TRACE2(("special raw cmd 0x%x param 0x%x\n", 
+                cmdp->OpCode, cmdp->u.raw.direction));
 
-    if (scp->use_sg) {
-        cmdp->u.raw.sdata  = -1UL;
-        sl = (struct scatterlist *)scp->request_buffer;
-        for (i=0; i<scp->use_sg; ++i,++sl) {
-            cmdp->u.raw.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
-            cmdp->u.raw.sg_lst[i].sg_len = (ulong)sl->length;
-        }
-        cmdp->u.raw.sg_ranz = (ulong)i;
+        /* evaluate command size */
+        ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
+    } else {
+        cmdp->OpCode           = GDT_WRITE;             /* always */
+        cmdp->BoardNode        = LOCALBOARD;
+        cmdp->u.raw.reserved   = 0;
+        cmdp->u.raw.mdisc_time = 0;
+        cmdp->u.raw.mcon_time  = 0;
+        cmdp->u.raw.clen       = scp->cmd_len;
+        cmdp->u.raw.target     = t;
+        cmdp->u.raw.lun        = l;
+        cmdp->u.raw.bus        = b;
+        cmdp->u.raw.priority   = 0;
+        cmdp->u.raw.link_p     = NULL;
+        cmdp->u.raw.sdlen      = scp->request_bufflen;
+        cmdp->u.raw.sense_len  = 16;
+        cmdp->u.raw.sense_data = virt_to_bus(scp->sense_buffer);
+        cmdp->u.raw.direction  = 
+            gdth_direction_tab[scp->cmnd[0]]==DOU ? DATA_OUT : DATA_IN;
+        memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
+
+        if (scp->use_sg) {
+            cmdp->u.raw.sdata  = 0xffffffff;
+            sl = (struct scatterlist *)scp->request_buffer;
+            for (i=0; i<scp->use_sg; ++i,++sl) {
+                cmdp->u.raw.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
+                cmdp->u.raw.sg_lst[i].sg_len = (ulong32)sl->length;
+            }
+            cmdp->u.raw.sg_ranz = (ulong32)i;
 
 #ifdef GDTH_STATISTICS
-        if (max_sg < (ulong)i) {
-            max_sg = (ulong)i;
-            TRACE3(("GDT: max_sg = %d\n",i));
-        }
+            if (max_sg < (ulong32)i) {
+                max_sg = (ulong32)i;
+                TRACE3(("GDT: max_sg = %d\n",i));
+            }
 #endif
-        if (i<GDTH_MAXSG)
-            cmdp->u.raw.sg_lst[i].sg_len = 0;
-    } else {
-        if (ha->raw_feat & SCATTER_GATHER) {
-            cmdp->u.raw.sdata  = -1UL;
-            cmdp->u.raw.sg_ranz= 1;
-            cmdp->u.raw.sg_lst[0].sg_ptr = virt_to_bus(scp->request_buffer);
-            cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
-            cmdp->u.raw.sg_lst[1].sg_len = 0;
+            if (i<GDTH_MAXSG)
+                cmdp->u.raw.sg_lst[i].sg_len = 0;
         } else {
-            cmdp->u.raw.sdata  = virt_to_bus(scp->request_buffer);
-            cmdp->u.raw.sg_ranz= 0;
+            if (ha->raw_feat & SCATTER_GATHER) {
+                cmdp->u.raw.sdata  = 0xffffffff;
+                cmdp->u.raw.sg_ranz= 1;
+                cmdp->u.raw.sg_lst[0].sg_ptr = virt_to_bus(scp->request_buffer);
+                cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
+                cmdp->u.raw.sg_lst[1].sg_len = 0;
+            } else {
+                cmdp->u.raw.sdata  = virt_to_bus(scp->request_buffer);
+                cmdp->u.raw.sg_ranz= 0;
+            }
         }
-    }
-    TRACE(("raw cmd: addr. %lx sganz %lx sgptr0 %lx sglen0 %lx\n",
-                  cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
-                  cmdp->u.raw.sg_lst[0].sg_ptr,
-                  cmdp->u.raw.sg_lst[0].sg_len));
+        TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
+               cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
+               cmdp->u.raw.sg_lst[0].sg_ptr,
+               cmdp->u.raw.sg_lst[0].sg_len));
 
-    /* evaluate command size, check space */
-    ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
-        (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
+        /* evaluate command size */
+        ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
+            (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
+    }
+    /* check space */
     if (ha->cmd_len & 3)
         ha->cmd_len += (4 - (ha->cmd_len & 3));
 
@@ -1961,7 +2331,7 @@
         if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
             ha->ic_all_size) {
             TRACE2(("gdth_fill_raw() DPMEM overflow\n"));
-            gdth_cmd_tab[cmd_index-2][hanum].cmnd = UNUSED_CMND;
+            ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
             return 0;
         }
     }
@@ -1971,7 +2341,7 @@
     return cmd_index;
 }
 
-static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
+static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
 {
     register gdth_ha_str *ha;
     register gdth_cmd_str *cmdp;
@@ -2000,13 +2370,16 @@
     /* evaluate command size, check space */
     if (cmdp->OpCode == GDT_IOCTL) {
         TRACE2(("IOCTL\n"));
-        ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong);
+        ha->cmd_len = 
+            GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong32);
     } else if (cmdp->Service == CACHESERVICE) {
         TRACE2(("cache command %d\n",cmdp->OpCode));
-        ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
+        ha->cmd_len = 
+            GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
     } else if (cmdp->Service == SCSIRAWSERVICE) {
         TRACE2(("raw command %d/%d\n",cmdp->OpCode,cmdp->u.raw.cmd[0]));
-        ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
+        ha->cmd_len = 
+            GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
     }
 
     if (ha->cmd_len & 3)
@@ -2016,7 +2389,7 @@
         if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
             ha->ic_all_size) {
             TRACE2(("gdth_special_cmd() DPMEM overflow\n"));
-            gdth_cmd_tab[cmd_index-2][hanum].cmnd = UNUSED_CMND;
+            ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
             return 0;
         }
     }
@@ -2028,8 +2401,8 @@
 
 
 /* Controller event handling functions */
-static gdth_evt_str *gdth_store_event(ushort source, ushort idx,
-                                      gdth_evt_data *evt)
+static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source, 
+                                      ushort idx, gdth_evt_data *evt)
 {
     gdth_evt_str *e;
     ulong flags;
@@ -2039,8 +2412,7 @@
     if (source == 0)                        /* no source -> no event */
         return 0;
 
-    save_flags(flags);
-    cli();
+    GDTH_LOCK_HA(ha, flags);
     if (ebuffer[elastidx].event_source == source &&
         ebuffer[elastidx].event_idx == idx &&
         !memcmp((char *)&ebuffer[elastidx].event_data.eu,
@@ -2068,19 +2440,18 @@
         e->same_count = 1;
         e->event_data = *evt;
     }
-    restore_flags(flags);
+    GDTH_UNLOCK_HA(ha, flags);
     return e;
 }
 
-static int gdth_read_event(int handle, gdth_evt_str *estr)
+static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
 {
     gdth_evt_str *e;
     int eindex;
     ulong flags;
 
     TRACE2(("gdth_read_event() handle %d\n", handle));
-    save_flags(flags);
-    cli();
+    GDTH_LOCK_HA(ha, flags);
     if (handle == -1)
         eindex = eoldidx;
     else
@@ -2088,7 +2459,7 @@
     estr->event_source = 0;
 
     if (eindex >= MAX_EVENTS) {
-        restore_flags(flags);
+        GDTH_UNLOCK_HA(ha, flags);
         return eindex;
     }
     e = &ebuffer[eindex];
@@ -2101,11 +2472,12 @@
         }
         memcpy(estr, e, sizeof(gdth_evt_str));
     }
-    restore_flags(flags);
+    GDTH_UNLOCK_HA(ha, flags);
     return eindex;
 }
 
-static void gdth_readapp_event(unchar application, gdth_evt_str *estr)
+static void gdth_readapp_event(gdth_ha_str *ha,
+                               unchar application, gdth_evt_str *estr)
 {
     gdth_evt_str *e;
     int eindex;
@@ -2113,8 +2485,7 @@
     unchar found = FALSE;
 
     TRACE2(("gdth_readapp_event() app. %d\n", application));
-    save_flags(flags);
-    cli();
+    GDTH_LOCK_HA(ha, flags);
     eindex = eoldidx;
     for (;;) {
         e = &ebuffer[eindex];
@@ -2134,35 +2505,21 @@
         memcpy(estr, e, sizeof(gdth_evt_str));
     else
         estr->event_source = 0;
-    restore_flags(flags);
+    GDTH_UNLOCK_HA(ha, flags);
 }
 
 static void gdth_clear_events()
 {
-    ulong flags;
-
     TRACE(("gdth_clear_events()"));
-    save_flags(flags);
-    cli();
 
     eoldidx = elastidx = 0;
     ebuffer[0].event_source = 0;
-    restore_flags(flags);
 }
 
 
 /* SCSI interface functions */
 
 #if LINUX_VERSION_CODE >= 0x010346
-static void do_gdth_interrupt(int irq, void *dev_id, struct pt_regs *regs)
-{
-    unsigned long flags;
-
-    spin_lock_irqsave(&io_request_lock, flags);
-    gdth_interrupt(irq, dev_id, regs);
-    spin_unlock_irqrestore(&io_request_lock, flags);
-}
-
 static void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs)
 #else
 static void gdth_interrupt(int irq,struct pt_regs *regs)
@@ -2173,11 +2530,12 @@
     gdt6_dpram_str *dp6_ptr;
     gdt2_dpram_str *dp2_ptr;
     Scsi_Cmnd *scp;
-    int hanum;
+    int hanum, rval;
     unchar IStatus;
     ushort CmdStatus, Service = 0;
-    ulong InfoBytes, InfoBytes2 = 0;
+    ulong32 InfoBytes, InfoBytes2 = 0;
     gdth_evt_data dvr;
+    ulong flags = 0;
 
     TRACE(("gdth_interrupt() IRQ %d\n",irq));
 
@@ -2188,6 +2546,8 @@
         }
     }
 
+    if (!gdth_polling)
+        GDTH_LOCK_HA((gdth_ha_str *)dev_id,flags);
     wait_index = 0;
 
     /* search controller */
@@ -2195,6 +2555,8 @@
         /*
         TRACE2(("gdth_interrupt(): Spurious interrupt received\n"));
         */
+        if (!gdth_polling)
+            GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
         return;
     }
 
@@ -2204,63 +2566,63 @@
     
     ha = HADATA(gdth_ctr_tab[hanum]);
     if (ha->type == GDT_EISA) {
-        if (IStatus & 0x80) {                   /* error flag */
+        if (IStatus & 0x80) {                       /* error flag */
             IStatus &= ~0x80;
             CmdStatus = inw(ha->bmic + MAILBOXREG+8);
             TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,CmdStatus));
-            if (IStatus == ASYNCINDEX) {        /* async. event ? */
+            if (IStatus == ASYNCINDEX) {            /* async. event ? */
                 Service = inw(ha->bmic + MAILBOXREG+10);
                 InfoBytes2 = inl(ha->bmic + MAILBOXREG+4);
             }
-        } else                                  /* no error */
+        } else                                      /* no error */
             CmdStatus = S_OK;
         InfoBytes = inl(ha->bmic + MAILBOXREG+12);
-	if (gdth_polling)			/* init. -> more info */
-	    InfoBytes2 = inl(ha->bmic + MAILBOXREG+4);
-        outb(0xff, ha->bmic + EDOORREG);    /* acknowledge interrupt */
-        outb(0x00, ha->bmic + SEMA1REG);    /* reset status semaphore */
+        if (gdth_polling)                           /* init. -> more info */
+            InfoBytes2 = inl(ha->bmic + MAILBOXREG+4);
+        outb(0xff, ha->bmic + EDOORREG);            /* acknowledge interrupt */
+        outb(0x00, ha->bmic + SEMA1REG);            /* reset status semaphore */
     } else if (ha->type == GDT_ISA) {
         dp2_ptr = (gdt2_dpram_str *)ha->brd;
-        if (IStatus & 0x80) {                   /* error flag */
+        if (IStatus & 0x80) {                       /* error flag */
             IStatus &= ~0x80;
-            CmdStatus = readw(&dp2_ptr->u.ic.Status);
+            CmdStatus = gdth_readw(&dp2_ptr->u.ic.Status);
             TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,CmdStatus));
-            if (IStatus == ASYNCINDEX) {        /* async. event ? */
-                Service = readw(&dp2_ptr->u.ic.Service);
-                InfoBytes2 = readl(&dp2_ptr->u.ic.Info[1]);
+            if (IStatus == ASYNCINDEX) {            /* async. event ? */
+                Service = gdth_readw(&dp2_ptr->u.ic.Service);
+                InfoBytes2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
             }
-        } else                                  /* no error */
+        } else                                      /* no error */
             CmdStatus = S_OK;
-        InfoBytes = readl(&dp2_ptr->u.ic.Info[0]);
-	if (gdth_polling)			/* init. -> more info */
-	    InfoBytes2 = readl(&dp2_ptr->u.ic.Info[1]);
-        writeb(0xff, &dp2_ptr->io.irqdel);              /* acknowledge interrupt */
-        writeb(0, &dp2_ptr->u.ic.Cmd_Index);            /* reset command index */
-        writeb(0, &dp2_ptr->io.Sema1);                 /* reset status semaphore */
+        InfoBytes = gdth_readl(&dp2_ptr->u.ic.Info[0]);
+        if (gdth_polling)                           /* init. -> more info */
+            InfoBytes2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
+        gdth_writeb(0xff, &dp2_ptr->io.irqdel);     /* acknowledge interrupt */
+        gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);   /* reset command index */
+        gdth_writeb(0, &dp2_ptr->io.Sema1);         /* reset status semaphore */
     } else if (ha->type == GDT_PCI) {
         dp6_ptr = (gdt6_dpram_str *)ha->brd;
-        if (IStatus & 0x80) {                   /* error flag */
+        if (IStatus & 0x80) {                       /* error flag */
             IStatus &= ~0x80;
-            CmdStatus = readw(&dp6_ptr->u.ic.Status);
+            CmdStatus = gdth_readw(&dp6_ptr->u.ic.Status);
             TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,CmdStatus));
             if (IStatus == ASYNCINDEX) {        /* async. event ? */
-                Service = readw(&dp6_ptr->u.ic.Service);
-                InfoBytes2 = readl(&dp6_ptr->u.ic.Info[1]);
+                Service = gdth_readw(&dp6_ptr->u.ic.Service);
+                InfoBytes2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
             }
-        } else                                  /* no error */
+        } else                                      /* no error */
             CmdStatus = S_OK;
-        InfoBytes = readl(&dp6_ptr->u.ic.Info[0]);
-	if (gdth_polling)			/* init. -> more info */
-	    InfoBytes2 = readl(&dp6_ptr->u.ic.Info[1]);
-        writeb(0xff, &dp6_ptr->io.irqdel);              /* acknowledge interrupt */
-        writeb(0, &dp6_ptr->u.ic.Cmd_Index);            /* reset command index */
-        writeb(0, &dp6_ptr->io.Sema1);                 /* reset status semaphore */
+        InfoBytes = gdth_readl(&dp6_ptr->u.ic.Info[0]);
+        if (gdth_polling)                           /* init. -> more info */
+            InfoBytes2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
+        gdth_writeb(0xff, &dp6_ptr->io.irqdel);     /* acknowledge interrupt */
+        gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);   /* reset command index */
+        gdth_writeb(0, &dp6_ptr->io.Sema1);         /* reset status semaphore */
     } else if (ha->type == GDT_PCINEW) {
-        if (IStatus & 0x80) {                   /* error flag */
+        if (IStatus & 0x80) {                       /* error flag */
             IStatus &= ~0x80;
             CmdStatus = inw(PTR2USHORT(&ha->plx->status));
             TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,CmdStatus));
-            if (IStatus == ASYNCINDEX) {        /* async. event ? */
+            if (IStatus == ASYNCINDEX) {            /* async. event ? */
                 Service = inw(PTR2USHORT(&ha->plx->service));
                 InfoBytes2 = inl(PTR2USHORT(&ha->plx->info[1]));
             }
@@ -2268,34 +2630,36 @@
             CmdStatus = S_OK;
 
         InfoBytes = inl(PTR2USHORT(&ha->plx->info[0]));
-	if (gdth_polling)			/* init. -> more info */
-	    InfoBytes2 = inl(PTR2USHORT(&ha->plx->info[1]));
+        if (gdth_polling)                           /* init. -> more info */
+            InfoBytes2 = inl(PTR2USHORT(&ha->plx->info[1]));
         outb(0xff, PTR2USHORT(&ha->plx->edoor_reg)); 
         outb(0x00, PTR2USHORT(&ha->plx->sema1_reg)); 
     } else if (ha->type == GDT_PCIMPR) {
         dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
-        if (IStatus & 0x80) {                   /* error flag */
+        if (IStatus & 0x80) {                       /* error flag */
             IStatus &= ~0x80;
-            CmdStatus = readw(&dp6m_ptr->i960r.status);
+            CmdStatus = gdth_readw(&dp6m_ptr->i960r.status);
             TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,CmdStatus));
-            if (IStatus == ASYNCINDEX) {        /* async. event ? */
-                Service = readw(&dp6m_ptr->i960r.service);
-                InfoBytes2 = readl(&dp6m_ptr->i960r.info[1]);
+            if (IStatus == ASYNCINDEX) {            /* async. event ? */
+                Service = gdth_readw(&dp6m_ptr->i960r.service);
+                InfoBytes2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
             }
-        } else                                  /* no error */
+        } else                                      /* no error */
             CmdStatus = S_OK;
-        InfoBytes = readl(&dp6m_ptr->i960r.info[0]);
-	if (gdth_polling)			/* init. -> more info */
-	    InfoBytes2 = readl(&dp6m_ptr->i960r.info[1]);
-        writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
-        writeb(0, &dp6m_ptr->i960r.sema1_reg);
+        InfoBytes = gdth_readl(&dp6m_ptr->i960r.info[0]);
+        if (gdth_polling)                           /* init. -> more info */
+            InfoBytes2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
+        gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
+        gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
     } else {
         TRACE2(("gdth_interrupt() unknown controller type\n"));
+        if (!gdth_polling)
+            GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
         return;
     }
 
-    TRACE(("gdth_interrupt() index %d stat %d info %ld\n",
-                 IStatus,CmdStatus,InfoBytes));
+    TRACE(("gdth_interrupt() index %d stat %d info %d\n",
+           IStatus,CmdStatus,InfoBytes));
     ha->status = CmdStatus;
     ha->info   = InfoBytes;
     ha->info2  = InfoBytes2;
@@ -2308,31 +2672,51 @@
     if (IStatus == ASYNCINDEX) {
         TRACE2(("gdth_interrupt() async. event\n"));
         gdth_async_event(hanum,Service);
-    } else {
-        if (IStatus == SPEZINDEX) {
-            TRACE2(("Service unknown or not initialized !\n"));
-            dvr.size = sizeof(dvr.eu.driver);
-            dvr.eu.driver.ionode = hanum;
-            gdth_store_event(ES_DRIVER, 4, &dvr);
-            return;
-        }
-        scp     = gdth_cmd_tab[IStatus-2][hanum].cmnd;
-        Service = gdth_cmd_tab[IStatus-2][hanum].service;
-        gdth_cmd_tab[IStatus-2][hanum].cmnd = UNUSED_CMND;
-        if (scp == UNUSED_CMND) {
-            TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
-            dvr.size = sizeof(dvr.eu.driver);
-            dvr.eu.driver.ionode = hanum;
-            dvr.eu.driver.index = IStatus;
-            gdth_store_event(ES_DRIVER, 1, &dvr);
-            return;
-        }
-        if (scp == INTERNAL_CMND) {
-            TRACE(("gdth_interrupt() answer to internal command\n"));
-            return;
-        }
-        TRACE(("gdth_interrupt() sync. status\n"));
-        gdth_sync_event(hanum,Service,IStatus,scp);
+        if (!gdth_polling)
+            GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
+        gdth_next(hanum);
+        return;
+    } 
+
+    if (IStatus == SPEZINDEX) {
+        TRACE2(("Service unknown or not initialized !\n"));
+        dvr.size = sizeof(dvr.eu.driver);
+        dvr.eu.driver.ionode = hanum;
+        gdth_store_event(ha, ES_DRIVER, 4, &dvr);
+        if (!gdth_polling)
+            GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
+        return;
+    }
+    scp     = ha->cmd_tab[IStatus-2].cmnd;
+    Service = ha->cmd_tab[IStatus-2].service;
+    ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
+    if (scp == UNUSED_CMND) {
+        TRACE2(("gdth_interrupt() index to unused command (%d)\n",IStatus));
+        dvr.size = sizeof(dvr.eu.driver);
+        dvr.eu.driver.ionode = hanum;
+        dvr.eu.driver.index = IStatus;
+        gdth_store_event(ha, ES_DRIVER, 1, &dvr);
+        if (!gdth_polling)
+            GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
+        return;
+    }
+    if (scp == INTERNAL_CMND) {
+        TRACE(("gdth_interrupt() answer to internal command\n"));
+        if (!gdth_polling)
+            GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
+        return;
+    }
+
+    TRACE(("gdth_interrupt() sync. status\n"));
+    rval = gdth_sync_event(hanum,Service,IStatus,scp);
+    if (!gdth_polling)
+        GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
+    if (rval == 2) {
+        gdth_putq(hanum,scp,scp->SCp.this_residual);
+    } else if (rval == 1) {
+        GDTH_LOCK_SCSI_DONE(flags);
+        scp->scsi_done(scp);
+        GDTH_UNLOCK_SCSI_DONE(flags);
     }
     gdth_next(hanum);
 }
@@ -2348,13 +2732,14 @@
 
     ha   = HADATA(gdth_ctr_tab[hanum]);
     cmdp = ha->pccb;
-    TRACE(("gdth_sync_event() scp %lx serv %d status %d\n",
-                 (ulong)scp,service,ha->status));
+    TRACE(("gdth_sync_event() serv %d status %d\n",
+           service,ha->status));
 
     if (service == SCREENSERVICE) {
         msg  = (gdth_msg_str *)ha->pscratch;
-        TRACE(("len: %ld, answer: %d, ext: %d, alen: %ld\n",
-                     msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
+        ha->scratch_busy = FALSE;
+        TRACE(("len: %d, answer: %d, ext: %d, alen: %d\n",
+               msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
         if (msg->msg_len)
             if (!(msg->msg_answer && msg->msg_ext)) {
                 msg->msg_text[msg->msg_len] = '\0';
@@ -2363,7 +2748,7 @@
 
         if (msg->msg_ext && !msg->msg_answer) {
             while (gdth_test_busy(hanum))
-                udelay(1);
+                gdth_delay(0);
             cmdp->Service       = SCREENSERVICE;
             cmdp->RequestBuffer = SCREEN_CMND;
             gdth_get_cmd_index(hanum);
@@ -2372,14 +2757,15 @@
             cmdp->BoardNode     = LOCALBOARD;
             cmdp->u.screen.reserved  = 0;
             cmdp->u.screen.msg_handle= msg->msg_handle;
-            cmdp->u.screen.msg_addr  = (ulong)msg;
+            cmdp->u.screen.msg_addr  = virt_to_bus(msg);
+            ha->scratch_busy = TRUE;
             ha->cmd_offs_dpmem = 0;
             ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.msg_addr) 
-                + sizeof(ulong);
+                + sizeof(ulong32);
             ha->cmd_cnt = 0;
             gdth_copy_command(hanum);
             gdth_release_event(hanum);
-            return 1;
+            return 0;
         }
 
         if (msg->msg_answer && msg->msg_alen) {
@@ -2400,7 +2786,7 @@
             }
             msg->msg_len = i;
             while (gdth_test_busy(hanum))
-                udelay(1);
+                gdth_delay(0);
             cmdp->Service       = SCREENSERVICE;
             cmdp->RequestBuffer = SCREEN_CMND;
             gdth_get_cmd_index(hanum);
@@ -2409,14 +2795,15 @@
             cmdp->BoardNode     = LOCALBOARD;
             cmdp->u.screen.reserved  = 0;
             cmdp->u.screen.msg_handle= msg->msg_handle;
-            cmdp->u.screen.msg_addr  = (ulong)msg;
+            cmdp->u.screen.msg_addr  = virt_to_bus(msg);
+            ha->scratch_busy = TRUE;
             ha->cmd_offs_dpmem = 0;
             ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.msg_addr) 
-                + sizeof(ulong);
+                + sizeof(ulong32);
             ha->cmd_cnt = 0;
             gdth_copy_command(hanum);
             gdth_release_event(hanum);
-            return 1;
+            return 0;
         }
         printk("\n");
 
@@ -2424,12 +2811,25 @@
         scp->SCp.Message = (int)ha->status;
         /* cache or raw service */
         if (ha->status == S_OK) {
+            if (scp->SCp.Status != -1) {
+                TRACE2(("gdth_sync_event(): special cmd 0x%x OK\n",
+                        scp->SCp.Status));
+                scp->SCp.Status = -1;
+                scp->SCp.this_residual = HIGH_PRI;
+                return 2;
+            }
             scp->result = DID_OK << 16;
         } else if (ha->status == S_BSY) {
             TRACE2(("Controller busy -> retry !\n"));
-            gdth_putq(hanum,scp,DEFAULT_PRI);
-            return 1;
+            return 2;
         } else {
+            if (scp->SCp.Status != -1) {
+                TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%x\n",
+                        scp->SCp.Status, ha->status));
+                scp->SCp.Status = -1;
+                scp->SCp.this_residual = HIGH_PRI;
+                return 2;
+            }
             if (service == CACHESERVICE) {
                 memset((char*)scp->sense_buffer,0,16);
                 scp->sense_buffer[0] = 0x70;
@@ -2442,30 +2842,27 @@
                     dvr.eu.sync.service = service;
                     dvr.eu.sync.status  = ha->status;
                     dvr.eu.sync.info    = ha->info;
-                    dvr.eu.sync.hostdrive =
-#if LINUX_VERSION_CODE >= 0x020000
-                        ha->id[scp->channel][scp->target].hostdrive;
-#else
-                        ha->id[NUMDATA(scp->host)->busnum][scp->target].hostdrive;
-#endif
+                    dvr.eu.sync.hostdrive = scp->target;
                     if (ha->status >= 0x8000)
-                        gdth_store_event(ES_SYNC, 0, &dvr);
+                        gdth_store_event(ha, ES_SYNC, 0, &dvr);
                     else
-                        gdth_store_event(ES_SYNC, service, &dvr);
+                        gdth_store_event(ha, ES_SYNC, service, &dvr);
                 }
             } else {
-                if (ha->status!=S_RAW_SCSI || ha->status==S_RAW_ILL) {
+                if (ha->status!=S_RAW_SCSI || ha->info>=0x100) {
                     scp->result = DID_BAD_TARGET << 16;
                 } else {
                     scp->result = (DID_OK << 16) | ha->info;
                 }
             }
         }
-        scp->SCp.have_data_in++;
-        scp->scsi_done(scp);
+        if (!scp->SCp.have_data_in)
+            scp->SCp.have_data_in++;
+        else 
+            return 1;
     }
 
-    return 1;
+    return 0;
 }
 
 static char *async_cache_tab[] = {
@@ -2587,15 +2984,40 @@
         "GDT HA %u, Array Drive %u: expand restarted",
 /*58*/  "\005\000\002\006\002"
         "GDT HA %u, Array Drive %u: expand stopped",
+/*59*/  "\005\000\002\010\002"
+        "GDT HA %u, Mirror Drive %u: drive build quited",
+/*60*/  "\005\000\002\006\002"
+        "GDT HA %u, Array Drive %u: parity build quited",
+/*61*/  "\005\000\002\006\002"
+        "GDT HA %u, Array Drive %u: drive rebuild quited",
+/*62*/  "\005\000\002\006\002"
+        "GDT HA %u, Array Drive %u: parity verify started",
+/*63*/  "\005\000\002\006\002"
+        "GDT HA %u, Array Drive %u: parity verify done",
+/*64*/  "\005\000\002\006\002"
+        "GDT HA %u, Array Drive %u: parity verify failed",
+/*65*/  "\005\000\002\006\002"
+        "GDT HA %u, Array Drive %u: parity error detected",
+/*66*/  "\005\000\002\006\002"
+        "GDT HA %u, Array Drive %u: parity verify quited",
+/*67*/  "\005\000\002\006\002"
+        "GDT HA %u, Host Drive %u reserved",
+/*68*/  "\005\000\002\006\002"
+        "GDT HA %u, Host Drive %u mounted and released",
+/*69*/  "\005\000\002\006\002"
+        "GDT HA %u, Host Drive %u released",
+/*70*/  "\003\000\002"
+        "GDT HA %u, DRAM error detected and corrected with ECC",
+/*71*/  "\003\000\002"
+        "GDT HA %u, Uncorrectable DRAM error detected with ECC",
+/*72*/  "\011\000\002\012\001\013\001\014\001"
+        "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
 };
 
 
 static int gdth_async_event(int hanum,int service)
 {
-    gdth_stackframe stack;
     gdth_evt_data dvr;
-    char *f = NULL;
-    int i,j;
     gdth_ha_str *ha;
     gdth_msg_str *msg;
     gdth_cmd_str *cmdp;
@@ -2605,12 +3027,12 @@
     cmdp= ha->pccb;
     msg = (gdth_msg_str *)ha->pscratch;
     TRACE2(("gdth_async_event() ha %d serv %d\n",
-                 hanum,service));
+            hanum,service));
 
     if (service == SCREENSERVICE) {
         if (ha->status == MSG_REQUEST) {
             while (gdth_test_busy(hanum))
-                udelay(1);
+                gdth_delay(0);
             cmdp->Service       = SCREENSERVICE;
             cmdp->RequestBuffer = SCREEN_CMND;
             cmd_index = gdth_get_cmd_index(hanum);
@@ -2619,10 +3041,11 @@
             cmdp->BoardNode     = LOCALBOARD;
             cmdp->u.screen.reserved  = 0;
             cmdp->u.screen.msg_handle= MSG_INV_HANDLE;
-            cmdp->u.screen.msg_addr  = (ulong)msg;
+            cmdp->u.screen.msg_addr  = virt_to_bus(msg);
+            ha->scratch_busy = TRUE;
             ha->cmd_offs_dpmem = 0;
             ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.msg_addr) 
-                + sizeof(ulong);
+                + sizeof(ulong32);
             ha->cmd_cnt = 0;
             gdth_copy_command(hanum);
             if (ha->type == GDT_EISA)
@@ -2641,80 +3064,89 @@
         dvr.eu.async.service = service;
         dvr.eu.async.status  = ha->status;
         dvr.eu.async.info    = ha->info;
-        *(ulong *)dvr.eu.async.scsi_coord  = ha->info2;
-        gdth_store_event(ES_ASYNC, service, &dvr);
+        *(ulong32 *)dvr.eu.async.scsi_coord  = ha->info2;
+        gdth_store_event(ha, ES_ASYNC, service, &dvr);
+        gdth_log_event( &dvr );
+    }
+    return 1;
+}
 
-        if (service==CACHESERVICE && INDEX_OK(ha->status,async_cache_tab)) {
-            TRACE2(("GDT: Async. event cache service, event no.: %d\n",
-                ha->status));
-        
-            f = async_cache_tab[ha->status];
+static void gdth_log_event(gdth_evt_data *dvr)
+{
+    gdth_stackframe stack;
+    char *f = NULL;
+    int i,j;
 
-            /* i: parameter to push, j: stack element to fill */
-            for (j=0,i=1; i < f[0]; i+=2) {
-                switch (f[i+1]) {
-                  case 4:
-                    stack.b[j++] = *(ulong*)&dvr.eu.stream[(int)f[i]];
-                    break;
-                  case 2:
-                    stack.b[j++] = *(ushort*)&dvr.eu.stream[(int)f[i]];
-                    break;
-                  case 1:
-                    stack.b[j++] = *(unchar*)&dvr.eu.stream[(int)f[i]];
-                    break;
-                  default:
-                    break;
-                }
+    TRACE2(("gdth_log_event()\n"));
+    if (dvr->eu.async.service == CACHESERVICE && 
+        INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
+        TRACE2(("GDT: Async. event cache service, event no.: %d\n",
+                dvr->eu.async.status));
+        
+        f = async_cache_tab[dvr->eu.async.status];
+        
+        /* i: parameter to push, j: stack element to fill */
+        for (j=0,i=1; i < f[0]; i+=2) {
+            switch (f[i+1]) {
+              case 4:
+                stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
+                break;
+              case 2:
+                stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
+                break;
+              case 1:
+                stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
+                break;
+              default:
+                break;
             }
+        }
 
-            printk(&f[f[0]],stack); printk("\n");
+        printk(&f[(int)f[0]],stack); printk("\n");
 
-        } else {
-            printk("GDT: Unknown async. event service %d event no. %d\n",
-                service,ha->status);
-        }
+    } else {
+        printk("GDT: Unknown async. event service %d event no. %d\n",
+               dvr->eu.async.service,dvr->eu.async.status);
     }
-    return 1;
 }
 
 #ifdef GDTH_STATISTICS
-void gdth_timeout(void)
+void gdth_timeout(ulong data)
 {
-    ulong flags,i;
+    ulong32 i;
     Scsi_Cmnd *nscp;
     gdth_ha_str *ha;
+    ulong flags;
     int hanum = 0;
 
-    save_flags(flags);
-    cli();
+    ha = HADATA(gdth_ctr_tab[hanum]);
+    GDTH_LOCK_HA(ha, flags);
 
     for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i) 
-        if (gdth_cmd_tab[i][hanum].cmnd != UNUSED_CMND)
+        if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
             ++act_stats;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
     for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
         ++act_rq;
 
-    TRACE2(("gdth_to(): ints %ld, ios %ld, act_stats %ld, act_rq %ld\n",
+    TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %d\n",
             act_ints, act_ios, act_stats, act_rq));
     act_ints = act_ios = 0;
 
-    timer_table[GDTH_TIMER].expires = jiffies + 30*HZ;
-    timer_active |= 1<<GDTH_TIMER;
-    restore_flags(flags);
+    gdth_timer.expires = jiffies + 30 * HZ;
+    add_timer(&gdth_timer);
+    GDTH_UNLOCK_HA(ha, flags);
 }
 #endif
 
-int gdth_detect(Scsi_Host_Template *shtp)
+
+__initfunc (int gdth_detect(Scsi_Host_Template *shtp))
 {
     struct Scsi_Host *shp;
     gdth_ha_str *ha;
-    unsigned long flags;
-    ulong isa_bios;
-    ushort eisa_slot,device_id,index;
-    gdth_pci_str pcistr;
-    int i,j,hanum;
+    ulong32 isa_bios;
+    ushort eisa_slot;
+    int i,hanum,cnt,ctr;
     unchar b;
     
  
@@ -2731,28 +3163,24 @@
 #else
     printk("Console\n");
 #endif
-    WAITSEC(3);
+    gdth_delay(3000);
 #endif
 
     TRACE(("gdth_detect()\n"));
 
-    if (disable_gdth_scan) {
+    if (disable) {
         printk("GDT: Controller driver disabled from command line !\n");
         return 0;
     }
 
     /* initializations */
     gdth_polling = TRUE; b = 0;
-    for (i=0; i<GDTH_MAXCMDS; ++i)
-        for (j=0; j<MAXHA; ++j)
-            gdth_cmd_tab[i][j].cmnd = UNUSED_CMND;
-    for (i=0; i<4; ++i)
-        for (j=0; j<MAXHA; ++j)
-            gdth_ioctl_tab[i][j] = NULL;
     gdth_clear_events();
 
     /* scanning for controllers, at first: ISA controller */
     for (isa_bios=0xc8000UL; isa_bios<=0xd8000UL; isa_bios+=0x8000UL) {
+        if (gdth_ctr_count >= MAXHA) 
+            break;
         if (gdth_search_isa(isa_bios)) {        /* controller found */
             shp = scsi_register(shtp,sizeof(gdth_ext_str));
             ha = HADATA(shp);
@@ -2761,19 +3189,16 @@
                 continue;
             }
             /* controller found and initialized */
-            printk("Configuring GDT-ISA HA at BIOS 0x%05lX IRQ %u DRQ %u\n",
+            printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",
                    isa_bios,ha->irq,ha->drq);
 
-            save_flags(flags);
-            cli();
 #if LINUX_VERSION_CODE >= 0x010346 
-            if (request_irq(ha->irq,do_gdth_interrupt,SA_INTERRUPT,"gdth",NULL))
+            if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha))
 #else
             if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth")) 
 #endif
             {
                 printk("GDT-ISA: Unable to allocate IRQ\n");
-                restore_flags(flags);
                 scsi_unregister(shp);
                 continue;
             }
@@ -2784,7 +3209,6 @@
 #else
                 free_irq(ha->irq);
 #endif
-                restore_flags(flags);
                 scsi_unregister(shp);
                 continue;
             }
@@ -2793,12 +3217,6 @@
             shp->unchecked_isa_dma = 1;
             shp->irq = ha->irq;
             shp->dma_channel = ha->drq;
-            for (i=0; i<MAXID; ++i) {
-                if (ha->id[0][i].type==SIOP_DTYP) {
-                    shp->this_id = i;
-                    break;
-                }
-            }
             hanum = gdth_ctr_count;         
             gdth_ctr_tab[gdth_ctr_count++] = shp;
             gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
@@ -2807,61 +3225,56 @@
             NUMDATA(shp)->busnum= 0;
 
             ha->pccb = CMDDATA(shp);
-            ha->pscratch = DMADATA(shp);
+            ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
+            ha->scratch_busy = FALSE;
             ha->req_first = NULL;
-            for (i=0; i<MAXBUS; ++i) {
-                for (j=0; j<MAXID; ++j) {
-                    ha->id[i][j].type = EMPTY_DTYP;
-                    ha->id[i][j].lock = 0;
-                }
-            }
-            restore_flags(flags);
+            ha->tid_cnt = MAX_HDRIVES;
+            if (max_ids > 0 && max_ids < ha->tid_cnt)
+                ha->tid_cnt = max_ids;
+            for (i=0; i<GDTH_MAXCMDS; ++i)
+                ha->cmd_tab[i].cmnd = UNUSED_CMND;
+            ha->scan_mode = rescan ? 0x10 : 0;
 
-            if (!gdth_search_drives(hanum)) {
+            if (ha->pscratch == NULL || !gdth_search_drives(hanum)) {
                 printk("GDT-ISA: Error during device scan\n");
                 --gdth_ctr_count;
-		--gdth_ctr_vcount;
-                save_flags(flags);
-                cli();
+                --gdth_ctr_vcount;
+                if (ha->pscratch != NULL)
+                    scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
 #if LINUX_VERSION_CODE >= 0x010346 
                 free_irq(ha->irq,NULL);
 #else
                 free_irq(ha->irq);
 #endif
-                restore_flags(flags);
                 scsi_unregister(shp);
                 continue;
             }
 
 #if LINUX_VERSION_CODE >= 0x020000
-            shp->max_id      = 8;
-            shp->max_lun     = 8;
-            shp->max_channel = ha->bus_cnt - 1;
+            shp->max_id      = ha->tid_cnt;
+            shp->max_lun     = MAXLUN;
+            shp->max_channel = ha->bus_cnt;
 #else
             /* register addit. SCSI channels as virtual controllers */
-            for (b=1; b<ha->bus_cnt; ++b) {
+            for (b=1; b<ha->bus_cnt+1; ++b) {
                 shp = scsi_register(shtp,sizeof(gdth_num_str));
                 shp->unchecked_isa_dma = 1;
                 shp->irq = ha->irq;
                 shp->dma_channel = ha->drq;
-                for (i=0; i<MAXID; ++i) {
-                    if (ha->id[b][i].type==SIOP_DTYP) {
-                        shp->this_id = i;
-                        break;
-                    }
-                }
                 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
                 NUMDATA(shp)->hanum = (ushort)hanum;
                 NUMDATA(shp)->busnum = b;
             }
 #endif
-
+            GDTH_INIT_LOCK_HA(ha);
             gdth_enable_int(hanum);
         }
     }
 
     /* scanning for EISA controllers */
     for (eisa_slot=0x1000; eisa_slot<=0x8000; eisa_slot+=0x1000) {
+        if (gdth_ctr_count >= MAXHA) 
+            break;
         if (gdth_search_eisa(eisa_slot)) {      /* controller found */
             shp = scsi_register(shtp,sizeof(gdth_ext_str));
             ha = HADATA(shp);
@@ -2873,134 +3286,117 @@
             printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
                    eisa_slot>>12,ha->irq);
 
-            save_flags(flags);
-            cli();
 #if LINUX_VERSION_CODE >= 0x010346 
-            if (request_irq(ha->irq,do_gdth_interrupt,SA_INTERRUPT,"gdth",NULL))
+            if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha))
 #else
             if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth")) 
 #endif
             {
                 printk("GDT-EISA: Unable to allocate IRQ\n");
-                restore_flags(flags);
                 scsi_unregister(shp);
                 continue;
             }
             shp->unchecked_isa_dma = 0;
             shp->irq = ha->irq;
             shp->dma_channel = 0xff;
-            for (i=0; i<MAXID; ++i) {
-                if (ha->id[0][i].type==SIOP_DTYP) {
-                    shp->this_id = i;
-                    break;
-                }
-            }
             hanum = gdth_ctr_count;
             gdth_ctr_tab[gdth_ctr_count++] = shp;
             gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
 
             NUMDATA(shp)->hanum = (ushort)hanum;
             NUMDATA(shp)->busnum= 0;
-            TRACE2(("EISA detect Bus 0: shp %lx hanum %d\n",
-                          (ulong)shp,NUMDATA(shp)->hanum));
+            TRACE2(("EISA detect Bus 0: hanum %d\n",
+                    NUMDATA(shp)->hanum));
 
             ha->pccb = CMDDATA(shp);
-            ha->pscratch = DMADATA(shp);
+            ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
+            ha->scratch_busy = FALSE;
             ha->req_first = NULL;
-            for (i=0; i<MAXBUS; ++i) {
-                for (j=0; j<MAXID; ++j) {
-                    ha->id[i][j].type = EMPTY_DTYP;
-                    ha->id[i][j].lock = 0;
-                }
-            }
-            restore_flags(flags);
+            ha->tid_cnt = MAX_HDRIVES;
+            if (max_ids > 0 && max_ids < ha->tid_cnt)
+                ha->tid_cnt = max_ids;
+            for (i=0; i<GDTH_MAXCMDS; ++i)
+                ha->cmd_tab[i].cmnd = UNUSED_CMND;
+            ha->scan_mode = rescan ? 0x10 : 0;
 
-            if (!gdth_search_drives(hanum)) {
+            if (ha->pscratch == NULL || !gdth_search_drives(hanum)) {
                 printk("GDT-EISA: Error during device scan\n");
                 --gdth_ctr_count;
-		--gdth_ctr_vcount;
-                save_flags(flags);
-                cli();
+                --gdth_ctr_vcount;
+                if (ha->pscratch != NULL)
+                    scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
 #if LINUX_VERSION_CODE >= 0x010346 
                 free_irq(ha->irq,NULL);
 #else
                 free_irq(ha->irq);
 #endif
-                restore_flags(flags);
                 scsi_unregister(shp);
                 continue;
             }
 
 #if LINUX_VERSION_CODE >= 0x020000
-            shp->max_id      = 8;
-            shp->max_lun     = 8;
-            shp->max_channel = ha->bus_cnt - 1;
+            shp->max_id      = ha->tid_cnt;
+            shp->max_lun     = MAXLUN;
+            shp->max_channel = ha->bus_cnt;
 #else
             /* register addit. SCSI channels as virtual controllers */
-            for (b=1; b<ha->bus_cnt; ++b) {
+            for (b=1; b<ha->bus_cnt+1; ++b) {
                 shp = scsi_register(shtp,sizeof(gdth_num_str));
                 shp->unchecked_isa_dma = 0;
                 shp->irq = ha->irq;
                 shp->dma_channel = 0xff;
-                for (i=0; i<MAXID; ++i) {
-                    if (ha->id[b][i].type==SIOP_DTYP) {
-                        shp->this_id = i;
-                        break;
-                    }
-                }
                 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
                 NUMDATA(shp)->hanum = (ushort)hanum;
                 NUMDATA(shp)->busnum = b;
-                TRACE2(("EISA detect Bus %d: shp %lx hanum %d\n",
-                              NUMDATA(shp)->busnum,(ulong)shp,
-                              NUMDATA(shp)->hanum));
+                TRACE2(("EISA detect Bus %d: shp %x hanum %d\n",
+                        NUMDATA(shp)->busnum,(ulong32)shp,
+                        NUMDATA(shp)->hanum));
             }
 #endif
-
+            GDTH_INIT_LOCK_HA(ha);
             gdth_enable_int(hanum);
         }
     }
 
     /* scanning for PCI controllers */
-    for (device_id = 0; device_id <= PCI_DEVICE_ID_VORTEX_GDT6x21RP2; ++device_id) {
-        if (device_id > PCI_DEVICE_ID_VORTEX_GDT6555 &&
-            device_id < PCI_DEVICE_ID_VORTEX_GDT6x17RP)
-            continue;
-        for (index = 0; ; ++index) {
-            if (!gdth_search_pci(device_id,index,&pcistr)) 
-                break;                          /* next device_id */
+#if LINUX_VERSION_CODE >= 0x2015C
+    if (pci_present())
+#else
+    if (pcibios_present())
+#endif
+    {
+        gdth_pci_str pcistr[MAXHA];
+
+        cnt = gdth_search_pci(pcistr);
+        gdth_sort_pci(pcistr,cnt);
+        for (ctr = 0; ctr < cnt; ++ctr) {
+            if (gdth_ctr_count >= MAXHA)
+                break;
             shp = scsi_register(shtp,sizeof(gdth_ext_str));
             ha = HADATA(shp);
-            if (!gdth_init_pci(&pcistr,ha)) {
+            if (!gdth_init_pci(&pcistr[ctr],ha)) {
                 scsi_unregister(shp);
                 continue;
             }
             /* controller found and initialized */
             printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
-                   pcistr.bus,pcistr.device_fn>>3,ha->irq);
+                   pcistr[ctr].bus,PCI_SLOT(pcistr[ctr].device_fn),ha->irq);
 
-            save_flags(flags);
-            cli();
 #if LINUX_VERSION_CODE >= 0x010346 
-            if (request_irq(ha->irq,do_gdth_interrupt,SA_INTERRUPT,"gdth",NULL))
+            if (request_irq(ha->irq, gdth_interrupt,
+                            SA_INTERRUPT|SA_SHIRQ, "gdth", ha))
 #else
-            if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth")) 
+            if (request_irq(ha->irq, gdth_interrupt,
+                            SA_INTERRUPT|SA_SHIRQ, "gdth")) 
 #endif
             {
                 printk("GDT-PCI: Unable to allocate IRQ\n");
-                restore_flags(flags);
                 scsi_unregister(shp);
                 continue;
             }
             shp->unchecked_isa_dma = 0;
             shp->irq = ha->irq;
             shp->dma_channel = 0xff;
-            for (i=0; i<MAXID; ++i) {
-                if (ha->id[0][i].type==SIOP_DTYP) {
-                    shp->this_id = i;
-                    break;
-                }
-            }
             hanum = gdth_ctr_count;
             gdth_ctr_tab[gdth_ctr_count++] = shp;
             gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
@@ -3009,55 +3405,48 @@
             NUMDATA(shp)->busnum= 0;
 
             ha->pccb = CMDDATA(shp);
-            ha->pscratch = DMADATA(shp);
+            ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
+            ha->scratch_busy = FALSE;
             ha->req_first = NULL;
-            for (i=0; i<MAXBUS; ++i) {
-                for (j=0; j<MAXID; ++j) {
-                    ha->id[i][j].type = EMPTY_DTYP;
-                    ha->id[i][j].lock = 0;
-                }
-            }
-            restore_flags(flags);
+            ha->tid_cnt = pcistr[ctr].device_id >= 0x200 ? MAXID : MAX_HDRIVES;
+            if (max_ids > 0 && max_ids < ha->tid_cnt)
+                ha->tid_cnt = max_ids;
+            for (i=0; i<GDTH_MAXCMDS; ++i)
+                ha->cmd_tab[i].cmnd = UNUSED_CMND;
+            ha->scan_mode = rescan ? 0x10 : 0;
 
-            if (!gdth_search_drives(hanum)) {
+            if (ha->pscratch == NULL || !gdth_search_drives(hanum)) {
                 printk("GDT-PCI: Error during device scan\n");
                 --gdth_ctr_count;
-		--gdth_ctr_vcount;
-                save_flags(flags);
-                cli();
+                --gdth_ctr_vcount;
+                if (ha->pscratch != NULL)
+                    scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
 #if LINUX_VERSION_CODE >= 0x010346 
                 free_irq(ha->irq,NULL);
 #else
                 free_irq(ha->irq);
 #endif
-                restore_flags(flags);
                 scsi_unregister(shp);
                 continue;
             }
 
 #if LINUX_VERSION_CODE >= 0x020000
-            shp->max_id      = 8;
-            shp->max_lun     = 8;
-            shp->max_channel = ha->bus_cnt - 1;
+            shp->max_id      = ha->tid_cnt;
+            shp->max_lun     = MAXLUN;
+            shp->max_channel = ha->bus_cnt;
 #else
             /* register addit. SCSI channels as virtual controllers */
-            for (b=1; b<ha->bus_cnt; ++b) {
+            for (b=1; b<ha->bus_cnt+1; ++b) {
                 shp = scsi_register(shtp,sizeof(gdth_num_str));
                 shp->unchecked_isa_dma = 0;
                 shp->irq = ha->irq;
                 shp->dma_channel = 0xff;
-                for (i=0; i<MAXID; ++i) {
-                    if (ha->id[b][i].type==SIOP_DTYP) {
-                        shp->this_id = i;
-                        break;
-                    }
-                }
                 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
                 NUMDATA(shp)->hanum = (ushort)hanum;
                 NUMDATA(shp)->busnum = b;
             }
 #endif
-
+            GDTH_INIT_LOCK_HA(ha);
             gdth_enable_int(hanum);
         }
     }
@@ -3065,13 +3454,15 @@
     TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));
     if (gdth_ctr_count > 0) {
 #ifdef GDTH_STATISTICS
-	TRACE2(("gdth_detect(): Initializing timer !\n"));
-	timer_table[GDTH_TIMER].fn = gdth_timeout;
-	timer_table[GDTH_TIMER].expires = jiffies + HZ;
-	timer_active |= 1<<GDTH_TIMER;
+        TRACE2(("gdth_detect(): Initializing timer !\n"));
+        init_timer(&gdth_timer);
+        gdth_timer.expires = jiffies + HZ;
+        gdth_timer.data = 0L;
+        gdth_timer.function = gdth_timeout;
+        add_timer(&gdth_timer);
 #endif
 #if LINUX_VERSION_CODE >= 0x020100
-	register_reboot_notifier(&gdth_notifier);
+        register_reboot_notifier(&gdth_notifier);
 #endif
     }
     gdth_polling = FALSE;
@@ -3081,13 +3472,15 @@
 
 int gdth_release(struct Scsi_Host *shp)
 {
-    unsigned long flags;
+    int hanum;
+    gdth_ha_str *ha;
 
     TRACE2(("gdth_release()\n"));
-
-    save_flags(flags);
-    cli();
     if (NUMDATA(shp)->busnum == 0) {
+        hanum = NUMDATA(shp)->hanum;
+        ha    = HADATA(gdth_ctr_tab[hanum]);
+        gdth_flush(hanum);
+
         if (shp->irq) {
 #if LINUX_VERSION_CODE >= 0x010346
             free_irq(shp->irq,NULL);
@@ -3098,9 +3491,21 @@
         if (shp->dma_channel != 0xff) {
             free_dma(shp->dma_channel);
         }
+        scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
+        gdth_ctr_released++;
+        TRACE2(("gdth_release(): HA %d of %d\n", 
+                gdth_ctr_released, gdth_ctr_count));
+
+        if (gdth_ctr_released == gdth_ctr_count) {
+#ifdef GDTH_STATISTICS
+            del_timer(&gdth_timer);
+#endif
+#if LINUX_VERSION_CODE >= 0x020100
+            unregister_reboot_notifier(&gdth_notifier);
+#endif
+        }
     }
 
-    restore_flags(flags);
     scsi_unregister(shp);
     return 0;
 }
@@ -3117,102 +3522,40 @@
     if (ha->type == GDT_EISA) {
         switch (ha->stype) {
           case GDT3_ID:
-            return("GDT3000/3020 (EISA)");
+            return("GDT3000/3020");
           case GDT3A_ID:
-            return("GDT3000A/3020A/3050A (EISA)");
+            return("GDT3000A/3020A/3050A");
           case GDT3B_ID:
-            return("GDT3000B/3010A (EISA)");
+            return("GDT3000B/3010A");
         }
     } else if (ha->type == GDT_ISA) {
-        return("GDT2000/2020 (ISA)");
+        return("GDT2000/2020");
     } else if (ha->type == GDT_PCI) {
         switch (ha->stype) {
           case PCI_DEVICE_ID_VORTEX_GDT60x0:
-            return("GDT6000/6020/6050 (PCI)");
+            return("GDT6000/6020/6050");
           case PCI_DEVICE_ID_VORTEX_GDT6000B:
-            return("GDT6000B/6010 (PCI)");
-        }
-    } else if (ha->type == GDT_PCINEW) {
-        switch (ha->stype) {
-          case PCI_DEVICE_ID_VORTEX_GDT6x10:
-            return("GDT6110/6510 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x20:
-            return("GDT6120/6520 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6530:
-            return("GDT6530 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6550:
-            return("GDT6550 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x17:
-            return("GDT6117/6517 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x27:
-            return("GDT6127/6527 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6537:
-            return("GDT6537 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6557:
-            return("GDT6557/6557-ECC (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x15:
-            return("GDT6115/6515 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x25:
-            return("GDT6125/6525 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6535:
-            return("GDT6535 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6555:
-            return("GDT6555/6555-ECC (PCI)");
-        }
-    } else if (ha->type == GDT_PCIMPR) {
-        switch (ha->stype) {
-          case PCI_DEVICE_ID_VORTEX_GDT6x17RP:
-            return("GDT6117RP/GDT6517RP (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x27RP:
-            return("GDT6127RP/GDT6527RP (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6537RP:
-            return("GDT6537RP (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6557RP:
-            return("GDT6557RP (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x11RP:
-            return("GDT6111RP/GDT6511RP (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x21RP:
-            return("GDT6121RP/GDT6521RP (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x17RP1:
-            return("GDT6117RP1/GDT6517RP1 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x27RP1:
-            return("GDT6127RP1/GDT6527RP1 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6537RP1:
-            return("GDT6537RP1 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6557RP1:
-            return("GDT6557RP1 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x11RP1:
-            return("GDT6111RP1/GDT6511RP1 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x21RP1:
-            return("GDT6121RP1/GDT6521RP1 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x17RP2:
-            return("GDT6117RP2/GDT6517RP2 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x27RP2:
-            return("GDT6127RP2/GDT6527RP2 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6537RP2:
-            return("GDT6537RP2 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6557RP2:
-            return("GDT6557RP2 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x11RP2:
-            return("GDT6111RP2/GDT6511RP2 (PCI)");
-          case PCI_DEVICE_ID_VORTEX_GDT6x21RP2:
-            return("GDT6121RP2/GDT6521RP2 (PCI)");
+            return("GDT6000B/6010");
         }
-    }
+    } 
+    /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
+
     return("");
 }
 
 const char *gdth_info(struct Scsi_Host *shp)
 {
     int hanum;
-    
+    gdth_ha_str *ha;
+
     TRACE2(("gdth_info()\n"));
     hanum = NUMDATA(shp)->hanum;
+    ha    = HADATA(gdth_ctr_tab[hanum]);
 
-    return (gdth_ctr_name(hanum));
+    return ((const char *)ha->ctr_name);
 }
 
-
+/* old error handling */
 int gdth_abort(Scsi_Cmnd *scp)
 {
     TRACE2(("gdth_abort() reason %d\n",scp->abort_reason));
@@ -3229,6 +3572,32 @@
     return SCSI_RESET_PUNT;
 }
 
+#if LINUX_VERSION_CODE >= 0x02015F
+/* new error handling */
+int gdth_eh_abort(Scsi_Cmnd *scp)
+{
+    TRACE2(("gdth_eh_abort()\n"));
+    return FAILED;
+}
+
+int gdth_eh_device_reset(Scsi_Cmnd *scp)
+{
+    TRACE2(("gdth_eh_device_reset()\n"));
+    return FAILED;
+}
+
+int gdth_eh_bus_reset(Scsi_Cmnd *scp)
+{
+    TRACE2(("gdth_eh_bus_reset()\n"));
+    return FAILED;
+}
+
+int gdth_eh_host_reset(Scsi_Cmnd *scp)
+{
+    TRACE2(("gdth_eh_host_reset()\n"));
+    return FAILED;
+}
+#endif
 
 #if LINUX_VERSION_CODE >= 0x010300
 int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
@@ -3236,18 +3605,36 @@
 int gdth_bios_param(Disk *disk,int dev,int *ip)
 #endif
 {
-    unchar b, t;
+    unchar t;
     int hanum;
     gdth_ha_str *ha;
+    int drv_hds, drv_secs;
 
     hanum = NUMDATA(disk->device->host)->hanum;
-    b = disk->device->channel;
     t = disk->device->id;
-    TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum, b, t));
+    TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", 
+            hanum, disk->device->channel, t));
     ha = HADATA(gdth_ctr_tab[hanum]);
 
-    ip[0] = ha->id[b][t].heads;
-    ip[1] = ha->id[b][t].secs;
+    if (ha->hdr[t].heads == 0) {
+        /* raw device: evaluate mapping (sectors per head, heads per cylinder) */
+        if (disk->capacity /HEADS/SECS <= MAXCYLS) {
+            drv_hds = HEADS;
+            drv_secs= SECS;
+        } else if (disk->capacity /MEDHEADS/MEDSECS <= MAXCYLS) {
+            drv_hds = MEDHEADS;
+            drv_secs= MEDSECS;
+        } else {
+            drv_hds = BIGHEADS;
+            drv_secs= BIGSECS;
+        }
+        ha->hdr[t].heads = drv_hds;
+        ha->hdr[t].secs = drv_secs;
+        TRACE2(("gdth_bios_param(): raw device -> params evaluated\n"));
+    }
+
+    ip[0] = ha->hdr[t].heads;
+    ip[1] = ha->hdr[t].secs;
     ip[2] = disk->capacity / ip[0] / ip[1];
 
     TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cyls\n",
@@ -3280,10 +3667,12 @@
     int priority;
 
     TRACE(("gdth_queuecommand() cmd 0x%x id %d lun %d\n",
-                  scp->cmnd[0],scp->target,scp->lun));
+           scp->cmnd[0],scp->target,scp->lun));
     
     scp->scsi_done = (void *)done;
-    scp->SCp.have_data_in = 0;
+    scp->SCp.have_data_in = 1;
+    scp->SCp.phase = -1;
+    scp->SCp.Status = -1;
     hanum = NUMDATA(scp->host)->hanum;
 #ifdef GDTH_STATISTICS
     ++act_ios;
@@ -3299,6 +3688,52 @@
     return 0;
 }
 
+/* flush routine */
+static void gdth_flush(int hanum)
+{
+    int             i;
+    gdth_ha_str     *ha;
+    Scsi_Cmnd       scp;
+    Scsi_Device     sdev;
+    gdth_cmd_str    gdtcmd;
+    char            cmnd[12];
+
+    TRACE2(("gdth_flush() hanum %d\n",hanum));
+    ha = HADATA(gdth_ctr_tab[hanum]);
+    memset(&sdev,0,sizeof(Scsi_Device));
+    memset(&scp, 0,sizeof(Scsi_Cmnd));
+    sdev.host = gdth_ctr_tab[hanum];
+    sdev.id = sdev.host->this_id;
+    scp.cmd_len = 12;
+    scp.host = gdth_ctr_tab[hanum];
+    scp.target = sdev.host->this_id;
+    scp.device = &sdev;
+    scp.use_sg = 0;
+
+    for (i = 0; i < MAX_HDRIVES; ++i) {
+        if (ha->hdr[i].present) {
+            gdtcmd.BoardNode = LOCALBOARD;
+            gdtcmd.Service = CACHESERVICE;
+            gdtcmd.OpCode = GDT_FLUSH;
+            gdtcmd.u.cache.DeviceNo = i;
+            gdtcmd.u.cache.BlockNo = 1;
+            gdtcmd.u.cache.sg_canz = 0;
+            TRACE2(("gdth_flush(): flush ha %d drive %d\n", hanum, i));
+            {
+                struct semaphore sem = MUTEX_LOCKED;
+                scp.request.rq_status = RQ_SCSI_BUSY;
+                scp.request.sem = &sem;
+                scp.SCp.this_residual = IOCTL_PRI;
+                GDTH_LOCK_SCSI_DOCMD();
+                scsi_do_cmd(&scp, cmnd, &gdtcmd,
+                            sizeof(gdth_cmd_str), gdth_scsi_done,
+                            30*HZ, 1);
+                GDTH_UNLOCK_SCSI_DOCMD();
+                down(&sem);
+            }
+        }
+    }
+}
 
 /* shutdown routine */
 #if LINUX_VERSION_CODE >= 0x020100
@@ -3307,23 +3742,32 @@
 void gdth_halt(void)
 #endif
 {
-    int             hanum, i, j;
-    gdth_ha_str     *ha;
+    int             hanum;
+#ifndef __alpha__
     Scsi_Cmnd       scp;
     Scsi_Device     sdev;
     gdth_cmd_str    gdtcmd;
     char            cmnd[12];
+#endif
 
 #if LINUX_VERSION_CODE >= 0x020100
     TRACE2(("gdth_halt() event %d\n",event));
     if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
-	return NOTIFY_DONE;
+        return NOTIFY_DONE;
 #else
     TRACE2(("gdth_halt()\n"));
+    if (halt_called) {
+        TRACE2(("already called\n"));
+        return;
+    }
+    halt_called = TRUE;
 #endif
     printk("GDT: Flushing all host drives .. ");
     for (hanum = 0; hanum < gdth_ctr_count; ++hanum) {
-        ha = HADATA(gdth_ctr_tab[hanum]);
+        gdth_flush(hanum);
+
+#ifndef __alpha__
+        /* controller reset */
         memset(&sdev,0,sizeof(Scsi_Device));
         memset(&scp, 0,sizeof(Scsi_Cmnd));
         sdev.host = gdth_ctr_tab[hanum];
@@ -3334,32 +3778,6 @@
         scp.device = &sdev;
         scp.use_sg = 0;
 
-        /* flush */
-        for (i = 0; i < MAXBUS; ++i) {
-            for (j = 0; j < MAXID; ++j) {
-                if (ha->id[i][j].type == CACHE_DTYP) {
-                    gdtcmd.BoardNode = LOCALBOARD;
-                    gdtcmd.Service = CACHESERVICE;
-                    gdtcmd.OpCode = GDT_FLUSH;
-                    gdtcmd.u.cache.DeviceNo = ha->id[i][j].hostdrive;
-                    gdtcmd.u.cache.BlockNo = 1;
-                    gdtcmd.u.cache.sg_canz = 0;
-                    TRACE2(("gdth_halt(): flush ha %d drive %d\n",
-                        hanum, ha->id[i][j].hostdrive));
-                    {
-                        struct semaphore sem = MUTEX_LOCKED;
-                        scp.request.rq_status = RQ_SCSI_BUSY;
-                        scp.request.sem = &sem;
-                        scsi_do_cmd(&scp, cmnd, &gdtcmd,
-                                    sizeof(gdth_cmd_str), gdth_scsi_done,
-                                    30*HZ, 1);
-                        down(&sem);
-                    }
-                }
-            }
-        }
-
-        /* controller reset */
         gdtcmd.BoardNode = LOCALBOARD;
         gdtcmd.Service = CACHESERVICE;
         gdtcmd.OpCode = GDT_RESET;
@@ -3368,16 +3786,20 @@
             struct semaphore sem = MUTEX_LOCKED;
             scp.request.rq_status = RQ_SCSI_BUSY;
             scp.request.sem = &sem;
+            scp.SCp.this_residual = IOCTL_PRI;
+            GDTH_LOCK_SCSI_DOCMD();
             scsi_do_cmd(&scp, cmnd, &gdtcmd,
                 sizeof(gdth_cmd_str), gdth_scsi_done,
                 10*HZ, 1);
+            GDTH_UNLOCK_SCSI_DOCMD();
             down(&sem);
         }
+#endif
     }
     printk("Done.\n");
 
 #ifdef GDTH_STATISTICS
-    timer_active &= ~(1<<GDTH_TIMER);
+    del_timer(&gdth_timer);
 #endif
 #if LINUX_VERSION_CODE >= 0x020100
     unregister_reboot_notifier(&gdth_notifier);
@@ -3387,35 +3809,69 @@
 
 
 /* called from init/main.c */
-void gdth_setup(char *str,int *ints)
+__initfunc (void gdth_setup(char *str,int *ints))
 {
-    static size_t setup_idx = 0;
+    int i, argc;
+    char *cur_str, *argv;
 
-    TRACE2(("gdth_setup() str %s ints[0] %d ints[1] %d\n",
-                  str ? str:"NULL", ints[0],
-                  ints[0] ? ints[1]:0));
+    TRACE2(("gdth_setup() str %s ints[0] %d\n", 
+            str ? str:"NULL", ints ? ints[0]:0));
 
-    if (setup_idx >= MAXHA) {
-        printk("GDT: gdth_setup() called too many times. Bad LILO params ?\n");
-        return;
-    }
-    if (ints[0] != 1) {
-        printk("GDT: Illegal command line !\n");
-        printk("Usage: gdth=<IRQ>\n");
-        printk("Where: <IRQ>: valid EISA controller IRQ (10,11,12,14)\n");
-        printk("              or 0 to disable controller driver\n");
-        return;
-    }
-    if (ints[1] == 10 || ints[1] == 11 || ints[1] == 12 || ints[1] == 14) {
-        irqs[setup_idx++] = ints[1];
-        irqs[setup_idx]   = 0xff;
-        return;
+    /* read irq[] from ints[] */
+    if (ints) {
+        argc = ints[0];
+        if (argc > 0) {
+            if (argc > MAXHA)
+                argc = MAXHA;
+            for (i = 0; i < argc; ++i)
+                irq[i] = ints[i+1];
+        }
     }
-    if (ints[1] == 0) {
-        disable_gdth_scan = TRUE;
-        return;
+
+    /* analyse string */
+    argv = str;
+    while (argv && (cur_str = strchr(argv, ':'))) {
+        int val = 0, c = *++cur_str;
+        
+        if (c == 'n' || c == 'N')
+            val = 0;
+        else if (c == 'y' || c == 'Y')
+            val = 1;
+        else
+            val = (int)simple_strtoul(cur_str, NULL, 0);
+
+        if (!strncmp(argv, "disable:", 8))
+            disable = val;
+        else if (!strncmp(argv, "reserve_mode:", 13))
+            reserve_mode = val;
+        else if (!strncmp(argv, "reverse_scan:", 13))
+            reverse_scan = val;
+        else if (!strncmp(argv, "max_ids:", 8))
+            max_ids = val;
+        else if (!strncmp(argv, "rescan:", 7))
+            rescan = val;
+        else if (!strncmp(argv, "reserve_list:", 13)) {
+            reserve_list[0] = val;
+            for (i = 1; i < MAX_RES_ARGS; i++) {
+                cur_str = strchr(cur_str, ',');
+                if (!cur_str)
+                    break;
+                if (!isdigit((int)*++cur_str)) {
+                    --cur_str;          
+                    break;
+                }
+                reserve_list[i] = 
+                    (int)simple_strtoul(cur_str, NULL, 0);
+            }
+            if (!cur_str)
+                break;
+            argv = ++cur_str;
+            continue;
+        }
+
+        if ((argv = strchr(argv, ',')))
+            ++argv;
     }
-    printk("GDT: Invalid IRQ (%d) specified\n",ints[1]);
 }
 
 
@@ -3423,4 +3879,3 @@
 Scsi_Host_Template driver_template = GDTH;
 #include "scsi_module.c"
 #endif
-

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