## Automatically generated incremental diff
## From:   linux-2.2.13-pre17
## To:     linux-2.2.13-pre18
## Robot:  $Id: make-incremental-diff,v 1.11 2002/02/20 02:59:33 hpa Exp $

diff -urN linux-2.2.13-pre17/arch/i386/kernel/setup.c linux-2.2.13-pre18/arch/i386/kernel/setup.c
--- linux-2.2.13-pre17/arch/i386/kernel/setup.c	2003-08-15 15:08:34.000000000 -0700
+++ linux-2.2.13-pre18/arch/i386/kernel/setup.c	2003-08-15 15:08:35.000000000 -0700
@@ -123,6 +123,8 @@
 #define RAMDISK_PROMPT_FLAG		0x8000
 #define RAMDISK_LOAD_FLAG		0x4000	
 
+#define BIOS_ENDBASE	0x9F000
+
 #ifdef	CONFIG_VISWS
 char visws_board_type = -1;
 char visws_board_rev = -1;
@@ -252,6 +254,7 @@
 
 static char command_line[COMMAND_LINE_SIZE] = { 0, };
        char saved_command_line[COMMAND_LINE_SIZE];
+unsigned long i386_endbase __initdata =  0;
 
 __initfunc(void setup_arch(char **cmdline_p,
 	unsigned long * memory_start_p, unsigned long * memory_end_p))
@@ -259,6 +262,7 @@
 	unsigned long memory_start, memory_end;
 	char c = ' ', *to = command_line, *from = COMMAND_LINE;
 	int len = 0;
+	int read_endbase_from_BIOS = 1;
 
 #ifdef CONFIG_VISWS
 	visws_get_board_type_and_rev();
@@ -327,6 +331,13 @@
 				}
 			}
 		}
+		else if (c == ' ' && !memcmp(from, "endbase=", 8))
+		{
+			if (to != command_line) to--;
+			i386_endbase = simple_strtoul(from+8, &from, 0);
+			i386_endbase += PAGE_OFFSET;
+			read_endbase_from_BIOS = 0;
+		}
 		c = *(from++);
 		if (!c)
 			break;
@@ -337,6 +348,32 @@
 	*to = '\0';
 	*cmdline_p = command_line;
 
+	if (read_endbase_from_BIOS)
+	{
+		/*
+		 * The amount of available base memory is now taken from 
+		 * WORD 40:13 (The BIOS EBDA pointer) in order to account for 
+		 * some recent systems, where its value is smaller than the 
+		 * 4K we blindly allowed before.
+		 *
+		 * (this was pointed out by Josef Moellers from
+		 * Siemens Paderborn (Germany) ).
+		 */
+		i386_endbase = (*(unsigned short *)__va(0x413)*1024)&PAGE_MASK;
+		
+		if (!i386_endbase || i386_endbase > 0xA0000)
+		{
+			/* Zero is valid according to the BIOS weenies */
+			if(i386_endbase)
+			{
+				printk(KERN_NOTICE "Ignoring bogus EBDA pointer %X\n", 
+					i386_endbase);
+			}
+			i386_endbase = BIOS_ENDBASE;
+		}
+		i386_endbase += PAGE_OFFSET;
+	}
+
 #define VMALLOC_RESERVE	(64 << 20)	/* 64MB for vmalloc */
 #define MAXMEM	((unsigned long)(-PAGE_OFFSET-VMALLOC_RESERVE))
 
@@ -620,6 +657,16 @@
 		 *	on the MediaGX. So we turn it off for now. 
 		 */
 		
+#ifdef CONFIG_PCI_QUIRKS
+                /* It isnt really a PCI quirk directly, but the cure is the
+       	           same. The MediaGX has deep magic SMM stuff that handles the
+                   SB emulation. It thows away the fifo on disable_dma() which
+                   is wrong and ruins the audio. */
+
+		printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bug.\n");
+                isa_dma_bridge_buggy = 1;
+                  	                                                                     	        
+#endif
 		/* GXm supports extended cpuid levels 'ala' AMD */
 		if (c->cpuid_level == 2) {
 			get_model_name(c);  /* get CPU marketing name */
@@ -632,16 +679,6 @@
 			c->x86_model = (dir1 & 0x20) ? 1 : 2;
 			c->x86_capability&=~X86_FEATURE_TSC;
 		}
-#ifdef CONFIG_PCI_QUIRKS
-                /* It isnt really a PCI quirk directly, but the cure is the
-       	           same. The MediaGX has deep magic SMM stuff that handles the
-                   SB emulation. It thows away the fifo on disable_dma() which
-                   is wrong and ruins the audio. */
-
-		printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bug.\n");
-                isa_dma_bridge_buggy = 1;
-                  	                                                                     	        
-#endif
 		break;
 
         case 5: /* 6x86MX/M II */
diff -urN linux-2.2.13-pre17/arch/i386/kernel/smp.c linux-2.2.13-pre18/arch/i386/kernel/smp.c
--- linux-2.2.13-pre17/arch/i386/kernel/smp.c	2003-08-15 15:08:34.000000000 -0700
+++ linux-2.2.13-pre18/arch/i386/kernel/smp.c	2003-08-15 15:08:35.000000000 -0700
@@ -657,13 +657,14 @@
 	return virt_to_phys(trampoline_base);
 }
 
+extern unsigned long i386_endbase __initdata;
 /*
  *	We are called very early to get the low memory for the
  *	SMP bootup trampoline page.
  */
 unsigned long __init smp_alloc_memory(unsigned long mem_base)
 {
-	if (virt_to_phys((void *)mem_base) >= 0x9F000)
+	if (mem_base + PAGE_SIZE > i386_endbase)
 		panic("smp_alloc_memory: Insufficient low memory for kernel trampoline 0x%lx.", mem_base);
 	trampoline_base = (void *)mem_base;
 	return mem_base + PAGE_SIZE;
@@ -930,6 +931,14 @@
 	unsigned short ss;
 } stack_start;
 
+static int __init fork_by_hand(void)
+{
+	struct pt_regs regs;
+	/* don't care about the eip and regs settings since we'll never
+	   reschedule the forked task. */
+	return do_fork(CLONE_VM|CLONE_PID, 0, &regs);
+}
+
 static void __init do_boot_cpu(int i)
 {
 	unsigned long cfg;
@@ -939,11 +948,11 @@
 	int timeout, num_starts, j;
 	unsigned long start_eip;
 
-	/*
-	 *	We need an idle process for each processor.
-	 */
-	kernel_thread(start_secondary, NULL, CLONE_PID);
 	cpucount++;
+	/* We can't use kernel_thread since we must _avoid_ to reschedule
+	   the child. */
+	if (fork_by_hand() < 0)
+		panic("failed fork for CPU %d", i);
 
 	idle = task[cpucount];
 	if (!idle)
diff -urN linux-2.2.13-pre17/arch/i386/mm/init.c linux-2.2.13-pre18/arch/i386/mm/init.c
--- linux-2.2.13-pre17/arch/i386/mm/init.c	1999-08-09 12:04:38.000000000 -0700
+++ linux-2.2.13-pre18/arch/i386/mm/init.c	2003-08-15 15:08:35.000000000 -0700
@@ -384,6 +384,8 @@
 		printk(".\n");
 }
 
+extern unsigned long i386_endbase __initdata;
+
 __initfunc(void mem_init(unsigned long start_mem, unsigned long end_mem))
 {
 	unsigned long start_low_mem = PAGE_SIZE;
@@ -415,12 +417,7 @@
 #endif
 	start_mem = PAGE_ALIGN(start_mem);
 
-	/*
-	 * IBM messed up *AGAIN* in their thinkpad: 0xA0000 -> 0x9F000.
-	 * They seem to have done something stupid with the floppy
-	 * controller as well..
-	 */
-	while (start_low_mem < 0x9f000+PAGE_OFFSET) {
+	while (start_low_mem < i386_endbase) {
 		clear_bit(PG_reserved, &mem_map[MAP_NR(start_low_mem)].flags);
 		start_low_mem += PAGE_SIZE;
 	}
diff -urN linux-2.2.13-pre17/Documentation/memory.txt linux-2.2.13-pre18/Documentation/memory.txt
--- linux-2.2.13-pre17/Documentation/memory.txt	1998-12-22 08:31:07.000000000 -0800
+++ linux-2.2.13-pre18/Documentation/memory.txt	2003-08-15 15:08:35.000000000 -0700
@@ -54,3 +54,11 @@
 
 	* Try passing the "no-hlt" option to disable the potentially
           buggy HLT instruction in your CPU.
+
+	* Passing for example the "endbase=0x9F000" option to the kernel,
+	  you'll _force_ the kernel to not touch the memory between 0x9F000
+	  and 1Mbyte. As default the kernel reads the endbase limit from
+	  the BIOS. So you need to specify this option only if the BIOS
+	  does not provide the right information to the kernel (or if you
+	  don't have a BIOS at all :). You can discover the endbase value
+	  of your running kernel with this command `dmesg | grep endbase`.
diff -urN linux-2.2.13-pre17/drivers/char/buz.c linux-2.2.13-pre18/drivers/char/buz.c
--- linux-2.2.13-pre17/drivers/char/buz.c	2003-08-15 15:08:34.000000000 -0700
+++ linux-2.2.13-pre18/drivers/char/buz.c	2003-08-15 15:08:35.000000000 -0700
@@ -3221,7 +3221,7 @@
 	}
 	/* i2c */
 	memcpy(&zr->i2c, &zoran_i2c_bus_template, sizeof(struct i2c_bus));
-	sprintf(zr->i2c.name, "zoran%u%u", zr->id);
+	sprintf(zr->i2c.name, "zoran%u", zr->id);
 	zr->i2c.data = zr;
 	if (i2c_register_bus(&zr->i2c) < 0) {
 		kfree((void *) zr->stat_com);
diff -urN linux-2.2.13-pre17/drivers/char/msp3400.c linux-2.2.13-pre18/drivers/char/msp3400.c
--- linux-2.2.13-pre17/drivers/char/msp3400.c	1999-02-17 09:37:51.000000000 -0800
+++ linux-2.2.13-pre18/drivers/char/msp3400.c	2003-08-15 15:08:35.000000000 -0700
@@ -76,6 +76,7 @@
 	int mode;
 	int norm;
 	int stereo;
+	int nicam_on;
 	int main, second;	/* sound carrier */
 
 	int left, right;	/* volume */
@@ -151,27 +152,39 @@
 static int
 msp3400c_read(struct i2c_bus *bus, int dev, int addr)
 {
-	int ret=0;
-	short val = 0;
-	i2c_start(bus);
-	if (0 != i2c_sendbyte(bus, I2C_MSP3400C,2000) ||
-	    0 != i2c_sendbyte(bus, dev+1,       0)    ||
-	    0 != i2c_sendbyte(bus, addr >> 8,   0)    ||
-	    0 != i2c_sendbyte(bus, addr & 0xff, 0)) {
-		ret = -1;
-	} else {
+	int err,ret;
+	short val=0;
+
+	for (err = 0; err < 3;) {
+		ret = 0;
 		i2c_start(bus);
-		if (0 != i2c_sendbyte(bus, I2C_MSP3400C+1,2000)) {
+		if (0 != i2c_sendbyte(bus, I2C_MSP3400C,2000) ||
+		    0 != i2c_sendbyte(bus, dev+1,       0)    ||
+		    0 != i2c_sendbyte(bus, addr >> 8,   0)    ||
+		    0 != i2c_sendbyte(bus, addr & 0xff, 0)) {
 			ret = -1;
 		} else {
-			val |= (int)i2c_readbyte(bus,0) << 8;
-			val |= (int)i2c_readbyte(bus,1);
+			i2c_start(bus);
+			if (0 != i2c_sendbyte(bus, I2C_MSP3400C+1,2000)) {
+				ret = -1;
+			} else {
+				val |= (int)i2c_readbyte(bus,0) << 8;
+				val |= (int)i2c_readbyte(bus,1);
+			}
 		}
+		i2c_stop(bus);
+		if (0 == ret)
+			break;
+
+		/* some I/O error */
+		err++;
+		printk(KERN_WARNING "msp34xx: I/O error #%d (read 0x%02x/0x%02x)\n",
+		       err, dev, addr);
+		current->state = TASK_INTERRUPTIBLE;
+		schedule_timeout(HZ/10);
 	}
-	i2c_stop(bus);
 	if (-1 == ret) {
-		printk(KERN_WARNING "msp3400: I/O error, trying reset (read %s 0x%x)\n",
-		       (dev == I2C_MSP3400C_DEM) ? "Demod" : "Audio", addr);
+		printk(KERN_WARNING "msp34xx: giving up, reseting chip. Sound will go off, sorry folks :-|\n");
 		msp3400c_reset(bus);
 	}
 	return val;
@@ -180,20 +193,31 @@
 static int
 msp3400c_write(struct i2c_bus *bus, int dev, int addr, int val)
 {
-	int ret = 0;
+	int ret,err;
     
-	i2c_start(bus);
-	if (0 != i2c_sendbyte(bus, I2C_MSP3400C,2000) ||
-	    0 != i2c_sendbyte(bus, dev,         0)    ||
-	    0 != i2c_sendbyte(bus, addr >> 8,   0)    ||
-	    0 != i2c_sendbyte(bus, addr & 0xff, 0)    ||
-	    0 != i2c_sendbyte(bus, val >> 8,    0)    ||
-	    0 != i2c_sendbyte(bus, val & 0xff,  0))
-		ret = -1;
-	i2c_stop(bus);
+	for (err = 0; err < 3;) {
+		ret = 0;
+		i2c_start(bus);
+		if (0 != i2c_sendbyte(bus, I2C_MSP3400C,2000) ||
+		    0 != i2c_sendbyte(bus, dev,         0)    ||
+		    0 != i2c_sendbyte(bus, addr >> 8,   0)    ||
+		    0 != i2c_sendbyte(bus, addr & 0xff, 0)    ||
+		    0 != i2c_sendbyte(bus, val >> 8,    0)    ||
+		    0 != i2c_sendbyte(bus, val & 0xff,  0))
+			ret = -1;
+		i2c_stop(bus);
+		if (0 == ret)
+			break;
+
+		/* some I/O error */
+		err++;
+		printk(KERN_WARNING "msp34xx: I/O error #%d (write 0x%02x/0x%02x)\n",
+		       err, dev, addr);
+		current->state = TASK_INTERRUPTIBLE;
+		schedule_timeout(HZ/10);
+	}
 	if (-1 == ret) {
-		printk(KERN_WARNING "msp3400: I/O error, trying reset (write %s 0x%x)\n",
-		       (dev == I2C_MSP3400C_DEM) ? "Demod" : "Audio", addr);
+		printk(KERN_WARNING "msp34xx: giving up, reseting chip. Sound will go off, sorry folks :-|\n");
 		msp3400c_reset(bus);
 	}
 	return ret;
@@ -383,12 +407,12 @@
 static void msp3400c_setstereo(struct msp3400c *msp, int mode)
 {
 	int nicam=0; /* channel source: FM/AM or nicam */
-
+	int src=0;
+	
 	/* switch demodulator */
 	switch (msp->mode) {
 	case MSP_MODE_FM_TERRA:
 		dprintk("msp3400: FM setstereo: %d\n",mode);
-		msp->stereo = mode;
 		msp3400c_setcarrier(msp->bus,msp->second,msp->main);
 		switch (mode) {
 		case VIDEO_SOUND_STEREO:
@@ -403,7 +427,6 @@
 		break;
 	case MSP_MODE_FM_SAT:
 		dprintk("msp3400: SAT setstereo: %d\n",mode);
-		msp->stereo = mode;
 		switch (mode) {
 		case VIDEO_SOUND_MONO:
 			msp3400c_setcarrier(msp->bus, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
@@ -424,7 +447,8 @@
 		dprintk("msp3400: NICAM setstereo: %d\n",mode);
 		msp->stereo = mode;
 		msp3400c_setcarrier(msp->bus,msp->second,msp->main);
-		nicam=0x0100;
+		if (msp->nicam_on)
+			nicam=0x0100;
 		break;
 	default:
 		/* can't do stereo - abort here */
@@ -434,25 +458,22 @@
 	/* switch audio */
 	switch (mode) {
 	case VIDEO_SOUND_STEREO:
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0008,0x0020|nicam);
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0009,0x0020|nicam);
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x000a,0x0020|nicam);
+		src = 0x0020 | nicam;
 #if 0
 		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0005,0x4000);
 #endif
 		break;
 	case VIDEO_SOUND_MONO:
 	case VIDEO_SOUND_LANG1:
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0008,0x0000|nicam);
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0009,0x0000|nicam);
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x000a,0x0000|nicam);
+		src = 0x0000 | nicam;
 		break;
 	case VIDEO_SOUND_LANG2:
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0008,0x0010|nicam);
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0009,0x0010|nicam);
-		msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x000a,0x0010|nicam);
+		src = 0x0010 | nicam;
 		break;
 	}
+	msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0008,src);
+	msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0009,src);
+	msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x000a,src);
 }
 
 static void
@@ -491,6 +512,77 @@
 	{ 0x0057, "ERROR_RATE" },
 };
 
+static int
+autodetect_stereo(struct msp3400c *msp)
+{
+	int val;
+	int newstereo = msp->stereo;
+	int newnicam  = msp->nicam_on;
+	int update = 0;
+
+	switch (msp->mode) {
+	case MSP_MODE_FM_TERRA:
+		val = msp3400c_read(msp->bus, I2C_MSP3400C_DFP, 0x18);
+		dprintk("msp3400: stereo detect register: %d\n",val);
+		
+		if (val > 4096) {
+			newstereo = VIDEO_SOUND_STEREO | VIDEO_SOUND_MONO;
+		} else if (val < -4096) {
+			newstereo = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
+		} else {
+			newstereo = VIDEO_SOUND_MONO;
+		}
+		newnicam = 0;
+		break;
+	case MSP_MODE_FM_NICAM1:
+	case MSP_MODE_FM_NICAM2:
+		val = msp3400c_read(msp->bus, I2C_MSP3400C_DEM, 0x23);
+		dprintk("msp3400: nicam sync=%d, mode=%d\n",val & 1, (val & 0x1e) >> 1);
+
+		if (val & 1) {
+			/* nicam synced */
+			switch ((val & 0x1e) >> 1)  {
+			case 0:
+			case 8:
+				newstereo = VIDEO_SOUND_STEREO;
+				break;
+			case 1:
+			case 9:
+				newstereo = VIDEO_SOUND_MONO
+					| VIDEO_SOUND_LANG1;
+				break;
+			case 2:
+			case 10:
+				newstereo = VIDEO_SOUND_MONO
+					| VIDEO_SOUND_LANG1
+					| VIDEO_SOUND_LANG2;
+				break;
+			default:
+				newstereo = VIDEO_SOUND_MONO;
+				break;
+			}
+			newnicam=1;
+		} else {
+			newnicam=0;
+			newstereo = VIDEO_SOUND_MONO;
+		}
+		break;
+	}
+	if (newstereo != msp->stereo) {
+		update = 1;
+		dprintk("msp3400: watch: stereo %d => %d\n",
+			msp->stereo,newstereo);
+		msp->stereo   = newstereo;
+	}
+	if (newnicam != msp->nicam_on) {
+		update = 1;
+		dprintk("msp3400: watch: nicam %d => %d\n",
+			msp->nicam_on,newnicam);
+		msp->nicam_on = newnicam;
+	}
+	return update;
+}
+
 /*
  * A kernel thread for msp3400 control -- we don't want to block the
  * in the ioctl while doing the sound carrier & stereo detect
@@ -503,13 +595,34 @@
 	wake_up_interruptible(&msp->wq);
 }
 
+/* stereo/multilang monitoring */
+static void watch_stereo(struct msp3400c *msp)
+{
+	LOCK_FLAGS;
+
+	LOCK_I2C_BUS(msp->bus);
+	if (autodetect_stereo(msp)) {
+		if (msp->stereo & VIDEO_SOUND_STEREO)
+			msp3400c_setstereo(msp,VIDEO_SOUND_STEREO);
+		else if (msp->stereo & VIDEO_SOUND_LANG1)
+			msp3400c_setstereo(msp,VIDEO_SOUND_LANG1);
+		else
+			msp3400c_setstereo(msp,VIDEO_SOUND_MONO);
+	}
+	UNLOCK_I2C_BUS(msp->bus);
+	if (msp->watch_stereo) {
+		del_timer(&msp->wake_stereo);
+		msp->wake_stereo.expires = jiffies + 5*HZ;
+		add_timer(&msp->wake_stereo);
+	}
+}
+
 static int msp3400c_thread(void *data)
 {
 	struct msp3400c *msp = data;
     
 	struct CARRIER_DETECT *cd;
 	int                   count, max1,max2,val1,val2, val,this;
-	int                   newstereo;
 	LOCK_FLAGS;
     
 #ifdef __SMP__
@@ -523,14 +636,13 @@
 	current->fs->umask = 0;
 	strcpy(current->comm,"msp3400");
 
-	msp->wq     = NULL;
 	msp->thread = current;
 
 #ifdef __SMP__
 	unlock_kernel();
 #endif
 
-	dprintk("msp3400: thread: start\n");
+	printk("msp3400: daemon started\n");
 	if(msp->notify != NULL)
 		up(msp->notify);
 		
@@ -551,48 +663,7 @@
 		msp->active = 1;
 
 		if (msp->watch_stereo) {
-			/* do that stereo/multilang handling */
-			LOCK_I2C_BUS(msp->bus);
-			newstereo = msp->stereo;
-			switch (msp->mode) {
-			case MSP_MODE_FM_TERRA:
-				val = msp3400c_read(msp->bus, I2C_MSP3400C_DFP, 0x18);
-				dprintk("msp3400: stereo detect register: %d\n",val);
-		
-				if (val > 4096) {
-					newstereo = VIDEO_SOUND_STEREO;
-				} else if (val < -4096) {
-					newstereo = VIDEO_SOUND_LANG1;
-				} else {
-					newstereo = VIDEO_SOUND_MONO;
-				}
-				break;
-			case MSP_MODE_FM_NICAM1:
-			case MSP_MODE_FM_NICAM2:
-				val = msp3400c_read(msp->bus, I2C_MSP3400C_DEM, 0x23);
-				switch ((val & 0x1e) >> 1)  {
-				case 0:
-				case 8:
-					newstereo = VIDEO_SOUND_STEREO;
-					break;
-				default:
-					newstereo = VIDEO_SOUND_MONO;
-					break;
-				}
-				break;
-			}
-			if (msp->stereo != newstereo) {
-				dprintk("msp3400: watch: stereo %d ==> %d\n",
-					msp->stereo,newstereo);
-				msp3400c_setstereo(msp,newstereo);
-			}
-			UNLOCK_I2C_BUS(msp->bus);
-			if (msp->watch_stereo) {
-				del_timer(&msp->wake_stereo);
-				msp->wake_stereo.expires = jiffies + 5*HZ;
-				add_timer(&msp->wake_stereo);
-			}
-
+			watch_stereo(msp);
 			msp->active = 0;
 			continue;
 		}
@@ -600,7 +671,7 @@
 	restart:
 		LOCK_I2C_BUS(msp->bus);
 		msp3400c_setvolume(msp->bus, 0, 0);
-		msp3400c_setmode(msp, MSP_MODE_AM_DETECT);
+		msp3400c_setmode(msp, MSP_MODE_AM_DETECT /* +1 */ );
 		val1 = val2 = 0;
 		max1 = max2 = -1;
 		del_timer(&msp->wake_stereo);
@@ -627,7 +698,7 @@
 				val1 = val, max1 = this;
 			dprintk("msp3400: carrier1 val: %5d / %s\n", val,cd[this].name);
 		}
-
+		
 		/* carrier detect pass #2 -- second (stereo) carrier */
 		switch (max1) {
 		case 1: /* 5.5 */
@@ -670,12 +741,14 @@
 				/* B/G FM-stereo */
 				msp->second = carrier_detect_55[max2].cdo;
 				msp3400c_setmode(msp, MSP_MODE_FM_TERRA);
+				msp->nicam_on = 0;
 				msp3400c_setstereo(msp, VIDEO_SOUND_MONO);
 				msp->watch_stereo = 1;
 			} else if (max2 == 1 && msp->nicam) {
 				/* B/G NICAM */
 				msp->second = carrier_detect_55[max2].cdo;
 				msp3400c_setmode(msp, MSP_MODE_FM_NICAM1);
+				msp->nicam_on = 1;
 				msp3400c_setcarrier(msp->bus, msp->second, msp->main);
 				msp->watch_stereo = 1;
 			} else {
@@ -686,6 +759,7 @@
 			/* PAL I NICAM */
 			msp->second = MSP_CARRIER(6.552);
 			msp3400c_setmode(msp, MSP_MODE_FM_NICAM2);
+			msp->nicam_on = 1;
 			msp3400c_setcarrier(msp->bus, msp->second, msp->main);
 			msp->watch_stereo = 1;
 			break;
@@ -694,12 +768,14 @@
 				/* D/K FM-stereo */
 				msp->second = carrier_detect_65[max2].cdo;
 				msp3400c_setmode(msp, MSP_MODE_FM_TERRA);
+				msp->nicam_on = 0;
 				msp3400c_setstereo(msp, VIDEO_SOUND_MONO);
 				msp->watch_stereo = 1;
 			} else if (max2 == 0 && msp->nicam) {
 				/* D/K NICAM */
 				msp->second = carrier_detect_65[max2].cdo;
 				msp3400c_setmode(msp, MSP_MODE_FM_NICAM1);
+				msp->nicam_on = 1;
 				msp3400c_setcarrier(msp->bus, msp->second, msp->main);
 				msp->watch_stereo = 1;
 			} else {
@@ -711,7 +787,10 @@
 		no_second:
 			msp->second = carrier_detect_main[max1].cdo;
 			msp3400c_setmode(msp, MSP_MODE_FM_TERRA);
+			msp->nicam_on = 0;
 			msp3400c_setcarrier(msp->bus, msp->second, msp->main);
+			msp->stereo = VIDEO_SOUND_MONO;
+			msp3400c_setstereo(msp, VIDEO_SOUND_MONO);
 			break;
 		}
 
@@ -721,7 +800,7 @@
 
 		if (msp->watch_stereo) {
 			del_timer(&msp->wake_stereo);
-			msp->wake_stereo.expires = jiffies + 2*HZ;
+			msp->wake_stereo.expires = jiffies + 5*HZ;
 			add_timer(&msp->wake_stereo);
 		}
 
@@ -741,7 +820,6 @@
 	return 0;
 }
 
-
 #if 0 /* not finished yet */
 
 static int msp3410d_thread(void *data)
@@ -1048,11 +1126,6 @@
 		return -1;
 	}
 
-	msp3400c_setmode(msp, MSP_MODE_FM_TERRA);
-	msp3400c_setvolume(msp->bus, msp->left, msp->right);
-	msp3400c_setbass(msp->bus, msp->bass);
-	msp3400c_settreble(msp->bus, msp->treble);
-    
 #if 0
 	/* this will turn on a 1kHz beep - might be useful for debugging... */
 	msp3400c_write(msp->bus,I2C_MSP3400C_DFP, 0x0014, 0x1040);
diff -urN linux-2.2.13-pre17/drivers/char/serial.c linux-2.2.13-pre18/drivers/char/serial.c
--- linux-2.2.13-pre17/drivers/char/serial.c	2003-08-15 15:08:34.000000000 -0700
+++ linux-2.2.13-pre18/drivers/char/serial.c	2003-08-15 15:08:35.000000000 -0700
@@ -1693,7 +1693,7 @@
 	if ((new_serial.type != state->type) ||
 	    (new_serial.xmit_fifo_size <= 0))
 		new_serial.xmit_fifo_size =
-			uart_config[state->type].dfl_xmit_fifo_size;
+			uart_config[new_serial.type].dfl_xmit_fifo_size;
 
 	/* Make sure address is not already in use */
 	if (new_serial.type) {
diff -urN linux-2.2.13-pre17/drivers/net/eepro100.c linux-2.2.13-pre18/drivers/net/eepro100.c
--- linux-2.2.13-pre17/drivers/net/eepro100.c	2003-08-15 15:08:34.000000000 -0700
+++ linux-2.2.13-pre18/drivers/net/eepro100.c	2003-08-15 15:08:35.000000000 -0700
@@ -823,6 +823,18 @@
 	dev->interrupt = 0;
 	dev->start = 1;
 
+	/*
+	 * Request the IRQ last, after we have set up all data structures.
+	 * It would be bad to get an interrupt before we're ready.
+	 *
+	 * Register ourself first before turn on the interrupt. Someone
+	 * else may share the same interrupt. H.J.
+	 */
+	if (request_irq(dev->irq, &speedo_interrupt, SA_SHIRQ,
+					"Intel EtherExpress Pro 10/100 Ethernet", dev)) {
+		return -EAGAIN;
+	}
+
 	/* Start the chip's Tx process and unmask interrupts. */
 	/* Todo: verify that we must wait for previous command completion. */
 	wait_for_cmd_done(ioaddr + SCBCmd);
@@ -844,15 +856,6 @@
 	wait_for_cmd_done(ioaddr + SCBCmd);
 	outw(CU_DUMPSTATS, ioaddr + SCBCmd);
 
-	/*
-	 * Request the IRQ last, after we have set up all data structures.
-	 * It would be bad to get an interrupt before we're ready.
-	 */
-	if (request_irq(dev->irq, &speedo_interrupt, SA_SHIRQ,
-					"Intel EtherExpress Pro 10/100 Ethernet", dev)) {
-		return -EAGAIN;
-	}
-
 	/* No need to wait for the command unit to accept here. */
 	if ((sp->phy[0] & 0x8000) == 0)
 		mdio_read(ioaddr, sp->phy[0] & 0x1f, 0);
diff -urN linux-2.2.13-pre17/drivers/pci/oldproc.c linux-2.2.13-pre18/drivers/pci/oldproc.c
--- linux-2.2.13-pre17/drivers/pci/oldproc.c	2003-08-15 15:08:34.000000000 -0700
+++ linux-2.2.13-pre18/drivers/pci/oldproc.c	2003-08-15 15:08:35.000000000 -0700
@@ -906,7 +906,7 @@
 			       vendor, device);
 	}
 
-	str = 0;	/* to keep gcc shut... */
+	str = "Confused devsel.";
 	switch (status & PCI_STATUS_DEVSEL_MASK) {
 	      case PCI_STATUS_DEVSEL_FAST:   str = "Fast devsel.  "; break;
 	      case PCI_STATUS_DEVSEL_MEDIUM: str = "Medium devsel.  "; break;
diff -urN linux-2.2.13-pre17/drivers/scsi/atp870u.c linux-2.2.13-pre18/drivers/scsi/atp870u.c
--- linux-2.2.13-pre17/drivers/scsi/atp870u.c	1999-08-09 12:04:40.000000000 -0700
+++ linux-2.2.13-pre18/drivers/scsi/atp870u.c	2003-08-15 15:08:35.000000000 -0700
@@ -1,7 +1,7 @@
 /* $Id: atp870u.c,v 1.0 1997/05/07 15:22:00 root Exp root $
  *  linux/kernel/atp870u.c
  *
- *  Copyright (C) 1997	Wu Ching Chen
+ *  Copyright (C) 1997  Wu Ching Chen
  *  2.1.x update (C) 1998  Krzysztof G. Baranowski
  *   
  * Marcelo Tosatti <marcelo@conectiva.com.br> : SMP fixes 
@@ -30,745 +30,620 @@
 
 #include<linux/stat.h>
 
-struct proc_dir_entry proc_scsi_atp870u = {
-    PROC_SCSI_ATP870U, 7, "atp870u",
-    S_IFDIR | S_IRUGO | S_IXUGO, 2
+struct proc_dir_entry proc_scsi_atp870u =
+{
+	PROC_SCSI_ATP870U, 7, "atp870u",
+	S_IFDIR | S_IRUGO | S_IXUGO, 2
 };
 
 void mydlyu(unsigned int);
+
 /*
-static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/atp870u.c,v 1.0 1997/05/07 15:22:00 root Exp root $";
-*/
+ *   static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/atp870u.c,v 1.0 1997/05/07 15:22:00 root Exp root $";
+ */
+
+static unsigned char admaxu = 1, host_idu[2], chip_veru[2], scam_on[2], global_map[2];
+static unsigned short int active_idu[2], wide_idu[2], sync_idu, ultra_map[2];
+static int workingu[2] = {0, 0};
+
+static Scsi_Cmnd *querequ[2][qcnt], *curr_req[2][16];
+
+static unsigned char devspu[2][16] = {
+	{0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+	 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20},
+	{0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+	 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20}
+};
 
-static unsigned char admaxu=1,host_idu[2],chip_veru[2],scam_on[2],global_map[2];
-static unsigned short int active_idu[2],wide_idu[2],sync_idu,ultra_map[2];
-static int  workingu[2]={0,0};
-static Scsi_Cmnd *querequ[2][qcnt],*curr_req[2][16];
-static unsigned char devspu[2][16] = {{0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
-				0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20},
-			       {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
-				0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}};
-static unsigned char dirctu[2][16],last_cmd[2],in_snd[2],in_int[2];
+static unsigned char dirctu[2][16], last_cmd[2], in_snd[2], in_int[2];
 static unsigned char ata_cdbu[2][16];
-static unsigned int ioportu[2]={0,0};
-static unsigned int irqnumu[2]={0,0};
+static unsigned int ioportu[2] = {0, 0};
+static unsigned int irqnumu[2] = {0, 0};
 static unsigned short int pciportu[2];
-static unsigned long prdaddru[2][16],tran_lenu[2][16],last_lenu[2][16];
+static unsigned long prdaddru[2][16], tran_lenu[2][16], last_lenu[2][16];
 static unsigned char prd_tableu[2][16][1024];
 static unsigned char *prd_posu[2][16];
-static unsigned char quhdu[2],quendu[2];
-static unsigned char devtypeu[2][16] = {{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
-				 { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
-static struct Scsi_Host * atp_host[2]={NULL,NULL};
+static unsigned char quhdu[2], quendu[2];
+
+static unsigned char devtypeu[2][16] =
+{
+	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+};
+
+static struct Scsi_Host *atp_host[2] = {NULL, NULL};
 
 static void atp870u_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
 {
-	 unsigned long flags;
-    unsigned short int	tmpcip,id;
-    unsigned char	i,j,h,tarid,lun;
-    unsigned char  *prd;
-    Scsi_Cmnd *workrequ;
-    unsigned int workportu,tmport;
-    unsigned long adrcntu,k;
-    int      errstus;
-
-    for ( h=0; h < 2; h++ )
-    {
-	if ( ( irq & 0x0f ) == irqnumu[h] )
-	{
-	   goto irq_numok;
+	unsigned long flags;
+	unsigned short int tmpcip, id;
+	unsigned char i, j, h, tarid, lun;
+	unsigned char *prd;
+	Scsi_Cmnd *workrequ;
+	unsigned int workportu, tmport;
+	unsigned long adrcntu, k;
+	int errstus;
+
+	for (h = 0; h < 2; h++) {
+		if (irq == irqnumu[h]) {
+			goto irq_numok;
+		}
 	}
-    }
-    return;
+	return;
 irq_numok:
-    in_int[h]=1;
-    workportu=ioportu[h];
-    tmport=workportu;
-
-    if ( workingu[h] != 0 )
-    {
-       tmport += 0x1f;
-       j=inb(tmport);
-       tmpcip=pciportu[h];
-       if ((inb(tmpcip) & 0x08) != 0)
-       {
-	  tmpcip += 0x2;
-	  while((inb(tmpcip) & 0x08) != 0);
-       }
-       tmpcip=pciportu[h];
-       outb(0x00,tmpcip);
-       tmport -=0x08;
-       i=inb(tmport);
-       if ((j & 0x40) == 0)
-       {
-	  if ((last_cmd[h] & 0x40) == 0)
-	  {
-	     last_cmd[h]=0xff;
-	  }
-       }
-       else
-       {
-	  last_cmd[h] |= 0x40;
-       }
-       tmport -= 0x02;
-       tarid=inb(tmport);
-       tmport += 0x02;
-       if ((tarid & 0x40) != 0)
-       {
-	  tarid=(tarid & 0x07) | 0x08;
-       }
-       else
-       {
-	  tarid &= 0x07;
-       }
-       if ( i == 0x85 )
-       {
-	  if (wide_idu[h] != 0)
-	  {
-	     tmport=workportu+0x1b;
-	     j=inb(tmport) & 0x0e;
-	     j |= 0x01;
-	     outb(j,tmport);
-	  }
-	  if (((quhdu[h] != quendu[h]) || (last_cmd[h] != 0xff)) &&
-	      (in_snd[h] == 0))
-	  {
-	     send_s870(h);
-	  }
-	  in_int[h]=0;
-	  return;
-       }
-       if ( i == 0x21 )
-       {
-	  tmport -= 0x05;
-	  adrcntu=0;
-	  ((unsigned char *)&adrcntu)[2]=inb(tmport++);
-	  ((unsigned char *)&adrcntu)[1]=inb(tmport++);
-	  ((unsigned char *)&adrcntu)[0]=inb(tmport);
-	  k=last_lenu[h][tarid];
-	  k -= adrcntu;
-	  tran_lenu[h][tarid]= k;
-	  last_lenu[h][tarid]=adrcntu;
-	  tmport -= 0x04;
-	  outb(0x41,tmport);
-	  tmport += 0x08;
-	  outb(0x08,tmport);
-	  in_int[h]=0;
-	  return ;
-       }
-
-       if ((i == 0x80) || (i == 0x8f))
-       {
-	  lun=0;
-	  tmport -= 0x07;
-	  j=inb(tmport);
-	  if ( j == 0x44 )
-	  {
-	     tmport += 0x0d;
-	     lun=inb(tmport) & 0x07;
-	  }
-	  else
-	  {
-	     if ( j == 0x41 )
-	     {
+	in_int[h] = 1;
+	workportu = ioportu[h];
+	tmport = workportu;
+
+	if (workingu[h] != 0) 
+	{
+		tmport += 0x1f;
+		j = inb(tmport);
+
+		tmpcip = pciportu[h];
+		if ((inb(tmpcip) & 0x08) != 0) 
+		{
+			tmpcip += 0x2;
+			while ((inb(tmpcip) & 0x08) != 0);
+		}
+		tmpcip = pciportu[h];
+		outb(0x00, tmpcip);
+		tmport -= 0x08;
+
+		i = inb(tmport);
+		if ((j & 0x40) == 0) 
+		{
+			if ((last_cmd[h] & 0x40) == 0) 
+			{
+				last_cmd[h] = 0xff;
+			}
+		}
+		else last_cmd[h] |= 0x40;
+
+		tmport -= 0x02;
+		tarid = inb(tmport);
 		tmport += 0x02;
-		adrcntu=0;
-		((unsigned char *)&adrcntu)[2]=inb(tmport++);
-		((unsigned char *)&adrcntu)[1]=inb(tmport++);
-		((unsigned char *)&adrcntu)[0]=inb(tmport);
-		k=last_lenu[h][tarid];
-		k -= adrcntu;
-		tran_lenu[h][tarid]= k;
-		last_lenu[h][tarid]=adrcntu;
-		tmport += 0x04;
-		outb(0x08,tmport);
-		in_int[h]=0;
-		return ;
-	     }
-	     else
-	     {
-		outb(0x46,tmport);
-		dirctu[h][tarid]=0x00;
+
+		if ((tarid & 0x40) != 0) {
+			tarid = (tarid & 0x07) | 0x08;
+		} else {
+			tarid &= 0x07;
+		}
+		if (i == 0x85) 
+		{
+			if (wide_idu[h] != 0) 
+			{
+				tmport = workportu + 0x1b;
+				j = inb(tmport) & 0x0e;
+				j |= 0x01;
+				outb(j, tmport);
+			}
+			if (((quhdu[h] != quendu[h]) || (last_cmd[h] != 0xff)) &&
+			    (in_snd[h] == 0)) 
+			{
+				send_s870(h);
+			}
+			in_int[h] = 0;
+			return;
+		}
+		if (i == 0x21) 
+		{
+			tmport -= 0x05;
+			adrcntu = 0;
+			((unsigned char *) &adrcntu)[2] = inb(tmport++);
+			((unsigned char *) &adrcntu)[1] = inb(tmport++);
+			((unsigned char *) &adrcntu)[0] = inb(tmport);
+			k = last_lenu[h][tarid];
+			k -= adrcntu;
+			tran_lenu[h][tarid] = k;
+			last_lenu[h][tarid] = adrcntu;
+			tmport -= 0x04;
+			outb(0x41, tmport);
+			tmport += 0x08;
+			outb(0x08, tmport);
+			in_int[h] = 0;
+			return;
+		}
+		if ((i == 0x80) || (i == 0x8f)) 
+		{
+			lun = 0;
+			tmport -= 0x07;
+			j = inb(tmport);
+			if (j == 0x44) {
+				tmport += 0x0d;
+				lun = inb(tmport) & 0x07;
+			} else {
+				if (j == 0x41) 
+				{
+					tmport += 0x02;
+					adrcntu = 0;
+					((unsigned char *) &adrcntu)[2] = inb(tmport++);
+					((unsigned char *) &adrcntu)[1] = inb(tmport++);
+					((unsigned char *) &adrcntu)[0] = inb(tmport);
+					k = last_lenu[h][tarid];
+					k -= adrcntu;
+					tran_lenu[h][tarid] = k;
+					last_lenu[h][tarid] = adrcntu;
+					tmport += 0x04;
+					outb(0x08, tmport);
+					in_int[h] = 0;
+					return;
+				}
+				else 
+				{
+					outb(0x46, tmport);
+					dirctu[h][tarid] = 0x00;
+					tmport += 0x02;
+					outb(0x00, tmport++);
+					outb(0x00, tmport++);
+					outb(0x00, tmport++);
+					tmport += 0x03;
+					outb(0x08, tmport);
+					in_int[h] = 0;
+					return;
+				}
+			}
+			tmport = workportu + 0x10;
+			outb(0x45, tmport);
+			tmport += 0x06;
+			tarid = inb(tmport);
+			if ((tarid & 0x10) != 0) 
+			{
+				tarid = (tarid & 0x07) | 0x08;
+			} else {
+				tarid &= 0x07;
+			}
+			workrequ = curr_req[h][tarid];
+			tmport = workportu + 0x0f;
+			outb(lun, tmport);
+			tmport += 0x02;
+			outb(devspu[h][tarid], tmport++);
+			adrcntu = tran_lenu[h][tarid];
+			k = last_lenu[h][tarid];
+			outb(((unsigned char *) &k)[2], tmport++);
+			outb(((unsigned char *) &k)[1], tmport++);
+			outb(((unsigned char *) &k)[0], tmport++);
+			j = tarid;
+			if (tarid > 7) {
+				j = (j & 0x07) | 0x40;
+			}
+			j |= dirctu[h][tarid];
+			outb(j, tmport++);
+			outb(0x80, tmport);
+			tmport = workportu + 0x1b;
+			j = inb(tmport) & 0x0e;
+			id = 1;
+			id = id << tarid;
+			if ((id & wide_idu[h]) != 0) {
+				j |= 0x01;
+			}
+			outb(j, tmport);
+			if (last_lenu[h][tarid] == 0) {
+				tmport = workportu + 0x18;
+				outb(0x08, tmport);
+				in_int[h] = 0;
+				return;
+			}
+			prd = prd_posu[h][tarid];
+			while (adrcntu != 0) 
+			{
+				id = ((unsigned short int *) (prd))[2];
+				if (id == 0) {
+					k = 0x10000;
+				} else {
+					k = id;
+				}
+				if (k > adrcntu) {
+					((unsigned short int *) (prd))[2] = (unsigned short int)
+					    (k - adrcntu);
+					((unsigned long *) (prd))[0] += adrcntu;
+					adrcntu = 0;
+					prd_posu[h][tarid] = prd;
+				} else {
+					adrcntu -= k;
+					prdaddru[h][tarid] += 0x08;
+					prd += 0x08;
+					if (adrcntu == 0) {
+						prd_posu[h][tarid] = prd;
+					}
+				}
+			}
+			tmpcip = pciportu[h] + 0x04;
+			outl(prdaddru[h][tarid], tmpcip);
+			tmpcip -= 0x02;
+			outb(0x06, tmpcip);
+			outb(0x00, tmpcip);
+			tmpcip -= 0x02;
+			tmport = workportu + 0x18;
+			if (dirctu[h][tarid] != 0) {
+				outb(0x08, tmport);
+				outb(0x01, tmpcip);
+				in_int[h] = 0;
+				return;
+			}
+			outb(0x08, tmport);
+			outb(0x09, tmpcip);
+			in_int[h] = 0;
+			return;
+		}
+		workrequ = curr_req[h][tarid];
+		if (i == 0x42) {
+			errstus = 0x02;
+			workrequ->result = errstus;
+			goto go_42;
+		}
+		if (i == 0x16) 
+		{
+			errstus = 0;
+			tmport -= 0x08;
+			errstus = inb(tmport);
+			workrequ->result = errstus;
+go_42:
+			spin_lock_irqsave(&io_request_lock, flags);
+			(*workrequ->scsi_done) (workrequ);
+			spin_unlock_irqrestore(&io_request_lock, flags);
+
+			curr_req[h][tarid] = 0;
+			workingu[h]--;
+			if (wide_idu[h] != 0) {
+				tmport = workportu + 0x1b;
+				j = inb(tmport) & 0x0e;
+				j |= 0x01;
+				outb(j, tmport);
+			}
+			if (((last_cmd[h] != 0xff) || (quhdu[h] != quendu[h])) &&
+			    (in_snd[h] == 0)) 
+			{
+				send_s870(h);
+			}
+			in_int[h] = 0;
+			return;
+		}
+		if (i == 0x4f) {
+			i = 0x89;
+		}
+		i &= 0x0f;
+		if (i == 0x09) {
+			tmpcip = tmpcip + 4;
+			outl(prdaddru[h][tarid], tmpcip);
+			tmpcip = tmpcip - 2;
+			outb(0x06, tmpcip);
+			outb(0x00, tmpcip);
+			tmpcip = tmpcip - 2;
+			tmport = workportu + 0x10;
+			outb(0x41, tmport);
+			dirctu[h][tarid] = 0x00;
+			tmport += 0x08;
+			outb(0x08, tmport);
+			outb(0x09, tmpcip);
+			in_int[h] = 0;
+			return;
+		}
+		if (i == 0x08) {
+			tmpcip = tmpcip + 4;
+			outl(prdaddru[h][tarid], tmpcip);
+			tmpcip = tmpcip - 2;
+			outb(0x06, tmpcip);
+			outb(0x00, tmpcip);
+			tmpcip = tmpcip - 2;
+			tmport = workportu + 0x10;
+			outb(0x41, tmport);
+			tmport += 0x05;
+			outb((unsigned char) (inb(tmport) | 0x20), tmport);
+			dirctu[h][tarid] = 0x20;
+			tmport += 0x03;
+			outb(0x08, tmport);
+			outb(0x01, tmpcip);
+			in_int[h] = 0;
+			return;
+		}
+		tmport -= 0x07;
+		if (i == 0x0a) {
+			outb(0x30, tmport);
+		} else {
+			outb(0x46, tmport);
+		}
+		dirctu[h][tarid] = 0x00;
 		tmport += 0x02;
-		outb(0x00,tmport++);
-		outb(0x00,tmport++);
-		outb(0x00,tmport++);
-		tmport+=0x03;
-		outb(0x08,tmport);
-		in_int[h]=0;
+		outb(0x00, tmport++);
+		outb(0x00, tmport++);
+		outb(0x00, tmport++);
+		tmport += 0x03;
+		outb(0x08, tmport);
+		in_int[h] = 0;
 		return;
-	     }
-	  }
-	  tmport=workportu + 0x10;
-	  outb(0x45,tmport);
-	  tmport += 0x06;
-	  tarid=inb(tmport);
-	  if ((tarid & 0x10) != 0)
-	  {
-	     tarid=(tarid & 0x07) | 0x08;
-	  }
-	  else
-	  {
-	     tarid &= 0x07;
-	  }
-	  workrequ=curr_req[h][tarid];
-	  tmport=workportu + 0x0f;
-	  outb(lun,tmport);
-	  tmport += 0x02;
-	  outb(devspu[h][tarid],tmport++);
-	  adrcntu=tran_lenu[h][tarid];
-	  k=last_lenu[h][tarid];
-	  outb(((unsigned char *)&k)[2],tmport++);
-	  outb(((unsigned char *)&k)[1],tmport++);
-	  outb(((unsigned char *)&k)[0],tmport++);
-	  j=tarid;
-	  if ( tarid > 7 )
-	  {
-	     j = (j & 0x07) | 0x40;
-	  }
-	  j |= dirctu[h][tarid];
-	  outb(j,tmport++);
-	  outb(0x80,tmport);
-	  tmport=workportu + 0x1b;
-	  j=inb(tmport) & 0x0e;
-	  id=1;
-	  id=id << tarid;
-	  if ((id & wide_idu[h]) != 0)
-	  {
-	     j |= 0x01;
-	  }
-	  outb(j,tmport);
-	  if ( last_lenu[h][tarid] == 0 )
-	  {
-	     tmport=workportu + 0x18;
-	     outb(0x08,tmport);
-	     in_int[h]=0;
-	     return ;
-	  }
-	  prd=prd_posu[h][tarid];
-	  while ( adrcntu != 0 )
-	  {
-	       id=((unsigned short int *)(prd))[2];
-	       if ( id == 0 )
-	       {
-		  k=0x10000;
-	       }
-	       else
-	       {
-		  k=id;
-	       }
-	       if ( k > adrcntu )
-	       {
-		  ((unsigned short int *)(prd))[2] =(unsigned short int)
-						     (k - adrcntu);
-		  ((unsigned long *)(prd))[0] += adrcntu;
-		  adrcntu=0;
-		  prd_posu[h][tarid]=prd;
-	       }
-	       else
-	       {
-		  adrcntu -= k;
-		  prdaddru[h][tarid] += 0x08;
-		  prd += 0x08;
-		  if ( adrcntu == 0 )
-		  {
-		     prd_posu[h][tarid]=prd;
-		  }
-	       }
-	  }
-	  tmpcip=pciportu[h] + 0x04;
-	  outl(prdaddru[h][tarid],tmpcip);
-	  tmpcip -= 0x02;
-	  outb(0x06,tmpcip);
-	  outb(0x00,tmpcip);
-	  tmpcip -= 0x02;
-	  tmport=workportu + 0x18;
-	  if ( dirctu[h][tarid] != 0 )
-	  {
-	     outb(0x08,tmport);
-	     outb(0x01,tmpcip);
-	     in_int[h]=0;
-	     return;
-	  }
-	  outb(0x08,tmport);
-	  outb(0x09,tmpcip);
-	  in_int[h]=0;
-	  return;
-       }
-
-       workrequ=curr_req[h][tarid];
-       if ( i == 0x42 )
-       {
-	  errstus=0x02;
-	  workrequ->result=errstus;
-	  goto go_42;
-       }
-       if ( i == 0x16 )
-       {
-	  errstus=0;
-	  tmport -= 0x08;
-	  errstus=inb(tmport);
-	  workrequ->result=errstus;
-/*	  if ( errstus == 0x02 )
-	  {
-	     tmport +=0x10;
-	     if ((inb(tmport) & 0x80) != 0)
-	     {
-		printk(" autosense ");
-	     }
-	     tmport -=0x09;
-	     outb(0,tmport);
-	     tmport=workportu+0x3a;
-	     outb((unsigned char)(inb(tmport) | 0x10),tmport);
-	     tmport -= 0x39;
-
-	     outb(0x08,tmport++);
-	     outb(0x7f,tmport++);
-	     outb(0x03,tmport++);
-	     outb(0x00,tmport++);
-	     outb(0x00,tmport++);
-	     outb(0x00,tmport++);
-	     outb(0x0e,tmport++);
-	     outb(0x00,tmport);
-	     tmport+=0x07;
-	     outb(0x00,tmport++);
-	     tmport++;
-	     outb(devspu[h][workrequ->target],tmport++);
-	     outb(0x00,tmport++);
-	     outb(0x00,tmport++);
-	     outb(0x0e,tmport++);
-	     tmport+=0x03;
-	     outb(0x09,tmport);
-	     tmport+=0x07;
-	     i=0;
-	     adrcntu=(unsigned long)(&workrequ->sense_buffer[0]);
-get_sens:
-	     j=inb(tmport);
-	     if ((j & 0x01) != 0)
-	     {
-		tmport-=0x06;
-		(unsigned char)(((caddr_t) adrcntu)[i++])=inb(tmport);
-		tmport+=0x06;
-		goto get_sens;
-	     }
-	     if ((j & 0x80) == 0)
-	     {
-		goto get_sens;
-	     }
-	     if ((j & 0x40) == 0)
-	     {
-		tmport-=0x08;
-		i=inb(tmport);
-	     }
-	     tmport=workportu+0x3a;
-	     outb((unsigned char)(inb(tmport) & 0xef),tmport);
-	     tmport=workportu+0x01;
-	     outb(0x2c,tmport);
-	     tmport += 0x15;
-	     outb(0x80,tmport);
-	  }   */
-go_42:
-	  spin_lock_irqsave(&io_request_lock, flags);
-	  (*workrequ->scsi_done)(workrequ);
-	  spin_unlock_irqrestore(&io_request_lock, flags);
-
-	  curr_req[h][tarid]=0;
-	  workingu[h]--;
-	  if (wide_idu[h] != 0)
-	  {
-	     tmport=workportu+0x1b;
-	     j=inb(tmport) & 0x0e;
-	     j |= 0x01;
-	     outb(j,tmport);
-	  }
-	  if (((last_cmd[h] != 0xff) || (quhdu[h] != quendu[h])) &&
-	      (in_snd[h] == 0))
-	  {
-	     send_s870(h);
-	  }
-	  in_int[h]=0;
-	  return;
-       }
-   if ( i == 0x4f )
-   {
-      i=0x89;
-   }
-   i &= 0x0f;
-   if ( i == 0x09 )
-   {
-      tmpcip=tmpcip+4;
-      outl(prdaddru[h][tarid],tmpcip);
-      tmpcip=tmpcip-2;
-      outb(0x06,tmpcip);
-      outb(0x00,tmpcip);
-      tmpcip=tmpcip-2;
-      tmport=workportu+0x10;
-      outb(0x41,tmport);
-      dirctu[h][tarid]=0x00;
-      tmport += 0x08;
-      outb(0x08,tmport);
-      outb(0x09,tmpcip);
-      in_int[h]=0;
-      return;
-   }
-   if ( i == 0x08 )
-   {
-      tmpcip=tmpcip+4;
-      outl(prdaddru[h][tarid],tmpcip);
-      tmpcip=tmpcip-2;
-      outb(0x06,tmpcip);
-      outb(0x00,tmpcip);
-      tmpcip=tmpcip-2;
-      tmport=workportu+0x10;
-      outb(0x41,tmport);
-      tmport += 0x05;
-      outb((unsigned char)(inb(tmport) | 0x20),tmport);
-      dirctu[h][tarid]=0x20;
-      tmport += 0x03;
-      outb(0x08,tmport);
-      outb(0x01,tmpcip);
-      in_int[h]=0;
-      return;
-   }
-   tmport -= 0x07;
-   if ( i == 0x0a )
-   {
-      outb(0x30,tmport);
-   }
-   else
-   {
-      outb(0x46,tmport);
-   }
-   dirctu[h][tarid]=0x00;
-   tmport += 0x02;
-   outb(0x00,tmport++);
-   outb(0x00,tmport++);
-   outb(0x00,tmport++);
-   tmport+=0x03;
-   outb(0x08,tmport);
-   in_int[h]=0;
-   return;
-  }
-  else
-  {
-     tmport=workportu+0x17;
-     inb(tmport);
-     workingu[h]=0;
-     in_int[h]=0;
-     return;
-  }
+	} else {
+		tmport = workportu + 0x17;
+		inb(tmport);
+		workingu[h] = 0;
+		in_int[h] = 0;
+		return;
+	}
 }
 
-int atp870u_queuecommand(Scsi_Cmnd * req_p, void (*done)(Scsi_Cmnd *))
+int atp870u_queuecommand(Scsi_Cmnd * req_p, void (*done) (Scsi_Cmnd *))
 {
-    unsigned char i,h;
-    unsigned long flags;
-    unsigned short int m;
-    unsigned int tmport;
-
-    for( h=0; h <= admaxu; h++ )
-    {
-       if ( req_p->host == atp_host[h] )
-       {
-	  goto host_ok;
-       }
-    }
-    return 0;
+	unsigned char i, h;
+	unsigned long flags;
+	unsigned short int m;
+	unsigned int tmport;
+
+	for (h = 0; h <= admaxu; h++) {
+		if (req_p->host == atp_host[h]) {
+			goto host_ok;
+		}
+	}
+	return 0;
 host_ok:
-   if ( req_p->channel != 0 )
-   {
-      req_p->result = 0x00040000;
-      done(req_p);
-      return 0;
-   }
-   m=1;
-   m=  m << req_p->target;
-   if ( ( m & active_idu[h] ) == 0 )
-   {
-      req_p->result = 0x00040000;
-      done(req_p);
-      return 0;
-   }
-   if (done)
-   {
-      req_p->scsi_done = done;
-   }
-   else
-   {
-      printk("atp870u_queuecommand: done can't be NULL\n");
-      req_p->result = 0;
-      done(req_p);
-      return 0;
-   }
-   quendu[h]++;
-   if ( quendu[h] >= qcnt )
-   {
-      quendu[h]=0;
-   }
-   wait_que_empty:
-     if ( quhdu[h] == quendu[h] )
-     {
-	goto wait_que_empty;
-     }
-     save_flags(flags);
-     cli();
-     querequ[h][quendu[h]]=req_p;
-     if ( quendu[h] == 0 )
-     {
-	i=qcnt-1;
-     }
-     else
-     {
-	i=quendu[h]-1;
-     }
-     tmport = ioportu[h]+0x1c;
-     restore_flags(flags);
-     if ((inb(tmport) == 0) && (in_int[h] == 0) && (in_snd[h] == 0))
-     {
-	 send_s870(h);
-     }
-     return 0;
+	if (req_p->channel != 0) {
+		req_p->result = 0x00040000;
+		done(req_p);
+		return 0;
+	}
+	m = 1;
+	m = m << req_p->target;
+	if ((m & active_idu[h]) == 0) {
+		req_p->result = 0x00040000;
+		done(req_p);
+		return 0;
+	}
+	if (done) {
+		req_p->scsi_done = done;
+	} else {
+		printk("atp870u_queuecommand: done can't be NULL\n");
+		req_p->result = 0;
+		done(req_p);
+		return 0;
+	}
+	quendu[h]++;
+	if (quendu[h] >= qcnt) {
+		quendu[h] = 0;
+	}
+wait_que_empty:
+	if (quhdu[h] == quendu[h]) {
+		goto wait_que_empty;
+	}
+	save_flags(flags);
+	cli();
+	querequ[h][quendu[h]] = req_p;
+	if (quendu[h] == 0) {
+		i = qcnt - 1;
+	} else {
+		i = quendu[h] - 1;
+	}
+	tmport = ioportu[h] + 0x1c;
+	restore_flags(flags);
+	if ((inb(tmport) == 0) && (in_int[h] == 0) && (in_snd[h] == 0)) {
+		send_s870(h);
+	}
+	return 0;
 }
 
-void mydlyu(unsigned int dlycnt )
+void mydlyu(unsigned int dlycnt)
 {
-    unsigned int i ;
-    for ( i = 0 ; i < dlycnt ; i++ )
-    {
-       inb(0x80);
-    }
+	unsigned int i;
+	for (i = 0; i < dlycnt; i++) {
+		inb(0x80);
+	}
 }
 
 void send_s870(unsigned char h)
 {
-     unsigned int  tmport;
-     Scsi_Cmnd *workrequ;
-     unsigned long flags;
-     unsigned int   i;
-     unsigned char  j,tarid;
-     unsigned char  *prd;
-     unsigned short int   tmpcip,w;
-     unsigned long  l,bttl;
-     unsigned int workportu;
-     struct scatterlist * sgpnt;
+	unsigned int tmport;
+	Scsi_Cmnd *workrequ;
+	unsigned long flags;
+	unsigned int i;
+	unsigned char j, tarid;
+	unsigned char *prd;
+	unsigned short int tmpcip, w;
+	unsigned long l, bttl;
+	unsigned int workportu;
+	struct scatterlist *sgpnt;
 
 	save_flags(flags);
 	cli();
-	if ( in_snd[h] != 0 )
-	{
-	   restore_flags(flags);
-	   return;
+	if (in_snd[h] != 0) {
+		restore_flags(flags);
+		return;
 	}
-	in_snd[h]=1;
-	if ((last_cmd[h] != 0xff) && ((last_cmd[h] & 0x40) != 0))
-	{
-	   last_cmd[h] &= 0x0f;
-	   workrequ=curr_req[h][last_cmd[h]];
-	   goto cmd_subp;
+	in_snd[h] = 1;
+	if ((last_cmd[h] != 0xff) && ((last_cmd[h] & 0x40) != 0)) {
+		last_cmd[h] &= 0x0f;
+		workrequ = curr_req[h][last_cmd[h]];
+		goto cmd_subp;
 	}
 	workingu[h]++;
-	j=quhdu[h];
+	j = quhdu[h];
 	quhdu[h]++;
-	if ( quhdu[h] >= qcnt )
-	{
-	   quhdu[h]=0;
+	if (quhdu[h] >= qcnt) {
+		quhdu[h] = 0;
 	}
-	workrequ=querequ[h][quhdu[h]];
-	if ( curr_req[h][workrequ->target] == 0 )
-	{
-	   curr_req[h][workrequ->target]=workrequ;
-	   last_cmd[h]=workrequ->target;
-	   goto cmd_subp;
+	workrequ = querequ[h][quhdu[h]];
+	if (curr_req[h][workrequ->target] == 0) {
+		curr_req[h][workrequ->target] = workrequ;
+		last_cmd[h] = workrequ->target;
+		goto cmd_subp;
 	}
-	quhdu[h]=j;
+	quhdu[h] = j;
 	workingu[h]--;
-	in_snd[h]=0;
+	in_snd[h] = 0;
 	restore_flags(flags);
-	return ;
+	return;
 cmd_subp:
-   workportu=ioportu[h];
-   tmport=workportu+0x1f;
-   if ((inb(tmport) & 0xb0) != 0)
-   {
-      goto abortsnd;
-   }
-   tmport=workportu+0x1c;
-   if ( inb(tmport) == 0 )
-   {
-      goto oktosend;
-   }
+	workportu = ioportu[h];
+	tmport = workportu + 0x1f;
+	if ((inb(tmport) & 0xb0) != 0) {
+		goto abortsnd;
+	}
+	tmport = workportu + 0x1c;
+	if (inb(tmport) == 0) {
+		goto oktosend;
+	}
 abortsnd:
-   last_cmd[h] |= 0x40;
-   in_snd[h]=0;
-   restore_flags(flags);
-   return;
-oktosend:
-   memcpy(&ata_cdbu[h][0], &workrequ->cmnd[0], workrequ->cmd_len);
-   if ( ata_cdbu[h][0] == 0x25 )
-   {
-      if ( workrequ->request_bufflen > 8 )
-      {
-	 workrequ->request_bufflen=0x08;
-      }
-   }
-   if ( ata_cdbu[h][0] == 0x12 )
-   {
-      if ( workrequ->request_bufflen > 0x24 )
-      {
-	 workrequ->request_bufflen = 0x24;
-	 ata_cdbu[h][4]=0x24;
-      }
-   }
-
-   tmport=workportu+0x1b;
-   j=inb(tmport) & 0x0e;
-   tarid=workrequ->target;
-   w=1;
-   w = w << tarid;
-   if ((w & wide_idu[h]) != 0)
-   {
-      j |= 0x01;
-   }
-   outb(j,tmport);
-   tmport=workportu;
-   outb(workrequ->cmd_len,tmport++);
-   outb(0x2c,tmport++);
-   outb(0xcf,tmport++);
-   for ( i=0 ; i < workrequ->cmd_len ; i++ )
-   {
-       outb(ata_cdbu[h][i],tmport++);
-   }
-   tmport=workportu+0x0f;
-   outb(0x00,tmport);
-   tmport+=0x02;
-   outb(devspu[h][tarid],tmport++);
-   if (workrequ->use_sg)
-   {
-
-     l=0;
-     sgpnt = (struct scatterlist *) workrequ->request_buffer;
-     for(i=0; i<workrequ->use_sg; i++)
-     {
-       if(sgpnt[i].length == 0 || workrequ->use_sg > ATP870U_SCATTER)
-       {
-	 panic("Foooooooood fight!");
-       }
-       l += sgpnt[i].length;
-     }
-   }
-   else
-   {
-     l=workrequ->request_bufflen;
-   }
-   outb((unsigned char)(((unsigned char *)(&l))[2]),tmport++);
-   outb((unsigned char)(((unsigned char *)(&l))[1]),tmport++);
-   outb((unsigned char)(((unsigned char *)(&l))[0]),tmport++);
-   j=tarid;
-   last_lenu[h][j]=l;
-   tran_lenu[h][j]=0;
-   if ((j & 0x08) != 0)
-   {
-      j=(j & 0x07) | 0x40;
-   }
-   if ((ata_cdbu[h][0] == 0x0a) || (ata_cdbu[h][0] == 0x2a) ||
-       (ata_cdbu[h][0] == 0xaa) || (ata_cdbu[h][0] == 0x15))
-   {
-      outb((unsigned char)(j | 0x20),tmport++);
-   }
-   else
-   {
-      outb(j,tmport++);
-   }
-   outb(0x80,tmport);
-   tmport=workportu + 0x1c;
-   dirctu[h][tarid]=0;
-   if ( l == 0 )
-   {
-      if ( inb(tmport) == 0 )
-      {
-	 tmport=workportu+0x18;
-	 outb(0x08,tmport);
-      }
-      else
-      {
 	last_cmd[h] |= 0x40;
-      }
-      in_snd[h]=0;
-      restore_flags(flags);
-      return;
-   }
-   tmpcip=pciportu[h];
-   prd=&prd_tableu[h][tarid][0];
-   prd_posu[h][tarid]=prd;
-   if (workrequ->use_sg)
-   {
-     sgpnt = (struct scatterlist *) workrequ->request_buffer;
-     i=0;
-     for(j=0; j<workrequ->use_sg; j++)
-     {
-	(unsigned long)(((unsigned long *)(prd))[i >> 1])=(unsigned long)sgpnt[j].address;
-	(unsigned short int)(((unsigned short int *)(prd))[i+2])=sgpnt[j].length;
-	(unsigned short int)(((unsigned short int *)(prd))[i+3])=0;
-	i +=0x04;
-     }
-     (unsigned short int)(((unsigned short int *)(prd))[i-1])=0x8000;
-   }
-   else
-   {
-     bttl=(unsigned long)workrequ->request_buffer;
-     l=workrequ->request_bufflen;
-     i=0;
-     while ( l > 0x10000 )
-     {
-	(unsigned short int)(((unsigned short int *)(prd))[i+3])=0x0000;
-	(unsigned short int)(((unsigned short int *)(prd))[i+2])=0x0000;
-	(unsigned long)(((unsigned long *)(prd))[i >> 1])=bttl;
-	l -= 0x10000;
-	bttl += 0x10000;
-	i += 0x04;
-     }
-     (unsigned short int)(((unsigned short int *)(prd))[i+3])=0x8000;
-     (unsigned short int)(((unsigned short int *)(prd))[i+2])=l;
-     (unsigned long)(((unsigned long *)(prd))[i >> 1])=bttl;
-   }
-   tmpcip=tmpcip+4;
-   prdaddru[h][tarid]=(unsigned long)&prd_tableu[h][tarid][0];
-   outl(prdaddru[h][tarid],tmpcip);
-   tmpcip=tmpcip-2;
-   outb(0x06,tmpcip);
-   outb(0x00,tmpcip);
-   tmpcip=tmpcip-2;
-   if ((ata_cdbu[h][0] == 0x0a) || (ata_cdbu[h][0] == 0x2a) ||
-       (ata_cdbu[h][0] == 0xaa) || (ata_cdbu[h][0] == 0x15))
-   {
-      dirctu[h][tarid]=0x20;
-      if ( inb(tmport) == 0 )
-      {
-	 tmport=workportu+0x18;
-	 outb(0x08,tmport);
-	 outb(0x01,tmpcip);
-      }
-      else
-      {
-	 last_cmd[h] |= 0x40;
-      }
-      in_snd[h]=0;
-      restore_flags(flags);
-      return;
-   }
-   if ( inb(tmport) == 0 )
-   {
-      tmport=workportu+0x18;
-      outb(0x08,tmport);
-      outb(0x09,tmpcip);
-   }
-   else
-   {
-      last_cmd[h] |= 0x40;
-   }
-   in_snd[h]=0;
-   restore_flags(flags);
-   return;
+	in_snd[h] = 0;
+	restore_flags(flags);
+	return;
+oktosend:
+	memcpy(&ata_cdbu[h][0], &workrequ->cmnd[0], workrequ->cmd_len);
+	if (ata_cdbu[h][0] == 0x25) {
+		if (workrequ->request_bufflen > 8) {
+			workrequ->request_bufflen = 0x08;
+		}
+	}
+	if (ata_cdbu[h][0] == 0x12) {
+		if (workrequ->request_bufflen > 0x24) {
+			workrequ->request_bufflen = 0x24;
+			ata_cdbu[h][4] = 0x24;
+		}
+	}
+	tmport = workportu + 0x1b;
+	j = inb(tmport) & 0x0e;
+	tarid = workrequ->target;
+	w = 1;
+	w = w << tarid;
+	if ((w & wide_idu[h]) != 0) {
+		j |= 0x01;
+	}
+	outb(j, tmport);
+	tmport = workportu;
+	outb(workrequ->cmd_len, tmport++);
+	outb(0x2c, tmport++);
+	outb(0xcf, tmport++);
+	for (i = 0; i < workrequ->cmd_len; i++) {
+		outb(ata_cdbu[h][i], tmport++);
+	}
+	tmport = workportu + 0x0f;
+	outb(0x00, tmport);
+	tmport += 0x02;
+	outb(devspu[h][tarid], tmport++);
+	if (workrequ->use_sg) 
+	{
+		l = 0;
+		sgpnt = (struct scatterlist *) workrequ->request_buffer;
+		for (i = 0; i < workrequ->use_sg; i++) 
+		{
+			if (sgpnt[i].length == 0 || workrequ->use_sg > ATP870U_SCATTER) 
+			{
+				panic("Foooooooood fight!");
+			}
+			l += sgpnt[i].length;
+		}
+	} else {
+		l = workrequ->request_bufflen;
+	}
+	outb((unsigned char) (((unsigned char *) (&l))[2]), tmport++);
+	outb((unsigned char) (((unsigned char *) (&l))[1]), tmport++);
+	outb((unsigned char) (((unsigned char *) (&l))[0]), tmport++);
+	j = tarid;
+	last_lenu[h][j] = l;
+	tran_lenu[h][j] = 0;
+	if ((j & 0x08) != 0) {
+		j = (j & 0x07) | 0x40;
+	}
+	if ((ata_cdbu[h][0] == 0x0a) || (ata_cdbu[h][0] == 0x2a) ||
+	    (ata_cdbu[h][0] == 0xaa) || (ata_cdbu[h][0] == 0x15)) {
+		outb((unsigned char) (j | 0x20), tmport++);
+	} else {
+		outb(j, tmport++);
+	}
+	outb(0x80, tmport);
+	tmport = workportu + 0x1c;
+	dirctu[h][tarid] = 0;
+	if (l == 0) {
+		if (inb(tmport) == 0) {
+			tmport = workportu + 0x18;
+			outb(0x08, tmport);
+		} else {
+			last_cmd[h] |= 0x40;
+		}
+		in_snd[h] = 0;
+		restore_flags(flags);
+		return;
+	}
+	tmpcip = pciportu[h];
+	prd = &prd_tableu[h][tarid][0];
+	prd_posu[h][tarid] = prd;
+	if (workrequ->use_sg) 
+	{
+		sgpnt = (struct scatterlist *) workrequ->request_buffer;
+		i = 0;
+		for (j = 0; j < workrequ->use_sg; j++) {
+			(unsigned long) (((unsigned long *) (prd))[i >> 1]) = virt_to_bus(sgpnt[j].address);
+			(unsigned short int) (((unsigned short int *) (prd))[i + 2]) = sgpnt[j].length;
+			(unsigned short int) (((unsigned short int *) (prd))[i + 3]) = 0;
+			i += 0x04;
+		}
+		(unsigned short int) (((unsigned short int *) (prd))[i - 1]) = 0x8000;
+	} else {
+		bttl = virt_to_bus(workrequ->request_buffer);
+		l = workrequ->request_bufflen;
+		i = 0;
+		while (l > 0x10000) {
+			(unsigned short int) (((unsigned short int *) (prd))[i + 3]) = 0x0000;
+			(unsigned short int) (((unsigned short int *) (prd))[i + 2]) = 0x0000;
+			(unsigned long) (((unsigned long *) (prd))[i >> 1]) = bttl;
+			l -= 0x10000;
+			bttl += 0x10000;
+			i += 0x04;
+		}
+		(unsigned short int) (((unsigned short int *) (prd))[i + 3]) = 0x8000;
+		(unsigned short int) (((unsigned short int *) (prd))[i + 2]) = l;
+		(unsigned long) (((unsigned long *) (prd))[i >> 1]) = bttl;
+	}
+	tmpcip = tmpcip + 4;
+	prdaddru[h][tarid] = virt_to_bus(&prd_tableu[h][tarid][0]);
+	outl(prdaddru[h][tarid], tmpcip);
+	tmpcip = tmpcip - 2;
+	outb(0x06, tmpcip);
+	outb(0x00, tmpcip);
+	tmpcip = tmpcip - 2;
+	if ((ata_cdbu[h][0] == 0x0a) || (ata_cdbu[h][0] == 0x2a) ||
+	    (ata_cdbu[h][0] == 0xaa) || (ata_cdbu[h][0] == 0x15)) 
+	{
+		dirctu[h][tarid] = 0x20;
+		if (inb(tmport) == 0) {
+			tmport = workportu + 0x18;
+			outb(0x08, tmport);
+			outb(0x01, tmpcip);
+		} else {
+			last_cmd[h] |= 0x40;
+		}
+		in_snd[h] = 0;
+		restore_flags(flags);
+		return;
+	}
+	if (inb(tmport) == 0) 
+	{
+		tmport = workportu + 0x18;
+		outb(0x08, tmport);
+		outb(0x09, tmpcip);
+	} else {
+		last_cmd[h] |= 0x40;
+	}
+	in_snd[h] = 0;
+	restore_flags(flags);
+	return;
 
 }
 
@@ -780,1101 +655,964 @@
 int atp870u_command(Scsi_Cmnd * SCpnt)
 {
 
-    atp870u_queuecommand(SCpnt, internal_done);
+	atp870u_queuecommand(SCpnt, internal_done);
 
-    SCpnt->SCp.Status = 0;
-    while (!SCpnt->SCp.Status)
-	barrier();
-    return SCpnt->result;
+	SCpnt->SCp.Status = 0;
+	while (!SCpnt->SCp.Status)
+		barrier();
+	return SCpnt->result;
 }
 
-unsigned char fun_scam ( unsigned char host,unsigned short int * val )
+unsigned char fun_scam(unsigned char host, unsigned short int *val)
 {
-    unsigned int  tmport ;
-    unsigned short int	 i,k;
-    unsigned char     j;
+	unsigned int tmport;
+	unsigned short int i, k;
+	unsigned char j;
 
-    tmport = ioportu[host]+0x1c;
-    outw(*val,tmport);
+	tmport = ioportu[host] + 0x1c;
+	outw(*val, tmport);
 FUN_D7:
-    for ( i=0; i < 10; i++ )	     /* stable >= bus settle delay(400 ns)  */
-    {
-	k=inw(tmport);
-	j= (unsigned char)(k >> 8);
-	if ((k & 0x8000) != 0)	     /* DB7 all release?    */
-	{
-	   goto  FUN_D7;
+	for (i = 0; i < 10; i++) {	/* stable >= bus settle delay(400 ns)  */
+		k = inw(tmport);
+		j = (unsigned char) (k >> 8);
+		if ((k & 0x8000) != 0) {	/* DB7 all release?    */
+			goto FUN_D7;
+		}
 	}
-    }
-    *val |= 0x4000;		    /* assert DB6	    */
-    outw(*val,tmport);
-    *val &= 0xdfff;		    /* assert DB5	    */
-    outw(*val,tmport);
+	*val |= 0x4000;		/* assert DB6           */
+	outw(*val, tmport);
+	*val &= 0xdfff;		/* assert DB5           */
+	outw(*val, tmport);
 FUN_D5:
-    for ( i=0; i < 10; i++ )	    /* stable >= bus settle delay(400 ns) */
-    {
-       if ((inw(tmport) & 0x2000) != 0)   /* DB5 all release?	*/
-       {
-	  goto	FUN_D5;
-       }
-    }
-    *val |= 0x8000;		     /* no DB4-0, assert DB7	*/
-    *val &= 0xe0ff;
-    outw(*val,tmport);
-    *val &= 0xbfff;		     /* release DB6		*/
-    outw(*val,tmport);
-FUN_D6:
-    for ( i=0; i < 10; i++ )	     /* stable >= bus settle delay(400 ns)  */
-    {
-       if ((inw(tmport) & 0x4000) != 0)   /* DB6 all release?  */
-       {
-	  goto	FUN_D6;
-       }
-    }
+	for (i = 0; i < 10; i++) {	/* stable >= bus settle delay(400 ns) */
+		if ((inw(tmport) & 0x2000) != 0) {	/* DB5 all release?       */
+			goto FUN_D5;
+		}
+	}
+	*val |= 0x8000;		/* no DB4-0, assert DB7    */
+	*val &= 0xe0ff;
+	outw(*val, tmport);
+	*val &= 0xbfff;		/* release DB6             */
+	outw(*val, tmport);
+      FUN_D6:
+	for (i = 0; i < 10; i++) {	/* stable >= bus settle delay(400 ns)  */
+		if ((inw(tmport) & 0x4000) != 0) {	/* DB6 all release?  */
+			goto FUN_D6;
+		}
+	}
 
-    return j;
+	return j;
 }
 
-void tscam( unsigned char host )
+void tscam(unsigned char host)
 {
 
-    unsigned int  tmport ;
-    unsigned char  i,j,k;
-    unsigned long  n;
-    unsigned short int	m,assignid_map,val;
-    unsigned char  mbuf[33],quintet[2];
-    static unsigned char g2q_tab[8]={ 0x38,0x31,0x32,0x2b,0x34,0x2d,0x2e,0x27 };
+	unsigned int tmport;
+	unsigned char i, j, k;
+	unsigned long n;
+	unsigned short int m, assignid_map, val;
+	unsigned char mbuf[33], quintet[2];
+	static unsigned char g2q_tab[8] =
+	{0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27};
 
 
-    for ( i=0; i < 0x10; i++ )
-    {
-	mydlyu(0xffff);
-    }
+	for (i = 0; i < 0x10; i++) {
+		mydlyu(0xffff);
+	}
 
-    tmport = ioportu[host]+1;
-    outb(0x08,tmport++);
-    outb(0x7f,tmport);
-    tmport = ioportu[host]+0x11;
-    outb(0x20,tmport);
-
-    if ((scam_on[host] & 0x40) == 0)
-    {
-       return;
-    }
-
-    m=1;
-    m <<= host_idu[host];
-    j=16;
-    if ( chip_veru[host] < 4 )
-    {
-       m |= 0xff00;
-       j=8;
-    }
-    assignid_map=m;
-    tmport = ioportu[host]+0x02;
-    outb(0x02,tmport++);	/* 2*2=4ms,3EH 2/32*3E=3.9ms */
-    outb(0,tmport++);
-    outb(0,tmport++);
-    outb(0,tmport++);
-    outb(0,tmport++);
-    outb(0,tmport++);
-    outb(0,tmport++);
-
-    for ( i = 0 ; i < j ; i ++ )
-    {
-	m=1;
-	m=m<<i;
-	if ( ( m & assignid_map ) != 0 )
-	{
-	   continue;
+	tmport = ioportu[host] + 1;
+	outb(0x08, tmport++);
+	outb(0x7f, tmport);
+	tmport = ioportu[host] + 0x11;
+	outb(0x20, tmport);
+
+	if ((scam_on[host] & 0x40) == 0) {
+		return;
+	}
+	m = 1;
+	m <<= host_idu[host];
+	j = 16;
+	if (chip_veru[host] < 4) {
+		m |= 0xff00;
+		j = 8;
 	}
-    tmport = ioportu[host]+0x0f;
-    outb(0,tmport++);
-    tmport += 0x02;
-    outb(0,tmport++);
-    outb(0,tmport++);
-    outb(0,tmport++);
-    if ( i > 7 )
-    {
-       k=(i & 0x07) | 0x40;
-    }
-    else
-    {
-       k=i;
-    }
-    outb(k,tmport++);
-    tmport = ioportu[host]+0x1b;
-    if ( chip_veru[host] == 4 )
-    {
-       outb((unsigned char)((inb(tmport) & 0x0e) | 0x01),tmport);
-    }
-    else
-    {
-       outb((unsigned char)(inb(tmport) & 0x0e),tmport);
-    }
+	assignid_map = m;
+	tmport = ioportu[host] + 0x02;
+	outb(0x02, tmport++);	/* 2*2=4ms,3EH 2/32*3E=3.9ms */
+	outb(0, tmport++);
+	outb(0, tmport++);
+	outb(0, tmport++);
+	outb(0, tmport++);
+	outb(0, tmport++);
+	outb(0, tmport++);
+
+	for (i = 0; i < j; i++) {
+		m = 1;
+		m = m << i;
+		if ((m & assignid_map) != 0) {
+			continue;
+		}
+		tmport = ioportu[host] + 0x0f;
+		outb(0, tmport++);
+		tmport += 0x02;
+		outb(0, tmport++);
+		outb(0, tmport++);
+		outb(0, tmport++);
+		if (i > 7) {
+			k = (i & 0x07) | 0x40;
+		} else {
+			k = i;
+		}
+		outb(k, tmport++);
+		tmport = ioportu[host] + 0x1b;
+		if (chip_veru[host] == 4) {
+			outb((unsigned char) ((inb(tmport) & 0x0e) | 0x01), tmport);
+		} else {
+			outb((unsigned char) (inb(tmport) & 0x0e), tmport);
+		}
 wait_rdyok:
-    tmport = ioportu[host]+0x18;
-    outb(0x09,tmport);
-    tmport += 0x07;
-
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport -= 0x08;
-    k=inb(tmport);
-    if ( k != 0x16 )
-    {
-       if ((k == 0x85) || (k == 0x42))
-       {
-	  continue;
-       }
-       tmport = ioportu[host]+0x10;
-       outb(0x41,tmport);
-       goto wait_rdyok;
-    }
-    assignid_map |= m;
-
-    }
-    tmport = ioportu[host]+0x02;
-    outb(0x7f,tmport);
-    tmport = ioportu[host]+0x1b;
-    outb(0x02,tmport);
-
-    outb(0,0x80);
-
-    val=0x0080;      /* bsy  */
-    tmport = ioportu[host]+0x1c;
-    outw(val,tmport);
-    val |=0x0040;    /* sel  */
-    outw(val,tmport);
-    val |=0x0004;    /* msg  */
-    outw(val,tmport);
-    inb(0x80);		      /* 2 deskew delay(45ns*2=90ns) */
-    val &=0x007f;    /* no bsy	*/
-    outw(val,tmport);
-    mydlyu(0xffff);  /* recommanded SCAM selection response time */
-    mydlyu(0xffff);
-    val &=0x00fb;    /* after 1ms no msg */
-    outw(val,tmport);
+		tmport = ioportu[host] + 0x18;
+		outb(0x09, tmport);
+		tmport += 0x07;
+
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		k = inb(tmport);
+		if (k != 0x16) {
+			if ((k == 0x85) || (k == 0x42)) {
+				continue;
+			}
+			tmport = ioportu[host] + 0x10;
+			outb(0x41, tmport);
+			goto wait_rdyok;
+		}
+		assignid_map |= m;
+
+	}
+	tmport = ioportu[host] + 0x02;
+	outb(0x7f, tmport);
+	tmport = ioportu[host] + 0x1b;
+	outb(0x02, tmport);
+
+	outb(0, 0x80);
+
+	val = 0x0080;		/* bsy  */
+	tmport = ioportu[host] + 0x1c;
+	outw(val, tmport);
+	val |= 0x0040;		/* sel  */
+	outw(val, tmport);
+	val |= 0x0004;		/* msg  */
+	outw(val, tmport);
+	inb(0x80);		/* 2 deskew delay(45ns*2=90ns) */
+	val &= 0x007f;		/* no bsy  */
+	outw(val, tmport);
+	mydlyu(0xffff);		/* recommanded SCAM selection response time */
+	mydlyu(0xffff);
+	val &= 0x00fb;		/* after 1ms no msg */
+	outw(val, tmport);
 wait_nomsg:
-    if ((inb(tmport) & 0x04) != 0)
-    {
-       goto wait_nomsg;
-    }
-    outb(1,0x80);
-    mydlyu(100);
-    for ( n=0; n < 0x30000; n++ )
-    {
-	if ((inb(tmport) & 0x80) != 0)	   /* bsy ? */
-	{
-	   goto wait_io;
+	if ((inb(tmport) & 0x04) != 0) {
+		goto wait_nomsg;
+	}
+	outb(1, 0x80);
+	mydlyu(100);
+	for (n = 0; n < 0x30000; n++) {
+		if ((inb(tmport) & 0x80) != 0) {	/* bsy ? */
+			goto wait_io;
+		}
 	}
-    }
-    goto  TCM_SYNC;
+	goto TCM_SYNC;
 wait_io:
-    for ( n=0; n < 0x30000; n++ )
-    {
-	if ((inb(tmport) & 0x81) == 0x0081)
-	{
-	   goto wait_io1;
+	for (n = 0; n < 0x30000; n++) {
+		if ((inb(tmport) & 0x81) == 0x0081) {
+			goto wait_io1;
+		}
 	}
-    }
-    goto  TCM_SYNC;
+	goto TCM_SYNC;
 wait_io1:
-    inb(0x80);
-    val |=0x8003;    /* io,cd,db7  */
-    outw(val,tmport);
-    inb(0x80);
-    val &=0x00bf;    /* no sel	   */
-    outw(val,tmport);
-    outb(2,0x80);
+	inb(0x80);
+	val |= 0x8003;		/* io,cd,db7  */
+	outw(val, tmport);
+	inb(0x80);
+	val &= 0x00bf;		/* no sel     */
+	outw(val, tmport);
+	outb(2, 0x80);
 TCM_SYNC:
-    mydlyu(0x800);
-    if ((inb(tmport) & 0x80) == 0x00)	 /* bsy ? */
-    {
-       outw(0,tmport--);
-       outb(0,tmport);
-       tmport=ioportu[host] + 0x15;
-       outb(0,tmport);
-       tmport += 0x03;
-       outb(0x09,tmport);
-       tmport += 0x07;
-       while ((inb(tmport) & 0x80) == 0);
-       tmport -= 0x08;
-       inb(tmport);
-       return;
-    }
-
-    val &= 0x00ff;		 /* synchronization  */
-    val |= 0x3f00;
-    fun_scam(host,&val);
-    outb(3,0x80);
-    val &= 0x00ff;		 /* isolation	     */
-    val |= 0x2000;
-    fun_scam(host,&val);
-    outb(4,0x80);
-    i=8;
-    j=0;
+	mydlyu(0x800);
+	if ((inb(tmport) & 0x80) == 0x00) {	/* bsy ? */
+		outw(0, tmport--);
+		outb(0, tmport);
+		tmport = ioportu[host] + 0x15;
+		outb(0, tmport);
+		tmport += 0x03;
+		outb(0x09, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0);
+		tmport -= 0x08;
+		inb(tmport);
+		return;
+	}
+	val &= 0x00ff;		/* synchronization  */
+	val |= 0x3f00;
+	fun_scam(host, &val);
+	outb(3, 0x80);
+	val &= 0x00ff;		/* isolation        */
+	val |= 0x2000;
+	fun_scam(host, &val);
+	outb(4, 0x80);
+	i = 8;
+	j = 0;
 TCM_ID:
-    if ((inw(tmport) & 0x2000) == 0)
-    {
-       goto TCM_ID;
-    }
-    outb(5,0x80);
-    val &= 0x00ff;		 /* get ID_STRING */
-    val |= 0x2000;
-    k=fun_scam(host,&val);
-    if ((k & 0x03) == 0)
-    {
-       goto TCM_5;
-    }
-    mbuf[j] <<= 0x01;
-    mbuf[j] &= 0xfe;
-    if ((k & 0x02) != 0)
-    {
-       mbuf[j] |= 0x01;
-    }
-    i--;
-    if ( i > 0 )
-    {
-       goto TCM_ID;
-    }
-    j++;
-    i=8;
-    goto TCM_ID;
+	if ((inw(tmport) & 0x2000) == 0) {
+		goto TCM_ID;
+	}
+	outb(5, 0x80);
+	val &= 0x00ff;		/* get ID_STRING */
+	val |= 0x2000;
+	k = fun_scam(host, &val);
+	if ((k & 0x03) == 0) {
+		goto TCM_5;
+	}
+	mbuf[j] <<= 0x01;
+	mbuf[j] &= 0xfe;
+	if ((k & 0x02) != 0) {
+		mbuf[j] |= 0x01;
+	}
+	i--;
+	if (i > 0) {
+		goto TCM_ID;
+	}
+	j++;
+	i = 8;
+	goto TCM_ID;
 
-TCM_5:			     /* isolation complete..  */
+TCM_5:			/* isolation complete..  */
 /*    mbuf[32]=0;
-    printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
-    i=15;
-    j=mbuf[0];
-    if ((j & 0x20) != 0)     /* bit5=1:ID upto 7      */
-    {
-       i=7;
-    }
-    if ((j & 0x06) == 0)     /* IDvalid?	      */
-    {
-       goto  G2Q5;
-    }
-    k=mbuf[1];
+	printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
+	i = 15;
+	j = mbuf[0];
+	if ((j & 0x20) != 0) {	/* bit5=1:ID upto 7      */
+		i = 7;
+	}
+	if ((j & 0x06) == 0) {	/* IDvalid?             */
+		goto G2Q5;
+	}
+	k = mbuf[1];
 small_id:
-    m=1;
-    m <<= k;
-    if ((m & assignid_map) == 0)
-    {
-       goto G2Q_QUIN;
-    }
-    if ( k > 0 )
-    {
-       k--;
-       goto small_id;
-    }
-G2Q5:			      /* srch from max acceptable ID#  */
-    k=i;		      /* max acceptable ID#	       */
+	m = 1;
+	m <<= k;
+	if ((m & assignid_map) == 0) {
+		goto G2Q_QUIN;
+	}
+	if (k > 0) {
+		k--;
+		goto small_id;
+	}
+G2Q5:				/* srch from max acceptable ID#  */
+	k = i;			/* max acceptable ID#            */
 G2Q_LP:
-    m=1;
-    m <<= k;
-    if ((m & assignid_map) == 0)
-    {
-       goto G2Q_QUIN;
-    }
-    if ( k > 0 )
-    {
-       k--;
-       goto G2Q_LP;
-    }
-G2Q_QUIN:		      /* k=binID#,	 */
-    assignid_map |= m;
-    if ( k < 8 )
-    {
-       quintet[0]=0x38;       /* 1st dft ID<8	 */
-    }
-    else
-    {
-       quintet[0]=0x31;       /* 1st  ID>=8	 */
-    }
-    k &= 0x07;
-    quintet[1]=g2q_tab[k];
-
-    val &= 0x00ff;	       /* AssignID 1stQuintet,AH=001xxxxx  */
-    m=quintet[0] << 8;
-    val |= m;
-    fun_scam(host,&val);
-    val &= 0x00ff;	       /* AssignID 2ndQuintet,AH=001xxxxx */
-    m=quintet[1] << 8;
-    val |= m;
-    fun_scam(host,&val);
+	m = 1;
+	m <<= k;
+	if ((m & assignid_map) == 0) {
+		goto G2Q_QUIN;
+	}
+	if (k > 0) {
+		k--;
+		goto G2Q_LP;
+	}
+G2Q_QUIN:		/* k=binID#,       */
+	assignid_map |= m;
+	if (k < 8) {
+		quintet[0] = 0x38;	/* 1st dft ID<8    */
+	} else {
+		quintet[0] = 0x31;	/* 1st  ID>=8      */
+	}
+	k &= 0x07;
+	quintet[1] = g2q_tab[k];
 
-    goto TCM_SYNC;
+	val &= 0x00ff;		/* AssignID 1stQuintet,AH=001xxxxx  */
+	m = quintet[0] << 8;
+	val |= m;
+	fun_scam(host, &val);
+	val &= 0x00ff;		/* AssignID 2ndQuintet,AH=001xxxxx */
+	m = quintet[1] << 8;
+	val |= m;
+	fun_scam(host, &val);
+
+	goto TCM_SYNC;
 
 }
 
-void is870(unsigned long host,unsigned int wkport )
+void is870(unsigned long host, unsigned int wkport)
 {
-    unsigned int  tmport ;
-    unsigned char i,j,k,rmb;
-    unsigned short int m;
-    static unsigned char mbuf[512];
-    static unsigned char satn[9] = { 0,0,0,0,0,0,0,6,6 };
-    static unsigned char inqd[9] = { 0x12,0,0,0,0x24,0,0,0x24,6 };
-    static unsigned char synn[6] = { 0x80,1,3,1,0x19,0x0e };
-    static unsigned char synu[6] = { 0x80,1,3,1,0x0c,0x0e };
-    static unsigned char synw[6] = { 0x80,1,3,1,0x0c,0x07 };
-    static unsigned char wide[6] = { 0x80,1,2,3,1,0 };
-
-    sync_idu=0;
-    tmport=wkport+0x3a;
-    outb((unsigned char)(inb(tmport) | 0x10),tmport);
-
-    for ( i = 0 ; i < 16 ; i ++ )
-    {
-	if ((chip_veru[host] != 4) && (i > 7))
-	{
-	   break;
-	}
-	m=1;
-	m=m<<i;
-	if ( ( m & active_idu[host] ) != 0 )
-	{
-	   continue;
-	}
-	if ( i == host_idu[host] )
-	{
-	   printk("         ID: %2d  Host Adapter\n",host_idu[host]);
-	   continue;
-	}
-	if ( chip_veru[host] == 4 )
-	{
-	   tmport=wkport+0x1b;
-	   j=(inb(tmport) & 0x0e) | 0x01;
-	   outb(j,tmport);
-	}
-    tmport=wkport+1;
-    outb(0x08,tmport++);
-    outb(0x7f,tmport++);
-    outb(satn[0],tmport++);
-    outb(satn[1],tmport++);
-    outb(satn[2],tmport++);
-    outb(satn[3],tmport++);
-    outb(satn[4],tmport++);
-    outb(satn[5],tmport++);
-    tmport+=0x06;
-    outb(0,tmport);
-    tmport+=0x02;
-    outb(devspu[host][i],tmport++);
-    outb(0,tmport++);
-    outb(satn[6],tmport++);
-    outb(satn[7],tmport++);
-    j=i;
-    if ((j & 0x08) != 0)
-    {
-       j=(j & 0x07) | 0x40;
-    }
-    outb(j,tmport);
-    tmport+=0x03;
-    outb(satn[8],tmport);
-    tmport+=0x07;
-
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport-=0x08;
-    if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e))
-    {
-       continue;
-    }
-    while ( inb(tmport) != 0x8e );
-    active_idu[host] |= m;
-
-    tmport=wkport+0x10;
-    outb(0x30,tmport);
-    tmport=wkport+0x04;
-    outb(0x00,tmport);
+	unsigned int tmport;
+	unsigned char i, j, k, rmb;
+	unsigned short int m;
+	static unsigned char mbuf[512];
+	static unsigned char satn[9] = 	{0, 0, 0, 0, 0, 0, 0, 6, 6};
+	static unsigned char inqd[9] =	{0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
+	static unsigned char synn[6] =  {0x80, 1, 3, 1, 0x19, 0x0e};
+	static unsigned char synu[6] =	{0x80, 1, 3, 1, 0x0c, 0x0e};
+	static unsigned char synw[6] =	{0x80, 1, 3, 1, 0x0c, 0x07};
+	static unsigned char wide[6] =  {0x80, 1, 2, 3, 1, 0};
+
+	sync_idu = 0;
+	tmport = wkport + 0x3a;
+	outb((unsigned char) (inb(tmport) | 0x10), tmport);
+
+	for (i = 0; i < 16; i++) {
+		if ((chip_veru[host] != 4) && (i > 7)) {
+			break;
+		}
+		m = 1;
+		m = m << i;
+		if ((m & active_idu[host]) != 0) {
+			continue;
+		}
+		if (i == host_idu[host]) {
+			printk("         ID: %2d  Host Adapter\n", host_idu[host]);
+			continue;
+		}
+		if (chip_veru[host] == 4) {
+			tmport = wkport + 0x1b;
+			j = (inb(tmport) & 0x0e) | 0x01;
+			outb(j, tmport);
+		}
+		tmport = wkport + 1;
+		outb(0x08, tmport++);
+		outb(0x7f, tmport++);
+		outb(satn[0], tmport++);
+		outb(satn[1], tmport++);
+		outb(satn[2], tmport++);
+		outb(satn[3], tmport++);
+		outb(satn[4], tmport++);
+		outb(satn[5], tmport++);
+		tmport += 0x06;
+		outb(0, tmport);
+		tmport += 0x02;
+		outb(devspu[host][i], tmport++);
+		outb(0, tmport++);
+		outb(satn[6], tmport++);
+		outb(satn[7], tmport++);
+		j = i;
+		if ((j & 0x08) != 0) {
+			j = (j & 0x07) | 0x40;
+		}
+		outb(j, tmport);
+		tmport += 0x03;
+		outb(satn[8], tmport);
+		tmport += 0x07;
+
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
+			continue;
+		}
+		while (inb(tmport) != 0x8e);
+		active_idu[host] |= m;
+
+		tmport = wkport + 0x10;
+		outb(0x30, tmport);
+		tmport = wkport + 0x04;
+		outb(0x00, tmport);
 
 phase_cmd:
-    tmport=wkport+0x18;
-    outb(0x08,tmport);
-    tmport+=0x07;
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport-=0x08;
-    j=inb(tmport);
-    if ( j != 0x16 )
-    {
-       tmport=wkport+0x10;
-       outb(0x41,tmport);
-       goto phase_cmd;
-    }
+		tmport = wkport + 0x18;
+		outb(0x08, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		j = inb(tmport);
+		if (j != 0x16) {
+			tmport = wkport + 0x10;
+			outb(0x41, tmport);
+			goto phase_cmd;
+		}
 sel_ok:
-       tmport=wkport+3;
-       outb(inqd[0],tmport++);
-       outb(inqd[1],tmport++);
-       outb(inqd[2],tmport++);
-       outb(inqd[3],tmport++);
-       outb(inqd[4],tmport++);
-       outb(inqd[5],tmport);
-       tmport+=0x07;
-       outb(0,tmport);
-       tmport+=0x02;
-       outb(devspu[host][i],tmport++);
-       outb(0,tmport++);
-       outb(inqd[6],tmport++);
-       outb(inqd[7],tmport++);
-       tmport+=0x03;
-       outb(inqd[8],tmport);
-       tmport+=0x07;
-       while ((inb(tmport) & 0x80) == 0x00);
-       tmport-=0x08;
-       if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e))
-       {
-	  continue;
-       }
-       while ( inb(tmport) != 0x8e );
-       if ( chip_veru[host] == 4 )
-       {
-	  tmport=wkport+0x1b;
-	  j=inb(tmport) & 0x0e;
-	  outb(j,tmport);
-       }
-       tmport=wkport+0x18;
-       outb(0x08,tmport);
-       tmport += 0x07;
-       j=0;
+		tmport = wkport + 3;
+		outb(inqd[0], tmport++);
+		outb(inqd[1], tmport++);
+		outb(inqd[2], tmport++);
+		outb(inqd[3], tmport++);
+		outb(inqd[4], tmport++);
+		outb(inqd[5], tmport);
+		tmport += 0x07;
+		outb(0, tmport);
+		tmport += 0x02;
+		outb(devspu[host][i], tmport++);
+		outb(0, tmport++);
+		outb(inqd[6], tmport++);
+		outb(inqd[7], tmport++);
+		tmport += 0x03;
+		outb(inqd[8], tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
+			continue;
+		}
+		while (inb(tmport) != 0x8e);
+		if (chip_veru[host] == 4) {
+			tmport = wkport + 0x1b;
+			j = inb(tmport) & 0x0e;
+			outb(j, tmport);
+		}
+		tmport = wkport + 0x18;
+		outb(0x08, tmport);
+		tmport += 0x07;
+		j = 0;
 rd_inq_data:
-       k=inb(tmport);
-       if ((k & 0x01) != 0 )
-       {
-	  tmport-=0x06;
-	  mbuf[j++]=inb(tmport);
-	  tmport+=0x06;
-	  goto rd_inq_data;
-       }
-       if ((k & 0x80) == 0 )
-       {
-	  goto rd_inq_data;
-       }
-       tmport-=0x08;
-       j=inb(tmport);
-       if ( j == 0x16 )
-       {
-	  goto inq_ok;
-       }
-    tmport=wkport+0x10;
-    outb(0x46,tmport);
-    tmport+=0x02;
-    outb(0,tmport++);
-    outb(0,tmport++);
-    outb(0,tmport++);
-    tmport+=0x03;
-    outb(0x08,tmport);
-    tmport+=0x07;
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport-=0x08;
-    if (inb(tmport) != 0x16)
-    {
-       goto sel_ok;
-    }
+		k = inb(tmport);
+		if ((k & 0x01) != 0) {
+			tmport -= 0x06;
+			mbuf[j++] = inb(tmport);
+			tmport += 0x06;
+			goto rd_inq_data;
+		}
+		if ((k & 0x80) == 0) {
+			goto rd_inq_data;
+		}
+		tmport -= 0x08;
+		j = inb(tmport);
+		if (j == 0x16) {
+			goto inq_ok;
+		}
+		tmport = wkport + 0x10;
+		outb(0x46, tmport);
+		tmport += 0x02;
+		outb(0, tmport++);
+		outb(0, tmport++);
+		outb(0, tmport++);
+		tmport += 0x03;
+		outb(0x08, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		if (inb(tmport) != 0x16) {
+			goto sel_ok;
+		}
 inq_ok:
-     mbuf[36]=0;
-     printk("         ID: %2d  %s\n",i,&mbuf[8]);
-     devtypeu[host][i]=mbuf[0];
-     rmb=mbuf[1];
-     if ( chip_veru[host] != 4 )
-     {
-	goto not_wide;
-     }
-     if ((mbuf[7] & 0x60) == 0)
-     {
-	goto not_wide;
-     }
-     if ((global_map[host] & 0x20) == 0)
-     {
-	goto not_wide;
-     }
-     tmport=wkport+0x1b;
-     j=(inb(tmport) & 0x0e) | 0x01;
-     outb(j,tmport);
-    tmport=wkport+3;
-    outb(satn[0],tmport++);
-    outb(satn[1],tmport++);
-    outb(satn[2],tmport++);
-    outb(satn[3],tmport++);
-    outb(satn[4],tmport++);
-    outb(satn[5],tmport++);
-    tmport+=0x06;
-    outb(0,tmport);
-    tmport+=0x02;
-    outb(devspu[host][i],tmport++);
-    outb(0,tmport++);
-    outb(satn[6],tmport++);
-    outb(satn[7],tmport++);
-    tmport+=0x03;
-    outb(satn[8],tmport);
-    tmport+=0x07;
-
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport-=0x08;
-    if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e))
-    {
-       continue;
-    }
-    while ( inb(tmport) != 0x8e );
+		mbuf[36] = 0;
+		printk("         ID: %2d  %s\n", i, &mbuf[8]);
+		devtypeu[host][i] = mbuf[0];
+		rmb = mbuf[1];
+		if (chip_veru[host] != 4) {
+			goto not_wide;
+		}
+		if ((mbuf[7] & 0x60) == 0) {
+			goto not_wide;
+		}
+		if ((global_map[host] & 0x20) == 0) {
+			goto not_wide;
+		}
+		tmport = wkport + 0x1b;
+		j = (inb(tmport) & 0x0e) | 0x01;
+		outb(j, tmport);
+		tmport = wkport + 3;
+		outb(satn[0], tmport++);
+		outb(satn[1], tmport++);
+		outb(satn[2], tmport++);
+		outb(satn[3], tmport++);
+		outb(satn[4], tmport++);
+		outb(satn[5], tmport++);
+		tmport += 0x06;
+		outb(0, tmport);
+		tmport += 0x02;
+		outb(devspu[host][i], tmport++);
+		outb(0, tmport++);
+		outb(satn[6], tmport++);
+		outb(satn[7], tmport++);
+		tmport += 0x03;
+		outb(satn[8], tmport);
+		tmport += 0x07;
+
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
+			continue;
+		}
+		while (inb(tmport) != 0x8e);
 try_wide:
-    j=0;
-    tmport=wkport+0x14;
-    outb(0x05,tmport);
-    tmport += 0x04;
-    outb(0x20,tmport);
-    tmport+=0x07;
-
-    while ((inb(tmport) & 0x80) == 0 )
-    {
-       if ((inb(tmport) & 0x01) != 0 )
-       {
-	  tmport-=0x06;
-	  outb(wide[j++],tmport);
-	  tmport+=0x06;
-       }
-    }
-    tmport-=0x08;
-    while ((inb(tmport) & 0x80) == 0x00);
-    j=inb(tmport) & 0x0f;
-    if ( j == 0x0f )
-    {
-       goto widep_in;
-    }
-    if ( j == 0x0a )
-    {
-       goto widep_cmd;
-    }
-    if ( j == 0x0e )
-    {
-       goto try_wide;
-    }
-    continue;
+		j = 0;
+		tmport = wkport + 0x14;
+		outb(0x05, tmport);
+		tmport += 0x04;
+		outb(0x20, tmport);
+		tmport += 0x07;
+
+		while ((inb(tmport) & 0x80) == 0) {
+			if ((inb(tmport) & 0x01) != 0) {
+				tmport -= 0x06;
+				outb(wide[j++], tmport);
+				tmport += 0x06;
+			}
+		}
+		tmport -= 0x08;
+		while ((inb(tmport) & 0x80) == 0x00);
+		j = inb(tmport) & 0x0f;
+		if (j == 0x0f) {
+			goto widep_in;
+		}
+		if (j == 0x0a) {
+			goto widep_cmd;
+		}
+		if (j == 0x0e) {
+			goto try_wide;
+		}
+		continue;
 widep_out:
-    tmport=wkport+0x18;
-    outb(0x20,tmport);
-    tmport+=0x07;
-    while ((inb(tmport) & 0x80) == 0 )
-    {
-	if ((inb(tmport) & 0x01) != 0 )
-	{
-	   tmport-=0x06;
-	   outb(0,tmport);
-	   tmport+=0x06;
-	}
-    }
-    tmport-=0x08;
-    j=inb(tmport) & 0x0f;
-    if ( j == 0x0f )
-    {
-       goto widep_in;
-    }
-    if ( j == 0x0a )
-    {
-       goto widep_cmd;
-    }
-    if ( j == 0x0e )
-    {
-       goto widep_out;
-    }
-    continue;
+		tmport = wkport + 0x18;
+		outb(0x20, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0) {
+			if ((inb(tmport) & 0x01) != 0) {
+				tmport -= 0x06;
+				outb(0, tmport);
+				tmport += 0x06;
+			}
+		}
+		tmport -= 0x08;
+		j = inb(tmport) & 0x0f;
+		if (j == 0x0f) {
+			goto widep_in;
+		}
+		if (j == 0x0a) {
+			goto widep_cmd;
+		}
+		if (j == 0x0e) {
+			goto widep_out;
+		}
+		continue;
 widep_in:
-    tmport=wkport+0x14;
-    outb(0xff,tmport);
-    tmport += 0x04;
-    outb(0x20,tmport);
-    tmport+=0x07;
-    k=0;
+		tmport = wkport + 0x14;
+		outb(0xff, tmport);
+		tmport += 0x04;
+		outb(0x20, tmport);
+		tmport += 0x07;
+		k = 0;
 widep_in1:
-    j=inb(tmport);
-    if ((j & 0x01) != 0)
-    {
-       tmport-=0x06;
-       mbuf[k++]=inb(tmport);
-       tmport+=0x06;
-       goto widep_in1;
-    }
-    if ((j & 0x80) == 0x00)
-    {
-       goto widep_in1;
-    }
-    tmport-=0x08;
-    j=inb(tmport) & 0x0f;
-    if ( j == 0x0f )
-    {
-       goto widep_in;
-    }
-    if ( j == 0x0a )
-    {
-       goto widep_cmd;
-    }
-    if ( j == 0x0e )
-    {
-       goto widep_out;
-    }
-    continue;
+		j = inb(tmport);
+		if ((j & 0x01) != 0) {
+			tmport -= 0x06;
+			mbuf[k++] = inb(tmport);
+			tmport += 0x06;
+			goto widep_in1;
+		}
+		if ((j & 0x80) == 0x00) {
+			goto widep_in1;
+		}
+		tmport -= 0x08;
+		j = inb(tmport) & 0x0f;
+		if (j == 0x0f) {
+			goto widep_in;
+		}
+		if (j == 0x0a) {
+			goto widep_cmd;
+		}
+		if (j == 0x0e) {
+			goto widep_out;
+		}
+		continue;
 widep_cmd:
-    tmport=wkport+0x10;
-    outb(0x30,tmport);
-    tmport=wkport+0x14;
-    outb(0x00,tmport);
-    tmport+=0x04;
-    outb(0x08,tmport);
-    tmport+=0x07;
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport-=0x08;
-    j=inb(tmport);
-    if ( j != 0x16 )
-    {
-       if ( j == 0x4e )
-       {
-	  goto widep_out;
-       }
-       continue;
-    }
-    if ( mbuf[0] != 0x01 )
-    {
-       goto not_wide;
-    }
-    if ( mbuf[1] != 0x02 )
-    {
-       goto not_wide;
-    }
-    if ( mbuf[2] != 0x03 )
-    {
-       goto not_wide;
-    }
-    if ( mbuf[3] != 0x01 )
-    {
-       goto not_wide;
-    }
-    m=1;
-    m = m << i;
-    wide_idu[host] |= m;
+		tmport = wkport + 0x10;
+		outb(0x30, tmport);
+		tmport = wkport + 0x14;
+		outb(0x00, tmport);
+		tmport += 0x04;
+		outb(0x08, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		j = inb(tmport);
+		if (j != 0x16) {
+			if (j == 0x4e) {
+				goto widep_out;
+			}
+			continue;
+		}
+		if (mbuf[0] != 0x01) {
+			goto not_wide;
+		}
+		if (mbuf[1] != 0x02) {
+			goto not_wide;
+		}
+		if (mbuf[2] != 0x03) {
+			goto not_wide;
+		}
+		if (mbuf[3] != 0x01) {
+			goto not_wide;
+		}
+		m = 1;
+		m = m << i;
+		wide_idu[host] |= m;
 not_wide:
-    if ((devtypeu[host][i] == 0x00) || (devtypeu[host][i] == 0x07))
-    {
-       goto set_sync;
-    }
-    continue;
+		if ((devtypeu[host][i] == 0x00) || (devtypeu[host][i] == 0x07)) {
+			goto set_sync;
+		}
+		continue;
 set_sync:
-    tmport=wkport+0x1b;
-    j=inb(tmport) & 0x0e;
-    if ((m & wide_idu[host]) != 0 )
-    {
-       j |= 0x01;
-    }
-    outb(j,tmport);
-    tmport=wkport+3;
-    outb(satn[0],tmport++);
-    outb(satn[1],tmport++);
-    outb(satn[2],tmport++);
-    outb(satn[3],tmport++);
-    outb(satn[4],tmport++);
-    outb(satn[5],tmport++);
-    tmport+=0x06;
-    outb(0,tmport);
-    tmport+=0x02;
-    outb(devspu[host][i],tmport++);
-    outb(0,tmport++);
-    outb(satn[6],tmport++);
-    outb(satn[7],tmport++);
-    tmport+=0x03;
-    outb(satn[8],tmport);
-    tmport+=0x07;
-
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport-=0x08;
-    if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e))
-    {
-       continue;
-    }
-    while ( inb(tmport) != 0x8e);
+		tmport = wkport + 0x1b;
+		j = inb(tmport) & 0x0e;
+		if ((m & wide_idu[host]) != 0) {
+			j |= 0x01;
+		}
+		outb(j, tmport);
+		tmport = wkport + 3;
+		outb(satn[0], tmport++);
+		outb(satn[1], tmport++);
+		outb(satn[2], tmport++);
+		outb(satn[3], tmport++);
+		outb(satn[4], tmport++);
+		outb(satn[5], tmport++);
+		tmport += 0x06;
+		outb(0, tmport);
+		tmport += 0x02;
+		outb(devspu[host][i], tmport++);
+		outb(0, tmport++);
+		outb(satn[6], tmport++);
+		outb(satn[7], tmport++);
+		tmport += 0x03;
+		outb(satn[8], tmport);
+		tmport += 0x07;
+
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
+			continue;
+		}
+		while (inb(tmport) != 0x8e);
 try_sync:
-    j=0;
-    tmport=wkport+0x14;
-    outb(0x06,tmport);
-    tmport += 0x04;
-    outb(0x20,tmport);
-    tmport+=0x07;
-
-    while ((inb(tmport) & 0x80) == 0 )
-    {
-       if ((inb(tmport) & 0x01) != 0 )
-       {
-	  tmport-=0x06;
-	  if ( rmb != 0 )
-	  {
-	     outb(synn[j++],tmport);
-	  }
-	  else
-	  {
-	     if ((m & wide_idu[host]) != 0)
-	     {
-		outb(synw[j++],tmport);
-	     }
-	     else
-	     {
-		if ((m & ultra_map[host]) != 0)
-		{
-		   outb(synu[j++],tmport);
+		j = 0;
+		tmport = wkport + 0x14;
+		outb(0x06, tmport);
+		tmport += 0x04;
+		outb(0x20, tmport);
+		tmport += 0x07;
+
+		while ((inb(tmport) & 0x80) == 0) {
+			if ((inb(tmport) & 0x01) != 0) {
+				tmport -= 0x06;
+				if (rmb != 0) {
+					outb(synn[j++], tmport);
+				} else {
+					if ((m & wide_idu[host]) != 0) {
+						outb(synw[j++], tmport);
+					} else {
+						if ((m & ultra_map[host]) != 0) {
+							outb(synu[j++], tmport);
+						} else {
+							outb(synn[j++], tmport);
+						}
+					}
+				}
+				tmport += 0x06;
+			}
 		}
-		else
-		{
-		   outb(synn[j++],tmport);
+		tmport -= 0x08;
+		while ((inb(tmport) & 0x80) == 0x00);
+		j = inb(tmport) & 0x0f;
+		if (j == 0x0f) {
+			goto phase_ins;
 		}
-	     }
-	  }
-	  tmport+=0x06;
-       }
-    }
-    tmport-=0x08;
-    while ((inb(tmport) & 0x80) == 0x00);
-    j=inb(tmport) & 0x0f;
-    if ( j == 0x0f )
-    {
-       goto phase_ins;
-    }
-    if ( j == 0x0a )
-    {
-       goto phase_cmds;
-    }
-    if ( j == 0x0e )
-    {
-       goto try_sync;
-    }
-    continue;
+		if (j == 0x0a) {
+			goto phase_cmds;
+		}
+		if (j == 0x0e) {
+			goto try_sync;
+		}
+		continue;
 phase_outs:
-    tmport=wkport+0x18;
-    outb(0x20,tmport);
-    tmport+=0x07;
-    while ((inb(tmport) & 0x80) == 0x00)
-    {
-      if ((inb(tmport) & 0x01) != 0x00)
-      {
-	 tmport-=0x06;
-	 outb(0x00,tmport);
-	 tmport+=0x06;
-      }
-    }
-    tmport-=0x08;
-    j=inb(tmport);
-    if ( j == 0x85 )
-    {
-       goto tar_dcons;
-    }
-    j &= 0x0f;
-    if ( j == 0x0f )
-    {
-       goto phase_ins;
-    }
-    if ( j == 0x0a )
-    {
-       goto phase_cmds;
-    }
-    if ( j == 0x0e )
-    {
-       goto phase_outs;
-    }
-    continue;
+		tmport = wkport + 0x18;
+		outb(0x20, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0x00) {
+			if ((inb(tmport) & 0x01) != 0x00) {
+				tmport -= 0x06;
+				outb(0x00, tmport);
+				tmport += 0x06;
+			}
+		}
+		tmport -= 0x08;
+		j = inb(tmport);
+		if (j == 0x85) {
+			goto tar_dcons;
+		}
+		j &= 0x0f;
+		if (j == 0x0f) {
+			goto phase_ins;
+		}
+		if (j == 0x0a) {
+			goto phase_cmds;
+		}
+		if (j == 0x0e) {
+			goto phase_outs;
+		}
+		continue;
 phase_ins:
-    tmport=wkport+0x14;
-    outb(0xff,tmport);
-    tmport += 0x04;
-    outb(0x20,tmport);
-    tmport+=0x07;
-    k=0;
+		tmport = wkport + 0x14;
+		outb(0xff, tmport);
+		tmport += 0x04;
+		outb(0x20, tmport);
+		tmport += 0x07;
+		k = 0;
 phase_ins1:
-    j=inb(tmport);
-    if ((j & 0x01) != 0x00)
-    {
-       tmport-=0x06;
-       mbuf[k++]=inb(tmport);
-       tmport+=0x06;
-       goto phase_ins1;
-    }
-    if ((j & 0x80) == 0x00)
-    {
-       goto phase_ins1;
-    }
-    tmport-=0x08;
-    while ((inb(tmport) & 0x80) == 0x00);
-    j=inb(tmport);
-    if ( j == 0x85 )
-    {
-       goto tar_dcons;
-    }
-    j &= 0x0f;
-    if ( j == 0x0f )
-    {
-       goto phase_ins;
-    }
-    if ( j == 0x0a )
-    {
-       goto phase_cmds;
-    }
-    if ( j == 0x0e )
-    {
-       goto phase_outs;
-    }
-    continue;
+		j = inb(tmport);
+		if ((j & 0x01) != 0x00) {
+			tmport -= 0x06;
+			mbuf[k++] = inb(tmport);
+			tmport += 0x06;
+			goto phase_ins1;
+		}
+		if ((j & 0x80) == 0x00) {
+			goto phase_ins1;
+		}
+		tmport -= 0x08;
+		while ((inb(tmport) & 0x80) == 0x00);
+		j = inb(tmport);
+		if (j == 0x85) {
+			goto tar_dcons;
+		}
+		j &= 0x0f;
+		if (j == 0x0f) {
+			goto phase_ins;
+		}
+		if (j == 0x0a) {
+			goto phase_cmds;
+		}
+		if (j == 0x0e) {
+			goto phase_outs;
+		}
+		continue;
 phase_cmds:
-    tmport=wkport+0x10;
-    outb(0x30,tmport);
+		tmport = wkport + 0x10;
+		outb(0x30, tmport);
 tar_dcons:
-    tmport=wkport+0x14;
-    outb(0x00,tmport);
-    tmport+=0x04;
-    outb(0x08,tmport);
-    tmport+=0x07;
-    while ((inb(tmport) & 0x80) == 0x00);
-    tmport-=0x08;
-    j=inb(tmport);
-    if ( j != 0x16 )
-    {
-       continue;
-    }
-    if ( mbuf[0] != 0x01 )
-    {
-       continue;
-    }
-    if ( mbuf[1] != 0x03 )
-    {
-       continue;
-    }
-    if ( mbuf[4] == 0x00 )
-    {
-       continue;
-    }
-    if ( mbuf[3] > 0x64 )
-    {
-       continue;
-    }
-    if ( mbuf[4] > 0x0c )
-    {
-       mbuf[4]=0x0c;
-    }
-    devspu[host][i] = mbuf[4];
-    if ((mbuf[3] < 0x0d) && (rmb == 0))
-    {
-       j=0xa0;
-       goto set_syn_ok;
-    }
-    if ( mbuf[3] < 0x1a )
-    {
-       j=0x20;
-       goto set_syn_ok;
-    }
-    if ( mbuf[3] < 0x33 )
-    {
-       j=0x40;
-       goto set_syn_ok;
-    }
-    if ( mbuf[3] < 0x4c )
-    {
-       j=0x50;
-       goto set_syn_ok;
-    }
-    j=0x60;
-set_syn_ok:
-    devspu[host][i] = (devspu[host][i] & 0x0f) | j;
-   }
-   tmport=wkport+0x3a;
-   outb((unsigned char)(inb(tmport) & 0xef),tmport);
+		tmport = wkport + 0x14;
+		outb(0x00, tmport);
+		tmport += 0x04;
+		outb(0x08, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0x00);
+		tmport -= 0x08;
+		j = inb(tmport);
+		if (j != 0x16) {
+			continue;
+		}
+		if (mbuf[0] != 0x01) {
+			continue;
+		}
+		if (mbuf[1] != 0x03) {
+			continue;
+		}
+		if (mbuf[4] == 0x00) {
+			continue;
+		}
+		if (mbuf[3] > 0x64) {
+			continue;
+		}
+		if (mbuf[4] > 0x0c) {
+			mbuf[4] = 0x0c;
+		}
+		devspu[host][i] = mbuf[4];
+		if ((mbuf[3] < 0x0d) && (rmb == 0)) {
+			j = 0xa0;
+			goto set_syn_ok;
+		}
+		if (mbuf[3] < 0x1a) {
+			j = 0x20;
+			goto set_syn_ok;
+		}
+		if (mbuf[3] < 0x33) {
+			j = 0x40;
+			goto set_syn_ok;
+		}
+		if (mbuf[3] < 0x4c) {
+			j = 0x50;
+			goto set_syn_ok;
+		}
+		j = 0x60;
+	      set_syn_ok:
+		devspu[host][i] = (devspu[host][i] & 0x0f) | j;
+	}
+	tmport = wkport + 0x3a;
+	outb((unsigned char) (inb(tmport) & 0xef), tmport);
 }
 
 /* return non-zero on detection */
 int atp870u_detect(Scsi_Host_Template * tpnt)
 {
-    unsigned char irq,h,k;
-    unsigned long flags;
-    unsigned int base_io,error,tmport;
-    unsigned short index = 0;
-    unsigned char pci_bus[3], pci_device_fn[3], chip_ver[3],host_id;
-    struct Scsi_Host * shpnt = NULL;
-    int count = 0;
-    static unsigned short devid[7]={0x8002,0x8010,0x8020,0x8030,0x8040,0x8050,0};
-    static struct pci_dev *pdev = NULL, *acard_pdev[3];
-
-    printk("aec671x_detect: \n");
-    if (!pci_present())
-    {
-       printk("   NO BIOS32 SUPPORT.\n");
-       return count;
-    }
-
-    tpnt->proc_dir = &proc_scsi_atp870u;
-
-    for ( h = 0 ; h < 2 ; h++ )
-    {
-      active_idu[h]=0;
-      wide_idu[h]=0;
-      host_idu[h]=0x07;
-      quhdu[h]=0;
-      quendu[h]=0;
-      pci_bus[h]=0;
-      pci_device_fn[h]=0xff;
-      chip_ver[h]=0;
-      last_cmd[h]=0xff;
-      in_snd[h]=0;
-      in_int[h]=0;
-      for ( k = 0 ; k < qcnt ; k++ )
-      {
-	  querequ[h][k]=0;
-      }
-      for ( k = 0 ; k < 16 ; k++ )
-      {
-	  curr_req[h][k]=0;
-      }
-    }
-    h=0;
-    while ( devid[h] != 0 )
-    {
-      pdev = pci_find_device(0x1191,devid[h],pdev);
-      if (pdev == NULL) {
-	  h++;
-	  index=0;
-	  continue;
-       }
-       chip_ver[2]=0;
-	   
-       /* To avoid messing with the things below...  */
-       acard_pdev[2] = pdev;
-       pci_device_fn[2] =  pdev->devfn;
-       pci_bus[2] = pdev->bus->number;
-
-       if ( devid[h] == 0x8002 )
-       {
-	  error = pci_read_config_byte(pdev,0x08,&chip_ver[2]);
-	  if ( chip_ver[2] < 2 )
-	  {
-	     goto nxt_devfn;
-	  }
-       }
-       if ( devid[h] == 0x8010 )
-       {
-	  chip_ver[2]=0x04;
-       }
-       if ( pci_device_fn[2] < pci_device_fn[0] )
-       {
-	  acard_pdev[1]=acard_pdev[0];
-	  pci_bus[1]=pci_bus[0];
-	  pci_device_fn[1]=pci_device_fn[0];
-	  chip_ver[1]=chip_ver[0];
-	  acard_pdev[0]=acard_pdev[2];
-	  pci_bus[0]=pci_bus[2];
-	  pci_device_fn[0]=pci_device_fn[2];
-	  chip_ver[0]=chip_ver[2];
-       }
-       else if ( pci_device_fn[2] < pci_device_fn[1] )
-       {
-	  acard_pdev[1]=acard_pdev[2];
-	  pci_bus[1]=pci_bus[2];
-	  pci_device_fn[1]=pci_device_fn[2];
-	  chip_ver[1]=chip_ver[2];
-       }
-nxt_devfn:
-       index++;
-       if ( index > 3 )
-       {
-	  index=0;
-	  h++;
-       }
-    }
-    for ( h=0; h < 2; h++ )
-    {
-    if ( pci_device_fn[h] == 0xff )
-    {
-       return count;
-    }
-
-    pdev = acard_pdev[h];
-    pdev->devfn = pci_device_fn[h];
-    pdev->bus->number = pci_bus[h];
-
-    /* Found an atp870u/w. */
-    error = pci_read_config_dword(pdev,0x10,&base_io);
-    error += pci_read_config_byte(pdev,0x3c,&irq);
-    error += pci_read_config_byte(pdev,0x49,&host_id);
-
-    base_io &= 0xfffffff8;
-    printk("   ACARD AEC-671X PCI Ultra/W SCSI-3 Host Adapter: %d    IO:%x, IRQ:%d.\n"
-			     ,h,base_io,irq);
-    ioportu[h]=base_io;
-    pciportu[h]=base_io + 0x20;
-    irqnumu[h]=irq;
-    host_id &= 0x07;
-    host_idu[h]=host_id;
-    chip_veru[h]=chip_ver[h];
-
-    tmport=base_io+0x22;
-    scam_on[h]=inb(tmport);
-    tmport += 0x0b;
-    global_map[h]=inb(tmport++);
-    ultra_map[h]=inw(tmport);
-    if ( ultra_map[h] == 0 )
-    {
-       scam_on[h]=0x00;
-       global_map[h]=0x20;
-       ultra_map[h]=0xffff;
-    }
-
-    shpnt = scsi_register(tpnt,4);
-
-    save_flags(flags);
-    cli();
-    if (request_irq(irq,atp870u_intr_handle, 0, "atp870u", NULL))
-    {
-       printk("Unable to allocate IRQ for Acard controller.\n");
-       goto unregister;
-    }
-
-    tmport=base_io+0x3a;
-    k=(inb(tmport) & 0xf3) | 0x10;
-    outb(k,tmport);
-    outb((k & 0xdf),tmport);
-    mydlyu(0x8000);
-    outb(k,tmport);
-    mydlyu(0x8000);
-    tmport=base_io;
-    outb((host_id | 0x08),tmport);
-    tmport += 0x18;
-    outb(0,tmport);
-    tmport += 0x07;
-    while ((inb(tmport) & 0x80) == 0);
-    tmport -= 0x08;
-    inb(tmport);
-    tmport = base_io +1;
-    outb(8,tmport++);
-    outb(0x7f,tmport);
-    tmport = base_io + 0x11;
-    outb(0x20,tmport);
-
-    tscam(h);
-    is870(h,base_io);
-    tmport=base_io+0x3a;
-    outb((inb(tmport) & 0xef),tmport);
-
-    atp_host[h] = shpnt;
-    if ( chip_ver[h] == 4 )
-    {
-       shpnt->max_id = 16;
-    }
-    shpnt->this_id = host_id;
-    shpnt->unique_id = base_io;
-    shpnt->io_port = base_io;
-    shpnt->n_io_port = 0x40;  /* Number of bytes of I/O space used */
-    shpnt->irq = irq;
-    restore_flags(flags);
-    request_region(base_io, 0x40,"atp870u");  /* Register the IO ports that we use */
-    count++;
-    index++;
-    continue;
+	unsigned char irq, h, k;
+	unsigned long flags;
+	unsigned int base_io, error, tmport;
+	unsigned short index = 0;
+	unsigned char pci_bus[3], pci_device_fn[3], chip_ver[3], host_id;
+	struct Scsi_Host *shpnt = NULL;
+	int count = 0;
+	static unsigned short devid[7] =
+	{0x8002, 0x8010, 0x8020, 0x8030, 0x8040, 0x8050, 0};
+	static struct pci_dev *pdev = NULL, *acard_pdev[3];
+
+	printk("aec671x_detect: \n");
+	if (!pci_present()) {
+		printk("   NO BIOS32 SUPPORT.\n");
+		return count;
+	}
+	tpnt->proc_dir = &proc_scsi_atp870u;
+
+	for (h = 0; h < 2; h++) {
+		active_idu[h] = 0;
+		wide_idu[h] = 0;
+		host_idu[h] = 0x07;
+		quhdu[h] = 0;
+		quendu[h] = 0;
+		pci_bus[h] = 0;
+		pci_device_fn[h] = 0xff;
+		chip_ver[h] = 0;
+		last_cmd[h] = 0xff;
+		in_snd[h] = 0;
+		in_int[h] = 0;
+		for (k = 0; k < qcnt; k++) {
+			querequ[h][k] = 0;
+		}
+		for (k = 0; k < 16; k++) {
+			curr_req[h][k] = 0;
+		}
+	}
+	h = 0;
+	while (devid[h] != 0) {
+		pdev = pci_find_device(0x1191, devid[h], pdev);
+		if (pdev == NULL) {
+			h++;
+			index = 0;
+			continue;
+		}
+		chip_ver[2] = 0;
+
+		/* To avoid messing with the things below...  */
+		acard_pdev[2] = pdev;
+		pci_device_fn[2] = pdev->devfn;
+		pci_bus[2] = pdev->bus->number;
+
+		if (devid[h] == 0x8002) {
+			error = pci_read_config_byte(pdev, 0x08, &chip_ver[2]);
+			if (chip_ver[2] < 2) {
+				goto nxt_devfn;
+			}
+		}
+		if (devid[h] == 0x8010) {
+			chip_ver[2] = 0x04;
+		}
+		if (pci_device_fn[2] < pci_device_fn[0]) {
+			acard_pdev[1] = acard_pdev[0];
+			pci_bus[1] = pci_bus[0];
+			pci_device_fn[1] = pci_device_fn[0];
+			chip_ver[1] = chip_ver[0];
+			acard_pdev[0] = acard_pdev[2];
+			pci_bus[0] = pci_bus[2];
+			pci_device_fn[0] = pci_device_fn[2];
+			chip_ver[0] = chip_ver[2];
+		} else if (pci_device_fn[2] < pci_device_fn[1]) {
+			acard_pdev[1] = acard_pdev[2];
+			pci_bus[1] = pci_bus[2];
+			pci_device_fn[1] = pci_device_fn[2];
+			chip_ver[1] = chip_ver[2];
+		}
+	      nxt_devfn:
+		index++;
+		if (index > 3) {
+			index = 0;
+			h++;
+		}
+	}
+	for (h = 0; h < 2; h++) {
+		if (pci_device_fn[h] == 0xff) {
+			return count;
+		}
+		pdev = acard_pdev[h];
+		pdev->devfn = pci_device_fn[h];
+		pdev->bus->number = pci_bus[h];
+
+		/* Found an atp870u/w. */
+		error = pci_read_config_dword(pdev, 0x10, &base_io);
+		error += pci_read_config_byte(pdev, 0x3c, &irq);
+		error += pci_read_config_byte(pdev, 0x49, &host_id);
+
+		base_io &= 0xfffffff8;
+		printk("   ACARD AEC-671X PCI Ultra/W SCSI-3 Host Adapter: %d    IO:%x, IRQ:%d.\n"
+		       ,h, base_io, irq);
+		ioportu[h] = base_io;
+		pciportu[h] = base_io + 0x20;
+		irqnumu[h] = irq;
+		host_id &= 0x07;
+		host_idu[h] = host_id;
+		chip_veru[h] = chip_ver[h];
+
+		tmport = base_io + 0x22;
+		scam_on[h] = inb(tmport);
+		tmport += 0x0b;
+		global_map[h] = inb(tmport++);
+		ultra_map[h] = inw(tmport);
+		if (ultra_map[h] == 0) {
+			scam_on[h] = 0x00;
+			global_map[h] = 0x20;
+			ultra_map[h] = 0xffff;
+		}
+		shpnt = scsi_register(tpnt, 4);
+
+		save_flags(flags);
+		cli();
+		if (request_irq(irq, atp870u_intr_handle, 0, "atp870u", NULL)) {
+			printk("Unable to allocate IRQ for Acard controller.\n");
+			goto unregister;
+		}
+		tmport = base_io + 0x3a;
+		k = (inb(tmport) & 0xf3) | 0x10;
+		outb(k, tmport);
+		outb((k & 0xdf), tmport);
+		mydlyu(0x8000);
+		outb(k, tmport);
+		mydlyu(0x8000);
+		tmport = base_io;
+		outb((host_id | 0x08), tmport);
+		tmport += 0x18;
+		outb(0, tmport);
+		tmport += 0x07;
+		while ((inb(tmport) & 0x80) == 0);
+		tmport -= 0x08;
+		inb(tmport);
+		tmport = base_io + 1;
+		outb(8, tmport++);
+		outb(0x7f, tmport);
+		tmport = base_io + 0x11;
+		outb(0x20, tmport);
+
+		tscam(h);
+		is870(h, base_io);
+		tmport = base_io + 0x3a;
+		outb((inb(tmport) & 0xef), tmport);
+
+		atp_host[h] = shpnt;
+		if (chip_ver[h] == 4) {
+			shpnt->max_id = 16;
+		}
+		shpnt->this_id = host_id;
+		shpnt->unique_id = base_io;
+		shpnt->io_port = base_io;
+		shpnt->n_io_port = 0x40;	/* Number of bytes of I/O space used */
+		shpnt->irq = irq;
+		restore_flags(flags);
+		request_region(base_io, 0x40, "atp870u");	/* Register the IO ports that we use */
+		count++;
+		index++;
+		continue;
 unregister:
-    scsi_unregister(shpnt);
-    restore_flags(flags);
-    index++;
-    continue;
-    }
+		scsi_unregister(shpnt);
+		restore_flags(flags);
+		index++;
+		continue;
+	}
 
-    return count;
+	return count;
 }
 
 /* The abort command does not leave the device in a clean state where
@@ -1883,162 +1621,147 @@
 
 int atp870u_abort(Scsi_Cmnd * SCpnt)
 {
-    unsigned char h,j;
-    unsigned int  tmport;
+	unsigned char h, j;
+	unsigned int tmport;
 /*    printk(" atp870u_abort: \n");   */
-    for ( h=0; h <= admaxu; h++ )
-    {
-	if ( SCpnt->host == atp_host[h] )
-	{
-	   goto find_adp;
+	for (h = 0; h <= admaxu; h++) {
+		if (SCpnt->host == atp_host[h]) {
+			goto find_adp;
+		}
 	}
-    }
-    panic("Abort host not found !");
+	panic("Abort host not found !");
 find_adp:
-    printk(" workingu=%x last_cmd=%x ",workingu[h],last_cmd[h]);
-    printk(" quhdu=%x quendu=%x ",quhdu[h],quendu[h]);
-    tmport=ioportu[h];
-    for ( j=0; j < 0x17; j++)
-    {
-	printk(" r%2x=%2x",j,inb(tmport++));
-    }
-    tmport += 0x05;
-    printk(" r1c=%2x",inb(tmport));
-    tmport += 0x03;
-    printk(" r1f=%2x in_snd=%2x ",inb(tmport),in_snd[h]);
-    tmport++;
-    printk(" r20=%2x",inb(tmport));
-    tmport += 0x02;
-    printk(" r22=%2x \n",inb(tmport));
-    return (SCSI_ABORT_SNOOZE);
+	printk(" workingu=%x last_cmd=%x ", workingu[h], last_cmd[h]);
+	printk(" quhdu=%x quendu=%x ", quhdu[h], quendu[h]);
+	tmport = ioportu[h];
+	for (j = 0; j < 0x17; j++) {
+		printk(" r%2x=%2x", j, inb(tmport++));
+	}
+	tmport += 0x05;
+	printk(" r1c=%2x", inb(tmport));
+	tmport += 0x03;
+	printk(" r1f=%2x in_snd=%2x ", inb(tmport), in_snd[h]);
+	tmport++;
+	printk(" r20=%2x", inb(tmport));
+	tmport += 0x02;
+	printk(" r22=%2x \n", inb(tmport));
+	return (SCSI_ABORT_SNOOZE);
 }
 
 int atp870u_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
 {
-    unsigned char h;
-    /*
-     * See if a bus reset was suggested.
-     */
-/*    printk("atp870u_reset: \n");    */
-    for( h=0; h <= admaxu; h++ )
-    {
-       if ( SCpnt->host == atp_host[h] )
-       {
-	  goto find_host;
-       }
-    }
-    panic("Reset bus host not found !");
+	unsigned char h;
+	/*
+	 * See if a bus reset was suggested.
+	 */
+/*	printk("atp870u_reset: \n");    */
+	for (h = 0; h <= admaxu; h++) {
+		if (SCpnt->host == atp_host[h]) {
+			goto find_host;
+		}
+	}
+	panic("Reset bus host not found !");
 find_host:
-/*    SCpnt->result = 0x00080000;
-    SCpnt->scsi_done(SCpnt);
-    workingu[h]=0;
-    quhdu[h]=0;
-    quendu[h]=0;
-    return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET);  */
-    return (SCSI_RESET_SNOOZE);
+/*      SCpnt->result = 0x00080000;
+	SCpnt->scsi_done(SCpnt);
+	workingu[h]=0;
+	quhdu[h]=0;
+	quendu[h]=0;
+	return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET);  */
+	return (SCSI_RESET_SNOOZE);
 }
 
-const char *
-atp870u_info(struct Scsi_Host *notused)
+const char *atp870u_info(struct Scsi_Host *notused)
 {
-  static char buffer[128];
+	static char buffer[128];
 
-  strcpy(buffer, "ACARD AEC-6710/6712 PCI Ultra/W SCSI-3 Adapter Driver V1.0 ");
+	strcpy(buffer, "ACARD AEC-6710/6712 PCI Ultra/W SCSI-3 Adapter Driver V1.0 ");
 
-  return buffer;
+	return buffer;
 }
 
-int
-atp870u_set_info(char *buffer, int length, struct Scsi_Host *HBAptr)
+int atp870u_set_info(char *buffer, int length, struct Scsi_Host *HBAptr)
 {
-  return (-ENOSYS);  /* Currently this is a no-op */
+	return (-ENOSYS);	/* Currently this is a no-op */
 }
 
 #define BLS buffer + len + size
-int
-atp870u_proc_info(char *buffer, char **start, off_t offset, int length,
-    int hostno, int inout)
+int atp870u_proc_info(char *buffer, char **start, off_t offset, int length,
+		      int hostno, int inout)
 {
-  struct Scsi_Host *HBAptr;
-  static u8 buff[512];
-  int	i;
-  int	size = 0;
-  int	len = 0;
-  off_t begin = 0;
-  off_t pos = 0;
-
-  HBAptr = NULL;
-  for (i = 0; i < 2; i++)
-  {
-    if ((HBAptr = atp_host[i]) != NULL)
-    {
-      if (HBAptr->host_no == hostno)
-      {
-	break;
-      }
-      HBAptr = NULL;
-    }
-  }
-
-  if (HBAptr == NULL)
-  {
-    size += sprintf(BLS, "Can't find adapter for host number %d\n", hostno);
-    len += size; pos = begin + len; size = 0;
-    goto stop_output;
-  }
-
-  if (inout == TRUE) /* Has data been written to the file? */
-  {
-    return (atp870u_set_info(buffer, length, HBAptr));
-  }
-
-  if (offset == 0)
-  {
-    memset(buff, 0, sizeof(buff));
-  }
-
-  size += sprintf(BLS, "ACARD AEC-671X Driver Version: 1.0\n");
-  len += size; pos = begin + len; size = 0;
-
-  size += sprintf(BLS, "\n");
-  size += sprintf(BLS, "Adapter Configuration:\n");
-  size += sprintf(BLS, "               Base IO: %#.4lx\n", HBAptr->io_port);
-  size += sprintf(BLS, "                   IRQ: %d\n", HBAptr->irq);
-  len += size; pos = begin + len; size = 0;
-
-stop_output:
-  *start = buffer + (offset - begin);	/* Start of wanted data */
-  len -= (offset - begin);	/* Start slop */
-  if (len > length)
-  {
-    len = length;		/* Ending slop */
-  }
+	struct Scsi_Host *HBAptr;
+	static u8 buff[512];
+	int i;
+	int size = 0;
+	int len = 0;
+	off_t begin = 0;
+	off_t pos = 0;
+
+	HBAptr = NULL;
+	for (i = 0; i < 2; i++) {
+		if ((HBAptr = atp_host[i]) != NULL) {
+			if (HBAptr->host_no == hostno) {
+				break;
+			}
+			HBAptr = NULL;
+		}
+	}
 
-  return (len);
+	if (HBAptr == NULL) {
+		size += sprintf(BLS, "Can't find adapter for host number %d\n", hostno);
+		len += size;
+		pos = begin + len;
+		size = 0;
+		goto stop_output;
+	}
+	if (inout == TRUE) {	/* Has data been written to the file? */
+		return (atp870u_set_info(buffer, length, HBAptr));
+	}
+	if (offset == 0) {
+		memset(buff, 0, sizeof(buff));
+	}
+	size += sprintf(BLS, "ACARD AEC-671X Driver Version: 1.0\n");
+	len += size;
+	pos = begin + len;
+	size = 0;
+
+	size += sprintf(BLS, "\n");
+	size += sprintf(BLS, "Adapter Configuration:\n");
+	size += sprintf(BLS, "               Base IO: %#.4lx\n", HBAptr->io_port);
+	size += sprintf(BLS, "                   IRQ: %d\n", HBAptr->irq);
+	len += size;
+	pos = begin + len;
+	size = 0;
+
+      stop_output:
+	*start = buffer + (offset - begin);	/* Start of wanted data */
+	len -= (offset - begin);	/* Start slop */
+	if (len > length) {
+		len = length;	/* Ending slop */
+	}
+	return (len);
 }
 
 #include "sd.h"
 
-int atp870u_biosparam(Scsi_Disk * disk, kdev_t dev, int * ip)
+int atp870u_biosparam(Scsi_Disk * disk, kdev_t dev, int *ip)
 {
-  int heads, sectors, cylinders;
+	int heads, sectors, cylinders;
 
-  heads = 64;
-  sectors = 32;
-  cylinders = disk->capacity / (heads * sectors);
-
-  if ( cylinders > 1024 )
-  {
-    heads = 255;
-    sectors = 63;
-    cylinders = disk->capacity / (heads * sectors);
-  }
-
-  ip[0] = heads;
-  ip[1] = sectors;
-  ip[2] = cylinders;
+	heads = 64;
+	sectors = 32;
+	cylinders = disk->capacity / (heads * sectors);
+
+	if (cylinders > 1024) {
+		heads = 255;
+		sectors = 63;
+		cylinders = disk->capacity / (heads * sectors);
+	}
+	ip[0] = heads;
+	ip[1] = sectors;
+	ip[2] = cylinders;
 
-  return 0;
+	return 0;
 }
 
 #ifdef MODULE
@@ -2046,4 +1769,3 @@
 
 #include "scsi_module.c"
 #endif
-
diff -urN linux-2.2.13-pre17/drivers/scsi/atp870u.h linux-2.2.13-pre18/drivers/scsi/atp870u.h
--- linux-2.2.13-pre17/drivers/scsi/atp870u.h	1998-12-27 22:19:20.000000000 -0800
+++ linux-2.2.13-pre18/drivers/scsi/atp870u.h	2003-08-15 15:08:35.000000000 -0700
@@ -1,7 +1,7 @@
 #ifndef _ATP870U_H
 
 /* $Id: atp870u.h,v 1.0 1997/05/07 15:09:00 root Exp root $
- *
+
  * Header file for the ACARD 870U/W driver for Linux
  *
  * $Log: atp870u.h,v $
@@ -20,10 +20,10 @@
 
 int atp870u_detect(Scsi_Host_Template *);
 int atp870u_command(Scsi_Cmnd *);
-int atp870u_queuecommand(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
+int atp870u_queuecommand(Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
 int atp870u_abort(Scsi_Cmnd *);
 int atp870u_reset(Scsi_Cmnd *, unsigned int);
-int atp870u_biosparam(Disk *, kdev_t, int*);
+int atp870u_biosparam(Disk *, kdev_t, int *);
 void send_s870(unsigned char);
 
 #define qcnt            32
@@ -31,7 +31,7 @@
 #define ATP870U_CMDLUN 1
 
 #ifndef NULL
-        #define NULL 0
+#define NULL 0
 #endif
 
 extern struct proc_dir_entry proc_scsi_atp870u;
diff -urN linux-2.2.13-pre17/drivers/scsi/g_NCR5380.c linux-2.2.13-pre18/drivers/scsi/g_NCR5380.c
--- linux-2.2.13-pre17/drivers/scsi/g_NCR5380.c	1998-12-27 10:53:45.000000000 -0800
+++ linux-2.2.13-pre18/drivers/scsi/g_NCR5380.c	2003-08-15 15:08:35.000000000 -0700
@@ -166,21 +166,25 @@
 	    printk("generic_NCR5380_setup : usage ncr5380=" STRVAL(NCR5380_map_name) ",irq,dma\n");
 	    return;
 	}
+	break;
     case BOARD_NCR53C400:
 	if (ints[0] != 2) {
 	    printk("generic_NCR53C400_setup : usage ncr53c400=" STRVAL(NCR5380_map_name) ",irq\n");
 	    return;
 	}
+	break;
     case BOARD_NCR53C400A:
 	if (ints[0] != 2) {
 	    printk("generic_NCR53C400A_setup : usage ncr53c400a=" STRVAL(NCR5380_map_name) ",irq\n");
 	    return;
 	}
+	break;
     case BOARD_DTC3181E:
 	if (ints[0] != 2) {
 	    printk("generic_DTC3181E_setup : usage dtc3181e=" STRVAL(NCR5380_map_name) ",irq\n");
 	    return;
 	}
+	break;
     }
 
     if (commandline_current < NO_OVERRIDES) {
diff -urN linux-2.2.13-pre17/fs/binfmt_aout.c linux-2.2.13-pre18/fs/binfmt_aout.c
--- linux-2.2.13-pre17/fs/binfmt_aout.c	2003-08-15 15:08:35.000000000 -0700
+++ linux-2.2.13-pre18/fs/binfmt_aout.c	2003-08-15 15:08:35.000000000 -0700
@@ -311,7 +311,6 @@
 	unsigned long fd_offset;
 	unsigned long rlim;
 	int retval;
-	static unsigned long error_time=0;
 
 	ex = *((struct exec *) bprm->buf);		/* exec-header */
 	if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
@@ -323,29 +322,6 @@
 
 	fd_offset = N_TXTOFF(ex);
 
-#ifdef __i386__
-	if (N_MAGIC(ex) == ZMAGIC && fd_offset != BLOCK_SIZE) {
-		if((jiffies-error_time) >5)
-		{
-			printk(KERN_NOTICE "N_TXTOFF != BLOCK_SIZE. See a.out.h.\n");
-			error_time=jiffies;
-		}
-		return -ENOEXEC;
-	}
-
-	if (N_MAGIC(ex) == ZMAGIC && ex.a_text &&
-	    bprm->dentry->d_inode->i_op &&
-	    bprm->dentry->d_inode->i_op->bmap &&
-	    (fd_offset < bprm->dentry->d_inode->i_sb->s_blocksize)) {
-		if((jiffies-error_time) >5)
-		{
-			printk(KERN_NOTICE "N_TXTOFF < BLOCK_SIZE. Please convert binary.\n");
-			error_time=jiffies;
-		}
-		return -ENOEXEC;
-	}
-#endif
-
 	/* Check initial limits. This avoids letting people circumvent
 	 * size limits imposed on them by creating programs with large
 	 * arrays in the data or bss.
@@ -413,18 +389,33 @@
 		flush_icache_range((unsigned long) 0,
 				   (unsigned long) ex.a_text+ex.a_data);
 	} else {
+		static unsigned long error_time, error_time2;
 		if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
-		    (N_MAGIC(ex) != NMAGIC))
+		    (N_MAGIC(ex) != NMAGIC) && (jiffies-error_time2) > 5*HZ)
+		{
 			printk(KERN_NOTICE "executable not page aligned\n");
+			error_time2 = jiffies;
+		}
 
 		fd = open_dentry(bprm->dentry, O_RDONLY);
 		if (fd < 0)
 			return fd;
-		file = fcheck(fd);
+		file = fget(fd);
 
-		if (!file->f_op || !file->f_op->mmap) {
+		if ((fd_offset & ~PAGE_MASK) != 0 &&
+		    (jiffies-error_time) > 5*HZ)
+		{
+			printk(KERN_WARNING 
+			       "fd_offset is not page aligned. Please convert program: %s\n",
+			       file->f_dentry->d_name.name
+			       );
+			error_time = jiffies;
+		}
+
+		if (!file->f_op || !file->f_op->mmap || ((fd_offset & ~PAGE_MASK) != 0)) {
+			fput(file);
 			sys_close(fd);
-			do_mmap(NULL, 0, ex.a_text+ex.a_data,
+			do_mmap(NULL, N_TXTADDR(ex), ex.a_text+ex.a_data,
 				PROT_READ|PROT_WRITE|PROT_EXEC,
 				MAP_FIXED|MAP_PRIVATE, 0);
 			read_exec(bprm->dentry, fd_offset,
@@ -441,6 +432,7 @@
 			fd_offset);
 
 		if (error != N_TXTADDR(ex)) {
+			fput(file);
 			sys_close(fd);
 			send_sig(SIGKILL, current, 0);
 			return error;
@@ -450,6 +442,7 @@
 				PROT_READ | PROT_WRITE | PROT_EXEC,
 				MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
 				fd_offset + ex.a_text);
+		fput(file);
 		sys_close(fd);
 		if (error != N_DATADDR(ex)) {
 			send_sig(SIGKILL, current, 0);
@@ -529,12 +522,6 @@
 		goto out_putf;
 	}
 
-	if (N_MAGIC(ex) == ZMAGIC && N_TXTOFF(ex) &&
-	    (N_TXTOFF(ex) < inode->i_sb->s_blocksize)) {
-		printk("N_TXTOFF < BLOCK_SIZE. Please convert library\n");
-		goto out_putf;
-	}
-
 	if (N_FLAGS(ex))
 		goto out_putf;
 
@@ -543,6 +530,26 @@
 
 	start_addr =  ex.a_entry & 0xfffff000;
 
+	if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
+		static unsigned long error_time;
+
+		if ((jiffies-error_time) > 5*HZ)
+		{
+			printk(KERN_WARNING 
+			       "N_TXTOFF is not page aligned. Please convert library: %s\n",
+			       file->f_dentry->d_name.name);
+			error_time = jiffies;
+		}
+		do_mmap(NULL, start_addr, ex.a_text + ex.a_data,
+			PROT_READ | PROT_WRITE | PROT_EXEC,
+			MAP_FIXED| MAP_PRIVATE, 0);
+		read_exec(file->f_dentry, N_TXTOFF(ex),
+			  (char *)start_addr, ex.a_text + ex.a_data, 0);
+		flush_icache_range((unsigned long) start_addr,
+				   (unsigned long) start_addr + ex.a_text + ex.a_data);
+		retval = 0;
+		goto out_putf;
+	}
 	/* Now use mmap to map the library into memory. */
 	error = do_mmap(file, start_addr, ex.a_text + ex.a_data,
 			PROT_READ | PROT_WRITE | PROT_EXEC,
diff -urN linux-2.2.13-pre17/fs/exec.c linux-2.2.13-pre18/fs/exec.c
--- linux-2.2.13-pre17/fs/exec.c	2003-08-15 15:08:35.000000000 -0700
+++ linux-2.2.13-pre18/fs/exec.c	2003-08-15 15:08:35.000000000 -0700
@@ -532,6 +532,8 @@
 	if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || 
 	    permission(bprm->dentry->d_inode,MAY_READ))
 		current->dumpable = 0;
+		
+	current->self_exec_id++;
 
 	flush_signal_handlers(current);
 	flush_old_files(current->files);
diff -urN linux-2.2.13-pre17/fs/namei.c linux-2.2.13-pre18/fs/namei.c
--- linux-2.2.13-pre17/fs/namei.c	1999-05-08 20:46:08.000000000 -0700
+++ linux-2.2.13-pre18/fs/namei.c	2003-08-15 15:08:35.000000000 -0700
@@ -793,7 +793,7 @@
 	struct dentry *dentry, *retval;
 
 	mode &= ~current->fs->umask;
-	dentry = lookup_dentry(filename, NULL, LOOKUP_FOLLOW);
+	dentry = lookup_dentry(filename, NULL, 0);
 	if (IS_ERR(dentry))
 		return dentry;
 
diff -urN linux-2.2.13-pre17/fs/nfs/dir.c linux-2.2.13-pre18/fs/nfs/dir.c
--- linux-2.2.13-pre17/fs/nfs/dir.c	2003-08-15 15:08:35.000000000 -0700
+++ linux-2.2.13-pre18/fs/nfs/dir.c	2003-08-15 15:08:35.000000000 -0700
@@ -506,21 +506,6 @@
 				dentry->d_name.name, error);
 	}
 
-#ifdef NFS_PARANOIA
-	/*
-	 * Sanity check: if the dentry has been unhashed and the
-	 * inode still has users, we could have problems ...
-	 */
-	if (list_empty(&dentry->d_hash) && dentry->d_inode) {
-		struct inode *inode = dentry->d_inode;
-		int max_count = (S_ISDIR(inode->i_mode) ? 1 : inode->i_nlink);
-		if (inode->i_count > max_count) {
-printk("nfs_dentry_delete: %s/%s: ino=%ld, count=%d, nlink=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name,
-inode->i_ino, inode->i_count, inode->i_nlink);
-		}
-	}
-#endif
 }
 
 /*
@@ -595,14 +580,6 @@
 		error = -EACCES;
 		inode = nfs_fhget(dentry, &fhandle, &fattr);
 		if (inode) {
-#ifdef NFS_PARANOIA
-if (inode->i_count > (S_ISDIR(inode->i_mode) ? 1 : inode->i_nlink)) {
-printk("nfs_lookup: %s/%s ino=%ld in use, count=%d, nlink=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name,
-inode->i_ino, inode->i_count, inode->i_nlink);
-show_dentry(&inode->i_dentry);
-}
-#endif
 	    no_entry:
 			d_add(dentry, inode);
 			nfs_renew_times(dentry);
@@ -624,14 +601,6 @@
 
 	inode = nfs_fhget(dentry, fhandle, fattr);
 	if (inode) {
-#ifdef NFS_PARANOIA
-if (inode->i_count > (S_ISDIR(inode->i_mode) ? 1 : inode->i_nlink)) {
-printk("nfs_instantiate: %s/%s ino=%ld in use, count=%d, nlink=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name,
-inode->i_ino, inode->i_count, inode->i_nlink);
-show_dentry(&inode->i_dentry);
-}
-#endif
 		d_instantiate(dentry, inode);
 		nfs_renew_times(dentry);
 		error = 0;
@@ -738,13 +707,6 @@
 	dfprintk(VFS, "NFS: rmdir(%x/%ld, %s\n",
 		dir->i_dev, dir->i_ino, dentry->d_name.name);
 
-#ifdef NFS_PARANOIA
-if (dentry->d_inode->i_count > 1)
-printk("nfs_rmdir: %s/%s inode busy?? i_count=%d, i_nlink=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name,
-dentry->d_inode->i_count, dentry->d_inode->i_nlink);
-#endif
-
 	nfs_invalidate_dircache(dir);
 	error = nfs_proc_rmdir(NFS_SERVER(dir), NFS_FH(dentry->d_parent),
 				dentry->d_name.name);
@@ -920,12 +882,6 @@
 #endif
 		goto out;
 	}
-#ifdef NFS_PARANOIA
-if (inode && inode->i_count > inode->i_nlink)
-printk("nfs_safe_remove: %s/%s inode busy?? i_count=%d, i_nlink=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name,
-inode->i_count, inode->i_nlink);
-#endif
 	/*
 	 * Unhash the dentry while we remove the file ...
 	 */
diff -urN linux-2.2.13-pre17/include/linux/sched.h linux-2.2.13-pre18/include/linux/sched.h
--- linux-2.2.13-pre17/include/linux/sched.h	2003-08-15 15:08:35.000000000 -0700
+++ linux-2.2.13-pre18/include/linux/sched.h	2003-08-15 15:08:35.000000000 -0700
@@ -324,6 +324,10 @@
 	struct signal_queue *sigqueue, **sigqueue_tail;
 	unsigned long sas_ss_sp;
 	size_t sas_ss_size;
+	
+/* Thread group tracking */
+   	u32 parent_exec_id;
+   	u32 self_exec_id;
 };
 
 /*
@@ -390,6 +394,7 @@
 /* files */	&init_files, \
 /* mm */	&init_mm, \
 /* signals */	SPIN_LOCK_UNLOCKED, &init_signals, {{0}}, {{0}}, NULL, &init_task.sigqueue, 0, 0, \
+/* exec cts */	0,0, \
 }
 
 union task_union {
diff -urN linux-2.2.13-pre17/kernel/exit.c linux-2.2.13-pre18/kernel/exit.c
--- linux-2.2.13-pre17/kernel/exit.c	2003-08-15 15:08:35.000000000 -0700
+++ linux-2.2.13-pre18/kernel/exit.c	2003-08-15 15:08:35.000000000 -0700
@@ -146,7 +146,9 @@
 	read_lock(&tasklist_lock);
 	for_each_task(p) {
 		if (p->p_opptr == father) {
+			/* We dont want people slaying init */
 			p->exit_signal = SIGCHLD;
+			p->self_exec_id++;
 			p->p_opptr = child_reaper; /* init */
 			if (p->pdeath_signal) send_sig(p->pdeath_signal, p, 0);
 		}
@@ -305,11 +307,20 @@
 	 * Thread signals are configurable, but you aren't going to use
 	 * that to send signals to arbitary processes. 
 	 * That stops right now.
+	 *
+	 * If the parent exec id doesn't match the exec id we saved
+	 * when we started then we know the parent has changed security
+	 * domain.
+	 *
+	 * If our self_exec id doesn't match our parent_exec_id then
+	 * we have changed execution domain as these two values started
+	 * the same after a fork.
+	 *	
 	 */
 	
 	if(current->exit_signal != SIGCHLD &&
-	    (current->euid ^ t->suid) && (current->euid ^ t->uid)
-	    && (current->uid ^ t->suid) && (current->uid ^ t->uid)
+	    ( current->parent_exec_id != t->self_exec_id  ||
+	      current->self_exec_id != current->parent_exec_id) 
 	    && !capable(CAP_KILL))
 		current->exit_signal = SIGCHLD;
 
diff -urN linux-2.2.13-pre17/kernel/fork.c linux-2.2.13-pre18/kernel/fork.c
--- linux-2.2.13-pre17/kernel/fork.c	2003-08-15 15:08:35.000000000 -0700
+++ linux-2.2.13-pre18/kernel/fork.c	2003-08-15 15:08:35.000000000 -0700
@@ -679,6 +679,11 @@
 	if (retval)
 		goto bad_fork_cleanup_mm;
 	p->semundo = NULL;
+	
+	/* Our parent execution domain becomes current domain
+	   These must match for thread signalling to apply */
+	   
+	p->parent_exec_id = p->self_exec_id;
 
 	/* ok, now we should be set up.. */
 	p->swappable = 1;
diff -urN linux-2.2.13-pre17/Makefile linux-2.2.13-pre18/Makefile
--- linux-2.2.13-pre17/Makefile	2003-08-15 15:08:34.000000000 -0700
+++ linux-2.2.13-pre18/Makefile	2003-08-15 15:08:35.000000000 -0700
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 2
 SUBLEVEL = 13
-EXTRAVERSION = pre17
+EXTRAVERSION = pre18
 
 ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
 
diff -urN linux-2.2.13-pre17/net/sunrpc/svcsock.c linux-2.2.13-pre18/net/sunrpc/svcsock.c
--- linux-2.2.13-pre17/net/sunrpc/svcsock.c	2003-08-15 15:08:35.000000000 -0700
+++ linux-2.2.13-pre18/net/sunrpc/svcsock.c	2003-08-15 15:08:35.000000000 -0700
@@ -531,16 +531,18 @@
 
 	ops = newsock->ops;
 	if ((err = ops->accept(sock, newsock, O_NONBLOCK)) < 0) {
-		printk(KERN_WARNING "%s: accept failed (err %d)!\n",
-					serv->sv_name, -err);
+		if (net_ratelimit())
+			printk(KERN_WARNING "%s: accept failed (err %d)!\n",
+				   serv->sv_name, -err);
 		goto failed;		/* aborted connection or whatever */
 	}
 
 	slen = sizeof(sin);
 	err = ops->getname(newsock, (struct sockaddr *) &sin, &slen, 1);
 	if (err < 0) {
-		printk(KERN_WARNING "%s: peername failed (err %d)!\n",
-					serv->sv_name, -err);
+		if (net_ratelimit())
+			printk(KERN_WARNING "%s: peername failed (err %d)!\n",
+				   serv->sv_name, -err);
 		goto failed;		/* aborted connection or whatever */
 	}
 
@@ -548,10 +550,11 @@
 	 * hosts here, but we have no generic client tables. For now,
 	 * we just punt connects from unprivileged ports. */
 	if (ntohs(sin.sin_port) >= 1024) {
-		printk(KERN_WARNING
-			"%s: connect from unprivileged port: %s:%d",
-			serv->sv_name, 
-			in_ntoa(sin.sin_addr.s_addr), ntohs(sin.sin_port));
+		if (net_ratelimit())
+			printk(KERN_WARNING
+				   "%s: connect from unprivileged port: %s:%d",
+				   serv->sv_name, 
+				   in_ntoa(sin.sin_addr.s_addr), ntohs(sin.sin_port));
 		goto failed;
 	}
 
