Subject: Fix for AHA-1542CP
To: None <netbsd-bugs@NetBSD.ORG>
From: David Rosenthal <dshr@abitare.org>
List: netbsd-bugs
Date: 09/17/1995 07:09:12
The current Adaptec ISA SCSI Host Adaptor is the AHA-1542CP.  It returns
boardid 0x46.  The NetBSD 1.0 and current drivers assume that any board
with an unrecongized boardid does *not* need its mailbox unlocked,  so
they don't work with the 1542CP.  Note that the 1542CP probably
needs to be configured with the Plug-and-Play BIOS disabled in all systems,
certainly in mine.

You need to assume that future 1542s and clones will need their mailbox
unlocked,  so that NetBSD doesn't fail every time they rev the BIOS.

	David.

*** aha1542.c.orig	Wed Jul 27 22:24:17 1994
--- aha1542.c	Sat Sep 16 11:44:42 1995
***************
*** 258,272 ****
  
  struct aha_inquire {
  	u_char	boardid;		/* type of board */
- 					/* 0x20 = BusLogic 545, but it gets
- 					   the command wrong, only returns
- 					   one byte */
- 					/* 0x31 = AHA-1540 */
- 					/* 0x41 = AHA-1540A/1542A/1542B */
- 					/* 0x42 = AHA-1640 */
- 					/* 0x43 = AHA-1542C */
- 					/* 0x44 = AHA-1542CF */
- 					/* 0x45 = AHA-1542CF, BIOS v2.01 */
  	u_char	spec_opts;		/* special options ID */
  					/* 0x41 = Board is standard model */
  	u_char	revision_1;		/* firmware revision [0-9A-Z] */
--- 258,263 ----
***************
*** 290,295 ****
--- 281,308 ----
  #define CHAN6	0x40
  #define CHAN7	0x80
  
+ #define	NO_MBOX	0x01
+ #define	SETUP_DELAY 0x02
+ static struct aha_boardtype {
+ 	char	*name;
+ 	u_char	boardid;
+ 	u_char	flags;
+ } boardtype[] = {
+ 	"BusLogic 545", 0x20, (NO_MBOX|SETUP_DELAY),
+ 					/* 0x20 = BusLogic 545, but it gets
+ 					   the command wrong, only returns
+ 					   one byte */
+ 	"AHA-1540", 0x31, NO_MBOX,	/* 0x31 = AHA-1540 */
+ 	"AHA-1540A,42A,42B", 0x41, NO_MBOX, /* 0x41 = AHA-1540A/1542A/1542B */
+ 	"AHA-1640", 0x42, NO_MBOX,	/* 0x42 = AHA-1640 */
+ 	"AHA-1542C", 0x43, 0,		/* 0x43 = AHA-1542C */
+ 	"AHA-1542CF", 0x44, 0,		/* 0x44 = AHA-1542CF */
+ 	"AHA-1542CF", 0x45, 0,		/* 0x45 = AHA-1542CF, BIOS v2.01 */
+ 	"AHA-1542CP", 0x46, 0,		/* 0x46 = AHA-1542CP */
+ 	"unknown AHA", 0x0, 0,		/* catch-all */
+ };
+ static struct aha_boardtype *btp = NULL;
+ 
  /*********************************** end of board definitions***************/
  
  #define PHYSTOKV(x)	(((long int)(x)) ^ aha->kv_phys_xor)
***************
*** 907,927 ****
  		inquire.boardid, inquire.spec_opts,
  		inquire.revision_1, inquire.revision_2);
  #endif	/* AHADEBUG */
  	/*
! 	 * If we are a 1542C or 1542CF disable the extended bios so that the
  	 * mailbox interface is unlocked.
  	 * No need to check the extended bios flags as some of the
  	 * extensions that cause us problems are not flagged in that byte.
  	 */
! 	if (inquire.boardid == 0x43 || inquire.boardid == 0x44 ||
! 	    inquire.boardid == 0x45) {
  		aha_cmd(aha, 0, sizeof(extbios), 0, &extbios, AHA_EXT_BIOS);
  #ifdef	AHADEBUG
  		printf("%s: extended bios flags %x\n", aha->sc_dev.dv_xname,
  			extbios.flags);
  #endif	/* AHADEBUG */
- 		printf("%s: 1542C/CF detected, unlocking mailbox\n",
- 			aha->sc_dev.dv_xname);
  		aha_cmd(aha, 2, 0, 0, 0, AHA_MBX_ENABLE,
  			0, extbios.mailboxlock);
  	}
--- 920,949 ----
  		inquire.boardid, inquire.spec_opts,
  		inquire.revision_1, inquire.revision_2);
  #endif	/* AHADEBUG */
+ 	{
+ 		int	i;
+ 		
+ 		for (i=0; i<(sizeof boardtype)/(sizeof boardtype[0]); i++) {
+ 			if (inquire.boardid == boardtype[i].boardid ||
+ 			    boardtype[i].boardid == 0) {
+ 				btp = boardtype + i;
+ 				break;
+ 			}
+ 		}
+ 	}
  	/*
! 	 * If we have a mailbox disable the extended bios so that the
  	 * mailbox interface is unlocked.
  	 * No need to check the extended bios flags as some of the
  	 * extensions that cause us problems are not flagged in that byte.
  	 */
! 	printf("%s: %s detected\n", aha->sc_dev.dv_xname, btp->name);
! 	if (!(btp->flags & NO_MBOX)) {
  		aha_cmd(aha, 0, sizeof(extbios), 0, &extbios, AHA_EXT_BIOS);
  #ifdef	AHADEBUG
  		printf("%s: extended bios flags %x\n", aha->sc_dev.dv_xname,
  			extbios.flags);
  #endif	/* AHADEBUG */
  		aha_cmd(aha, 2, 0, 0, 0, AHA_MBX_ENABLE,
  			0, extbios.mailboxlock);
  	}
***************
*** 931,937 ****
  	 * setup dma channel from jumpers and save int
  	 * level
  	 */
! 	delay(1000);		/* for Bustek 545 */
  	aha_cmd(aha, 0, sizeof(conf), 0, &conf, AHA_CONF_GET);
  	switch (conf.chan) {
  	case CHAN0:
--- 953,959 ----
  	 * setup dma channel from jumpers and save int
  	 * level
  	 */
! 	if (btp->flags & SETUP_DELAY) delay(1000);	/* for Bustek 545 */
  	aha_cmd(aha, 0, sizeof(conf), 0, &conf, AHA_CONF_GET);
  	switch (conf.chan) {
  	case CHAN0: