2007-10-19 15:59:34 +04:00
|
|
|
/* $NetBSD: ld_cac.c,v 1.19 2007/10/19 11:59:55 ad Exp $ */
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/*-
|
2007-02-10 00:55:00 +03:00
|
|
|
* Copyright (c) 2000, 2006 The NetBSD Foundation, Inc.
|
2000-10-19 18:06:02 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-11-26 20:44:02 +03:00
|
|
|
* Compaq array controller front-end for ld(4) driver.
|
2000-10-19 18:06:02 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ld_cac.c,v 1.19 2007/10/19 11:59:55 ad Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
#include "rnd.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/buf.h>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/dkio.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
#include <dev/ldvar.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
#include <dev/ic/cacreg.h>
|
|
|
|
#include <dev/ic/cacvar.h>
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_cac_softc {
|
|
|
|
struct ld_softc sc_ld;
|
2007-02-10 00:55:00 +03:00
|
|
|
kmutex_t *sc_mutex;
|
2000-10-19 18:06:02 +04:00
|
|
|
int sc_hwunit;
|
2000-12-11 16:19:50 +03:00
|
|
|
int sc_serrcnt;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct timeval sc_serrtm;
|
2000-10-19 18:06:02 +04:00
|
|
|
};
|
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
void ld_cac_attach(struct device *, struct device *, void *);
|
|
|
|
void ld_cac_done(struct device *, void *, int);
|
|
|
|
int ld_cac_dump(struct ld_softc *, void *, int, int);
|
|
|
|
int ld_cac_match(struct device *, struct cfdata *, void *);
|
|
|
|
int ld_cac_start(struct ld_softc *, struct buf *);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
static const struct timeval ld_cac_serrintvl = { 60, 0 };
|
2000-12-11 16:19:50 +03:00
|
|
|
|
2002-10-01 01:17:57 +04:00
|
|
|
CFATTACH_DECL(ld_cac, sizeof(struct ld_cac_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
ld_cac_match, ld_cac_attach, NULL, NULL);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
ld_cac_match(struct device *parent, struct cfdata *match,
|
|
|
|
void *aux)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
void
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_cac_attach(struct device *parent, struct device *self, void *aux)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
struct cac_drive_info dinfo;
|
|
|
|
struct cac_attach_args *caca;
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *ld;
|
|
|
|
struct ld_cac_softc *sc;
|
2000-11-08 22:20:33 +03:00
|
|
|
struct cac_softc *cac;
|
2000-10-19 18:06:02 +04:00
|
|
|
const char *type;
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
sc = (struct ld_cac_softc *)self;
|
|
|
|
ld = &sc->sc_ld;
|
2000-10-19 18:06:02 +04:00
|
|
|
caca = (struct cac_attach_args *)aux;
|
|
|
|
sc->sc_hwunit = caca->caca_unit;
|
2000-11-08 22:20:33 +03:00
|
|
|
cac = (struct cac_softc *)parent;
|
2007-02-10 00:55:00 +03:00
|
|
|
sc->sc_mutex = &cac->sc_mutex;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-08 22:20:33 +03:00
|
|
|
if (cac_cmd(cac, CAC_CMD_GET_LOG_DRV_INFO, &dinfo, sizeof(dinfo),
|
|
|
|
sc->sc_hwunit, 0, CAC_CCB_DATA_IN, NULL)) {
|
2005-02-08 08:16:17 +03:00
|
|
|
aprint_error(": CMD_GET_LOG_DRV_INFO failed\n");
|
2000-10-19 18:06:02 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_secsize = CAC_GET2(dinfo.secsize);
|
|
|
|
ld->sc_maxxfer = CAC_MAX_XFER;
|
|
|
|
ld->sc_maxqueuecnt = CAC_MAX_CCBS / cac->sc_nunits; /* XXX */
|
2001-06-10 14:48:42 +04:00
|
|
|
ld->sc_secperunit = CAC_GET2(dinfo.ncylinders) *
|
|
|
|
CAC_GET1(dinfo.nheads) * CAC_GET1(dinfo.nsectors);
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_start = ld_cac_start;
|
|
|
|
ld->sc_dump = ld_cac_dump;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
switch (CAC_GET1(dinfo.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;
|
|
|
|
}
|
|
|
|
|
2005-02-08 08:16:17 +03:00
|
|
|
aprint_normal(": %s array\n", type);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/* XXX We should verify this... */
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_flags = LDF_ENABLED;
|
|
|
|
ldattach(ld);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
int
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_cac_start(struct ld_softc *ld, struct buf *bp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
int flags, cmd;
|
|
|
|
struct cac_softc *cac;
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_cac_softc *sc;
|
2000-10-19 18:06:02 +04:00
|
|
|
struct cac_context cc;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
sc = (struct ld_cac_softc *)ld;
|
2006-03-26 01:55:55 +03:00
|
|
|
cac = (struct cac_softc *)device_parent(&ld->sc_dv);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
cc.cc_handler = ld_cac_done;
|
2000-10-19 18:06:02 +04:00
|
|
|
cc.cc_context = bp;
|
2000-11-26 20:44:02 +03:00
|
|
|
cc.cc_dv = &ld->sc_dv;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
if ((bp->b_flags & B_READ) == 0) {
|
|
|
|
cmd = CAC_CMD_WRITE;
|
|
|
|
flags = CAC_CCB_DATA_OUT;
|
|
|
|
} else {
|
|
|
|
cmd = CAC_CMD_READ;
|
|
|
|
flags = CAC_CCB_DATA_IN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cac_cmd(cac, cmd, bp->b_data, bp->b_bcount, sc->sc_hwunit,
|
|
|
|
bp->b_rawblkno, flags, &cc));
|
|
|
|
}
|
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
int
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_cac_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_cac_softc *sc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
sc = (struct ld_cac_softc *)ld;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2006-03-26 01:55:55 +03:00
|
|
|
return (cac_cmd((struct cac_softc *)device_parent(&ld->sc_dv),
|
2000-11-26 20:44:02 +03:00
|
|
|
CAC_CMD_WRITE_MEDIA, data, blkcnt * ld->sc_secsize,
|
2000-10-19 18:06:02 +04:00
|
|
|
sc->sc_hwunit, blkno, CAC_CCB_DATA_OUT, NULL));
|
|
|
|
}
|
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
void
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_cac_done(struct device *dv, void *context, int error)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
2000-12-11 16:19:50 +03:00
|
|
|
struct ld_cac_softc *sc;
|
2006-11-28 23:29:14 +03:00
|
|
|
int rv;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-08 22:20:33 +03:00
|
|
|
bp = context;
|
2006-11-28 23:29:14 +03:00
|
|
|
rv = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
sc = device_private(dv);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2006-11-28 23:29:14 +03:00
|
|
|
if ((error & CAC_RET_CMD_REJECTED) == CAC_RET_CMD_REJECTED) {
|
|
|
|
printf("%s: command rejected\n", dv->dv_xname);
|
|
|
|
rv = EIO;
|
|
|
|
}
|
|
|
|
if (rv == 0 && (error & CAC_RET_INVAL_BLOCK) != 0) {
|
|
|
|
printf("%s: invalid request block\n", dv->dv_xname);
|
|
|
|
rv = EIO;
|
2000-12-11 16:19:50 +03:00
|
|
|
}
|
2006-11-28 23:29:14 +03:00
|
|
|
if (rv == 0 && (error & CAC_RET_HARD_ERROR) != 0) {
|
|
|
|
printf("%s: hard error\n", dv->dv_xname);
|
|
|
|
rv = EIO;
|
2000-12-11 16:19:50 +03:00
|
|
|
}
|
2006-11-28 23:29:14 +03:00
|
|
|
if (rv == 0 && (error & CAC_RET_SOFT_ERROR) != 0) {
|
2000-12-11 16:19:50 +03:00
|
|
|
sc->sc_serrcnt++;
|
|
|
|
if (ratecheck(&sc->sc_serrtm, &ld_cac_serrintvl)) {
|
2007-02-10 00:55:00 +03:00
|
|
|
sc->sc_serrcnt = 0;
|
2000-12-11 16:19:50 +03:00
|
|
|
printf("%s: %d soft errors; array may be degraded\n",
|
|
|
|
dv->dv_xname, sc->sc_serrcnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-28 23:29:14 +03:00
|
|
|
if (rv) {
|
|
|
|
bp->b_error = rv;
|
2000-10-19 18:06:02 +04:00
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
} else
|
|
|
|
bp->b_resid = 0;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(sc->sc_mutex);
|
2000-11-26 20:44:02 +03:00
|
|
|
lddone((struct ld_softc *)dv, bp);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(sc->sc_mutex);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|