The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/ic/ld_cac.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ld_cac.c,v 1.8 2002/10/02 16:33:33 thorpej Exp $       */
    2 
    3 /*-
    4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Andrew Doran.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 /*
   40  * Compaq array controller front-end for ld(4) driver.
   41  */
   42 
   43 #include <sys/cdefs.h>
   44 __KERNEL_RCSID(0, "$NetBSD: ld_cac.c,v 1.8 2002/10/02 16:33:33 thorpej Exp $");
   45 
   46 #include "rnd.h"
   47 
   48 #include <sys/param.h>
   49 #include <sys/systm.h>
   50 #include <sys/kernel.h>
   51 #include <sys/device.h>
   52 #include <sys/buf.h>
   53 #include <sys/endian.h>
   54 #include <sys/dkio.h>
   55 #include <sys/disk.h>
   56 #if NRND > 0
   57 #include <sys/rnd.h>
   58 #endif
   59 
   60 #include <machine/bus.h>
   61 
   62 #include <dev/ldvar.h>
   63 
   64 #include <dev/ic/cacreg.h>
   65 #include <dev/ic/cacvar.h>
   66 
   67 struct ld_cac_softc {
   68         struct  ld_softc sc_ld;
   69         int     sc_hwunit;
   70         struct  timeval sc_serrtm;
   71         int     sc_serrcnt;
   72 };
   73 
   74 void    ld_cac_attach(struct device *, struct device *, void *);
   75 void    ld_cac_done(struct device *, void *, int);
   76 int     ld_cac_dump(struct ld_softc *, void *, int, int);
   77 int     ld_cac_match(struct device *, struct cfdata *, void *);
   78 int     ld_cac_start(struct ld_softc *, struct buf *);
   79 
   80 static const struct     timeval ld_cac_serrintvl = { 60, 0 };
   81 
   82 CFATTACH_DECL(ld_cac, sizeof(struct ld_cac_softc),
   83     ld_cac_match, ld_cac_attach, NULL, NULL);
   84 
   85 int
   86 ld_cac_match(struct device *parent, struct cfdata *match, void *aux)
   87 {
   88 
   89         return (1);
   90 }
   91 
   92 void
   93 ld_cac_attach(struct device *parent, struct device *self, void *aux)
   94 {
   95         struct cac_drive_info dinfo;
   96         struct cac_attach_args *caca;
   97         struct ld_softc *ld;
   98         struct ld_cac_softc *sc;
   99         struct cac_softc *cac;
  100         const char *type;
  101 
  102         sc = (struct ld_cac_softc *)self;
  103         ld = &sc->sc_ld;
  104         caca = (struct cac_attach_args *)aux;
  105         sc->sc_hwunit = caca->caca_unit;
  106         cac = (struct cac_softc *)parent;
  107 
  108         if (cac_cmd(cac, CAC_CMD_GET_LOG_DRV_INFO, &dinfo, sizeof(dinfo),
  109             sc->sc_hwunit, 0, CAC_CCB_DATA_IN, NULL)) {
  110                 printf("%s: CMD_GET_LOG_DRV_INFO failed\n", self->dv_xname);
  111                 return;
  112         }
  113 
  114         ld->sc_secsize = CAC_GET2(dinfo.secsize);
  115         ld->sc_maxxfer = CAC_MAX_XFER;
  116         ld->sc_maxqueuecnt = CAC_MAX_CCBS / cac->sc_nunits;     /* XXX */
  117         ld->sc_secperunit = CAC_GET2(dinfo.ncylinders) *
  118             CAC_GET1(dinfo.nheads) * CAC_GET1(dinfo.nsectors);
  119         ld->sc_start = ld_cac_start;
  120         ld->sc_dump = ld_cac_dump;
  121 
  122         switch (CAC_GET1(dinfo.mirror)) {
  123         case 0:
  124                 type = "standalone disk or RAID0";
  125                 break;
  126         case 1:
  127                 type = "RAID4";
  128                 break;
  129         case 2:
  130                 type = "RAID1";
  131                 break;
  132         case 3:
  133                 type = "RAID5";
  134                 break;
  135         default:
  136                 type = "unknown type of";
  137                 break;
  138         }
  139 
  140         printf(": %s array\n", type);
  141 
  142         /* XXX We should verify this... */
  143         ld->sc_flags = LDF_ENABLED;
  144         ldattach(ld);
  145 }
  146 
  147 int
  148 ld_cac_start(struct ld_softc *ld, struct buf *bp)
  149 {
  150         int flags, cmd;
  151         struct cac_softc *cac;
  152         struct ld_cac_softc *sc;
  153         struct cac_context cc;
  154         
  155         sc = (struct ld_cac_softc *)ld;
  156         cac = (struct cac_softc *)ld->sc_dv.dv_parent;
  157 
  158         cc.cc_handler = ld_cac_done;
  159         cc.cc_context = bp;
  160         cc.cc_dv = &ld->sc_dv;
  161 
  162         if ((bp->b_flags & B_READ) == 0) {
  163                 cmd = CAC_CMD_WRITE;
  164                 flags = CAC_CCB_DATA_OUT;
  165         } else {
  166                 cmd = CAC_CMD_READ;
  167                 flags = CAC_CCB_DATA_IN;
  168         }
  169 
  170         return (cac_cmd(cac, cmd, bp->b_data, bp->b_bcount, sc->sc_hwunit,
  171             bp->b_rawblkno, flags, &cc));
  172 }
  173 
  174 int
  175 ld_cac_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
  176 {
  177         struct ld_cac_softc *sc;
  178 
  179         sc = (struct ld_cac_softc *)ld;
  180 
  181         return (cac_cmd((struct cac_softc *)ld->sc_dv.dv_parent,
  182             CAC_CMD_WRITE_MEDIA, data, blkcnt * ld->sc_secsize,
  183             sc->sc_hwunit, blkno, CAC_CCB_DATA_OUT, NULL));
  184 }
  185 
  186 void
  187 ld_cac_done(struct device *dv, void *context, int error)
  188 {
  189         struct buf *bp;
  190         struct ld_cac_softc *sc;
  191 
  192         bp = context;
  193 
  194         if ((error & CAC_RET_HARD_ERROR) != 0) {
  195                 printf("%s: hard error\n", dv->dv_xname);
  196                 error = EIO;
  197         }
  198         if ((error & CAC_RET_CMD_REJECTED) != 0) {
  199                 printf("%s: invalid request\n", dv->dv_xname);
  200                 error = EIO;
  201         }
  202         if ((error & CAC_RET_SOFT_ERROR) != 0) {
  203                 sc = (struct ld_cac_softc *)dv;
  204                 sc->sc_serrcnt++;
  205                 if (ratecheck(&sc->sc_serrtm, &ld_cac_serrintvl)) {
  206                         printf("%s: %d soft errors; array may be degraded\n",
  207                             dv->dv_xname, sc->sc_serrcnt);
  208                         sc->sc_serrcnt = 0;
  209                 }
  210                 error = 0;
  211         }
  212 
  213         if (error) {
  214                 bp->b_flags |= B_ERROR;
  215                 bp->b_error = error;
  216                 bp->b_resid = bp->b_bcount;
  217         } else
  218                 bp->b_resid = 0;
  219 
  220         lddone((struct ld_softc *)dv, bp);
  221 }

Cache object: 478d01a2609ee413a12f1c612e713779


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.