Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ata Basic support for RAID0 and RAID1 for the Adapte...



details:   https://anonhg.NetBSD.org/src/rev/4616fec128cd
branches:  trunk
changeset: 582193:4616fec128cd
user:      briggs <briggs%NetBSD.org@localhost>
date:      Mon Jun 20 02:11:57 2005 +0000

description:
Basic support for RAID0 and RAID1 for the Adaptec HostRAID format as found
on the Intel 6300ESB on-board RAID.  Adapted from FreeBSD.

diffstat:

 sys/dev/ata/ata_raid.c         |    6 +-
 sys/dev/ata/ata_raid_adaptec.c |  187 +++++++++++++++++++++++++++++++++++++++++
 sys/dev/ata/ata_raidreg.h      |   62 +++++++++++++-
 sys/dev/ata/ata_raidvar.h      |    8 +-
 sys/dev/ata/files.ata          |    3 +-
 5 files changed, 260 insertions(+), 6 deletions(-)

diffs (truncated from 336 to 300 lines):

diff -r f1a371949d48 -r 4616fec128cd sys/dev/ata/ata_raid.c
--- a/sys/dev/ata/ata_raid.c    Mon Jun 20 02:10:18 2005 +0000
+++ b/sys/dev/ata/ata_raid.c    Mon Jun 20 02:11:57 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata_raid.c,v 1.12 2005/05/29 22:11:28 christos Exp $   */
+/*     $NetBSD: ata_raid.c,v 1.13 2005/06/20 02:11:57 briggs Exp $     */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata_raid.c,v 1.12 2005/05/29 22:11:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata_raid.c,v 1.13 2005/06/20 02:11:57 briggs Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -259,6 +259,8 @@
 {
        struct wd_softc *sc = (void *) self;
 
+       if (ata_raid_read_config_adaptec(sc) == 0)
+               return;
        if (ata_raid_read_config_promise(sc) == 0)
                return;
 }
diff -r f1a371949d48 -r 4616fec128cd sys/dev/ata/ata_raid_adaptec.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ata/ata_raid_adaptec.c    Mon Jun 20 02:11:57 2005 +0000
@@ -0,0 +1,187 @@
+/*     $NetBSD: ata_raid_adaptec.c,v 1.1 2005/06/20 02:11:57 briggs Exp $      */
+
+/*-
+ * Copyright (c) 2000,2001,2002 Søren Schmidt <sos%FreeBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer,
+ *    without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Support for parsing Adaptec ATA RAID controller configuration blocks.
+ *
+ * Adapted to NetBSD by Allen K. Briggs
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ata_raid_adaptec.c,v 1.1 2005/06/20 02:11:57 briggs Exp $");
+
+#include <sys/param.h>
+#include <sys/buf.h>
+#include <sys/bufq.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/disk.h>
+#include <sys/disklabel.h>
+#include <sys/fcntl.h>
+#include <sys/malloc.h>
+#include <sys/vnode.h>
+
+#include <miscfs/specfs/specdev.h>
+
+#include <dev/ata/atareg.h>
+#include <dev/ata/atavar.h>
+#include <dev/ata/wdvar.h>
+
+#include <dev/ata/ata_raidreg.h>
+#include <dev/ata/ata_raidvar.h>
+
+#ifdef ATA_RAID_DEBUG
+#define        DPRINTF(x)      printf x
+#else
+#define        DPRINTF(x)      /* nothing */
+#endif
+
+int
+ata_raid_read_config_adaptec(struct wd_softc *sc)
+{
+       struct adaptec_raid_conf *info;
+       struct atabus_softc *atabus;
+       struct vnode *vp;
+       int bmajor, error;
+       dev_t dev;
+       uint32_t gen, drive;
+       struct ataraid_array_info *aai;
+       struct ataraid_disk_info *adi;
+
+       info = malloc(sizeof(*info), M_DEVBUF, M_WAITOK);
+
+       bmajor = devsw_name2blk(sc->sc_dev.dv_xname, NULL, 0);
+
+       /* Get a vnode for the raw partition of this disk. */
+       dev = MAKEDISKDEV(bmajor, sc->sc_dev.dv_unit, RAW_PART);
+       error = bdevvp(dev, &vp);
+       if (error)
+               goto out;
+
+       error = VOP_OPEN(vp, FREAD, NOCRED, 0);
+       if (error) {
+               vput(vp);
+               goto out;
+       }
+
+       error = ata_raid_config_block_rw(vp, ADP_LBA(sc), info,
+           sizeof(*info), B_READ);
+       vput(vp);
+       if (error) {
+               printf("%s: error %d reading Adaptec config block\n",
+                   sc->sc_dev.dv_xname, error);
+               goto out;
+       }
+
+       info->magic_0 = be32toh(info->magic_0);
+       info->magic_1 = be32toh(info->magic_1);
+       info->magic_2 = be32toh(info->magic_2);
+       info->magic_3 = be32toh(info->magic_3);
+       info->magic_4 = be32toh(info->magic_4);
+       /* Check the signature. */
+       if (info->magic_0 != ADP_MAGIC_0 || info->magic_3 != ADP_MAGIC_3) {
+               DPRINTF(("%s: Adaptec signature check failed\n",
+                   sc->sc_dev.dv_xname));
+               error = ESRCH;
+               goto out;
+       }
+
+       /*
+        * Lookup or allocate a new array info structure for
+        * this array.
+        */
+       aai = ata_raid_get_array_info(ATA_RAID_TYPE_ADAPTEC,
+               be32toh(info->configs[0].disk_number));
+
+       gen = be32toh(info->generation);
+
+       if (gen == 0 || gen > aai->aai_generation) {
+               aai->aai_generation = gen;
+
+               aai->aai_status = AAI_S_READY;
+
+               switch (info->configs[0].type) {
+               case ADP_T_RAID0:
+                       aai->aai_level = AAI_L_RAID0;
+                       aai->aai_interleave = 
+                           (be16toh(info->configs[0].stripe_sectors) >> 1);
+                       aai->aai_width = be16toh(info->configs[0].total_disks);
+                       break;
+
+               case ADP_T_RAID1:
+                       aai->aai_level = AAI_L_RAID1;
+                       aai->aai_interleave = 0;
+                       aai->aai_width = be16toh(info->configs[0].total_disks)
+                           / 2;
+                       break;
+
+               default:
+                       aprint_error("%s: unknown Adaptec RAID type 0x%02x\n",
+                           sc->sc_dev.dv_xname, info->configs[0].type);
+                       error = EINVAL;
+                       goto out;
+               }
+
+               aai->aai_type = ATA_RAID_TYPE_ADAPTEC;
+               aai->aai_ndisks = be16toh(info->configs[0].total_disks);
+               aai->aai_capacity = be32toh(info->configs[0].sectors);
+               aai->aai_heads = 255;
+               aai->aai_sectors = 63;
+               aai->aai_cylinders = aai->aai_capacity / (63 * 255);
+               aai->aai_offset = 0;
+               aai->aai_reserved = 17;
+
+               /* XXX - bogus.  RAID1 shouldn't really have an interleave */
+               if (aai->aai_interleave == 0)
+                       aai->aai_interleave = aai->aai_capacity;
+       }
+
+       atabus = (struct atabus_softc *) sc->sc_dev.dv_parent;
+       drive = atabus->sc_chan->ch_channel;
+       if (drive >= aai->aai_ndisks) {
+               aprint_error("%s: drive number %d doesn't make sense within "
+                   "%d-disk array\n",
+                   sc->sc_dev.dv_xname, drive, aai->aai_ndisks);
+               error = EINVAL;
+               goto out;
+       }
+
+       adi = &aai->aai_disks[drive];
+       adi->adi_dev = &sc->sc_dev;
+       adi->adi_status = ADI_S_ONLINE | ADI_S_ASSIGNED;
+       adi->adi_sectors = aai->aai_capacity;
+       adi->adi_compsize = be32toh(info->configs[drive+1].sectors);
+
+       error = 0;
+
+ out:
+       free(info, M_DEVBUF);
+       return (error);
+}
diff -r f1a371949d48 -r 4616fec128cd sys/dev/ata/ata_raidreg.h
--- a/sys/dev/ata/ata_raidreg.h Mon Jun 20 02:10:18 2005 +0000
+++ b/sys/dev/ata/ata_raidreg.h Mon Jun 20 02:11:57 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata_raidreg.h,v 1.1 2003/01/27 18:21:28 thorpej Exp $  */
+/*     $NetBSD: ata_raidreg.h,v 1.2 2005/06/20 02:11:57 briggs Exp $   */
 
 /*-
  * Copyright (c) 2000,2001,2002 Søren Schmidt <sos%FreeBSD.org@localhost>
@@ -110,4 +110,64 @@
        uint32_t        checksum;
 } __attribute__((__packed__));
 
+/*
+ * Macro to compute the LBA of the Adaptec HostRAID configuration structure,
+ * using the disk's softc structure.
+ */
+#define        ADP_LBA(wd)                                                     \
+       ((wd)->sc_capacity - 17)
+
+struct adaptec_raid_conf {
+       uint32_t        magic_0;
+#define        ADP_MAGIC_0     0x900765c4
+
+       uint32_t        generation;
+       uint16_t        dummy_0;
+       uint16_t        total_configs;
+       uint16_t        dummy_1;
+       uint16_t        checksum;
+       uint32_t        dummy_2;
+       uint32_t        dummy_3;
+       uint32_t        flags;
+       uint32_t        timestamp;
+       uint32_t        dummy_4[4];
+       uint32_t        dummy_5[4];
+       struct {
+               uint16_t        total_disks;
+               uint16_t        generation;
+               uint32_t        magic_0;
+               uint8_t         dummy_0;
+               uint8_t         type;
+#define ADP_T_RAID0                    0x00
+#define ADP_T_RAID1                    0x01
+               uint8_t         dummy_1;
+               uint8_t         flags;
+
+               uint8_t         dummy_2;
+               uint8_t         dummy_3;
+               uint8_t         dummy_4;
+               uint8_t         dummy_5;
+
+               uint32_t        disk_number;
+               uint32_t        dummy_6;
+               uint32_t        sectors;
+               uint16_t        stripe_sectors;
+               uint16_t        dummy_7;
+
+               uint32_t        dummy_8[4];
+               uint8_t         name[16];
+       } configs[127];
+       uint32_t        dummy_6[13];
+       uint32_t        magic_1;
+#define ADP_MAGIC_1            0x0950f89f
+       uint32_t        dummy_7[3];
+       uint32_t        magic_2;
+       uint32_t        dummy_8[46];
+       uint32_t        magic_3;
+#define ADP_MAGIC_3            0x4450544d
+       uint32_t        magic_4;
+#define ADP_MAGIC_4            0x0950f89f
+       uint32_t        dummy_9[62];
+} __attribute__((__packed__));
+
 #endif /* _DEV_PCI_PCIIDE_PROMISE_RAID_H_ */
diff -r f1a371949d48 -r 4616fec128cd sys/dev/ata/ata_raidvar.h
--- a/sys/dev/ata/ata_raidvar.h Mon Jun 20 02:10:18 2005 +0000
+++ b/sys/dev/ata/ata_raidvar.h Mon Jun 20 02:11:57 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata_raidvar.h,v 1.1 2003/01/27 18:21:28 thorpej Exp $  */
+/*     $NetBSD: ata_raidvar.h,v 1.2 2005/06/20 02:11:57 briggs Exp $   */
 
 /*



Home | Main Index | Thread Index | Old Index