Home | History | Annotate | Line # | Download | only in qbus
uda.c revision 1.57
      1  1.57        ad /*	$NetBSD: uda.c,v 1.57 2007/10/19 12:01:09 ad Exp $	*/
      2  1.49       agc /*
      3  1.49       agc  * Copyright (c) 1988 Regents of the University of California.
      4  1.49       agc  * All rights reserved.
      5  1.49       agc  *
      6  1.49       agc  * This code is derived from software contributed to Berkeley by
      7  1.49       agc  * Chris Torek.
      8  1.49       agc  *
      9  1.49       agc  * Redistribution and use in source and binary forms, with or without
     10  1.49       agc  * modification, are permitted provided that the following conditions
     11  1.49       agc  * are met:
     12  1.49       agc  * 1. Redistributions of source code must retain the above copyright
     13  1.49       agc  *    notice, this list of conditions and the following disclaimer.
     14  1.49       agc  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.49       agc  *    notice, this list of conditions and the following disclaimer in the
     16  1.49       agc  *    documentation and/or other materials provided with the distribution.
     17  1.49       agc  * 3. Neither the name of the University nor the names of its contributors
     18  1.49       agc  *    may be used to endorse or promote products derived from this software
     19  1.49       agc  *    without specific prior written permission.
     20  1.49       agc  *
     21  1.49       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.49       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.49       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.49       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.49       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.49       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.49       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.49       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.49       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.49       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.49       agc  * SUCH DAMAGE.
     32  1.49       agc  *
     33  1.49       agc  *	@(#)uda.c	7.32 (Berkeley) 2/13/91
     34  1.49       agc  */
     35  1.49       agc 
     36   1.1     ragge /*
     37  1.17     ragge  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
     38   1.1     ragge  * All rights reserved.
     39   1.1     ragge  *
     40   1.1     ragge  * This code is derived from software contributed to Berkeley by
     41   1.1     ragge  * Chris Torek.
     42   1.1     ragge  *
     43   1.1     ragge  * Redistribution and use in source and binary forms, with or without
     44   1.1     ragge  * modification, are permitted provided that the following conditions
     45   1.1     ragge  * are met:
     46   1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     47   1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     48   1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     50   1.1     ragge  *    documentation and/or other materials provided with the distribution.
     51   1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     52   1.1     ragge  *    must display the following acknowledgement:
     53   1.1     ragge  *	This product includes software developed by the University of
     54   1.1     ragge  *	California, Berkeley and its contributors.
     55   1.1     ragge  * 4. Neither the name of the University nor the names of its contributors
     56   1.1     ragge  *    may be used to endorse or promote products derived from this software
     57   1.1     ragge  *    without specific prior written permission.
     58   1.1     ragge  *
     59   1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60   1.1     ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61   1.1     ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62   1.1     ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63   1.1     ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64   1.1     ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65   1.1     ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66   1.1     ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67   1.1     ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68   1.1     ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69   1.1     ragge  * SUCH DAMAGE.
     70   1.1     ragge  *
     71   1.3       cgd  *	@(#)uda.c	7.32 (Berkeley) 2/13/91
     72   1.1     ragge  */
     73   1.1     ragge 
     74   1.1     ragge /*
     75  1.18     ragge  * UDA50 disk device driver
     76   1.1     ragge  */
     77  1.42     lukem 
     78  1.42     lukem #include <sys/cdefs.h>
     79  1.57        ad __KERNEL_RCSID(0, "$NetBSD: uda.c,v 1.57 2007/10/19 12:01:09 ad Exp $");
     80   1.1     ragge 
     81  1.11   mycroft #include <sys/param.h>
     82  1.17     ragge #include <sys/kernel.h>
     83  1.20     ragge #include <sys/systm.h>
     84  1.30     ragge #include <sys/device.h>
     85  1.30     ragge #include <sys/buf.h>
     86  1.50        he #include <sys/bufq.h>
     87  1.30     ragge #include <sys/malloc.h>
     88  1.11   mycroft 
     89  1.57        ad #include <sys/bus.h>
     90  1.18     ragge #include <machine/sid.h>
     91   1.1     ragge 
     92  1.30     ragge #include <dev/qbus/ubavar.h>
     93  1.30     ragge 
     94  1.30     ragge #include <dev/mscp/mscp.h>
     95  1.30     ragge #include <dev/mscp/mscpreg.h>
     96  1.30     ragge #include <dev/mscp/mscpvar.h>
     97  1.30     ragge 
     98  1.30     ragge #include "ioconf.h"
     99   1.1     ragge 
    100   1.1     ragge /*
    101   1.1     ragge  * Software status, per controller.
    102   1.1     ragge  */
    103   1.1     ragge struct	uda_softc {
    104  1.17     ragge 	struct	device sc_dev;	/* Autoconfig info */
    105  1.36      matt 	struct	evcnt sc_intrcnt; /* Interrupt counting */
    106  1.17     ragge 	struct	uba_unit sc_unit; /* Struct common for UBA to communicate */
    107  1.40     ragge 	struct	ubinfo sc_ui;
    108  1.30     ragge 	bus_dma_tag_t		sc_dmat;
    109  1.30     ragge 	bus_space_tag_t		sc_iot;
    110  1.30     ragge 	bus_space_handle_t	sc_iph;
    111  1.30     ragge 	bus_space_handle_t	sc_sah;
    112  1.17     ragge 	struct	mscp_softc *sc_softc;	/* MSCP info (per mscpvar.h) */
    113  1.30     ragge 	int	sc_inq;
    114  1.17     ragge };
    115   1.1     ragge 
    116  1.40     ragge static	int udamatch(struct device *, struct cfdata *, void *);
    117  1.40     ragge static	void udaattach(struct device *, struct device *, void *);
    118  1.40     ragge static	void udareset(struct device *);
    119  1.40     ragge static	void udaintr(void *);
    120  1.40     ragge static	int udaready(struct uba_unit *);
    121  1.40     ragge static	void udactlrdone(struct device *);
    122  1.40     ragge static	int udaprint(void *, const char *);
    123  1.40     ragge static	void udasaerror(struct device *, int);
    124  1.40     ragge static	void udago(struct device *, struct mscp_xi *);
    125  1.20     ragge 
    126  1.46   thorpej CFATTACH_DECL(mtc, sizeof(struct uda_softc),
    127  1.47   thorpej     udamatch, udaattach, NULL, NULL);
    128  1.10     ragge 
    129  1.46   thorpej CFATTACH_DECL(uda, sizeof(struct uda_softc),
    130  1.47   thorpej     udamatch, udaattach, NULL, NULL);
    131  1.10     ragge 
    132   1.1     ragge /*
    133   1.1     ragge  * More driver definitions, for generic MSCP code.
    134   1.1     ragge  */
    135  1.17     ragge struct	mscp_ctlr uda_mscp_ctlr = {
    136  1.17     ragge 	udactlrdone,
    137  1.17     ragge 	udago,
    138  1.17     ragge 	udasaerror,
    139  1.17     ragge };
    140   1.1     ragge 
    141  1.17     ragge int
    142  1.40     ragge udaprint(void *aux, const char *name)
    143  1.17     ragge {
    144  1.17     ragge 	if (name)
    145  1.48   thorpej 		aprint_normal("%s: mscpbus", name);
    146  1.17     ragge 	return UNCONF;
    147  1.17     ragge }
    148   1.1     ragge 
    149   1.1     ragge /*
    150   1.1     ragge  * Poke at a supposed UDA50 to see if it is there.
    151   1.1     ragge  */
    152  1.10     ragge int
    153  1.40     ragge udamatch(struct device *parent, struct cfdata *cf, void *aux)
    154   1.1     ragge {
    155  1.17     ragge 	struct	uba_attach_args *ua = aux;
    156  1.18     ragge 	struct	mscp_softc mi;	/* Nice hack */
    157  1.17     ragge 	struct	uba_softc *ubasc;
    158  1.20     ragge 	int	tries;
    159   1.1     ragge 
    160  1.17     ragge 	/* Get an interrupt vector. */
    161  1.17     ragge 	ubasc = (void *)parent;
    162   1.1     ragge 
    163  1.30     ragge 	mi.mi_iot = ua->ua_iot;
    164  1.30     ragge 	mi.mi_iph = ua->ua_ioh;
    165  1.30     ragge 	mi.mi_sah = ua->ua_ioh + 2;
    166  1.30     ragge 	mi.mi_swh = ua->ua_ioh + 2;
    167   1.1     ragge 
    168   1.1     ragge 	/*
    169   1.1     ragge 	 * Initialise the controller (partially).  The UDA50 programmer's
    170   1.1     ragge 	 * manual states that if initialisation fails, it should be retried
    171   1.1     ragge 	 * at least once, but after a second failure the port should be
    172   1.1     ragge 	 * considered `down'; it also mentions that the controller should
    173   1.1     ragge 	 * initialise within ten seconds.  Or so I hear; I have not seen
    174   1.1     ragge 	 * this manual myself.
    175   1.1     ragge 	 */
    176   1.1     ragge 	tries = 0;
    177   1.1     ragge again:
    178   1.8     ragge 
    179  1.30     ragge 	bus_space_write_2(mi.mi_iot, mi.mi_iph, 0, 0); /* Start init */
    180  1.18     ragge 	if (mscp_waitstep(&mi, MP_STEP1, MP_STEP1) == 0)
    181  1.18     ragge 		return 0; /* Nothing here... */
    182   1.8     ragge 
    183  1.51    simonb 	bus_space_write_2(mi.mi_iot, mi.mi_sah, 0,
    184  1.40     ragge 	    MP_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | MP_IE |
    185  1.40     ragge 	    ((ubasc->uh_lastiv - 4) >> 2));
    186   1.8     ragge 
    187  1.18     ragge 	if (mscp_waitstep(&mi, MP_STEP2, MP_STEP2) == 0) {
    188  1.51    simonb 		printf("udaprobe: init step2 no change. sa=%x\n",
    189  1.30     ragge 		    bus_space_read_2(mi.mi_iot, mi.mi_sah, 0));
    190   1.8     ragge 		goto bad;
    191   1.8     ragge 	}
    192   1.8     ragge 
    193   1.1     ragge 	/* should have interrupted by now */
    194  1.17     ragge 	return 1;
    195   1.1     ragge bad:
    196   1.1     ragge 	if (++tries < 2)
    197   1.1     ragge 		goto again;
    198  1.17     ragge 	return 0;
    199   1.1     ragge }
    200   1.1     ragge 
    201  1.17     ragge void
    202  1.40     ragge udaattach(struct device *parent, struct device *self, void *aux)
    203   1.1     ragge {
    204  1.56   thorpej 	struct	uda_softc *sc = device_private(self);
    205  1.19     ragge 	struct	uba_attach_args *ua = aux;
    206  1.17     ragge 	struct	uba_softc *uh = (void *)parent;
    207  1.17     ragge 	struct	mscp_attach_args ma;
    208  1.40     ragge 	int	error;
    209   1.6     ragge 
    210  1.23  christos 	printf("\n");
    211   1.1     ragge 
    212  1.17     ragge 	uh->uh_lastiv -= 4;	/* remove dynamic interrupt vector */
    213   1.1     ragge 
    214  1.36      matt 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec,
    215  1.36      matt 		udaintr, sc, &sc->sc_intrcnt);
    216  1.36      matt 	uba_reset_establish(udareset, &sc->sc_dev);
    217  1.37      matt 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    218  1.37      matt 		sc->sc_dev.dv_xname, "intr");
    219  1.32      matt 
    220  1.30     ragge 	sc->sc_iot = ua->ua_iot;
    221  1.30     ragge 	sc->sc_iph = ua->ua_ioh;
    222  1.30     ragge 	sc->sc_sah = ua->ua_ioh + 2;
    223  1.30     ragge 	sc->sc_dmat = ua->ua_dmat;
    224   1.1     ragge 
    225   1.1     ragge 	/*
    226  1.17     ragge 	 * Fill in the uba_unit struct, so we can communicate with the uba.
    227   1.1     ragge 	 */
    228  1.17     ragge 	sc->sc_unit.uu_softc = sc;	/* Backpointer to softc */
    229  1.20     ragge 	sc->sc_unit.uu_ready = udaready;/* go routine called from adapter */
    230  1.19     ragge 	sc->sc_unit.uu_keepbdp = vax_cputype == VAX_750 ? 1 : 0;
    231   1.1     ragge 
    232  1.18     ragge 	/*
    233  1.18     ragge 	 * Map the communication area and command and
    234  1.18     ragge 	 * response packets into Unibus space.
    235  1.18     ragge 	 */
    236  1.40     ragge 	sc->sc_ui.ui_size = sizeof(struct mscp_pack);
    237  1.40     ragge 	if ((error = ubmemalloc((void *)parent, &sc->sc_ui, UBA_CANTWAIT)))
    238  1.40     ragge 		return printf("ubmemalloc failed: %d\n", error);
    239  1.18     ragge 
    240  1.40     ragge 	bzero(sc->sc_ui.ui_vaddr, sizeof (struct mscp_pack));
    241   1.1     ragge 
    242  1.20     ragge 	/*
    243  1.20     ragge 	 * The only thing that differ UDA's and Tape ctlr's is
    244  1.20     ragge 	 * their vcid. Beacuse there are no way to determine which
    245  1.20     ragge 	 * ctlr type it is, we check what is generated and later
    246  1.20     ragge 	 * set the correct vcid.
    247  1.20     ragge 	 */
    248  1.54   thorpej 	ma.ma_type = (device_is_a(self, "mtc") ? MSCPBUS_TAPE : MSCPBUS_DISK);
    249  1.20     ragge 
    250  1.17     ragge 	ma.ma_mc = &uda_mscp_ctlr;
    251  1.20     ragge 	ma.ma_type |= MSCPBUS_UDA;
    252  1.40     ragge 	ma.ma_uda = (struct mscp_pack *)sc->sc_ui.ui_vaddr;
    253  1.20     ragge 	ma.ma_softc = &sc->sc_softc;
    254  1.30     ragge 	ma.ma_iot = sc->sc_iot;
    255  1.30     ragge 	ma.ma_iph = sc->sc_iph;
    256  1.30     ragge 	ma.ma_sah = sc->sc_sah;
    257  1.30     ragge 	ma.ma_swh = sc->sc_sah;
    258  1.30     ragge 	ma.ma_dmat = sc->sc_dmat;
    259  1.40     ragge 	ma.ma_dmam = sc->sc_ui.ui_dmam;
    260  1.40     ragge 	ma.ma_ivec = uh->uh_lastiv;
    261  1.25     ragge 	ma.ma_ctlrnr = (ua->ua_iaddr == 0172150 ? 0 : 1);	/* XXX */
    262  1.18     ragge 	ma.ma_adapnr = uh->uh_nr;
    263  1.17     ragge 	config_found(&sc->sc_dev, &ma, udaprint);
    264  1.17     ragge }
    265   1.1     ragge 
    266  1.20     ragge /*
    267  1.20     ragge  * Start a transfer if there are free resources available, otherwise
    268  1.20     ragge  * let it go in udaready, forget it for now.
    269  1.30     ragge  * Called from mscp routines.
    270  1.20     ragge  */
    271  1.30     ragge void
    272  1.40     ragge udago(struct device *usc, struct mscp_xi *mxi)
    273  1.17     ragge {
    274  1.17     ragge 	struct uda_softc *sc = (void *)usc;
    275  1.30     ragge 	struct uba_unit *uu;
    276  1.30     ragge 	struct buf *bp = mxi->mxi_bp;
    277  1.30     ragge 	int err;
    278   1.1     ragge 
    279  1.20     ragge 	/*
    280  1.30     ragge 	 * If we already have transfers queued, don't try to load
    281  1.30     ragge 	 * the map again.
    282  1.20     ragge 	 */
    283  1.30     ragge 	if (sc->sc_inq == 0) {
    284  1.30     ragge 		err = bus_dmamap_load(sc->sc_dmat, mxi->mxi_dmam,
    285  1.51    simonb 		    bp->b_data, bp->b_bcount,
    286  1.41     ragge 		    (bp->b_flags & B_PHYS ? bp->b_proc : 0), BUS_DMA_NOWAIT);
    287  1.30     ragge 		if (err == 0) {
    288  1.30     ragge 			mscp_dgo(sc->sc_softc, mxi);
    289  1.30     ragge 			return;
    290  1.30     ragge 		}
    291  1.20     ragge 	}
    292  1.30     ragge 	uu = malloc(sizeof(struct uba_unit), M_DEVBUF, M_NOWAIT);
    293  1.30     ragge 	if (uu == 0)
    294  1.30     ragge 		panic("udago: no mem");
    295  1.30     ragge 	uu->uu_ready = udaready;
    296  1.30     ragge 	uu->uu_softc = sc;
    297  1.30     ragge 	uu->uu_ref = mxi;
    298  1.30     ragge 	uba_enqueue(uu);
    299  1.30     ragge 	sc->sc_inq++;
    300   1.1     ragge }
    301   1.1     ragge 
    302   1.1     ragge /*
    303  1.20     ragge  * Called if we have been blocked for resources, and resources
    304  1.51    simonb  * have been freed again. Return 1 if we could start all
    305  1.20     ragge  * transfers again, 0 if we still are waiting.
    306  1.30     ragge  * Called from uba resource free routines.
    307   1.1     ragge  */
    308  1.20     ragge int
    309  1.40     ragge udaready(struct uba_unit *uu)
    310   1.1     ragge {
    311  1.17     ragge 	struct uda_softc *sc = uu->uu_softc;
    312  1.30     ragge 	struct mscp_xi *mxi = uu->uu_ref;
    313  1.30     ragge 	struct buf *bp = mxi->mxi_bp;
    314  1.30     ragge 	int err;
    315  1.30     ragge 
    316  1.35   thorpej 	err = bus_dmamap_load(sc->sc_dmat, mxi->mxi_dmam, bp->b_data,
    317  1.43     ragge 	    bp->b_bcount, (bp->b_flags & B_PHYS ? bp->b_proc : 0),
    318  1.43     ragge 	    BUS_DMA_NOWAIT);
    319  1.43     ragge 
    320  1.30     ragge 	if (err)
    321  1.30     ragge 		return 0;
    322  1.30     ragge 	mscp_dgo(sc->sc_softc, mxi);
    323  1.30     ragge 	sc->sc_inq--;
    324  1.30     ragge 	free(uu, M_DEVBUF);
    325  1.20     ragge 	return 1;
    326  1.17     ragge }
    327  1.17     ragge 
    328  1.17     ragge static struct saerr {
    329  1.17     ragge 	int	code;		/* error code (including UDA_ERR) */
    330  1.52     ragge 	const char	*desc;		/* what it means: Efoo => foo error */
    331  1.17     ragge } saerr[] = {
    332  1.17     ragge 	{ 0100001, "Eunibus packet read" },
    333  1.17     ragge 	{ 0100002, "Eunibus packet write" },
    334  1.17     ragge 	{ 0100003, "EUDA ROM and RAM parity" },
    335  1.17     ragge 	{ 0100004, "EUDA RAM parity" },
    336  1.17     ragge 	{ 0100005, "EUDA ROM parity" },
    337  1.17     ragge 	{ 0100006, "Eunibus ring read" },
    338  1.17     ragge 	{ 0100007, "Eunibus ring write" },
    339  1.17     ragge 	{ 0100010, " unibus interrupt master failure" },
    340  1.17     ragge 	{ 0100011, "Ehost access timeout" },
    341  1.17     ragge 	{ 0100012, " host exceeded command limit" },
    342  1.17     ragge 	{ 0100013, " unibus bus master failure" },
    343  1.17     ragge 	{ 0100014, " DM XFC fatal error" },
    344  1.17     ragge 	{ 0100015, " hardware timeout of instruction loop" },
    345  1.17     ragge 	{ 0100016, " invalid virtual circuit id" },
    346  1.17     ragge 	{ 0100017, "Eunibus interrupt write" },
    347  1.17     ragge 	{ 0104000, "Efatal sequence" },
    348  1.17     ragge 	{ 0104040, " D proc ALU" },
    349  1.17     ragge 	{ 0104041, "ED proc control ROM parity" },
    350  1.17     ragge 	{ 0105102, "ED proc w/no BD#2 or RAM parity" },
    351  1.17     ragge 	{ 0105105, "ED proc RAM buffer" },
    352  1.17     ragge 	{ 0105152, "ED proc SDI" },
    353  1.17     ragge 	{ 0105153, "ED proc write mode wrap serdes" },
    354  1.17     ragge 	{ 0105154, "ED proc read mode serdes, RSGEN & ECC" },
    355  1.17     ragge 	{ 0106040, "EU proc ALU" },
    356  1.17     ragge 	{ 0106041, "EU proc control reg" },
    357  1.17     ragge 	{ 0106042, " U proc DFAIL/cntl ROM parity/BD #1 test CNT" },
    358  1.17     ragge 	{ 0106047, " U proc const PROM err w/D proc running SDI test" },
    359  1.17     ragge 	{ 0106055, " unexpected trap" },
    360  1.17     ragge 	{ 0106071, "EU proc const PROM" },
    361  1.17     ragge 	{ 0106072, "EU proc control ROM parity" },
    362  1.17     ragge 	{ 0106200, "Estep 1 data" },
    363  1.17     ragge 	{ 0107103, "EU proc RAM parity" },
    364  1.17     ragge 	{ 0107107, "EU proc RAM buffer" },
    365  1.17     ragge 	{ 0107115, " test count wrong (BD 12)" },
    366  1.17     ragge 	{ 0112300, "Estep 2" },
    367  1.17     ragge 	{ 0122240, "ENPR" },
    368  1.17     ragge 	{ 0122300, "Estep 3" },
    369  1.17     ragge 	{ 0142300, "Estep 4" },
    370  1.17     ragge 	{ 0, " unknown error code" }
    371  1.17     ragge };
    372   1.6     ragge 
    373  1.17     ragge /*
    374  1.17     ragge  * If the error bit was set in the controller status register, gripe,
    375  1.17     ragge  * then (optionally) reset the controller and requeue pending transfers.
    376  1.17     ragge  */
    377  1.17     ragge void
    378  1.40     ragge udasaerror(struct device *usc, int doreset)
    379  1.17     ragge {
    380  1.17     ragge 	struct	uda_softc *sc = (void *)usc;
    381  1.33  augustss 	int code = bus_space_read_2(sc->sc_iot, sc->sc_sah, 0);
    382  1.33  augustss 	struct saerr *e;
    383   1.1     ragge 
    384  1.17     ragge 	if ((code & MP_ERR) == 0)
    385   1.1     ragge 		return;
    386  1.17     ragge 	for (e = saerr; e->code; e++)
    387  1.17     ragge 		if (e->code == code)
    388  1.17     ragge 			break;
    389  1.23  christos 	printf("%s: controller error, sa=0%o (%s%s)\n",
    390  1.17     ragge 		sc->sc_dev.dv_xname, code, e->desc + 1,
    391  1.17     ragge 		*e->desc == 'E' ? " error" : "");
    392  1.24     ragge #if 0 /* XXX we just avoid panic when autoconfig non-existent KFQSA devices */
    393  1.17     ragge 	if (doreset) {
    394  1.17     ragge 		mscp_requeue(sc->sc_softc);
    395  1.17     ragge /*		(void) udainit(sc);	XXX */
    396   1.1     ragge 	}
    397  1.24     ragge #endif
    398   1.1     ragge }
    399   1.1     ragge 
    400   1.1     ragge /*
    401  1.17     ragge  * Interrupt routine.  Depending on the state of the controller,
    402  1.17     ragge  * continue initialisation, or acknowledge command and response
    403  1.17     ragge  * interrupts, and process responses.
    404   1.1     ragge  */
    405  1.20     ragge static void
    406  1.40     ragge udaintr(void *arg)
    407   1.1     ragge {
    408  1.32      matt 	struct uda_softc *sc = arg;
    409  1.32      matt 	struct uba_softc *uh;
    410   1.1     ragge 
    411  1.30     ragge 	/* ctlr fatal error */
    412  1.30     ragge 	if (bus_space_read_2(sc->sc_iot, sc->sc_sah, 0) & MP_ERR) {
    413  1.17     ragge 		udasaerror(&sc->sc_dev, 1);
    414  1.17     ragge 		return;
    415  1.17     ragge 	}
    416   1.1     ragge 	/*
    417  1.17     ragge 	 * Handle buffer purge requests.
    418  1.30     ragge 	 * XXX - should be done in bus_dma_sync().
    419   1.1     ragge 	 */
    420  1.55   thorpej 	uh = (void *)device_parent(&sc->sc_dev);
    421  1.40     ragge #ifdef notyet
    422  1.17     ragge 	if (ud->mp_ca.ca_bdp) {
    423  1.20     ragge 		if (uh->uh_ubapurge)
    424  1.20     ragge 			(*uh->uh_ubapurge)(uh, ud->mp_ca.ca_bdp);
    425  1.30     ragge 		/* signal purge complete */
    426  1.30     ragge 		bus_space_write_2(sc->sc_iot, sc->sc_sah, 0, 0);
    427   1.1     ragge 	}
    428  1.40     ragge #endif
    429   1.1     ragge 
    430  1.17     ragge 	mscp_intr(sc->sc_softc);
    431   1.1     ragge }
    432   1.1     ragge 
    433   1.1     ragge /*
    434  1.17     ragge  * A Unibus reset has occurred on UBA uban.  Reinitialise the controller(s)
    435  1.17     ragge  * on that Unibus, and requeue outstanding I/O.
    436   1.1     ragge  */
    437  1.20     ragge static void
    438  1.36      matt udareset(struct device *dev)
    439  1.20     ragge {
    440  1.34     ragge 	struct uda_softc *sc = (void *)dev;
    441   1.1     ragge 	/*
    442  1.17     ragge 	 * Our BDP (if any) is gone; our command (if any) is
    443  1.17     ragge 	 * flushed; the device is no longer mapped; and the
    444  1.17     ragge 	 * UDA50 is not yet initialised.
    445   1.1     ragge 	 */
    446  1.17     ragge 	if (sc->sc_unit.uu_bdp) {
    447  1.30     ragge 		/* printf("<%d>", UBAI_BDP(sc->sc_unit.uu_bdp)); */
    448  1.17     ragge 		sc->sc_unit.uu_bdp = 0;
    449   1.1     ragge 	}
    450   1.1     ragge 
    451  1.17     ragge 	/* reset queues and requeue pending transfers */
    452  1.17     ragge 	mscp_requeue(sc->sc_softc);
    453   1.1     ragge 
    454   1.1     ragge 	/*
    455  1.17     ragge 	 * If it fails to initialise we will notice later and
    456  1.17     ragge 	 * try again (and again...).  Do not call udastart()
    457  1.17     ragge 	 * here; it will be done after the controller finishes
    458  1.17     ragge 	 * initialisation.
    459   1.1     ragge 	 */
    460  1.17     ragge /* XXX	if (udainit(sc)) */
    461  1.23  christos 		printf(" (hung)");
    462   1.1     ragge }
    463   1.1     ragge 
    464  1.17     ragge void
    465  1.40     ragge udactlrdone(struct device *usc)
    466   1.1     ragge {
    467  1.17     ragge 	struct uda_softc *sc = (void *)usc;
    468  1.39   thorpej 	int s;
    469   1.1     ragge 
    470  1.39   thorpej 	s = spluba();
    471  1.55   thorpej 	uba_done((struct uba_softc *)device_parent(&sc->sc_dev));
    472  1.39   thorpej 	splx(s);
    473   1.1     ragge }
    474