Module Name: src Committed By: andvar Date: Tue Mar 11 16:51:31 UTC 2025
Modified Files: src/sys/dev/ata: ata_raid_via.c Log Message: ataraid(4): obtain VIA V-RAID drive index from configuration blocks. The original logic resolved disk index based on the drive channel it was attached to. However, VX800 and some other VIA controllers have two SATA ports per channel, which causes unintended overrides when two disks share the same channel. VIA V-RAID configuration blocks store the disk index as a value incrementing by 0x04 (0x00, 0x04, 0x08, 0x0C). Therefore, shift the value left by 2 obtains the disk number. Additionally, limit disk number to 4, which is the maximum supported by any VIA RAID configuration. Fixes PR kern/59130. Tested on VX800/VT6421A/VT8251 RAID controllers. pull-ups needed for netbsd-9, netbsd-10. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/dev/ata/ata_raid_via.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ata/ata_raid_via.c diff -u src/sys/dev/ata/ata_raid_via.c:1.10 src/sys/dev/ata/ata_raid_via.c:1.11 --- src/sys/dev/ata/ata_raid_via.c:1.10 Sat Mar 19 13:51:01 2022 +++ src/sys/dev/ata/ata_raid_via.c Tue Mar 11 16:51:31 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: ata_raid_via.c,v 1.10 2022/03/19 13:51:01 hannken Exp $ */ +/* $NetBSD: ata_raid_via.c,v 1.11 2025/03/11 16:51:31 andvar Exp $ */ /*- * Copyright (c) 2000,2001,2002 Søren Schmidt <s...@freebsd.org> @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ata_raid_via.c,v 1.10 2022/03/19 13:51:01 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ata_raid_via.c,v 1.11 2025/03/11 16:51:31 andvar Exp $"); #include <sys/param.h> #include <sys/buf.h> @@ -115,7 +115,6 @@ ata_raid_read_config_via(struct wd_softc { struct dk_softc *dksc = &sc->sc_dksc; struct via_raid_conf *info; - struct atabus_softc *atabus; struct vnode *vp; int bmajor, error; dev_t dev; @@ -223,7 +222,11 @@ ata_raid_read_config_via(struct wd_softc } aai->aai_type = ATA_RAID_TYPE_VIA; - for (count = 0, disk = 0; disk < 8; disk++) + /* + * VIA V-RAID supports up to four drives in RAID 0 and JBOD + * configurations and up to two drives in a RAID 1 configuration. + */ + for (count = 0, disk = 0; disk < 4; disk++) if (info->disks[disk]) count++; aai->aai_interleave = @@ -239,8 +242,12 @@ ata_raid_read_config_via(struct wd_softc if (aai->aai_interleave == 0) aai->aai_interleave = aai->aai_capacity; - atabus = device_private(device_parent(dksc->sc_dev)); - drive = atabus->sc_chan->ch_channel; + /* + * VIA V-RAID configuration blocks store the disk index as a value + * incrementing by 0x04 (0x00, 0x04, 0x08, 0x0C). Therefore, shift + * the value left by 2 to obtain the disk number. + */ + drive = info->disk_index >> 2; if (drive >= aai->aai_ndisks) { aprint_error_dev(dksc->sc_dev, "drive number %d doesn't make sense within %d-disk "