Source-Changes-HG archive

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

[src/trunk]: src/sys Driver for Compaq array controllers and disks (cac(4)/ca...



details:   https://anonhg.NetBSD.org/src/rev/f5ea0d21249a
branches:  trunk
changeset: 483708:f5ea0d21249a
user:      ad <ad%NetBSD.org@localhost>
date:      Thu Mar 16 14:52:22 2000 +0000

description:
Driver for Compaq array controllers and disks (cac(4)/ca(4)).

diffstat:

 sys/conf/files        |   10 +-
 sys/dev/ic/ca.c       |  701 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/cac.c      |  499 +++++++++++++++++++++++++++++++++++
 sys/dev/ic/cacreg.h   |  171 ++++++++++++
 sys/dev/ic/cacvar.h   |  119 ++++++++
 sys/dev/pci/cac_pci.c |  290 ++++++++++++++++++++
 sys/dev/pci/files.pci |    6 +-
 sys/sys/conf.h        |    8 +-
 8 files changed, 1801 insertions(+), 3 deletions(-)

diffs (truncated from 1866 to 300 lines):

diff -r 253862ddf45e -r f5ea0d21249a sys/conf/files
--- a/sys/conf/files    Thu Mar 16 14:15:26 2000 +0000
+++ b/sys/conf/files    Thu Mar 16 14:52:22 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.354 2000/03/15 02:10:09 fvdl Exp $
+#      $NetBSD: files,v 1.355 2000/03/16 14:52:23 ad Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -211,6 +211,14 @@
 device dpt: scsi
 file   dev/ic/dpt.c                    dpt
 
+# Compaq Smart ARRAY controllers
+device cac {unit = -1}
+file   dev/ic/cac.c                    cac
+
+device ca: disk
+attach ca at cac
+file   dev/ic/ca.c                     ca      needs-flag
+
 # AdvanSys 1200A, 1200B and ULTRA SCSI controllers
 device adv: scsi
 file   dev/ic/adv.c                    adv
diff -r 253862ddf45e -r f5ea0d21249a sys/dev/ic/ca.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/ca.c   Thu Mar 16 14:52:22 2000 +0000
@@ -0,0 +1,701 @@
+/*     $NetBSD: ca.c,v 1.1 2000/03/16 14:52:23 ad Exp $        */
+
+/*-
+ * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum and Andy Doran.
+ *
+ * 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.
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/*
+ * Originally written by Julian Elischer (julian%dialix.oz.au@localhost)
+ * for TRW Financial Systems for use under the MACH(2.5) operating system.
+ *
+ * TRW Financial Systems, in accordance with their agreement with Carnegie
+ * Mellon University, makes this software available to CMU to distribute
+ * or use in any manner that they see fit as long as this message is kept with
+ * the software. For this reason TFS also grants any other persons or
+ * organisations permission to use or modify this software.
+ *
+ * TFS supplies this software to be publicly redistributed
+ * on the understanding that TFS is not responsible for the correct
+ * functioning of this software in any circumstances.
+ *
+ * Ported to run under 386BSD by Julian Elischer (julian%dialix.oz.au@localhost) Sept 1992
+ */
+
+/*
+ * Disk driver for Compaq arrays, based on sd.c (revision 1.157).
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ca.c,v 1.1 2000/03/16 14:52:23 ad Exp $");
+
+#include "rnd.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/queue.h>
+#include <sys/proc.h>
+#include <sys/buf.h>
+#include <sys/endian.h>
+#include <sys/disklabel.h>
+#include <sys/disk.h>
+#include <sys/dkio.h>
+#include <sys/stat.h>
+#include <sys/lock.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+
+#include <machine/bswap.h>
+#include <machine/bus.h>
+
+#include <dev/ic/cacreg.h>
+#include <dev/ic/cacvar.h>
+
+#define        CAUNIT(dev)                     DISKUNIT(dev)
+#define        CAPART(dev)                     DISKPART(dev)
+#define        CAMINOR(unit, part)             DISKMINOR(unit, part)
+#define        CAMAKEDEV(maj, unit, part)      MAKEDISKDEV(maj, unit, part)
+
+#define        CALABELDEV(dev) (CAMAKEDEV(major(dev), CAUNIT(dev), RAW_PART))
+
+struct ca_softc {
+       struct  device sc_dv;
+       int     sc_unit;
+       int     sc_flags;
+       struct  cac_softc *sc_cac;
+       struct  disk sc_dk;
+#if NRND > 0
+       rndsource_element_t     sc_rnd_source;
+#endif
+
+       /* Parameters from controller. */
+       int     sc_ncylinders;
+       int     sc_nheads;
+       int     sc_nsectors;
+       int     sc_secsize;
+       int     sc_secperunit;
+       int     sc_mirror;
+};
+
+#define        CAF_ENABLED     0x01            /* device enabled */
+#define        CAF_LOCKED      0x02            /* lock held */
+#define        CAF_WANTED      0x04            /* lock wanted */
+#define        CAF_WLABEL      0x08            /* label is writable */
+#define        CAF_LABELLING   0x10            /* writing label */
+
+static int     calock __P((struct ca_softc *));
+static void    caunlock __P((struct ca_softc *));
+static int     camatch __P((struct device *, struct cfdata *, void *));
+static void    cacttach __P((struct device *, struct device *, void *));
+static void    cadone __P((struct cac_ccb *, int));
+static void    cagetdisklabel __P((struct ca_softc *));
+static void    cagetdefaultlabel __P((struct ca_softc *, struct disklabel *));
+
+struct cfattach ca_ca = {
+       sizeof(struct ca_softc), camatch, cacttach
+};
+
+extern struct cfdriver ca_cd;
+
+struct dkdriver cadkdriver = { castrategy };
+
+static int
+camatch(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+#if 0
+       struct cac_attach_args *caca;
+       
+       caca = (struct cac_attach_args *)aux;
+
+       /* Unit 0 is the controller */
+       return (caca->caca_unit != 0);
+#endif
+       return (1);
+}
+
+static void
+cacttach(parent, self, aux)
+       struct device *parent;
+       struct device *self;
+       void *aux;
+{
+       struct cac_drive_info dinfo;
+       struct cac_attach_args *caca;
+       struct ca_softc *sc;
+       char *type;
+       int mb;
+
+       sc = (struct ca_softc *)self;
+       caca = (struct cac_attach_args *)aux;
+       sc->sc_cac = (struct cac_softc *)parent;
+       sc->sc_unit = caca->caca_unit;
+       
+       if (cac_cmd(sc->sc_cac, CAC_CMD_GET_LOG_DRV_INFO, &dinfo, sizeof(dinfo),
+           sc->sc_unit, 0, CAC_CCB_DATA_IN, NULL)) {
+               printf("%s: CMD_GET_LOG_DRV_INFO failed\n", 
+                   sc->sc_dv.dv_xname);
+               return;
+       }
+
+       sc->sc_ncylinders = CAC_GET2(dinfo.ncylinders);
+       sc->sc_nheads = CAC_GET1(dinfo.nheads);
+       sc->sc_nsectors = CAC_GET1(dinfo.nsectors);
+       sc->sc_secsize = CAC_GET2(dinfo.secsize);
+       sc->sc_mirror = CAC_GET1(dinfo.mirror);
+       sc->sc_secperunit = sc->sc_ncylinders * sc->sc_nheads * sc->sc_nsectors;
+       
+       switch (sc->sc_mirror) {
+       case 0:
+               type = "standalone disk or RAID0";
+               break;
+       case 1:
+               type = "RAID4";
+               break;
+       case 2:
+               type = "RAID1";
+               break;
+       case 3:
+               type = "RAID5";
+               break;
+       default:
+               type = "unknown type of";
+               break;
+       }
+
+       printf(": %s array\n", type);
+
+       mb = sc->sc_secperunit / (1048576 / sc->sc_secsize);
+       printf("%s: %uMB, %u cyl, %u head, %u sec, %d bytes/sect "
+           "x %d sectors\n", sc->sc_dv.dv_xname, mb, sc->sc_ncylinders, 
+           sc->sc_nheads, sc->sc_nsectors, sc->sc_secsize, sc->sc_secperunit);
+           
+       /* Initialize and attach the disk structure */
+       sc->sc_dk.dk_driver = &cadkdriver;
+       sc->sc_dk.dk_name = sc->sc_dv.dv_xname;
+       disk_attach(&sc->sc_dk);
+       sc->sc_flags |= CAF_ENABLED;
+       
+#if !defined(__i386__) && !defined(__vax__)
+       dk_establish(&sc->sc_dk, &sc->sc_dv);           /* XXX */
+#endif
+
+#if NRND > 0
+       /* Attach the device into the rnd source list. */
+       rnd_attach_source(&sc->sc_rnd_source, sc->sc_dv.dv_xname,
+           RND_TYPE_DISK, 0);
+#endif
+}
+
+int
+caopen(dev, flags, fmt, p)
+       dev_t dev;
+       int flags;
+       int fmt;
+       struct proc *p;
+{
+       struct ca_softc *sc;
+       int unit, part;
+
+       unit = CAUNIT(dev);
+       if (unit >= ca_cd.cd_ndevs)
+               return (ENXIO);
+       if ((sc = ca_cd.cd_devs[unit]) == NULL)
+               return (ENXIO);
+       if ((sc->sc_flags & CAF_ENABLED) == 0)
+               return (ENODEV);
+       part = CAPART(dev);
+       calock(sc);
+       
+       if (sc->sc_dk.dk_openmask == 0) 
+               cagetdisklabel(sc);
+
+       /* Check that the partition exists. */
+       if (part != RAW_PART && (part >= sc->sc_dk.dk_label->d_npartitions ||
+            sc->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
+               caunlock(sc);
+               return (ENXIO);
+       }
+
+       /* Insure only one open at a time. */
+       switch (fmt) {
+       case S_IFCHR:
+               sc->sc_dk.dk_copenmask |= (1 << part);
+               break;
+       case S_IFBLK:
+               sc->sc_dk.dk_bopenmask |= (1 << part);
+               break;
+       }
+       sc->sc_dk.dk_openmask =
+           sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
+
+       caunlock(sc);
+       return (0);
+}



Home | Main Index | Thread Index | Old Index