Subject: kern/36593: VIA raid checksum error
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <prlw1@cam.ac.uk>
List: netbsd-bugs
Date: 07/02/2007 11:40:00
>Number:         36593
>Category:       kern
>Synopsis:       Odd checksum calculation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 02 11:40:00 +0000 2007
>Originator:     Patrick Welche
>Release:        NetBSD 4.99.22/i386
>Organization:
	
>Environment:
VIA Tech. VT8237 SATA RAID BIOS Ver 2.31
>Description:
Back in December 2005, I knocked together ata_via_raid.c for a computer with
a VT8237 which I don't have access to much. Finally, I thought I would tidy
the code up and send it in, but happily see that Tim already added support
for this card in March, so I tried it, but my disks aren't recognised by
a standard GENERIC kernel due to a checksum mismatch. The difference
between our codes is the way the checksum is calculated in the driver,
and given that we both must have used the FreeBSD driver as documentation,
I wonder why there is an additional complication in the NetBSD version.

My disks look like this:

        uint16_t        magic   =       0xaa55
        uint8_t         dummy_0 =       0
        uint8_t         type    =       0x0d = 00001101
                                        0x7e = 01111110        = VIA_T_MASK
                                 0x0d & 0x7e = 00001100 = 0x0c = VIA_T_RAID1
        uint8_t         disk_index =    0                       0x4
        uint8_t         stripe_layout = 0
        uint64_t        disk_sectors =  0x17bd87ff = 398297087 = 190GB
        uint32_t        disk_id =       0xf50e6f4e              0x181a5c63
        uint32_t        disks[0] =      0xf50e6f4e              0xf50e6f4e
                        disks[1] =      0x181a5c63              0x181a5c63
        uint8_t         checksum =      0xd7                    0x0c

        uint8_t         filler_1[461];

>How-To-Repeat:
>Fix:
Index: ata_raid_via.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ata/ata_raid_via.c,v
retrieving revision 1.1
diff -u -r1.1 ata_raid_via.c
--- ata_raid_via.c	27 Mar 2007 00:10:20 -0000	1.1
+++ ata_raid_via.c	2 Jul 2007 11:23:45 -0000
@@ -166,10 +166,7 @@
 	/* calculate checksum and compare for valid */
 	for (checksum = 0, ptr = (uint8_t *)info, count = 0; count < 50;
 	    count++)
-		if (count == 3)
-			checksum += *ptr++ & ~ VIA_T_BOOTABLE;
-		else
-			checksum += *ptr++;
+		checksum += *ptr++;
 	if (checksum != info->checksum) {
 		DPRINTF(("%s: VIA V-RAID checksum failed 0x%02x != 0x%02x\n",
 		    sc->sc_dev.dv_xname, checksum, info->checksum));