2008-05-10 19:31:03 +04:00
|
|
|
/* $NetBSD: wdsc.c,v 1.25 2008/05/10 15:31:05 martin Exp $ */
|
2001-08-19 07:16:21 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2001 Wayne Knowles
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Wayne Knowles
|
|
|
|
*
|
|
|
|
* 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.
|
2008-05-10 19:31:03 +04:00
|
|
|
* 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.
|
2001-08-19 07:16:21 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:54:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
2008-05-10 19:31:03 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wdsc.c,v 1.25 2008/05/10 15:31:05 martin Exp $");
|
2003-07-15 06:54:31 +04:00
|
|
|
|
2001-08-19 07:16:21 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
|
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/autoconf.h>
|
2006-12-23 02:36:42 +03:00
|
|
|
#include <machine/machtype.h>
|
2007-02-21 00:54:44 +03:00
|
|
|
#include <machine/sysconf.h>
|
2001-08-19 07:16:21 +04:00
|
|
|
|
|
|
|
#include <sgimips/hpc/hpcvar.h>
|
|
|
|
#include <sgimips/hpc/hpcreg.h>
|
|
|
|
#include <sgimips/hpc/hpcdma.h>
|
|
|
|
|
2006-08-27 02:06:36 +04:00
|
|
|
#include <dev/ic/wd33c93reg.h>
|
|
|
|
#include <dev/ic/wd33c93var.h>
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
#include <opt_kgdb.h>
|
|
|
|
#include <sys/kgdb.h>
|
|
|
|
|
2001-08-19 07:16:21 +04:00
|
|
|
struct wdsc_softc {
|
2001-11-22 02:22:25 +03:00
|
|
|
struct wd33c93_softc sc_wd33c93; /* Must be first */
|
2002-03-13 16:12:25 +03:00
|
|
|
struct evcnt sc_intrcnt; /* Interrupt counter */
|
2001-11-10 10:32:42 +03:00
|
|
|
bus_dma_tag_t sc_dmat;
|
|
|
|
bus_dmamap_t sc_dmamap;
|
|
|
|
int sc_flags;
|
|
|
|
#define WDSC_DMA_ACTIVE 0x1
|
2002-03-13 16:12:25 +03:00
|
|
|
#define WDSC_DMA_MAPLOADED 0x2
|
2001-08-19 07:16:21 +04:00
|
|
|
struct hpc_dma_softc sc_hpcdma;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-01-10 05:55:54 +03:00
|
|
|
void wdsc_attach (struct device *, struct device *, void *);
|
|
|
|
int wdsc_match (struct device *, struct cfdata *, void *);
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2002-10-02 08:06:36 +04:00
|
|
|
CFATTACH_DECL(wdsc, sizeof(struct wdsc_softc),
|
|
|
|
wdsc_match, wdsc_attach, NULL, NULL);
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
int wdsc_dmasetup (struct wd33c93_softc *, void **,size_t *,
|
2004-01-10 05:55:54 +03:00
|
|
|
int, size_t *);
|
|
|
|
int wdsc_dmago (struct wd33c93_softc *);
|
|
|
|
void wdsc_dmastop (struct wd33c93_softc *);
|
|
|
|
void wdsc_reset (struct wd33c93_softc *);
|
|
|
|
int wdsc_dmaintr (void *);
|
|
|
|
int wdsc_scsiintr (void *);
|
2001-08-19 07:16:21 +04:00
|
|
|
|
|
|
|
/*
|
2007-02-21 00:54:44 +03:00
|
|
|
* Match for SCSI devices on the onboard and GIO32 adapter WD33C93 chips
|
2001-08-19 07:16:21 +04:00
|
|
|
*/
|
|
|
|
int
|
2004-01-10 05:55:54 +03:00
|
|
|
wdsc_match(struct device *pdp, struct cfdata *cf, void *auxp)
|
2001-08-19 07:16:21 +04:00
|
|
|
{
|
2001-11-10 10:32:42 +03:00
|
|
|
struct hpc_attach_args *haa = auxp;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2007-02-21 00:54:44 +03:00
|
|
|
if (strcmp(haa->ha_name, cf->cf_name) == 0) {
|
|
|
|
uint32_t reset, asr, reg;
|
|
|
|
|
|
|
|
reset = MIPS_PHYS_TO_KSEG1(haa->ha_sh + haa->ha_dmaoff +
|
|
|
|
haa->hpc_regs->scsi0_ctl);
|
|
|
|
asr = MIPS_PHYS_TO_KSEG1(haa->ha_sh + haa->ha_devoff);
|
|
|
|
|
|
|
|
/* XXX: hpc1 offset due to SGIMIPS_BUS_SPACE_HPC brain damage */
|
|
|
|
asr = (asr + 3) & ~0x3;
|
|
|
|
|
|
|
|
if (platform.badaddr((void *)reset, sizeof(reset)))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
*(volatile uint32_t *)reset = haa->hpc_regs->scsi_dmactl_reset;
|
|
|
|
delay(1000);
|
|
|
|
*(volatile uint32_t *)reset = 0x0;
|
|
|
|
|
|
|
|
if (platform.badaddr((void *)asr, sizeof(asr)))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
reg = *(volatile uint32_t *)asr;
|
|
|
|
if (haa->hpc_regs->revision == 3) {
|
|
|
|
if ((reg & 0xff) == SBIC_ASR_INT)
|
|
|
|
return (1);
|
|
|
|
} else {
|
|
|
|
if (((reg >> 8) & 0xff) == SBIC_ASR_INT)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
2001-11-18 11:16:15 +03:00
|
|
|
|
|
|
|
return (0);
|
2001-08-19 07:16:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the wdsc driver
|
|
|
|
*/
|
|
|
|
void
|
2004-01-10 05:55:54 +03:00
|
|
|
wdsc_attach(struct device *pdp, struct device *dp, void *auxp)
|
2001-08-19 07:16:21 +04:00
|
|
|
{
|
2001-11-22 02:22:25 +03:00
|
|
|
struct wd33c93_softc *sc = (void *)dp;
|
2001-11-10 10:32:42 +03:00
|
|
|
struct wdsc_softc *wsc = (void *)dp;
|
|
|
|
struct hpc_attach_args *haa = auxp;
|
|
|
|
int err;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-18 11:16:15 +03:00
|
|
|
sc->sc_regt = haa->ha_st;
|
2001-11-10 10:32:42 +03:00
|
|
|
wsc->sc_dmat = haa->ha_dmat;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2003-12-16 14:59:04 +03:00
|
|
|
wsc->sc_hpcdma.hpc = haa->hpc_regs;
|
|
|
|
|
2001-11-18 11:16:15 +03:00
|
|
|
if ((err = bus_space_subregion(haa->ha_st, haa->ha_sh,
|
|
|
|
haa->ha_devoff,
|
2003-12-16 14:59:04 +03:00
|
|
|
wsc->sc_hpcdma.hpc->scsi0_devregs_size,
|
2002-03-13 16:12:25 +03:00
|
|
|
&sc->sc_regh)) != 0) {
|
2001-11-10 10:32:42 +03:00
|
|
|
printf(": unable to map regs, err=%d\n", err);
|
|
|
|
return;
|
|
|
|
}
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2003-12-29 09:33:57 +03:00
|
|
|
if (bus_dmamap_create(wsc->sc_dmat,
|
|
|
|
wsc->sc_hpcdma.hpc->scsi_max_xfer,
|
2003-12-16 14:59:04 +03:00
|
|
|
wsc->sc_hpcdma.hpc->scsi_dma_segs,
|
|
|
|
wsc->sc_hpcdma.hpc->scsi_dma_segs_size,
|
|
|
|
wsc->sc_hpcdma.hpc->scsi_dma_segs_size,
|
2001-08-19 07:16:21 +04:00
|
|
|
BUS_DMA_WAITOK,
|
2001-11-10 10:32:42 +03:00
|
|
|
&wsc->sc_dmamap) != 0) {
|
2001-08-19 07:16:21 +04:00
|
|
|
printf(": failed to create dmamap\n");
|
2001-11-10 10:32:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
sc->sc_dmasetup = wdsc_dmasetup;
|
|
|
|
sc->sc_dmago = wdsc_dmago;
|
|
|
|
sc->sc_dmastop = wdsc_dmastop;
|
2001-11-18 08:14:38 +03:00
|
|
|
sc->sc_reset = wdsc_reset;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-22 02:22:25 +03:00
|
|
|
sc->sc_adapter.adapt_request = wd33c93_scsi_request;
|
2001-11-10 10:32:42 +03:00
|
|
|
sc->sc_adapter.adapt_minphys = minphys;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2003-12-16 14:59:04 +03:00
|
|
|
sc->sc_id = 0; /* Host ID = 0 */
|
2007-03-30 23:04:40 +04:00
|
|
|
sc->sc_clkfreq = 200; /* 20MHz */
|
2007-05-07 03:49:57 +04:00
|
|
|
sc->sc_dmamode = SBIC_CTL_BURST_DMA;
|
2001-11-10 10:32:42 +03:00
|
|
|
|
|
|
|
evcnt_attach_dynamic(&wsc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
|
|
|
|
sc->sc_dev.dv_xname, "intr");
|
|
|
|
|
2001-11-18 11:16:15 +03:00
|
|
|
if ((cpu_intr_establish(haa->ha_irq, IPL_BIO,
|
|
|
|
wdsc_scsiintr, sc)) == NULL) {
|
2001-11-10 10:32:42 +03:00
|
|
|
printf(": unable to establish interrupt!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-29 09:33:57 +03:00
|
|
|
hpcdma_init(haa, &wsc->sc_hpcdma, wsc->sc_hpcdma.hpc->scsi_dma_segs);
|
2001-11-22 02:22:25 +03:00
|
|
|
wd33c93_attach(sc);
|
2001-11-10 10:32:42 +03:00
|
|
|
return;
|
2001-08-19 07:16:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prime the hardware for a DMA transfer
|
2001-11-10 10:32:42 +03:00
|
|
|
*
|
|
|
|
* Requires splbio() interrupts to be disabled by the caller
|
2001-08-19 07:16:21 +04:00
|
|
|
*/
|
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
wdsc_dmasetup(struct wd33c93_softc *dev, void **addr, size_t *len, int datain, size_t *dmasize)
|
2001-08-19 07:16:21 +04:00
|
|
|
{
|
2001-11-10 10:32:42 +03:00
|
|
|
struct wdsc_softc *wsc = (void *)dev;
|
|
|
|
struct hpc_dma_softc *dsc = &wsc->sc_hpcdma;
|
2002-03-13 16:12:25 +03:00
|
|
|
int count, err;
|
|
|
|
void *vaddr;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
KASSERT((wsc->sc_flags & WDSC_DMA_ACTIVE) == 0);
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
vaddr = *addr;
|
|
|
|
count = dsc->sc_dlen = *len;
|
|
|
|
if (count) {
|
|
|
|
KASSERT((wsc->sc_flags & WDSC_DMA_MAPLOADED) == 0);
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
/* Build list of physical addresses for this transfer */
|
|
|
|
if ((err=bus_dmamap_load(wsc->sc_dmat, wsc->sc_dmamap,
|
2001-08-19 07:16:21 +04:00
|
|
|
vaddr, count,
|
2002-03-13 16:12:25 +03:00
|
|
|
NULL /* kernel address */,
|
2001-08-19 07:16:21 +04:00
|
|
|
BUS_DMA_NOWAIT)) != 0)
|
2001-11-10 10:32:42 +03:00
|
|
|
panic("%s: bus_dmamap_load err=%d",
|
|
|
|
dev->sc_dev.dv_xname, err);
|
|
|
|
|
|
|
|
hpcdma_sglist_create(dsc, wsc->sc_dmamap);
|
|
|
|
wsc->sc_flags |= WDSC_DMA_MAPLOADED;
|
|
|
|
|
|
|
|
if (datain) {
|
2006-12-23 02:36:42 +03:00
|
|
|
dsc->sc_dmacmd =
|
|
|
|
wsc->sc_hpcdma.hpc->scsi_dma_datain_cmd;
|
2001-11-10 10:32:42 +03:00
|
|
|
dsc->sc_flags |= HPCDMA_READ;
|
|
|
|
} else {
|
2006-12-23 02:36:42 +03:00
|
|
|
dsc->sc_dmacmd =
|
|
|
|
wsc->sc_hpcdma.hpc->scsi_dma_dataout_cmd;
|
2001-11-10 10:32:42 +03:00
|
|
|
dsc->sc_flags &= ~HPCDMA_READ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(count);
|
2001-08-19 07:16:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prime the hardware for the next DMA transfer
|
|
|
|
*/
|
|
|
|
int
|
2004-01-10 05:55:54 +03:00
|
|
|
wdsc_dmago(struct wd33c93_softc *dev)
|
2001-08-19 07:16:21 +04:00
|
|
|
{
|
2001-11-10 10:32:42 +03:00
|
|
|
struct wdsc_softc *wsc = (void *)dev;
|
|
|
|
struct hpc_dma_softc *dsc = &wsc->sc_hpcdma;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
if (dsc->sc_dlen == 0)
|
|
|
|
return(0);
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
KASSERT((wsc->sc_flags & WDSC_DMA_ACTIVE) == 0);
|
|
|
|
KASSERT((wsc->sc_flags & WDSC_DMA_MAPLOADED));
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
wsc->sc_flags |= WDSC_DMA_ACTIVE;
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
bus_dmamap_sync(wsc->sc_dmat, wsc->sc_dmamap, 0,
|
|
|
|
wsc->sc_dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
|
2001-08-19 07:16:21 +04:00
|
|
|
|
2001-11-10 10:32:42 +03:00
|
|
|
hpcdma_cntl(dsc, dsc->sc_dmacmd); /* Thunderbirds are go! */
|
|
|
|
|
|
|
|
return(wsc->sc_dmamap->dm_mapsize);
|
2001-08-19 07:16:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-11-10 10:32:42 +03:00
|
|
|
* Stop DMA and unload active DMA maps
|
2001-08-19 07:16:21 +04:00
|
|
|
*/
|
|
|
|
void
|
2004-01-10 05:55:54 +03:00
|
|
|
wdsc_dmastop(struct wd33c93_softc *dev)
|
2001-08-19 07:16:21 +04:00
|
|
|
{
|
2001-11-10 10:32:42 +03:00
|
|
|
struct wdsc_softc *wsc = (void *)dev;
|
|
|
|
struct hpc_dma_softc *dsc = &wsc->sc_hpcdma;
|
|
|
|
|
|
|
|
if (wsc->sc_flags & WDSC_DMA_ACTIVE) {
|
|
|
|
if (dsc->sc_flags & HPCDMA_READ)
|
|
|
|
hpcdma_flush(dsc);
|
|
|
|
hpcdma_cntl(dsc, 0); /* Stop DMA */
|
|
|
|
bus_dmamap_sync(wsc->sc_dmat, wsc->sc_dmamap, 0,
|
|
|
|
wsc->sc_dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
|
|
|
|
}
|
|
|
|
if (wsc->sc_flags & WDSC_DMA_MAPLOADED)
|
|
|
|
bus_dmamap_unload(wsc->sc_dmat, wsc->sc_dmamap);
|
|
|
|
wsc->sc_flags &= ~(WDSC_DMA_ACTIVE | WDSC_DMA_MAPLOADED);
|
2001-08-19 07:16:21 +04:00
|
|
|
}
|
|
|
|
|
2001-11-18 08:14:38 +03:00
|
|
|
/*
|
|
|
|
* Reset the controller.
|
|
|
|
*/
|
|
|
|
void
|
2004-01-10 05:55:54 +03:00
|
|
|
wdsc_reset(struct wd33c93_softc *dev)
|
2001-11-18 08:14:38 +03:00
|
|
|
{
|
|
|
|
struct wdsc_softc *wsc = (void *)dev;
|
|
|
|
struct hpc_dma_softc *dsc = &wsc->sc_hpcdma;
|
|
|
|
|
|
|
|
hpcdma_reset(dsc);
|
|
|
|
}
|
|
|
|
|
2001-08-19 07:16:21 +04:00
|
|
|
/*
|
2001-11-10 10:32:42 +03:00
|
|
|
* WD33c93 SCSI controller interrupt
|
2001-08-19 07:16:21 +04:00
|
|
|
*/
|
|
|
|
int
|
2004-01-10 05:55:54 +03:00
|
|
|
wdsc_scsiintr(void *arg)
|
2001-08-19 07:16:21 +04:00
|
|
|
{
|
2001-11-22 02:22:25 +03:00
|
|
|
struct wd33c93_softc *dev = arg;
|
2001-11-10 10:32:42 +03:00
|
|
|
struct wdsc_softc *wsc = arg;
|
|
|
|
int found;
|
|
|
|
|
2001-11-22 02:22:25 +03:00
|
|
|
found = wd33c93_intr(dev);
|
2001-11-10 10:32:42 +03:00
|
|
|
if (found)
|
|
|
|
wsc->sc_intrcnt.ev_count++;
|
|
|
|
return(found);
|
2001-08-19 07:16:21 +04:00
|
|
|
}
|