Subject: port-i386/5706: Broken aic7xxx driver (data overrums)
To: None <current-users@NetBSD.ORG>
From: Justin T. Gibbs <gibbs@plutotech.com>
List: current-users
Date: 07/05/1998 23:43:14
The originator of this PR is currently unable to test a possible fix for
this problem, which is the integration of another, fairly old, bug fix from
the FreeBSD driver.  In a normal situation, the sequencer testing I've done
under FreeBSD would be satisfactory preparation for a commit, but the 
version skew between the NetBSD and FreeBSD drivers is so large that, as
was the case in this last commit, a small change in one area could reveil
missing bug fixes in "unrelated" code.  Is there anyone willing to test
this patch?

My immediate goal is to get the NetBSD driver working for Rev. B aic7880
chips.  In the long run, some effort will need to be made to bring the
FreeBSD driver changes into NetBSD.  For that to happen, NetBSD needs to
make a strategic decision on whether to incorporate FreeBSD CAM or to
continue with the SCSI layer in use now.  I just don't have the energy or
inclination to port the current aic7xxx driver back to the old SCSI system
(mostly because getting the error recovery to work satisfactorily is next
to impossible).  So, I'm definitely backing the CAM approach, but I'll
aid anyone who is interested in porting the CAM driver back to the old
SCSI layer.

--
Justin

? aic7xxx_asm
Index: aic7xxx.seq
===================================================================
RCS file: /cvsroot/src/sys/dev/microcode/aic7xxx/aic7xxx.seq,v
retrieving revision 1.10
diff -c -r1.10 aic7xxx.seq
*** aic7xxx.seq	1998/07/04 22:29:46	1.10
--- aic7xxx.seq	1998/07/05 04:58:30
***************
*** 361,367 ****
  	test	SXFRCTL1,BITBUCKET jnz data_phase_overrun
  
  /* Exit if we had an underrun */
! 	test	SSTAT0,SDONE	jz data_phase_finish /* underrun STCNT != 0 */
  
  /*
   * Advance the scatter-gather pointers if needed 
--- 361,367 ----
  	test	SXFRCTL1,BITBUCKET jnz data_phase_overrun
  
  /* Exit if we had an underrun */
! 	test	SINDEX,0xff	jz data_phase_finish
  
  /*
   * Advance the scatter-gather pointers if needed 
***************
*** 905,913 ****
   */
  dma:
  	mov	DFCNTRL,SINDEX
! dma1:
! 	test	SSTAT0,DMADONE	jnz dma3
! 	test	SSTAT1,PHASEMIS	jz dma1		/* ie. underrun */
  
  /*
   * We will be "done" DMAing when the transfer count goes to zero, or
--- 905,914 ----
   */
  dma:
  	mov	DFCNTRL,SINDEX
! dma_loop:
! 	test	SSTAT0,DMADONE	jnz dma_checkfifo
! 	test	SSTAT1,PHASEMIS	jz dma_loop	/* i.e. underrun */
! 	mov	SINDEX,ALLZEROS			/* Notify caller of phasemiss */
  
  /*
   * We will be "done" DMAing when the transfer count goes to zero, or
***************
*** 917,936 ****
   * magically on STCNT=0 or a phase change, so just wait for FIFO empty
   * status.
   */
! dma3:
! 	test	SINDEX,DIRECTION	jnz dma5
! dma4:
! 	test	DFSTATUS,FIFOEMP	jz dma4
! 
  /*
!  * Now shut the DMA enables off and make sure that the DMA enables are 
   * actually off first lest we get an ILLSADDR.
   */
! dma5:
! 	/* disable DMA, but maintain WIDEODD */
! 	and	DFCNTRL,WIDEODD
! dma6:
! 	test	DFCNTRL,0x38	jnz dma6  /* SCSIENACK|SDMAENACK|HDMAENACK */
  return:
  	ret
  
--- 918,947 ----
   * magically on STCNT=0 or a phase change, so just wait for FIFO empty
   * status.
   */
! dma_checkfifo:
! 	test	DFCNTRL,DIRECTION	jnz dma_fifoempty
! dma_fifoflush:
! 	test	DFSTATUS,FIFOEMP	jz dma_fifoflush
!  
! dma_fifoempty:
! 	/* Don't clobber an inprogress host data transfer */ 
! 	test	DFSTATUS, MREQPEND	jnz dma_fifoempty
  /*
!  * Now shut the DMA enables off and make sure that the DMA enables are
   * actually off first lest we get an ILLSADDR.
   */
! dma_dmadone:
! 	and	DFCNTRL, 0xc7	/* ~(SCSIEN|SDMAEN|HDMAEN); */
! dma_halt:
! 	/*
! 	 * Some revisions of the aic7880 have a problem where, if the
! 	 * data fifo is full, but the PCI input latch is not empty,
! 	 * HDMAEN cannot be cleared.  The fix used here is to attempt
! 	 * to drain the data fifo until there is space for the input
! 	 * latch to drain and HDMAEN de-asserts.
! 	 */
! 	mov	NONE, DFDAT
! 	test	DFCNTRL, HDMAEN jnz dma_halt
  return:
  	ret
  
Index: aic7xxx_seq.h
===================================================================
RCS file: /cvsroot/src/sys/dev/microcode/aic7xxx/aic7xxx_seq.h,v
retrieving revision 1.4
diff -c -r1.4 aic7xxx_seq.h
*** aic7xxx_seq.h	1998/07/04 22:29:46	1.4
--- aic7xxx_seq.h	1998/07/05 04:58:30
***************
*** 1,4 ****
! #define AIC7XXX_SEQ_VER "$NetBSD: aic7xxx_seq.h,v 1.4 1998/07/04 22:29:46 mjacob Exp $"
  	0xff, 0x6a, 0x93, 0x02,
  	0xff, 0x6a, 0x03, 0x02,
  	0x0f, 0x4a, 0x4a, 0x02,
--- 1,4 ----
! #define AIC7XXX_SEQ_VER "$NetBSD: aic7xxx.seq,v 1.10 1998/07/04 22:29:46 mjacob Exp $"
  	0xff, 0x6a, 0x93, 0x02,
  	0xff, 0x6a, 0x03, 0x02,
  	0x0f, 0x4a, 0x4a, 0x02,
***************
*** 33,39 ****
  	0x08, 0xa1, 0x64, 0x02,
  	0x00, 0x65, 0x65, 0x00,
  	0xff, 0x65, 0x1f, 0x02,
! 	0x00, 0xa1, 0x35, 0x17,
  	0x58, 0x6a, 0x00, 0x00,
  	0x40, 0xa0, 0x64, 0x02,
  	0x07, 0xa1, 0x35, 0x02,
--- 33,39 ----
  	0x08, 0xa1, 0x64, 0x02,
  	0x00, 0x65, 0x65, 0x00,
  	0xff, 0x65, 0x1f, 0x02,
! 	0x00, 0xa1, 0x38, 0x17,
  	0x58, 0x6a, 0x00, 0x00,
  	0x40, 0xa0, 0x64, 0x02,
  	0x07, 0xa1, 0x35, 0x02,
***************
*** 50,62 ****
  	0x40, 0x0b, 0x36, 0x1a,
  	0x20, 0x0b, 0x30, 0x1e,
  	0xff, 0x6a, 0x34, 0x02,
! 	0x00, 0x19, 0x35, 0x17,
  	0x80, 0x4a, 0x4a, 0x00,
  	0x00, 0x65, 0x38, 0x10,
  	0xff, 0xba, 0x4e, 0x02,
  	0x20, 0x4a, 0x4a, 0x00,
  	0x02, 0x01, 0x01, 0x00,
! 	0x00, 0x65, 0x7c, 0x17,
  	0xff, 0x6c, 0x04, 0x02,
  	0xff, 0x05, 0x6e, 0x02,
  	0xff, 0x6e, 0x64, 0x02,
--- 50,62 ----
  	0x40, 0x0b, 0x36, 0x1a,
  	0x20, 0x0b, 0x30, 0x1e,
  	0xff, 0x6a, 0x34, 0x02,
! 	0x00, 0x19, 0x38, 0x17,
  	0x80, 0x4a, 0x4a, 0x00,
  	0x00, 0x65, 0x38, 0x10,
  	0xff, 0xba, 0x4e, 0x02,
  	0x20, 0x4a, 0x4a, 0x00,
  	0x02, 0x01, 0x01, 0x00,
! 	0x00, 0x65, 0x7f, 0x17,
  	0xff, 0x6c, 0x04, 0x02,
  	0xff, 0x05, 0x6e, 0x02,
  	0xff, 0x6e, 0x64, 0x02,
***************
*** 91,99 ****
  	0xff, 0xab, 0x0a, 0x02,
  	0x00, 0x65, 0x60, 0x10,
  	0x79, 0x6a, 0x41, 0x00,
! 	0x00, 0x65, 0x39, 0x17,
  	0x10, 0x4a, 0x57, 0x1a,
! 	0x00, 0x65, 0x60, 0x17,
  	0x10, 0x4a, 0x4a, 0x00,
  	0xff, 0x42, 0x65, 0x1a,
  	0x80, 0x02, 0x02, 0x00,
--- 91,99 ----
  	0xff, 0xab, 0x0a, 0x02,
  	0x00, 0x65, 0x60, 0x10,
  	0x79, 0x6a, 0x41, 0x00,
! 	0x00, 0x65, 0x3c, 0x17,
  	0x10, 0x4a, 0x57, 0x1a,
! 	0x00, 0x65, 0x63, 0x17,
  	0x10, 0x4a, 0x4a, 0x00,
  	0xff, 0x42, 0x65, 0x1a,
  	0x80, 0x02, 0x02, 0x00,
***************
*** 104,110 ****
  	0xbf, 0x41, 0x41, 0x02,
  	0x00, 0x41, 0x2d, 0x17,
  	0x80, 0x02, 0x8a, 0x1a,
! 	0x04, 0x0b, 0x85, 0x1e,
  	0xff, 0x42, 0x42, 0x06,
  	0xff, 0x42, 0x85, 0x1e,
  	0xff, 0x6a, 0x64, 0x02,
--- 104,110 ----
  	0xbf, 0x41, 0x41, 0x02,
  	0x00, 0x41, 0x2d, 0x17,
  	0x80, 0x02, 0x8a, 0x1a,
! 	0xff, 0x65, 0x85, 0x1e,
  	0xff, 0x42, 0x42, 0x06,
  	0xff, 0x42, 0x85, 0x1e,
  	0xff, 0x6a, 0x64, 0x02,
***************
*** 140,146 ****
  	0x7f, 0x02, 0x02, 0x02,
  	0xe1, 0x6a, 0x91, 0x00,
  	0x00, 0x65, 0x48, 0x10,
! 	0x00, 0x65, 0x39, 0x17,
  	0xff, 0xb4, 0x88, 0x02,
  	0xff, 0xb5, 0x89, 0x02,
  	0xff, 0xb6, 0x8a, 0x02,
--- 140,146 ----
  	0x7f, 0x02, 0x02, 0x02,
  	0xe1, 0x6a, 0x91, 0x00,
  	0x00, 0x65, 0x48, 0x10,
! 	0x00, 0x65, 0x3c, 0x17,
  	0xff, 0xb4, 0x88, 0x02,
  	0xff, 0xb5, 0x89, 0x02,
  	0xff, 0xb6, 0x8a, 0x02,
***************
*** 240,246 ****
  	0xff, 0x4f, 0x90, 0x02,
  	0x10, 0x6a, 0x60, 0x00,
  	0x00, 0x65, 0xbd, 0x10,
! 	0x00, 0x65, 0x6f, 0x17,
  	0x00, 0x65, 0xbd, 0x10,
  	0xef, 0x4a, 0x4a, 0x02,
  	0x00, 0x65, 0xbd, 0x10,
--- 240,246 ----
  	0xff, 0x4f, 0x90, 0x02,
  	0x10, 0x6a, 0x60, 0x00,
  	0x00, 0x65, 0xbd, 0x10,
! 	0x00, 0x65, 0x72, 0x17,
  	0x00, 0x65, 0xbd, 0x10,
  	0xef, 0x4a, 0x4a, 0x02,
  	0x00, 0x65, 0xbd, 0x10,
***************
*** 263,269 ****
  	0x00, 0x65, 0x12, 0x13,
  	0x04, 0x4a, 0x0c, 0x1f,
  	0x00, 0x65, 0x2a, 0x17,
! 	0x00, 0x6a, 0x3c, 0x17,
  	0xfb, 0xa0, 0xa0, 0x02,
  	0x40, 0x4a, 0x4a, 0x00,
  	0x00, 0x65, 0x48, 0x10,
--- 263,269 ----
  	0x00, 0x65, 0x12, 0x13,
  	0x04, 0x4a, 0x0c, 0x1f,
  	0x00, 0x65, 0x2a, 0x17,
! 	0x00, 0x6a, 0x3f, 0x17,
  	0xfb, 0xa0, 0xa0, 0x02,
  	0x40, 0x4a, 0x4a, 0x00,
  	0x00, 0x65, 0x48, 0x10,
***************
*** 301,337 ****
  	0xd1, 0x6a, 0x91, 0x00,
  	0x00, 0x65, 0x48, 0x10,
  	0xff, 0x65, 0x93, 0x02,
! 	0x01, 0x0b, 0x30, 0x1b,
  	0x10, 0x0c, 0x2e, 0x1f,
! 	0x04, 0x65, 0x32, 0x1b,
! 	0x01, 0x94, 0x31, 0x1f,
! 	0x40, 0x93, 0x93, 0x02,
! 	0x38, 0x93, 0x33, 0x1b,
  	0xff, 0x6a, 0x6a, 0x03,
  	0xf0, 0x65, 0x65, 0x02,
  	0x0f, 0x05, 0x64, 0x02,
  	0x00, 0x65, 0x65, 0x00,
  	0xff, 0x65, 0x05, 0x03,
! 	0x80, 0x4a, 0x34, 0x1f,
! 	0x40, 0x4a, 0x34, 0x1b,
  	0x21, 0x6a, 0x91, 0x01,
  	0xff, 0x4b, 0x64, 0x02,
  	0xff, 0x65, 0x90, 0x02,
  	0x50, 0x6a, 0x60, 0x00,
! 	0x00, 0xa1, 0x54, 0x19,
! 	0x04, 0xa0, 0x54, 0x1f,
! 	0x20, 0xa0, 0x44, 0x1b,
! 	0xff, 0x3e, 0x46, 0x1d,
! 	0x00, 0x65, 0x54, 0x11,
  	0xff, 0x3e, 0x64, 0x02,
! 	0x00, 0xb9, 0x54, 0x19,
! 	0x04, 0x4a, 0x53, 0x1f,
! 	0xff, 0xba, 0x4c, 0x1d,
  	0xff, 0xbb, 0x50, 0x02,
  	0xff, 0xba, 0x90, 0x02,
  	0xff, 0x50, 0xbb, 0x02,
  	0xff, 0x65, 0x90, 0x02,
! 	0xff, 0xbb, 0x52, 0x1d,
  	0xff, 0xba, 0x50, 0x02,
  	0xff, 0xbb, 0x90, 0x02,
  	0xff, 0x50, 0xba, 0x02,
--- 301,340 ----
  	0xd1, 0x6a, 0x91, 0x00,
  	0x00, 0x65, 0x48, 0x10,
  	0xff, 0x65, 0x93, 0x02,
! 	0x01, 0x0b, 0x31, 0x1b,
  	0x10, 0x0c, 0x2e, 0x1f,
! 	0xff, 0x6a, 0x65, 0x02,
! 	0x04, 0x93, 0x33, 0x1b,
! 	0x01, 0x94, 0x32, 0x1f,
! 	0x10, 0x94, 0x33, 0x1b,
! 	0xc7, 0x93, 0x93, 0x02,
! 	0xff, 0x99, 0x6a, 0x02,
! 	0x08, 0x93, 0x35, 0x1b,
  	0xff, 0x6a, 0x6a, 0x03,
  	0xf0, 0x65, 0x65, 0x02,
  	0x0f, 0x05, 0x64, 0x02,
  	0x00, 0x65, 0x65, 0x00,
  	0xff, 0x65, 0x05, 0x03,
! 	0x80, 0x4a, 0x37, 0x1f,
! 	0x40, 0x4a, 0x37, 0x1b,
  	0x21, 0x6a, 0x91, 0x01,
  	0xff, 0x4b, 0x64, 0x02,
  	0xff, 0x65, 0x90, 0x02,
  	0x50, 0x6a, 0x60, 0x00,
! 	0x00, 0xa1, 0x57, 0x19,
! 	0x04, 0xa0, 0x57, 0x1f,
! 	0x20, 0xa0, 0x47, 0x1b,
! 	0xff, 0x3e, 0x49, 0x1d,
! 	0x00, 0x65, 0x57, 0x11,
  	0xff, 0x3e, 0x64, 0x02,
! 	0x00, 0xb9, 0x57, 0x19,
! 	0x04, 0x4a, 0x56, 0x1f,
! 	0xff, 0xba, 0x4f, 0x1d,
  	0xff, 0xbb, 0x50, 0x02,
  	0xff, 0xba, 0x90, 0x02,
  	0xff, 0x50, 0xbb, 0x02,
  	0xff, 0x65, 0x90, 0x02,
! 	0xff, 0xbb, 0x55, 0x1d,
  	0xff, 0xba, 0x50, 0x02,
  	0xff, 0xbb, 0x90, 0x02,
  	0xff, 0x50, 0xba, 0x02,
***************
*** 342,352 ****
  	0x10, 0x6a, 0x60, 0x00,
  	0x01, 0x65, 0x65, 0x06,
  	0xff, 0x47, 0x64, 0x02,
! 	0x00, 0x65, 0x3c, 0x19,
  	0x31, 0x6a, 0x91, 0x00,
! 	0x10, 0x3f, 0x34, 0x1d,
  	0x10, 0x03, 0x03, 0x00,
! 	0xff, 0x3e, 0x5e, 0x19,
  	0x06, 0x6a, 0x1c, 0x17,
  	0x00, 0x65, 0x48, 0x10,
  	0x0d, 0x6a, 0x1c, 0x17,
--- 345,355 ----
  	0x10, 0x6a, 0x60, 0x00,
  	0x01, 0x65, 0x65, 0x06,
  	0xff, 0x47, 0x64, 0x02,
! 	0x00, 0x65, 0x3f, 0x19,
  	0x31, 0x6a, 0x91, 0x00,
! 	0x10, 0x3f, 0x37, 0x1d,
  	0x10, 0x03, 0x03, 0x00,
! 	0xff, 0x3e, 0x61, 0x19,
  	0x06, 0x6a, 0x1c, 0x17,
  	0x00, 0x65, 0x48, 0x10,
  	0x0d, 0x6a, 0x1c, 0x17,
***************
*** 366,372 ****
  	0xff, 0xa5, 0x44, 0x02,
  	0xff, 0xa6, 0x45, 0x02,
  	0xff, 0xa7, 0x46, 0x03,
! 	0x10, 0x4a, 0x34, 0x1f,
  	0xff, 0x42, 0xa3, 0x02,
  	0xff, 0x43, 0xa4, 0x02,
  	0xff, 0x44, 0xa5, 0x02,
--- 369,375 ----
  	0xff, 0xa5, 0x44, 0x02,
  	0xff, 0xa6, 0x45, 0x02,
  	0xff, 0xa7, 0x46, 0x03,
! 	0x10, 0x4a, 0x37, 0x1f,
  	0xff, 0x42, 0xa3, 0x02,
  	0xff, 0x43, 0xa4, 0x02,
  	0xff, 0x44, 0xa5, 0x02,
***************
*** 380,385 ****
  	0xff, 0xaa, 0xb1, 0x02,
  	0xff, 0xab, 0xb2, 0x03,
  	0x4c, 0x05, 0x64, 0x0a,
! 	0x08, 0x1f, 0x7f, 0x1f,
  	0x08, 0x64, 0x64, 0x00,
  	0x20, 0x64, 0x65, 0x07,
--- 383,388 ----
  	0xff, 0xaa, 0xb1, 0x02,
  	0xff, 0xab, 0xb2, 0x03,
  	0x4c, 0x05, 0x64, 0x0a,
! 	0x08, 0x1f, 0x82, 0x1f,
  	0x08, 0x64, 0x64, 0x00,
  	0x20, 0x64, 0x65, 0x07,