| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ata_raid_via.c,v 1.5 2008/03/18 20:46:36 cube Exp $ */ | | 1 | /* $NetBSD: ata_raid_via.c,v 1.6 2008/09/19 16:49:27 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2000,2001,2002 Søren Schmidt <sos@FreeBSD.org> | | 4 | * Copyright (c) 2000,2001,2002 Søren Schmidt <sos@FreeBSD.org> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer, | | 11 | * notice, this list of conditions and the following disclaimer, |
12 | * without modification, immediately at the beginning of the file. | | 12 | * without modification, immediately at the beginning of the file. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -25,27 +25,27 @@ | | | @@ -25,27 +25,27 @@ |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ | | 29 | */ |
30 | | | 30 | |
31 | /* | | 31 | /* |
32 | * Support for parsing VIA V-RAID ATA RAID controller configuration blocks. | | 32 | * Support for parsing VIA V-RAID ATA RAID controller configuration blocks. |
33 | * | | 33 | * |
34 | * Adapted to NetBSD by Tim Rightnour (garbled@netbsd.org) | | 34 | * Adapted to NetBSD by Tim Rightnour (garbled@netbsd.org) |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: ata_raid_via.c,v 1.5 2008/03/18 20:46:36 cube Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: ata_raid_via.c,v 1.6 2008/09/19 16:49:27 christos Exp $"); |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/buf.h> | | 41 | #include <sys/buf.h> |
42 | #include <sys/bufq.h> | | 42 | #include <sys/bufq.h> |
43 | #include <sys/conf.h> | | 43 | #include <sys/conf.h> |
44 | #include <sys/device.h> | | 44 | #include <sys/device.h> |
45 | #include <sys/disk.h> | | 45 | #include <sys/disk.h> |
46 | #include <sys/disklabel.h> | | 46 | #include <sys/disklabel.h> |
47 | #include <sys/fcntl.h> | | 47 | #include <sys/fcntl.h> |
48 | #include <sys/malloc.h> | | 48 | #include <sys/malloc.h> |
49 | #include <sys/vnode.h> | | 49 | #include <sys/vnode.h> |
50 | #include <sys/kauth.h> | | 50 | #include <sys/kauth.h> |
51 | | | 51 | |
| @@ -110,27 +110,27 @@ ata_raid_via_print_info(struct via_raid_ | | | @@ -110,27 +110,27 @@ ata_raid_via_print_info(struct via_raid_ |
110 | printf("=================================================\n"); | | 110 | printf("=================================================\n"); |
111 | } | | 111 | } |
112 | #endif | | 112 | #endif |
113 | | | 113 | |
114 | int | | 114 | int |
115 | ata_raid_read_config_via(struct wd_softc *sc) | | 115 | ata_raid_read_config_via(struct wd_softc *sc) |
116 | { | | 116 | { |
117 | struct via_raid_conf *info; | | 117 | struct via_raid_conf *info; |
118 | struct atabus_softc *atabus; | | 118 | struct atabus_softc *atabus; |
119 | struct vnode *vp; | | 119 | struct vnode *vp; |
120 | int bmajor, error; | | 120 | int bmajor, error; |
121 | dev_t dev; | | 121 | dev_t dev; |
122 | uint32_t drive; | | 122 | uint32_t drive; |
123 | uint8_t checksum, *ptr; | | 123 | uint8_t checksum, checksum_alt, byte3, *ptr; |
124 | int count, disk; | | 124 | int count, disk; |
125 | struct ataraid_array_info *aai; | | 125 | struct ataraid_array_info *aai; |
126 | struct ataraid_disk_info *adi; | | 126 | struct ataraid_disk_info *adi; |
127 | | | 127 | |
128 | info = malloc(sizeof(*info), M_DEVBUF, M_WAITOK); | | 128 | info = malloc(sizeof(*info), M_DEVBUF, M_WAITOK); |
129 | | | 129 | |
130 | bmajor = devsw_name2blk(device_xname(sc->sc_dev), NULL, 0); | | 130 | bmajor = devsw_name2blk(device_xname(sc->sc_dev), NULL, 0); |
131 | | | 131 | |
132 | /* Get a vnode for the raw partition of this disk. */ | | 132 | /* Get a vnode for the raw partition of this disk. */ |
133 | dev = MAKEDISKDEV(bmajor, device_unit(sc->sc_dev), RAW_PART); | | 133 | dev = MAKEDISKDEV(bmajor, device_unit(sc->sc_dev), RAW_PART); |
134 | error = bdevvp(dev, &vp); | | 134 | error = bdevvp(dev, &vp); |
135 | if (error) | | 135 | if (error) |
136 | goto out; | | 136 | goto out; |
| @@ -155,35 +155,38 @@ ata_raid_read_config_via(struct wd_softc | | | @@ -155,35 +155,38 @@ ata_raid_read_config_via(struct wd_softc |
155 | ata_raid_via_print_info(info); | | 155 | ata_raid_via_print_info(info); |
156 | printf("MAGIC == 0x%02x\n", info->magic); | | 156 | printf("MAGIC == 0x%02x\n", info->magic); |
157 | #endif | | 157 | #endif |
158 | | | 158 | |
159 | /* Check the signature. */ | | 159 | /* Check the signature. */ |
160 | if (info->magic != VIA_MAGIC) { | | 160 | if (info->magic != VIA_MAGIC) { |
161 | DPRINTF(("%s: VIA V-RAID signature check failed\n", | | 161 | DPRINTF(("%s: VIA V-RAID signature check failed\n", |
162 | device_xname(sc->sc_dev))); | | 162 | device_xname(sc->sc_dev))); |
163 | error = ESRCH; | | 163 | error = ESRCH; |
164 | goto out; | | 164 | goto out; |
165 | } | | 165 | } |
166 | | | 166 | |
167 | /* calculate checksum and compare for valid */ | | 167 | /* calculate checksum and compare for valid */ |
168 | for (checksum = 0, ptr = (uint8_t *)info, count = 0; count < 50; | | 168 | for (byte3 = 0, checksum = 0, ptr = (uint8_t *)info, count = 0; |
169 | count++) | | 169 | count < 50; count++) |
170 | if (count == 3) | | 170 | if (count == 3) |
171 | checksum += *ptr++ & ~ VIA_T_BOOTABLE; | | 171 | byte3 = *ptr++; |
172 | else | | 172 | else |
173 | checksum += *ptr++; | | 173 | checksum += *ptr++; |
174 | if (checksum != info->checksum) { | | 174 | checksum_alt = checksum + (byte3 & ~VIA_T_BOOTABLE); |
175 | DPRINTF(("%s: VIA V-RAID checksum failed 0x%02x != 0x%02x\n", | | 175 | checksum += byte3; |
176 | device_xname(sc->sc_dev), checksum, info->checksum)); | | 176 | if (checksum != info->checksum && checksum_alt != info->checksum) { |
| | | 177 | DPRINTF(("%s: VIA V-RAID checksum failed 0x%02x != " |
| | | 178 | "0x%02x or 0x%02x\n", device_xname(sc->sc_dev), |
| | | 179 | info->checksum, checksum, checksum_alt)); |
177 | error = ESRCH; | | 180 | error = ESRCH; |
178 | goto out; | | 181 | goto out; |
179 | } | | 182 | } |
180 | | | 183 | |
181 | /* | | 184 | /* |
182 | * Lookup or allocate a new array info structure for | | 185 | * Lookup or allocate a new array info structure for |
183 | * this array. Use the serial number of disk0 as the array# | | 186 | * this array. Use the serial number of disk0 as the array# |
184 | */ | | 187 | */ |
185 | aai = ata_raid_get_array_info(ATA_RAID_TYPE_VIA, info->disks[0]); | | 188 | aai = ata_raid_get_array_info(ATA_RAID_TYPE_VIA, info->disks[0]); |
186 | | | 189 | |
187 | aai->aai_status = AAI_S_READY; | | 190 | aai->aai_status = AAI_S_READY; |
188 | | | 191 | |
189 | switch (info->type & VIA_T_MASK) { | | 192 | switch (info->type & VIA_T_MASK) { |