2000-11-26 20:44:02 +03:00
|
|
|
/* $NetBSD: ld_twe.c,v 1.1 2000/11/26 17:44:06 ad Exp $ */
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* 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
|
|
|
* 3ware "Escalade" RAID controller front-end for ld(4) driver.
|
2000-10-19 18:11:30 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rnd.h"
|
|
|
|
#include "opt_twe.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/dkio.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2000-11-14 22:44:34 +03: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 *);
|
|
|
|
static int ld_twe_dobio(struct ld_twe_softc *, int, void *, int, int,
|
2000-10-19 18:11:30 +04:00
|
|
|
int, struct twe_context *);
|
2000-11-26 20:44:02 +03:00
|
|
|
static int ld_twe_dump(struct ld_softc *, void *, int, int);
|
|
|
|
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
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
struct cfattach ld_twe_ca = {
|
|
|
|
sizeof(struct ld_twe_softc), ld_twe_match, ld_twe_attach
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
sc->sc_hwunit = twea->twea_unit;
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_flags = LDF_ENABLED;
|
|
|
|
ld->sc_maxxfer = TWE_MAX_XFER;
|
|
|
|
ld->sc_secperunit = twe->sc_dsize[twea->twea_unit];
|
|
|
|
ld->sc_secsize = TWE_SECTOR_SIZE;
|
|
|
|
ld->sc_maxqueuecnt =
|
2000-11-08 22:20:33 +03:00
|
|
|
min((twe->sc_nccbs - 1) / twe->sc_nunits, TWE_MAX_PU_QUEUECNT);
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_start = ld_twe_start;
|
|
|
|
ld->sc_dump = ld_twe_dump;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
/* Build synthetic geometry as per controller internal rules. */
|
2000-11-26 20:44:02 +03:00
|
|
|
if (ld->sc_secperunit > 0x200000) {
|
|
|
|
ld->sc_nheads = 255;
|
|
|
|
ld->sc_nsectors = 63;
|
2000-10-19 18:11:30 +04:00
|
|
|
} else {
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_nheads = 64;
|
|
|
|
ld->sc_nsectors = 32;
|
2000-10-19 18:11:30 +04:00
|
|
|
}
|
2000-11-26 20:44:02 +03:00
|
|
|
ld->sc_ncylinders = ld->sc_secperunit /
|
|
|
|
(ld->sc_nheads * ld->sc_nsectors);
|
2000-10-19 18:11:30 +04:00
|
|
|
|
|
|
|
printf("\n");
|
2000-11-26 20:44:02 +03:00
|
|
|
ldattach(ld);
|
2000-10-19 18:11:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-11-26 20:44:02 +03:00
|
|
|
ld_twe_dobio(struct ld_twe_softc *sc, int unit, void *data, int datasize,
|
2000-10-19 18:11:30 +04:00
|
|
|
int blkno, int dowrite, struct twe_context *tx)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
if ((rv = twe_ccb_alloc(twe, &ccb, flags)) != 0)
|
2000-10-19 18:11:30 +04:00
|
|
|
return (rv);
|
|
|
|
|
|
|
|
ccb->ccb_data = data;
|
|
|
|
ccb->ccb_datasize = datasize;
|
|
|
|
tc = ccb->ccb_cmd;
|
|
|
|
|
|
|
|
/* Build the command. */
|
|
|
|
tc->tc_size = 3;
|
|
|
|
tc->tc_unit = unit;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tx == NULL) {
|
|
|
|
/*
|
|
|
|
* Polled commands must not sit on the software queue. Wait
|
|
|
|
* up to 2 seconds for the command to complete.
|
|
|
|
*/
|
|
|
|
s = splbio();
|
|
|
|
if ((rv = twe_ccb_submit(twe, ccb)) == 0)
|
|
|
|
rv = twe_ccb_poll(twe, ccb, 2000);
|
|
|
|
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 {
|
|
|
|
memcpy(&ccb->ccb_tx, tx, sizeof(struct twe_context));
|
|
|
|
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
|
|
|
{
|
|
|
|
struct twe_context tx;
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_twe_softc *sc;
|
2000-11-08 22:20:33 +03:00
|
|
|
struct twe_softc *twe;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
sc = (struct ld_twe_softc *)ld;
|
|
|
|
twe = (struct twe_softc *)ld->sc_dv.dv_parent;
|
2000-10-20 19:14:25 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
tx.tx_handler = ld_twe_handler;
|
2000-10-19 18:11:30 +04:00
|
|
|
tx.tx_context = bp;
|
2000-11-26 20:44:02 +03:00
|
|
|
tx.tx_dv = &ld->sc_dv;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
return (ld_twe_dobio(sc, sc->sc_hwunit, bp->b_data, bp->b_bcount,
|
2000-11-08 22:20:33 +03:00
|
|
|
bp->b_rawblkno, (bp->b_flags & B_READ) == 0, &tx));
|
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
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_twe_softc *sc;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
sc = (struct ld_twe_softc *)ld;
|
2000-10-19 18:11:30 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
return (ld_twe_dobio(sc, sc->sc_hwunit, data, blkcnt * ld->sc_secsize,
|
2000-10-19 18:11:30 +04:00
|
|
|
blkno, 1, NULL));
|
|
|
|
}
|