Resent-Date: Sat, 7 Nov 1998 00:28:20 +0100 (MET)
Sender: schmitz@lbl.gov
Date: Fri, 06 Nov 1998 15:29:10 -0800
From: Michael Schmitz <MSchmitz@lbl.gov>
Reply-To: MSchmitz@lbl.gov
Organization: Tinoco Lab, UC Berkekely / Lawrence Berkeley Laboratory
To: linux-m68k@lists.linux-m68k.org
Subject: Patch for NCR53c9x.c (was: Re: SCSI freeze with 2.1.124)
References: <199811060954.KAA11251@valhall.cern.ch>
		<m0zboaZ-000lU2C@schmitzm.hip.berkeley.edu> <199811061630.RAA12022@valhall.cern.ch>
Resent-From: linux-m68k@phil.uni-sb.de

This is a multi-part message in MIME format.
--------------B1730ACF17F1FAE5407E7AD8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

I've patched NCR53C9x.c to catch up with the changes to esp.c in the
vger tree. Changes include:

- use io_request spinlock
- default to async transfer if sync target barfs on us
- bugfix for wide negotiation in recent esp.c

Please test this patch, I have no way of testing it (2.1.120 refuses to
boot on Mac again).

	Michael
--------------B1730ACF17F1FAE5407E7AD8
Content-Type: text/plain; charset=us-ascii; name="NCR53C9x-981106.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="NCR53C9x-981106.diff"

--- drivers/scsi/NCR53C9x.c.981106	Fri Nov  6 09:08:31 1998
+++ drivers/scsi/NCR53C9x.c	Fri Nov  6 10:09:31 1998
@@ -1144,7 +1144,6 @@
 			   (SDptr->type != TYPE_ROM ||
 			    strncmp(SDptr->vendor, "TOSHIBA", 7))) {
 				build_wide_nego_msg(esp, 16);
-				esp->config3[SCptr->target] |= ESP_CONFIG3_EWIDE;
 				SDptr->wide = 1;
 				esp->wnip = 1;
 				goto after_nego_msg_built;
@@ -1196,11 +1195,7 @@
 		 *           thank you very much. ;-)
 		 */
 		if(((SDptr->scsi_level < 3) && (SDptr->type != TYPE_TAPE)) ||
-#if 1 /* Until I find out why HME barfs with disconnects enabled... */
-		   toshiba_cdrom_hwbug_wkaround || SDptr->borken || esp->erev == fashme) {
-#else
 		   toshiba_cdrom_hwbug_wkaround || SDptr->borken) {
-#endif
 			printk(KERN_INFO "esp%d: Disabling DISCONNECT for target %d "
 			       "lun %d\n", esp->esp_id, SCptr->target, SCptr->lun);
 			SDptr->disconnect = 0;
@@ -2236,6 +2231,10 @@
 		ESPLOG(("esp%d: use_sg=%d ptr=%p this_residual=%d\n",
 			esp->esp_id,
 			SCptr->use_sg, SCptr->SCp.ptr, SCptr->SCp.this_residual));
+		ESPLOG(("esp%d: Forcing async for target %d\n", esp->esp_id, 
+			SCptr->target));
+		SCptr->device->borken = 1;
+		SCptr->device->sync = 0;
 		bytes_sent = 0;
 	}
 
@@ -3337,9 +3336,11 @@
 		esp_cmd(esp, eregs, (ESP_CMD_DMA | ESP_CMD_TI));
 		esp->dma_init_write(esp, esp->esp_command_dvma, i);
 	} else {
+		unsigned char tmp;
 		esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-		eregs->esp_fdata = *esp->esp_scmdp++;
+		tmp = *esp->esp_scmdp++;
 		esp->esp_scmdleft--;
+		eregs->esp_fdata = tmp;
 		esp_cmd(esp, eregs, ESP_CMD_TI);
 	}
 	return do_intr_end;
@@ -3861,9 +3862,11 @@
 void esp_intr(int irq, void *dev_id, struct pt_regs *pregs)
 {
 	struct NCR_ESP *esp;
+	unsigned long flags;
 	int again;
 
 	/* Handle all ESP interrupts showing at this IRQ level. */
+	spin_lock_irqsave(&io_request_lock, flags);
 repeat:
 	again = 0;
 	for_each_esp(esp) {
@@ -3887,14 +3890,17 @@
 	}
 	if(again)
 		goto repeat;
+	spin_unlock_irqrestore(&io_request_lock, flags);
 }
 #else
 /* For SMP we only service one ESP on the list list at our IRQ level! */
 static void esp_intr(int irq, void *dev_id, struct pt_regs *pregs)
 {
 	struct NCR_ESP *esp;
+	unsigned long flags;
 
 	/* Handle all ESP interrupts showing at this IRQ level. */
+	spin_lock_irqsave(&io_request_lock, flags);
 	for_each_esp(esp) {
 		if(((esp)->irq & 0xf) == irq) {
 			if(esp->dma_irq_p(esp)) {
@@ -3906,10 +3912,12 @@
 				ESPIRQ((")"));
 
 				esp->dma_ints_on(esp);
-				return;
+				goto out;
 			}
 		}
 	}
+out:
+	spin_unlock_irqrestore(&io_request_lock, flags);
 }
 #endif
 
@@ -3918,7 +3926,9 @@
 static void esp_intr(int irq, void *dev_id, struct pt_regs *pregs)
 {
 	struct NCR_ESP *esp = dev_id;
+	unsigned long flags;
 
+	spin_lock_irqsave(&io_request_lock, flags);
 	if(esp->dma_irq_p(esp)) {
 		esp->dma_ints_off(dregs);
 
@@ -3928,6 +3938,7 @@
 
 		esp->dma_ints_on(esp);
 	}
+	spin_unlock_irqrestore(&io_request_lock, flags);
 }
 
 #endif

--------------B1730ACF17F1FAE5407E7AD8--

