Subject: kern/22078: New ahc driver accesses channel A instead of channel B on an AHA-274x adapter
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mhitch@lightning.msu.montana.edu>
List: netbsd-bugs
Date: 07/06/2003 20:30:24
>Number:         22078
>Category:       kern
>Synopsis:       New ahc driver fails to access channel B on a Twin channel AHA-274x adapter
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 07 02:31:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Michael Hitch
>Release:        NetBSD 1.6U
>Organization:
Montana State University
	
>Environment:
	
	
System: NetBSD net4.msu.montana.edu 1.6U NetBSD 1.6U (PROXY) #2: Thu Jul 3 22:22:12 MDT 2003 mhitch@net4.msu.montana.edu:/src/NetBSD-current/src/sys/arch/i386/compile/PROXY i386
Architecture: i386
Machine: i386
>Description:
The new ahc driver in -current (1.6U) fails to access the second channel (channel B)
on a Twin channel AHA-274x adapter, and accesses the first channel (channel A)
instead.
>How-To-Repeat:
  Install a disk drive on the second channel of an Adaptec AHA-274x SCSI adapter to
test.

  Boot 1.6 or 1.6.1  with no glitches.  Boot a recent (1.6U) kernel and
see *way* too many disks probed.  Realize that the new drive on channel B doesn't
get probed and that all the extra disks are the same ones found on channel A.

Jul  1 17:10:15 net4 /netbsd: ahc1 at eisa0 slot 1: Adaptec AHA-274x SCSI
Jul  1 17:10:15 net4 /netbsd: ahc1: level sensitive interrupting at irq 11
Jul  1 17:10:15 net4 /netbsd: ahc1: aic7770 >= Rev E, ahc1: aic7770: Twin Channel, A SCSI Id=7, B SCSI Id=7, primary A, 4/253 SCBs
Jul  1 17:10:15 net4 /netbsd: scsibus0 at ahc1 channel 0: 8 targets, 8 luns per target
Jul  1 17:10:15 net4 /netbsd: scsibus1 at ahc1 channel 1: 8 targets, 8 luns per target
--
Jul  1 17:10:16 net4 /netbsd: scsibus0: waiting 2 seconds for devices to settle...
Jul  1 17:10:16 net4 /netbsd: scsibus1: waiting 2 seconds for devices to settle...
Jul  1 17:10:16 net4 /netbsd: sd0 at scsibus0 target 0 lun 0: <SEAGATE, ST51080N, 0958> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd0: 1030 MB, 4826 cyl, 4 head, 109 sec, 512 bytes/sect x 2109840 sectors
Jul  1 17:10:16 net4 /netbsd: sd0: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
Jul  1 17:10:16 net4 /netbsd: sd1 at scsibus0 target 1 lun 0: <SEAGATE, ST51080N, 0958> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd1: 1030 MB, 4826 cyl, 4 head, 109 sec, 512 bytes/sect x 2109840 sectors
Jul  1 17:10:16 net4 /netbsd: sd1: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
Jul  1 17:10:16 net4 /netbsd: sd2 at scsibus0 target 2 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd2: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
Jul  1 17:10:16 net4 /netbsd: sd2: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
Jul  1 17:10:16 net4 /netbsd: sd3 at scsibus0 target 3 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd3: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
Jul  1 17:10:16 net4 /netbsd: sd3: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
Jul  1 17:10:16 net4 /netbsd: sd4 at scsibus0 target 4 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd4: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
Jul  1 17:10:16 net4 /netbsd: sd4: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
Jul  1 17:10:16 net4 /netbsd: cd0 at scsibus0 target 6 lun 0: <PLEXTOR, CD-ROM PX-8XCS, 1.02> cdrom removable
Jul  1 17:10:16 net4 /netbsd: cd0: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers
Jul  1 17:10:16 net4 /netbsd: sd5 at scsibus1 target 0 lun 0: <SEAGATE, ST51080N, 0958> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd5: 1030 MB, 4826 cyl, 4 head, 109 sec, 512 bytes/sect x 2109840 sectors
Jul  1 17:10:16 net4 /netbsd: sd6 at scsibus1 target 1 lun 0: <SEAGATE, ST51080N, 0958> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd6: 1030 MB, 4826 cyl, 4 head, 109 sec, 512 bytes/sect x 2109840 sectors
Jul  1 17:10:16 net4 /netbsd: sd7 at scsibus1 target 2 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd7: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
Jul  1 17:10:16 net4 /netbsd: sd8 at scsibus1 target 3 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd8: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
Jul  1 17:10:16 net4 /netbsd: sd9 at scsibus1 target 4 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
Jul  1 17:10:16 net4 /netbsd: sd9: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
Jul  1 17:10:16 net4 /netbsd: cd1 at scsibus1 target 6 lun 0: <PLEXTOR, CD-ROM PX-8XCS, 1.02> cdrom removable
Jul  1 17:10:16 net4 /netbsd: raid0: RAID Level 5


  Poke around in the new driver and try to compare with the old driver and become
rather confused (the driver was changed significantly).  Guessing that the adapter
is not selecting the B channel correctly, try to figure out how the old driver
does the selection and try to figure out where the new driver is (or should be)
selecting the B channel.  Find a possible place that looks like maybe the channel
B select bit is never set, but can't be certain because the driver had changed
so much.

  Finally take a look at the FreeBSD driver and almost immediately spot
where the channel B select bit gets set, and notice that part is completely
missing in the NetBSD driver.  Add the missing code to the NetBSD driver and
find it fails to compile because it's using FreeBSD-specific data.
>Fix:
  The missing bit of code was in the BUILD_SCSIID() macro defined in
aic7xxx_osm.h.  The FreeBSD code passed the address of a data structure
which contains the channel information, and had been replaced with a 0
in the NetBSD version, and never referenced in the macro.  I modified the
macro to use that argument as a channel B flag, and changed the macro call
to reference periph->periph_channel->chan_channel.  With this change, the
adapter no longer probes channel A when it's supposed to be probing channel
B.  I have not verified that channel B is accessed properly yet, since I do
not currently have any drives on channel B.

ahc0 at eisa0 slot 1: Adaptec AHA-274x SCSI
ahc0: level sensitive interrupting at irq 11
ahc0: aic7770 >= Rev E, ahc0: aic7770: Twin Channel, A SCSI Id=7, B SCSI Id=7, primary A, 4/253 SCBs
scsibus0 at ahc0 channel 0: 8 targets, 8 luns per target
scsibus1 at ahc0 channel 1: 8 targets, 8 luns per target
--
scsibus0: waiting 2 seconds for devices to settle...
scsibus1: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <SEAGATE, ST51080N, 0958> disk fixed
sd0: 1030 MB, 4826 cyl, 4 head, 109 sec, 512 bytes/sect x 2109840 sectors
sd0: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
sd1 at scsibus0 target 1 lun 0: <SEAGATE, ST51080N, 0958> disk fixed
sd1: 1030 MB, 4826 cyl, 4 head, 109 sec, 512 bytes/sect x 2109840 sectors
sd1: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
sd2 at scsibus0 target 2 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
sd2: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
sd2: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
sd3 at scsibus0 target 3 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
sd3: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
sd3: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
sd4 at scsibus0 target 4 lun 0: <CONNER, CFP4207S  4.28GB, 5767> disk fixed
sd4: 4096 MB, 3999 cyl, 20 head, 104 sec, 512 bytes/sect x 8388608 sectors
sd4: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers, tagged queueing
cd0 at scsibus0 target 6 lun 0: <PLEXTOR, CD-ROM PX-8XCS, 1.02> cdrom removable
cd0: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers
raid0: RAID Level 5

  (The adapter configured as ahc0 in this kernel since it was a trimmed down
custom kernel, while the previous log output was from a GENERIC kernel).

  This is the patch I used to fix this problem.

Index: aic7xxx_osm.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/aic7xxx_osm.c,v
retrieving revision 1.9
diff -u -b -r1.9 aic7xxx_osm.c
--- aic7xxx_osm.c	2003/06/19 20:11:14	1.9
+++ aic7xxx_osm.c	2003/07/04 17:44:45
@@ -312,7 +312,8 @@
 		 * Put all the arguments for the xfer in the scb
 		 */
 		hscb->control = 0;
-		hscb->scsiid = BUILD_SCSIID(ahc, 0, target_id, our_id);
+		hscb->scsiid = BUILD_SCSIID(ahc, periph->periph_channel->chan_channel,
+		    target_id, our_id);
 		hscb->lun = periph->periph_lun;
 		if (xs->xs_control & XS_CTL_RESET) {
 			hscb->cdb_len = 0;
Index: aic7xxx_osm.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/aic7xxx_osm.h,v
retrieving revision 1.5
diff -u -b -r1.5 aic7xxx_osm.h
--- aic7xxx_osm.h	2003/05/04 23:37:27	1.5
+++ aic7xxx_osm.h	2003/07/04 17:44:45
@@ -86,7 +86,8 @@
 	(((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
 					      : ahc->platform_data->path)
 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
-        ((((target_id) << TID_SHIFT) & TID) | (our_id))
+        ((((target_id) << TID_SHIFT) & TID) | (our_id) \
+	| (sim ? TWIN_CHNLB : 0))
 
 #define SCB_GET_SIM(ahc, scb) \
 	(SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \

>Release-Note:
>Audit-Trail:
>Unformatted: