From 39250c18b8924844bd5126af30cd96f80bf53a4d Mon Sep 17 00:00:00 2001
From: "Justin T. Gibbs" <gibbs@FreeBSD.org>
Date: Fri, 13 Aug 2004 21:41:23 +0000
Subject: [PATCH] Extend critical section protection around portions of
 selection processing that cannot tolerate changes to the waiting for
 selection queue by the host or the host canceling an active selection.

---
 sys/dev/aic7xxx/aic7xxx.seq | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys/dev/aic7xxx/aic7xxx.seq b/sys/dev/aic7xxx/aic7xxx.seq
index 15196390e28d..810d766beeaf 100644
--- a/sys/dev/aic7xxx/aic7xxx.seq
+++ b/sys/dev/aic7xxx/aic7xxx.seq
@@ -83,7 +83,9 @@ poll_for_work:
 		xor	SBLKCTL,SELBUSB;	/* Toggle to the other bus */
 		test	SCSISEQ, ENSELO		jnz poll_for_selection;
 	}
+BEGIN_CRITICAL;
 	cmp	WAITING_SCBH,SCB_LIST_NULL jne start_waiting;
+END_CRITICAL;
 poll_for_work_loop:
 	if ((ahc->features & AHC_TWIN) != 0) {
 		xor	SBLKCTL,SELBUSB;	/* Toggle to the other bus */
@@ -141,13 +143,13 @@ BEGIN_CRITICAL;
 		inc	QINPOS;
 	}
 	and	SEQ_FLAGS2, ~SCB_DMA;
-END_CRITICAL;
 start_waiting:
 	/*
 	 * Start the first entry on the waiting SCB list.
 	 */
 	mov	SCBPTR, WAITING_SCBH;
 	call	start_selection;
+END_CRITICAL;
 
 poll_for_selection:
 	/*
@@ -355,6 +357,7 @@ abort_qinscb:
 	call	add_scb_to_free_list;
 	jmp	poll_for_work_loop;
 
+BEGIN_CRITICAL;
 start_selection:
 	/*
 	 * If bus reset interrupts have been disabled (from a previous
@@ -388,6 +391,7 @@ initialize_scsiid:
 	} else {
 		mov	SCSISEQ, SCSISEQ_TEMPLATE ret;
 	}
+END_CRITICAL;
 
 /*
  * Initialize transfer settings with SCB provided settings.