2005-12-11 15:16:03 +03:00
|
|
|
/* $NetBSD: ld_twe.c,v 1.23 2005/12/11 12:22:50 christos Exp $ */
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
/*-
|
2003-09-21 23:20:18 +04:00
|
|
|
* Copyright (c) 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
|
2000-10-19 18:11:30 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2003-09-21 23:20:18 +04:00
|
|
|
* by Andrew Doran; and by Jason R. Thorpe of Wasabi Systems, Inc.
|
2000-10-19 18:11:30 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
* 3ware "Escalade" RAID controller front-end for ld(4) driver.
|
2000-10-19 18:11:30 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-12-11 15:16:03 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ld_twe.c,v 1.23 2005/12/11 12:22:50 christos Exp $");
|
2001-11-13 10:48:40 +03:00
|
|
|
|
2000-10-19 18:11:30 +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:11:30 +04:00
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/dkio.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2002-05-19 00:59:20 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
#include <dev/ldvar.h>
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
#include <dev/pci/twereg.h>
|
|
|
|
#include <dev/pci/twevar.h>
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_twe_softc {
|
|
|
|
struct ld_softc sc_ld;
|
2000-10-19 18:11:30 +04:00
|
|
|
int sc_hwunit;
|
|
|
|
};
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
static void ld_twe_attach(struct device *, struct device *, void *);
|
2003-09-22 22:31:10 +04:00
|
|
|
static int ld_twe_detach(struct device *, int);
|
2001-01-23 00:56:11 +03:00
|
|
|
static int ld_twe_dobio(struct ld_twe_softc *, void *, int, int, int,
|
|
|
|
struct buf *);
|
2000-11-26 20:44:02 +03:00
|
|
|
static int ld_twe_dump(struct ld_softc *, void *, int, int);
|
2004-05-28 03:48:34 +04:00
|
|
|
static int ld_twe_flush(struct ld_softc *);
|
2000-11-26 20:44:02 +03:00
|
|
|
static void ld_twe_handler(struct twe_ccb *, int);
|
|
|
|
static int ld_twe_match(struct device *, struct cfdata *, void *);
|
|
|
|
static int ld_twe_start(struct ld_softc *, struct buf *);
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2003-09-22 22:31:10 +04:00
|
|
|
static void ld_twe_adjqparam(struct device *, int);
|
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(ld_twe, sizeof(struct ld_twe_softc),
|
2003-09-22 22:31:10 +04:00
|
|
|
ld_twe_match, ld_twe_attach, ld_twe_detach, NULL);
|
|
|
|
|
|
|
|
static const struct twe_callbacks ld_twe_callbacks = {
|
|
|
|
ld_twe_adjqparam,
|
|
|
|
};
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
static int
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_twe_match(struct device *parent, struct cfdata *match, void *aux)
|
2000-10-19 18:11:30 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_twe_attach(struct device *parent, struct device *self, void *aux)
|
2000-10-19 18:11:30 +04:00
|
|
|
{
|
|
|
|
struct twe_attach_args *twea;
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_twe_softc *sc;
|
|
|
|
struct ld_softc *ld;
|
2000-10-19 18:11:30 +04:00
|
|
|
struct twe_softc *twe;
|
2003-09-21 23:20:18 +04:00
|
|
|
struct twe_drive *td;
|
2003-09-21 23:33:10 +04:00
|
|
|
const char *typestr, *stripestr, *statstr;
|
|
|
|
char unktype[16], stripebuf[32], unkstat[32];
|
|
|
|
int error;
|
|
|
|
uint8_t status;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
sc = (struct ld_twe_softc *)self;
|
|
|
|
ld = &sc->sc_ld;
|
2000-10-19 18:11:30 +04:00
|
|
|
twe = (struct twe_softc *)parent;
|
|
|
|
twea = aux;
|
2003-09-21 23:20:18 +04:00
|
|
|
td = &twe->sc_units[twea->twea_unit];
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2003-09-22 22:31:10 +04:00
|
|
|
twe_register_callbacks(twe, twea->twea_unit, &ld_twe_callbacks);
|
|
|
|
|
2000-10-19 18:11:30 +04:00
|
|
|
sc->sc_hwunit = twea->twea_unit;
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_flags = LDF_ENABLED;
|
2002-05-24 22:10:06 +04:00
|
|
|
ld->sc_maxxfer = twe_get_maxxfer(twe_get_maxsegs());
|
2003-09-21 23:20:18 +04:00
|
|
|
ld->sc_secperunit = td->td_size;
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_secsize = TWE_SECTOR_SIZE;
|
2003-09-22 22:31:10 +04:00
|
|
|
ld->sc_maxqueuecnt = twe->sc_openings;
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_start = ld_twe_start;
|
|
|
|
ld->sc_dump = ld_twe_dump;
|
2004-05-28 03:48:34 +04:00
|
|
|
ld->sc_flush = ld_twe_flush;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2003-09-21 23:20:18 +04:00
|
|
|
typestr = twe_describe_code(twe_table_unittype, td->td_type);
|
|
|
|
if (typestr == NULL) {
|
2004-04-22 04:17:10 +04:00
|
|
|
snprintf(unktype, sizeof(unktype), "<0x%02x>", td->td_type);
|
2003-09-21 23:20:18 +04:00
|
|
|
typestr = unktype;
|
|
|
|
}
|
|
|
|
switch (td->td_type) {
|
|
|
|
case TWE_AD_CONFIG_RAID0:
|
|
|
|
case TWE_AD_CONFIG_RAID5:
|
|
|
|
case TWE_AD_CONFIG_RAID10:
|
|
|
|
stripestr = twe_describe_code(twe_table_stripedepth,
|
|
|
|
td->td_stripe);
|
|
|
|
if (stripestr == NULL)
|
2004-04-22 04:17:10 +04:00
|
|
|
snprintf(stripebuf, sizeof(stripebuf),
|
|
|
|
"<stripe code 0x%02x> ", td->td_stripe);
|
2003-09-21 23:20:18 +04:00
|
|
|
else
|
2004-04-22 04:17:10 +04:00
|
|
|
snprintf(stripebuf, sizeof(stripebuf), "%s stripe ",
|
|
|
|
stripestr);
|
2003-09-21 23:20:18 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
stripebuf[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2003-09-21 23:33:10 +04:00
|
|
|
error = twe_param_get_1(twe, TWE_PARAM_UNITINFO + twea->twea_unit,
|
|
|
|
TWE_PARAM_UNITINFO_Status, &status);
|
|
|
|
status &= TWE_PARAM_UNITSTATUS_MASK;
|
|
|
|
if (error) {
|
2004-04-22 04:17:10 +04:00
|
|
|
snprintf(unkstat, sizeof(unkstat), "<unknown>");
|
2003-09-21 23:33:10 +04:00
|
|
|
statstr = unkstat;
|
|
|
|
} else if ((statstr =
|
|
|
|
twe_describe_code(twe_table_unitstate, status)) == NULL) {
|
2004-04-22 04:17:10 +04:00
|
|
|
snprintf(unkstat, sizeof(unkstat), "<status code 0x%02x>",
|
|
|
|
status);
|
2003-09-21 23:33:10 +04:00
|
|
|
statstr = unkstat;
|
|
|
|
}
|
|
|
|
|
2005-02-08 08:16:17 +03:00
|
|
|
aprint_normal(": %s%s, status: %s\n", stripebuf, typestr, statstr);
|
2000-11-26 20:44:02 +03:00
|
|
|
ldattach(ld);
|
2000-10-19 18:11:30 +04:00
|
|
|
}
|
|
|
|
|
2003-09-22 22:31:10 +04:00
|
|
|
static int
|
|
|
|
ld_twe_detach(struct device *self, int flags)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if ((rv = ldbegindetach((struct ld_softc *)self, flags)) != 0)
|
|
|
|
return (rv);
|
|
|
|
ldenddetach((struct ld_softc *)self);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-19 18:11:30 +04:00
|
|
|
static int
|
2001-01-23 00:56:11 +03:00
|
|
|
ld_twe_dobio(struct ld_twe_softc *sc, void *data, int datasize, int blkno,
|
|
|
|
int dowrite, struct buf *bp)
|
2000-10-19 18:11:30 +04:00
|
|
|
{
|
|
|
|
struct twe_ccb *ccb;
|
|
|
|
struct twe_cmd *tc;
|
|
|
|
struct twe_softc *twe;
|
2000-11-08 22:20:33 +03:00
|
|
|
int s, rv, flags;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
twe = (struct twe_softc *)sc->sc_ld.sc_dv.dv_parent;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2000-11-08 22:20:33 +03:00
|
|
|
flags = (dowrite ? TWE_CCB_DATA_OUT : TWE_CCB_DATA_IN);
|
2003-09-24 03:50:04 +04:00
|
|
|
if ((ccb = twe_ccb_alloc(twe, flags)) == NULL)
|
|
|
|
return (EAGAIN);
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
ccb->ccb_data = data;
|
|
|
|
ccb->ccb_datasize = datasize;
|
|
|
|
tc = ccb->ccb_cmd;
|
|
|
|
|
|
|
|
/* Build the command. */
|
|
|
|
tc->tc_size = 3;
|
2001-01-23 00:56:11 +03:00
|
|
|
tc->tc_unit = sc->sc_hwunit;
|
2000-10-19 18:11:30 +04:00
|
|
|
tc->tc_count = htole16(datasize / TWE_SECTOR_SIZE);
|
|
|
|
tc->tc_args.io.lba = htole32(blkno);
|
|
|
|
|
2000-11-08 22:20:33 +03:00
|
|
|
if (dowrite)
|
2000-10-19 18:11:30 +04:00
|
|
|
tc->tc_opcode = TWE_OP_WRITE | (tc->tc_size << 5);
|
2000-11-08 22:20:33 +03:00
|
|
|
else
|
2000-10-19 18:11:30 +04:00
|
|
|
tc->tc_opcode = TWE_OP_READ | (tc->tc_size << 5);
|
|
|
|
|
|
|
|
/* Map the data transfer. */
|
|
|
|
if ((rv = twe_ccb_map(twe, ccb)) != 0) {
|
2000-10-20 19:14:25 +04:00
|
|
|
twe_ccb_free(twe, ccb);
|
2000-10-19 18:11:30 +04:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2001-01-22 20:44:28 +03:00
|
|
|
if (bp == NULL) {
|
2000-10-19 18:11:30 +04:00
|
|
|
/*
|
|
|
|
* Polled commands must not sit on the software queue. Wait
|
|
|
|
* up to 2 seconds for the command to complete.
|
|
|
|
*/
|
|
|
|
s = splbio();
|
2001-01-26 22:53:15 +03:00
|
|
|
rv = twe_ccb_poll(twe, ccb, 2000);
|
2000-10-19 18:11:30 +04:00
|
|
|
twe_ccb_unmap(twe, ccb);
|
2000-10-20 19:14:25 +04:00
|
|
|
twe_ccb_free(twe, ccb);
|
2000-10-19 18:11:30 +04:00
|
|
|
splx(s);
|
|
|
|
} else {
|
2001-01-22 20:44:28 +03:00
|
|
|
ccb->ccb_tx.tx_handler = ld_twe_handler;
|
|
|
|
ccb->ccb_tx.tx_context = bp;
|
|
|
|
ccb->ccb_tx.tx_dv = (struct device *)sc;
|
2000-10-19 18:11:30 +04:00
|
|
|
twe_ccb_enqueue(twe, ccb);
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_twe_start(struct ld_softc *ld, struct buf *bp)
|
2000-10-19 18:11:30 +04:00
|
|
|
{
|
|
|
|
|
2001-01-23 00:56:11 +03:00
|
|
|
return (ld_twe_dobio((struct ld_twe_softc *)ld, bp->b_data,
|
|
|
|
bp->b_bcount, bp->b_rawblkno, (bp->b_flags & B_READ) == 0, bp));
|
2000-10-19 18:11:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_twe_handler(struct twe_ccb *ccb, int error)
|
2000-10-19 18:11:30 +04:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
struct twe_context *tx;
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_twe_softc *sc;
|
2000-10-19 18:11:30 +04:00
|
|
|
struct twe_softc *twe;
|
|
|
|
|
|
|
|
tx = &ccb->ccb_tx;
|
|
|
|
bp = tx->tx_context;
|
2000-11-26 20:44:02 +03:00
|
|
|
sc = (struct ld_twe_softc *)tx->tx_dv;
|
|
|
|
twe = (struct twe_softc *)sc->sc_ld.sc_dv.dv_parent;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
twe_ccb_unmap(twe, ccb);
|
2000-10-20 19:14:25 +04:00
|
|
|
twe_ccb_free(twe, ccb);
|
|
|
|
|
2000-10-19 18:11:30 +04:00
|
|
|
if (error) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = error;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
} else
|
|
|
|
bp->b_resid = 0;
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
lddone(&sc->sc_ld, bp);
|
2000-10-19 18:11:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_twe_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
|
2000-10-19 18:11:30 +04:00
|
|
|
{
|
|
|
|
|
2001-01-23 00:56:11 +03:00
|
|
|
return (ld_twe_dobio((struct ld_twe_softc *)ld, data,
|
|
|
|
blkcnt * ld->sc_secsize, blkno, 1, NULL));
|
2000-10-19 18:11:30 +04:00
|
|
|
}
|
2003-09-22 22:31:10 +04:00
|
|
|
|
2004-05-28 03:48:34 +04:00
|
|
|
static int
|
|
|
|
ld_twe_flush(struct ld_softc *ld)
|
|
|
|
{
|
|
|
|
struct ld_twe_softc *sc = (void *) ld;
|
|
|
|
struct twe_softc *twe = (void *) ld->sc_dv.dv_parent;
|
|
|
|
struct twe_ccb *ccb;
|
|
|
|
struct twe_cmd *tc;
|
|
|
|
int s, rv;
|
|
|
|
|
|
|
|
ccb = twe_ccb_alloc_wait(twe, 0);
|
|
|
|
KASSERT(ccb != NULL);
|
|
|
|
|
|
|
|
ccb->ccb_data = NULL;
|
|
|
|
ccb->ccb_datasize = 0;
|
|
|
|
ccb->ccb_tx.tx_handler = twe_ccb_wait_handler;
|
|
|
|
ccb->ccb_tx.tx_context = NULL;
|
|
|
|
ccb->ccb_tx.tx_dv = &ld->sc_dv;
|
|
|
|
|
|
|
|
tc = ccb->ccb_cmd;
|
|
|
|
tc->tc_size = 2;
|
|
|
|
tc->tc_opcode = TWE_OP_FLUSH;
|
|
|
|
tc->tc_unit = sc->sc_hwunit;
|
|
|
|
tc->tc_count = 0;
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
twe_ccb_enqueue(twe, ccb);
|
|
|
|
s = splbio();
|
|
|
|
while ((ccb->ccb_flags & TWE_CCB_COMPLETE) == 0)
|
|
|
|
if ((rv = tsleep(ccb, PRIBIO, "tweflush", 60 * hz)) != 0)
|
|
|
|
break;
|
|
|
|
twe_ccb_free(twe, ccb);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2003-09-22 22:31:10 +04:00
|
|
|
static void
|
|
|
|
ld_twe_adjqparam(struct device *self, int openings)
|
|
|
|
{
|
|
|
|
|
|
|
|
ldadjqparam((struct ld_softc *)self, openings);
|
|
|
|
}
|