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