NetBSD/sys/dev/eisa/uha_eisa.c

338 lines
8.8 KiB
C
Raw Normal View History

/* $NetBSD: uha_eisa.c,v 1.33 2009/12/04 11:13:04 njoly Exp $ */
1996-09-01 04:20:20 +04:00
1998-08-15 14:10:47 +04:00
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
1996-09-01 04:20:20 +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.
*
1998-08-15 14:10:47 +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.
1996-09-01 04:20:20 +04:00
*/
2001-11-13 15:47:33 +03:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uha_eisa.c,v 1.33 2009/12/04 11:13:04 njoly Exp $");
2001-11-13 15:47:33 +03:00
1998-07-05 02:18:13 +04:00
#include "opt_ddb.h"
1996-09-01 00:26:48 +04:00
#include <sys/param.h>
1996-10-10 23:54:10 +04:00
#include <sys/systm.h>
1996-09-01 00:26:48 +04:00
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/bus.h>
#include <sys/intr.h>
1996-09-01 00:26:48 +04:00
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsiconf.h>
1996-09-01 00:26:48 +04:00
#include <dev/eisa/eisavar.h>
#include <dev/eisa/eisadevs.h>
#include <dev/ic/uhareg.h>
#include <dev/ic/uhavar.h>
#define UHA_EISA_SLOT_OFFSET 0xc80
#define UHA_EISA_IOSIZE 0x020
static int uha_eisa_match(device_t, cfdata_t, void *);
static void uha_eisa_attach(device_t, device_t, void *);
1996-09-01 00:26:48 +04:00
2002-10-01 01:04:24 +04:00
CFATTACH_DECL(uha_eisa, sizeof(struct uha_softc),
2002-10-02 20:33:28 +04:00
uha_eisa_match, uha_eisa_attach, NULL, NULL);
1996-09-01 00:26:48 +04:00
#ifndef DDB
#define Debugger() panic("should call debugger here (uha_eisa.c)")
#endif /* ! DDB */
1996-09-01 00:26:48 +04:00
static int u24_find(bus_space_tag_t, bus_space_handle_t,
struct uha_probe_data *);
static void u24_start_mbox(struct uha_softc *, struct uha_mscp *);
static int u24_poll(struct uha_softc *, struct scsipi_xfer *, int);
static int u24_intr(void *);
static void u24_init(struct uha_softc *);
1996-09-01 00:26:48 +04:00
/*
* Check the slots looking for a board we recognise
* If we find one, note it's address (slot) and call
* the actual probe routine to check it out.
*/
static int
uha_eisa_match(device_t parent, cfdata_t match,
void *aux)
1996-09-01 00:26:48 +04:00
{
struct eisa_attach_args *ea = aux;
bus_space_tag_t iot = ea->ea_iot;
bus_space_handle_t ioh;
1996-09-01 00:26:48 +04:00
int rv;
/* must match one of our known ID strings */
if (strncmp(ea->ea_idstring, "USC024", 6))
return (0);
if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
UHA_EISA_SLOT_OFFSET, UHA_EISA_IOSIZE, 0, &ioh))
1996-09-01 00:26:48 +04:00
return (0);
rv = u24_find(iot, ioh, NULL);
1996-09-01 00:26:48 +04:00
bus_space_unmap(iot, ioh, UHA_EISA_IOSIZE);
1996-09-01 00:26:48 +04:00
return (rv);
}
/*
* Attach all the sub-devices we can find
*/
static void
uha_eisa_attach(device_t parent, device_t self, void *aux)
1996-09-01 00:26:48 +04:00
{
struct eisa_attach_args *ea = aux;
2006-03-29 10:28:38 +04:00
struct uha_softc *sc = device_private(self);
bus_space_tag_t iot = ea->ea_iot;
bus_dma_tag_t dmat = ea->ea_dmat;
bus_space_handle_t ioh;
struct uha_probe_data upd;
1996-09-01 00:26:48 +04:00
eisa_chipset_tag_t ec = ea->ea_ec;
eisa_intr_handle_t ih;
const char *model, *intrstr;
if (!strncmp(ea->ea_idstring, "USC024", 6))
model = EISA_PRODUCT_USC0240;
else
model = "unknown model!";
1996-10-13 05:37:04 +04:00
printf(": %s\n", model);
1996-09-01 00:26:48 +04:00
if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
UHA_EISA_SLOT_OFFSET, UHA_EISA_IOSIZE, 0, &ioh))
panic("uha_eisa_attach: could not map I/O addresses");
1996-09-01 00:26:48 +04:00
sc->sc_iot = iot;
1996-09-01 00:26:48 +04:00
sc->sc_ioh = ioh;
sc->sc_dmat = dmat;
if (!u24_find(iot, ioh, &upd))
panic("uha_eisa_attach: u24_find failed!");
1996-09-01 00:26:48 +04:00
sc->sc_dmaflags = 0;
if (eisa_intr_map(ec, upd.sc_irq, &ih)) {
2008-04-06 12:54:43 +04:00
aprint_error_dev(&sc->sc_dev, "couldn't map interrupt (%d)\n",
upd.sc_irq);
1996-09-01 00:26:48 +04:00
return;
}
intrstr = eisa_intr_string(ec, ih);
sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
u24_intr, sc);
if (sc->sc_ih == NULL) {
2008-04-06 12:54:43 +04:00
aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt");
1996-09-01 00:26:48 +04:00
if (intrstr != NULL)
aprint_error(" at %s", intrstr);
aprint_error("\n");
1996-09-01 00:26:48 +04:00
return;
}
aprint_normal_dev(&sc->sc_dev, "interrupting at %s\n", intrstr);
1996-09-01 00:26:48 +04:00
/* Save function pointers for later use. */
sc->start_mbox = u24_start_mbox;
sc->poll = u24_poll;
sc->init = u24_init;
uha_attach(sc, &upd);
1996-09-01 00:26:48 +04:00
}
static int
u24_find(bus_space_tag_t iot, bus_space_handle_t ioh, struct uha_probe_data *sc)
1996-09-01 00:26:48 +04:00
{
u_int8_t config0, config1, config2;
int irq, drq;
int resetcount = 4000; /* 4 secs? */
config0 = bus_space_read_1(iot, ioh, U24_CONFIG + 0);
config1 = bus_space_read_1(iot, ioh, U24_CONFIG + 1);
config2 = bus_space_read_1(iot, ioh, U24_CONFIG + 2);
1996-09-01 00:26:48 +04:00
if ((config0 & U24_MAGIC1) == 0 ||
(config1 & U24_MAGIC2) == 0)
return (0);
drq = -1;
switch (config0 & U24_IRQ_MASK) {
case U24_IRQ10:
irq = 10;
break;
case U24_IRQ11:
irq = 11;
break;
case U24_IRQ14:
irq = 14;
break;
case U24_IRQ15:
irq = 15;
break;
default:
1996-10-13 05:37:04 +04:00
printf("u24_find: illegal irq setting %x\n",
1996-09-01 00:26:48 +04:00
config0 & U24_IRQ_MASK);
return (0);
}
bus_space_write_1(iot, ioh, U24_LINT, UHA_ASRST);
1996-09-01 00:26:48 +04:00
while (--resetcount) {
if (bus_space_read_1(iot, ioh, U24_LINT))
1996-09-01 00:26:48 +04:00
break;
delay(1000); /* 1 mSec per loop */
}
if (!resetcount) {
1996-10-13 05:37:04 +04:00
printf("u24_find: board timed out during reset\n");
1996-09-01 00:26:48 +04:00
return (0);
}
/* if we want to fill in softc, do so now */
if (sc) {
1996-09-01 00:26:48 +04:00
sc->sc_irq = irq;
sc->sc_drq = drq;
sc->sc_scsi_dev = config2 & U24_HOSTID_MASK;
}
return (1);
}
static void
u24_start_mbox(struct uha_softc *sc, struct uha_mscp *mscp)
1996-09-01 00:26:48 +04:00
{
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh = sc->sc_ioh;
1996-09-01 00:26:48 +04:00
int spincount = 100000; /* 1s should be enough */
while (--spincount) {
if ((bus_space_read_1(iot, ioh, U24_LINT) & U24_LDIP) == 0)
1996-09-01 00:26:48 +04:00
break;
delay(100);
}
if (!spincount) {
2008-04-06 12:54:43 +04:00
aprint_error_dev(&sc->sc_dev, "uha_start_mbox, board not responding\n");
1996-09-01 00:26:48 +04:00
Debugger();
}
bus_space_write_4(iot, ioh, U24_OGMPTR,
sc->sc_dmamap_mscp->dm_segs[0].ds_addr + UHA_MSCP_OFF(mscp));
1996-09-01 00:26:48 +04:00
if (mscp->flags & MSCP_ABORT)
bus_space_write_1(iot, ioh, U24_OGMCMD, 0x80);
1996-09-01 00:26:48 +04:00
else
bus_space_write_1(iot, ioh, U24_OGMCMD, 0x01);
bus_space_write_1(iot, ioh, U24_LINT, U24_OGMFULL);
1996-09-01 00:26:48 +04:00
1999-10-01 03:04:39 +04:00
if ((mscp->xs->xs_control & XS_CTL_POLL) == 0)
callout_reset(&mscp->xs->xs_callout,
mstohz(mscp->timeout), uha_timeout, mscp);
1996-09-01 00:26:48 +04:00
}
static int
u24_poll(struct uha_softc *sc, struct scsipi_xfer *xs, int count)
1996-09-01 00:26:48 +04:00
{
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh = sc->sc_ioh;
1996-09-01 00:26:48 +04:00
while (count) {
/*
* If we had interrupts enabled, would we
* have got an interrupt?
*/
if (bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP)
1996-09-01 00:26:48 +04:00
u24_intr(sc);
1999-10-01 03:04:39 +04:00
if (xs->xs_status & XS_STS_DONE)
1996-09-01 00:26:48 +04:00
return (0);
delay(1000);
count--;
}
return (1);
}
static int
u24_intr(void *arg)
1996-09-01 00:26:48 +04:00
{
struct uha_softc *sc = arg;
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh = sc->sc_ioh;
1996-09-01 00:26:48 +04:00
struct uha_mscp *mscp;
u_char uhastat;
u_long mboxval;
#ifdef UHADEBUG
2008-04-06 12:54:43 +04:00
printf("%s: uhaintr ", device_xname(&sc->sc_dev));
1996-09-01 00:26:48 +04:00
#endif /*UHADEBUG */
if ((bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP) == 0)
1996-09-01 00:26:48 +04:00
return (0);
for (;;) {
/*
* First get all the information and then
* acknowledge the interrupt
*/
uhastat = bus_space_read_1(iot, ioh, U24_SINT);
mboxval = bus_space_read_4(iot, ioh, U24_ICMPTR);
bus_space_write_1(iot, ioh, U24_SINT, U24_ICM_ACK);
bus_space_write_1(iot, ioh, U24_ICMCMD, 0);
1996-09-01 00:26:48 +04:00
#ifdef UHADEBUG
1996-10-13 05:37:04 +04:00
printf("status = 0x%x ", uhastat);
1996-09-01 00:26:48 +04:00
#endif /*UHADEBUG*/
/*
* Process the completed operation
*/
mscp = uha_mscp_phys_kv(sc, mboxval);
if (!mscp) {
1996-10-13 05:37:04 +04:00
printf("%s: BAD MSCP RETURNED!\n",
2008-04-06 12:54:43 +04:00
device_xname(&sc->sc_dev));
1996-09-01 00:26:48 +04:00
continue; /* whatever it was, it'll timeout */
}
callout_stop(&mscp->xs->xs_callout);
1996-09-01 00:26:48 +04:00
uha_done(sc, mscp);
if ((bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP) == 0)
1996-09-01 00:26:48 +04:00
return (1);
}
}
static void
u24_init(struct uha_softc *sc)
1996-09-01 00:26:48 +04:00
{
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh = sc->sc_ioh;
1996-09-01 00:26:48 +04:00
/* free OGM and ICM */
bus_space_write_1(iot, ioh, U24_OGMCMD, 0);
bus_space_write_1(iot, ioh, U24_ICMCMD, 0);
1996-09-01 00:26:48 +04:00
/* make sure interrupts are enabled */
#ifdef UHADEBUG
1996-10-13 05:37:04 +04:00
printf("u24_init: lmask=%02x, smask=%02x\n",
bus_space_read_1(iot, ioh, U24_LMASK),
bus_space_read_1(iot, ioh, U24_SMASK));
1996-09-01 00:26:48 +04:00
#endif
bus_space_write_1(iot, ioh, U24_LMASK, 0xd2); /* XXX */
bus_space_write_1(iot, ioh, U24_SMASK, 0x92); /* XXX */
1996-09-01 00:26:48 +04:00
}