Home | History | Annotate | Line # | Download | only in mscp
mscp_subr.c revision 1.24
      1  1.24       agc /*	$NetBSD: mscp_subr.c,v 1.24 2003/08/07 16:31:09 agc Exp $	*/
      2   1.1     ragge /*
      3   1.1     ragge  * Copyright (c) 1988 Regents of the University of California.
      4   1.1     ragge  * All rights reserved.
      5   1.1     ragge  *
      6   1.1     ragge  * This code is derived from software contributed to Berkeley by
      7   1.1     ragge  * Chris Torek.
      8   1.1     ragge  *
      9   1.1     ragge  * Redistribution and use in source and binary forms, with or without
     10   1.1     ragge  * modification, are permitted provided that the following conditions
     11   1.1     ragge  * are met:
     12   1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     13   1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     14   1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     16   1.1     ragge  *    documentation and/or other materials provided with the distribution.
     17  1.24       agc  * 3. Neither the name of the University nor the names of its contributors
     18  1.24       agc  *    may be used to endorse or promote products derived from this software
     19  1.24       agc  *    without specific prior written permission.
     20  1.24       agc  *
     21  1.24       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.24       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.24       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.24       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.24       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.24       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.24       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.24       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.24       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.24       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.24       agc  * SUCH DAMAGE.
     32  1.24       agc  *
     33  1.24       agc  *	@(#)mscp.c	7.5 (Berkeley) 12/16/90
     34  1.24       agc  */
     35  1.24       agc 
     36  1.24       agc /*
     37  1.24       agc  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
     38  1.24       agc  *
     39  1.24       agc  * This code is derived from software contributed to Berkeley by
     40  1.24       agc  * Chris Torek.
     41  1.24       agc  *
     42  1.24       agc  * Redistribution and use in source and binary forms, with or without
     43  1.24       agc  * modification, are permitted provided that the following conditions
     44  1.24       agc  * are met:
     45  1.24       agc  * 1. Redistributions of source code must retain the above copyright
     46  1.24       agc  *    notice, this list of conditions and the following disclaimer.
     47  1.24       agc  * 2. Redistributions in binary form must reproduce the above copyright
     48  1.24       agc  *    notice, this list of conditions and the following disclaimer in the
     49  1.24       agc  *    documentation and/or other materials provided with the distribution.
     50   1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     51   1.1     ragge  *    must display the following acknowledgement:
     52   1.1     ragge  *	This product includes software developed by the University of
     53   1.1     ragge  *	California, Berkeley and its contributors.
     54   1.1     ragge  * 4. Neither the name of the University nor the names of its contributors
     55   1.1     ragge  *    may be used to endorse or promote products derived from this software
     56   1.1     ragge  *    without specific prior written permission.
     57   1.1     ragge  *
     58   1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59   1.1     ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60   1.1     ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61   1.1     ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62   1.1     ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63   1.1     ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64   1.1     ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65   1.1     ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66   1.1     ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67   1.1     ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68   1.1     ragge  * SUCH DAMAGE.
     69   1.1     ragge  *
     70   1.1     ragge  *	@(#)mscp.c	7.5 (Berkeley) 12/16/90
     71   1.1     ragge  */
     72   1.1     ragge 
     73   1.1     ragge /*
     74   1.1     ragge  * MSCP generic driver routines
     75   1.1     ragge  */
     76  1.18     lukem 
     77  1.18     lukem #include <sys/cdefs.h>
     78  1.24       agc __KERNEL_RCSID(0, "$NetBSD: mscp_subr.c,v 1.24 2003/08/07 16:31:09 agc Exp $");
     79   1.1     ragge 
     80   1.1     ragge #include <sys/param.h>
     81   1.2     ragge #include <sys/device.h>
     82   1.1     ragge #include <sys/buf.h>
     83   1.6     ragge #include <sys/systm.h>
     84   1.6     ragge #include <sys/proc.h>
     85   1.1     ragge 
     86  1.12     ragge #include <machine/bus.h>
     87   1.1     ragge #include <machine/sid.h>
     88   1.1     ragge 
     89  1.12     ragge #include <dev/mscp/mscp.h>
     90  1.12     ragge #include <dev/mscp/mscpreg.h>
     91  1.12     ragge #include <dev/mscp/mscpvar.h>
     92   1.1     ragge 
     93   1.1     ragge #include "ra.h"
     94   1.2     ragge #include "mt.h"
     95   1.1     ragge 
     96   1.9     ragge #define b_forw	b_hash.le_next
     97   1.1     ragge 
     98   1.8     ragge int	mscp_match __P((struct device *, struct cfdata *, void *));
     99   1.1     ragge void	mscp_attach __P((struct device *, struct device *, void *));
    100   1.9     ragge void	mscp_start __P((struct	mscp_softc *));
    101   1.1     ragge int	mscp_init __P((struct  mscp_softc *));
    102   1.1     ragge void	mscp_initds __P((struct mscp_softc *));
    103   1.1     ragge int	mscp_waitstep __P((struct mscp_softc *, int, int));
    104   1.1     ragge 
    105  1.21   thorpej CFATTACH_DECL(mscpbus, sizeof(struct mscp_softc),
    106  1.22   thorpej     mscp_match, mscp_attach, NULL, NULL);
    107   1.1     ragge 
    108  1.12     ragge #define	READ_SA		(bus_space_read_2(mi->mi_iot, mi->mi_sah, 0))
    109  1.12     ragge #define	READ_IP		(bus_space_read_2(mi->mi_iot, mi->mi_iph, 0))
    110  1.12     ragge #define	WRITE_IP(x)	bus_space_write_2(mi->mi_iot, mi->mi_iph, 0, (x))
    111  1.12     ragge #define	WRITE_SW(x)	bus_space_write_2(mi->mi_iot, mi->mi_swh, 0, (x))
    112  1.12     ragge 
    113   1.1     ragge struct	mscp slavereply;
    114   1.1     ragge 
    115   1.1     ragge /*
    116   1.1     ragge  * This function is for delay during init. Some MSCP clone card (Dilog)
    117   1.1     ragge  * can't handle fast read from its registers, and therefore need
    118   1.1     ragge  * a delay between them.
    119   1.1     ragge  */
    120   1.1     ragge 
    121   1.1     ragge #define DELAYTEN 1000
    122   1.1     ragge int
    123   1.1     ragge mscp_waitstep(mi, mask, result)
    124   1.1     ragge 	struct mscp_softc *mi;
    125   1.1     ragge 	int mask, result;
    126   1.1     ragge {
    127   1.1     ragge 	int	status = 1;
    128   1.1     ragge 
    129  1.12     ragge 	if ((READ_SA & mask) != result) {
    130   1.1     ragge 		volatile int count = 0;
    131  1.12     ragge 		while ((READ_SA & mask) != result) {
    132   1.1     ragge 			DELAY(10000);
    133   1.1     ragge 			count += 1;
    134   1.1     ragge 			if (count > DELAYTEN)
    135   1.1     ragge 				break;
    136   1.1     ragge 		}
    137   1.1     ragge 		if (count > DELAYTEN)
    138   1.1     ragge 			status = 0;
    139   1.1     ragge 	}
    140   1.1     ragge 	return status;
    141   1.1     ragge }
    142   1.1     ragge 
    143   1.1     ragge int
    144   1.1     ragge mscp_match(parent, match, aux)
    145   1.1     ragge 	struct device *parent;
    146   1.8     ragge 	struct cfdata *match;
    147   1.8     ragge 	void *aux;
    148   1.1     ragge {
    149   1.1     ragge 	struct	mscp_attach_args *ma = aux;
    150   1.1     ragge 
    151   1.9     ragge #if NRA || NRX
    152   1.1     ragge 	if (ma->ma_type & MSCPBUS_DISK)
    153   1.1     ragge 		return 1;
    154   1.1     ragge #endif
    155   1.1     ragge #if NMT
    156   1.1     ragge 	if (ma->ma_type & MSCPBUS_TAPE)
    157   1.1     ragge 		return 1;
    158   1.1     ragge #endif
    159   1.1     ragge 	return 0;
    160   1.1     ragge };
    161   1.1     ragge 
    162   1.1     ragge void
    163   1.1     ragge mscp_attach(parent, self, aux)
    164   1.1     ragge 	struct device *parent, *self;
    165   1.1     ragge 	void *aux;
    166   1.1     ragge {
    167   1.1     ragge 	struct	mscp_attach_args *ma = aux;
    168   1.1     ragge 	struct	mscp_softc *mi = (void *)self;
    169   1.9     ragge 	volatile struct mscp *mp;
    170   1.1     ragge 	volatile int i;
    171   1.1     ragge 	int	timeout, next = 0;
    172   1.1     ragge 
    173   1.1     ragge 	mi->mi_mc = ma->ma_mc;
    174   1.1     ragge 	mi->mi_me = NULL;
    175   1.1     ragge 	mi->mi_type = ma->ma_type;
    176   1.1     ragge 	mi->mi_uda = ma->ma_uda;
    177  1.12     ragge 	mi->mi_dmat = ma->ma_dmat;
    178  1.12     ragge 	mi->mi_dmam = ma->ma_dmam;
    179  1.12     ragge 	mi->mi_iot = ma->ma_iot;
    180  1.12     ragge 	mi->mi_iph = ma->ma_iph;
    181  1.12     ragge 	mi->mi_sah = ma->ma_sah;
    182  1.12     ragge 	mi->mi_swh = ma->ma_swh;
    183   1.1     ragge 	mi->mi_ivec = ma->ma_ivec;
    184   1.3     ragge 	mi->mi_adapnr = ma->ma_adapnr;
    185   1.3     ragge 	mi->mi_ctlrnr = ma->ma_ctlrnr;
    186   1.1     ragge 	*ma->ma_softc = mi;
    187   1.1     ragge 	/*
    188   1.1     ragge 	 * Go out to init the bus, so that we can give commands
    189   1.1     ragge 	 * to its devices.
    190   1.1     ragge 	 */
    191   1.9     ragge 	mi->mi_cmd.mri_size = NCMD;
    192   1.9     ragge 	mi->mi_cmd.mri_desc = mi->mi_uda->mp_ca.ca_cmddsc;
    193   1.9     ragge 	mi->mi_cmd.mri_ring = mi->mi_uda->mp_cmd;
    194   1.9     ragge 	mi->mi_rsp.mri_size = NRSP;
    195   1.9     ragge 	mi->mi_rsp.mri_desc = mi->mi_uda->mp_ca.ca_rspdsc;
    196   1.9     ragge 	mi->mi_rsp.mri_ring = mi->mi_uda->mp_rsp;
    197  1.19   hannken 	bufq_alloc(&mi->mi_resq, BUFQ_FCFS);
    198   1.1     ragge 
    199   1.1     ragge 	if (mscp_init(mi)) {
    200   1.5  christos 		printf("%s: can't init, controller hung\n",
    201   1.1     ragge 		    mi->mi_dev.dv_xname);
    202   1.1     ragge 		return;
    203   1.1     ragge 	}
    204  1.12     ragge 	for (i = 0; i < NCMD; i++) {
    205  1.12     ragge 		mi->mi_mxiuse |= (1 << i);
    206  1.14     ragge 		if (bus_dmamap_create(mi->mi_dmat, (64*1024), 16, (64*1024),
    207  1.12     ragge 		    0, BUS_DMA_NOWAIT, &mi->mi_xi[i].mxi_dmam)) {
    208  1.12     ragge 			printf("Couldn't alloc dmamap %d\n", i);
    209  1.12     ragge 			return;
    210  1.12     ragge 		}
    211  1.12     ragge 	}
    212  1.12     ragge 
    213   1.1     ragge 
    214   1.1     ragge #if NRA
    215   1.1     ragge 	if (ma->ma_type & MSCPBUS_DISK) {
    216   1.1     ragge 		extern	struct mscp_device ra_device;
    217   1.1     ragge 
    218   1.1     ragge 		mi->mi_me = &ra_device;
    219   1.1     ragge 	}
    220   1.1     ragge #endif
    221   1.1     ragge #if NMT
    222   1.1     ragge 	if (ma->ma_type & MSCPBUS_TAPE) {
    223   1.1     ragge 		extern	struct mscp_device mt_device;
    224   1.1     ragge 
    225   1.1     ragge 		mi->mi_me = &mt_device;
    226   1.1     ragge 	}
    227   1.1     ragge #endif
    228   1.1     ragge 	/*
    229   1.1     ragge 	 * Go out and search for sub-units on this MSCP bus,
    230   1.1     ragge 	 * and call config_found for each found.
    231   1.1     ragge 	 */
    232   1.1     ragge findunit:
    233   1.1     ragge 	mp = mscp_getcp(mi, MSCP_DONTWAIT);
    234   1.1     ragge 	if (mp == NULL)
    235   1.1     ragge 		panic("mscpattach: no packets");
    236   1.1     ragge 	mp->mscp_opcode = M_OP_GETUNITST;
    237   1.1     ragge 	mp->mscp_unit = next;
    238   1.1     ragge 	mp->mscp_modifier = M_GUM_NEXTUNIT;
    239   1.1     ragge 	*mp->mscp_addr |= MSCP_OWN | MSCP_INT;
    240   1.1     ragge 	slavereply.mscp_opcode = 0;
    241   1.1     ragge 
    242  1.12     ragge 	i = bus_space_read_2(mi->mi_iot, mi->mi_iph, 0);
    243   1.1     ragge 	mp = &slavereply;
    244   1.1     ragge 	timeout = 1000;
    245   1.1     ragge 	while (timeout-- > 0) {
    246   1.1     ragge 		DELAY(10000);
    247   1.1     ragge 		if (mp->mscp_opcode)
    248   1.1     ragge 			goto gotit;
    249   1.1     ragge 	}
    250   1.5  christos 	printf("%s: no response to Get Unit Status request\n",
    251   1.1     ragge 	    mi->mi_dev.dv_xname);
    252   1.1     ragge 	return;
    253   1.1     ragge 
    254   1.1     ragge gotit:	/*
    255   1.1     ragge 	 * Got a slave response.  If the unit is there, use it.
    256   1.1     ragge 	 */
    257   1.1     ragge 	switch (mp->mscp_status & M_ST_MASK) {
    258   1.1     ragge 
    259   1.9     ragge 	case M_ST_SUCCESS:	/* worked */
    260   1.9     ragge 	case M_ST_AVAILABLE:	/* found another drive */
    261   1.9     ragge 		break;		/* use it */
    262   1.1     ragge 
    263   1.1     ragge 	case M_ST_OFFLINE:
    264   1.1     ragge 		/*
    265   1.1     ragge 		 * Figure out why it is off line.  It may be because
    266   1.9     ragge 		 * it is nonexistent, or because it is spun down, or
    267   1.9     ragge 		 * for some other reason.
    268   1.9     ragge 		 */
    269   1.9     ragge 		switch (mp->mscp_status & ~M_ST_MASK) {
    270   1.9     ragge 
    271   1.9     ragge 		case M_OFFLINE_UNKNOWN:
    272   1.9     ragge 			/*
    273   1.9     ragge 			 * No such drive, and there are none with
    274   1.9     ragge 			 * higher unit numbers either, if we are
    275   1.9     ragge 			 * using M_GUM_NEXTUNIT.
    276   1.9     ragge 			 */
    277   1.2     ragge 			mi->mi_ierr = 3;
    278   1.9     ragge 			return;
    279   1.9     ragge 
    280   1.9     ragge 		case M_OFFLINE_UNMOUNTED:
    281   1.9     ragge 			/*
    282   1.9     ragge 			 * The drive is not spun up.  Use it anyway.
    283   1.9     ragge 			 *
    284   1.9     ragge 			 * N.B.: this seems to be a common occurrance
    285   1.9     ragge 			 * after a power failure.  The first attempt
    286   1.9     ragge 			 * to bring it on line seems to spin it up
    287   1.9     ragge 			 * (and thus takes several minutes).  Perhaps
    288   1.9     ragge 			 * we should note here that the on-line may
    289   1.9     ragge 			 * take longer than usual.
    290   1.9     ragge 			 */
    291   1.9     ragge 			break;
    292   1.1     ragge 
    293   1.9     ragge 		default:
    294   1.9     ragge 			/*
    295   1.9     ragge 			 * In service, or something else equally unusable.
    296   1.9     ragge 			 */
    297   1.9     ragge 			printf("%s: unit %d off line: ", mi->mi_dev.dv_xname,
    298   1.9     ragge 				mp->mscp_unit);
    299   1.9     ragge 			mscp_printevent((struct mscp *)mp);
    300   1.1     ragge 			next++;
    301   1.9     ragge 			goto findunit;
    302   1.9     ragge 		}
    303   1.9     ragge 		break;
    304   1.1     ragge 
    305   1.9     ragge 	default:
    306   1.9     ragge 		printf("%s: unable to get unit status: ", mi->mi_dev.dv_xname);
    307   1.9     ragge 		mscp_printevent((struct mscp *)mp);
    308   1.9     ragge 		return;
    309   1.9     ragge 	}
    310   1.9     ragge 
    311   1.9     ragge 	/*
    312   1.9     ragge 	 * If we get a lower number, we have circulated around all
    313   1.1     ragge 	 * devices and are finished, otherwise try to find next unit.
    314   1.2     ragge 	 * We shouldn't ever get this, it's a workaround.
    315   1.9     ragge 	 */
    316   1.9     ragge 	if (mp->mscp_unit < next)
    317   1.9     ragge 		return;
    318   1.1     ragge 
    319   1.1     ragge 	next = mp->mscp_unit + 1;
    320   1.1     ragge 	goto findunit;
    321   1.1     ragge }
    322   1.1     ragge 
    323   1.1     ragge 
    324   1.1     ragge /*
    325   1.1     ragge  * The ctlr gets initialised, normally after boot but may also be
    326   1.1     ragge  * done if the ctlr gets in an unknown state. Returns 1 if init
    327   1.1     ragge  * fails, 0 otherwise.
    328   1.1     ragge  */
    329   1.1     ragge int
    330   1.1     ragge mscp_init(mi)
    331   1.1     ragge 	struct	mscp_softc *mi;
    332   1.1     ragge {
    333   1.1     ragge 	struct	mscp *mp;
    334   1.1     ragge 	volatile int i;
    335   1.1     ragge 	int	status, count;
    336   1.6     ragge 	unsigned int j = 0;
    337   1.1     ragge 
    338   1.9     ragge 	/*
    339   1.9     ragge 	 * While we are thinking about it, reset the next command
    340   1.9     ragge 	 * and response indicies.
    341   1.9     ragge 	 */
    342   1.1     ragge 	mi->mi_cmd.mri_next = 0;
    343   1.1     ragge 	mi->mi_rsp.mri_next = 0;
    344   1.1     ragge 
    345   1.1     ragge 	mi->mi_flags |= MSC_IGNOREINTR;
    346   1.6     ragge 
    347   1.6     ragge 	if ((mi->mi_type & MSCPBUS_KDB) == 0)
    348  1.12     ragge 		WRITE_IP(0); /* Kick off */;
    349   1.6     ragge 
    350   1.1     ragge 	status = mscp_waitstep(mi, MP_STEP1, MP_STEP1);/* Wait to it wakes up */
    351   1.1     ragge 	if (status == 0)
    352   1.1     ragge 		return 1; /* Init failed */
    353  1.12     ragge 	if (READ_SA & MP_ERR) {
    354   1.1     ragge 		(*mi->mi_mc->mc_saerror)(mi->mi_dev.dv_parent, 0);
    355   1.1     ragge 		return 1;
    356   1.1     ragge 	}
    357   1.1     ragge 
    358   1.1     ragge 	/* step1 */
    359  1.12     ragge 	WRITE_SW(MP_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) |
    360  1.12     ragge 	    MP_IE | (mi->mi_ivec >> 2));
    361   1.1     ragge 	status = mscp_waitstep(mi, STEP1MASK, STEP1GOOD);
    362   1.1     ragge 	if (status == 0) {
    363   1.1     ragge 		(*mi->mi_mc->mc_saerror)(mi->mi_dev.dv_parent, 0);
    364   1.1     ragge 		return 1;
    365   1.1     ragge 	}
    366   1.1     ragge 
    367   1.1     ragge 	/* step2 */
    368  1.12     ragge 	WRITE_SW(((mi->mi_dmam->dm_segs[0].ds_addr & 0xffff) +
    369  1.12     ragge 	    offsetof(struct mscp_pack, mp_ca.ca_rspdsc[0])) |
    370  1.12     ragge 	    (vax_cputype == VAX_780 || vax_cputype == VAX_8600 ? MP_PI : 0));
    371   1.1     ragge 	status = mscp_waitstep(mi, STEP2MASK, STEP2GOOD(mi->mi_ivec >> 2));
    372   1.9     ragge 	if (status == 0) {
    373   1.9     ragge 		(*mi->mi_mc->mc_saerror)(mi->mi_dev.dv_parent, 0);
    374   1.9     ragge 		return 1;
    375   1.9     ragge 	}
    376   1.1     ragge 
    377   1.1     ragge 	/* step3 */
    378  1.12     ragge 	WRITE_SW((mi->mi_dmam->dm_segs[0].ds_addr >> 16));
    379   1.1     ragge 	status = mscp_waitstep(mi, STEP3MASK, STEP3GOOD);
    380   1.9     ragge 	if (status == 0) {
    381   1.9     ragge 		(*mi->mi_mc->mc_saerror)(mi->mi_dev.dv_parent, 0);
    382   1.9     ragge 		return 1;
    383   1.9     ragge 	}
    384  1.12     ragge 	i = READ_SA & 0377;
    385   1.5  christos 	printf(": version %d model %d\n", i & 15, i >> 4);
    386   1.1     ragge 
    387   1.9     ragge #define BURST 4 /* XXX */
    388   1.1     ragge 	if (mi->mi_type & MSCPBUS_UDA) {
    389  1.12     ragge 		WRITE_SW(MP_GO | (BURST - 1) << 2);
    390   1.5  christos 		printf("%s: DMA burst size set to %d\n",
    391   1.1     ragge 		    mi->mi_dev.dv_xname, BURST);
    392   1.1     ragge 	}
    393  1.12     ragge 	WRITE_SW(MP_GO);
    394   1.1     ragge 
    395   1.1     ragge 	mscp_initds(mi);
    396   1.1     ragge 	mi->mi_flags &= ~MSC_IGNOREINTR;
    397   1.1     ragge 
    398   1.1     ragge 	/*
    399   1.1     ragge 	 * Set up all necessary info in the bus softc struct, get a
    400   1.1     ragge 	 * mscp packet and set characteristics for this controller.
    401   1.1     ragge 	 */
    402   1.1     ragge 	mi->mi_credits = MSCP_MINCREDITS + 1;
    403   1.1     ragge 	mp = mscp_getcp(mi, MSCP_DONTWAIT);
    404   1.2     ragge 
    405   1.1     ragge 	mi->mi_credits = 0;
    406   1.1     ragge 	mp->mscp_opcode = M_OP_SETCTLRC;
    407   1.2     ragge 	mp->mscp_unit = mp->mscp_modifier = mp->mscp_flags =
    408   1.2     ragge 	    mp->mscp_sccc.sccc_version = mp->mscp_sccc.sccc_hosttimo =
    409   1.2     ragge 	    mp->mscp_sccc.sccc_time = mp->mscp_sccc.sccc_time1 =
    410   1.2     ragge 	    mp->mscp_sccc.sccc_errlgfl = 0;
    411   1.1     ragge 	mp->mscp_sccc.sccc_ctlrflags = M_CF_ATTN | M_CF_MISC | M_CF_THIS;
    412   1.1     ragge 	*mp->mscp_addr |= MSCP_OWN | MSCP_INT;
    413  1.12     ragge 	i = READ_IP;
    414   1.1     ragge 
    415   1.9     ragge 	count = 0;
    416   1.9     ragge 	while (count < DELAYTEN) {
    417  1.10     ragge 		if (((volatile int)mi->mi_flags & MSC_READY) != 0)
    418   1.9     ragge 			break;
    419  1.12     ragge 		if ((j = READ_SA) & MP_ERR)
    420   1.2     ragge 			goto out;
    421   1.9     ragge 		DELAY(10000);
    422   1.9     ragge 		count += 1;
    423   1.9     ragge 	}
    424   1.1     ragge 	if (count == DELAYTEN) {
    425   1.2     ragge out:
    426   1.5  christos 		printf("%s: couldn't set ctlr characteristics, sa=%x\n",
    427   1.2     ragge 		    mi->mi_dev.dv_xname, j);
    428   1.1     ragge 		return 1;
    429   1.1     ragge 	}
    430   1.1     ragge 	return 0;
    431   1.1     ragge }
    432   1.1     ragge 
    433   1.1     ragge /*
    434   1.1     ragge  * Initialise the various data structures that control the mscp protocol.
    435   1.1     ragge  */
    436   1.1     ragge void
    437   1.1     ragge mscp_initds(mi)
    438   1.1     ragge 	struct mscp_softc *mi;
    439   1.1     ragge {
    440   1.1     ragge 	struct mscp_pack *ud = mi->mi_uda;
    441   1.1     ragge 	struct mscp *mp;
    442   1.1     ragge 	int i;
    443   1.1     ragge 
    444   1.1     ragge 	for (i = 0, mp = ud->mp_rsp; i < NRSP; i++, mp++) {
    445   1.1     ragge 		ud->mp_ca.ca_rspdsc[i] = MSCP_OWN | MSCP_INT |
    446  1.12     ragge 		    (mi->mi_dmam->dm_segs[0].ds_addr +
    447  1.12     ragge 		    offsetof(struct mscp_pack, mp_rsp[i].mscp_cmdref));
    448   1.1     ragge 		mp->mscp_addr = &ud->mp_ca.ca_rspdsc[i];
    449   1.1     ragge 		mp->mscp_msglen = MSCP_MSGLEN;
    450   1.1     ragge 	}
    451   1.1     ragge 	for (i = 0, mp = ud->mp_cmd; i < NCMD; i++, mp++) {
    452   1.1     ragge 		ud->mp_ca.ca_cmddsc[i] = MSCP_INT |
    453  1.12     ragge 		    (mi->mi_dmam->dm_segs[0].ds_addr +
    454  1.12     ragge 		    offsetof(struct mscp_pack, mp_cmd[i].mscp_cmdref));
    455   1.1     ragge 		mp->mscp_addr = &ud->mp_ca.ca_cmddsc[i];
    456   1.1     ragge 		mp->mscp_msglen = MSCP_MSGLEN;
    457   1.2     ragge 		if (mi->mi_type & MSCPBUS_TAPE)
    458   1.2     ragge 			mp->mscp_vcid = 1;
    459   1.1     ragge 	}
    460   1.1     ragge }
    461   1.1     ragge 
    462  1.12     ragge static	void mscp_kickaway(struct mscp_softc *);
    463  1.12     ragge 
    464   1.1     ragge void
    465   1.1     ragge mscp_intr(mi)
    466   1.1     ragge 	struct mscp_softc *mi;
    467   1.1     ragge {
    468   1.1     ragge 	struct mscp_pack *ud = mi->mi_uda;
    469   1.1     ragge 
    470   1.1     ragge 	if (mi->mi_flags & MSC_IGNOREINTR)
    471   1.1     ragge 		return;
    472   1.9     ragge 	/*
    473   1.9     ragge 	 * Check for response and command ring transitions.
    474   1.9     ragge 	 */
    475   1.9     ragge 	if (ud->mp_ca.ca_rspint) {
    476   1.9     ragge 		ud->mp_ca.ca_rspint = 0;
    477   1.9     ragge 		mscp_dorsp(mi);
    478   1.9     ragge 	}
    479   1.9     ragge 	if (ud->mp_ca.ca_cmdint) {
    480   1.9     ragge 		ud->mp_ca.ca_cmdint = 0;
    481   1.9     ragge 		MSCP_DOCMD(mi);
    482   1.9     ragge 	}
    483   1.6     ragge 
    484   1.6     ragge 	/*
    485  1.12     ragge 	 * If there are any not-yet-handled request, try them now.
    486   1.6     ragge 	 */
    487  1.19   hannken 	if (BUFQ_PEEK(&mi->mi_resq))
    488  1.12     ragge 		mscp_kickaway(mi);
    489   1.1     ragge }
    490   1.1     ragge 
    491   1.1     ragge int
    492   1.1     ragge mscp_print(aux, name)
    493   1.1     ragge 	void *aux;
    494   1.6     ragge 	const char *name;
    495   1.1     ragge {
    496   1.9     ragge 	struct drive_attach_args *da = aux;
    497   1.9     ragge 	struct	mscp *mp = da->da_mp;
    498   1.9     ragge 	int type = mp->mscp_guse.guse_mediaid;
    499   1.9     ragge 
    500   1.9     ragge 	if (name) {
    501  1.23   thorpej 		aprint_normal("%c%c", MSCP_MID_CHAR(2, type),
    502  1.23   thorpej 		    MSCP_MID_CHAR(1, type));
    503   1.9     ragge 		if (MSCP_MID_ECH(0, type))
    504  1.23   thorpej 			aprint_normal("%c", MSCP_MID_CHAR(0, type));
    505  1.23   thorpej 		aprint_normal("%d at %s drive %d", MSCP_MID_NUM(type), name,
    506   1.9     ragge 		    mp->mscp_unit);
    507   1.9     ragge 	}
    508   1.1     ragge 	return UNCONF;
    509   1.1     ragge }
    510   1.1     ragge 
    511   1.1     ragge /*
    512   1.1     ragge  * common strategy routine for all types of MSCP devices.
    513   1.1     ragge  */
    514   1.1     ragge void
    515   1.6     ragge mscp_strategy(bp, usc)
    516   1.6     ragge 	struct buf *bp;
    517   1.1     ragge 	struct device *usc;
    518   1.1     ragge {
    519   1.1     ragge 	struct	mscp_softc *mi = (void *)usc;
    520  1.17   thorpej 	int s = spluba();
    521  1.12     ragge 
    522  1.19   hannken 	BUFQ_PUT(&mi->mi_resq, bp);
    523  1.12     ragge 	mscp_kickaway(mi);
    524  1.12     ragge 	splx(s);
    525  1.12     ragge }
    526  1.12     ragge 
    527  1.12     ragge 
    528  1.12     ragge void
    529  1.12     ragge mscp_kickaway(mi)
    530  1.12     ragge 	struct	mscp_softc *mi;
    531  1.12     ragge {
    532  1.12     ragge 	struct buf *bp;
    533   1.1     ragge 	struct	mscp *mp;
    534  1.12     ragge 	int next;
    535   1.1     ragge 
    536  1.19   hannken 	while ((bp = BUFQ_PEEK(&mi->mi_resq)) != NULL) {
    537  1.12     ragge 		/*
    538  1.12     ragge 		 * Ok; we are ready to try to start a xfer. Get a MSCP packet
    539  1.12     ragge 		 * and try to start...
    540  1.12     ragge 		 */
    541  1.12     ragge 		if ((mp = mscp_getcp(mi, MSCP_DONTWAIT)) == NULL) {
    542  1.12     ragge 			if (mi->mi_credits > MSCP_MINCREDITS)
    543  1.12     ragge 				printf("%s: command ring too small\n",
    544  1.12     ragge 				    mi->mi_dev.dv_parent->dv_xname);
    545  1.12     ragge 			/*
    546  1.12     ragge 			 * By some (strange) reason we didn't get a MSCP packet.
    547  1.12     ragge 			 * Just return and wait for free packets.
    548  1.12     ragge 			 */
    549  1.12     ragge 			return;
    550  1.12     ragge 		}
    551  1.12     ragge 
    552  1.12     ragge 		if ((next = (ffs(mi->mi_mxiuse) - 1)) < 0)
    553  1.12     ragge 			panic("no mxi buffers");
    554  1.12     ragge 		mi->mi_mxiuse &= ~(1 << next);
    555  1.12     ragge 		if (mi->mi_xi[next].mxi_inuse)
    556  1.12     ragge 			panic("mxi inuse");
    557   1.6     ragge 		/*
    558  1.12     ragge 		 * Set up the MSCP packet and ask the ctlr to start.
    559   1.6     ragge 		 */
    560  1.12     ragge 		mp->mscp_opcode =
    561  1.12     ragge 		    (bp->b_flags & B_READ) ? M_OP_READ : M_OP_WRITE;
    562  1.12     ragge 		mp->mscp_cmdref = next;
    563  1.12     ragge 		mi->mi_xi[next].mxi_bp = bp;
    564  1.12     ragge 		mi->mi_xi[next].mxi_mp = mp;
    565  1.12     ragge 		mi->mi_xi[next].mxi_inuse = 1;
    566  1.12     ragge 		bp->b_resid = next;
    567  1.12     ragge 		(*mi->mi_me->me_fillin)(bp, mp);
    568  1.12     ragge 		(*mi->mi_mc->mc_go)(mi->mi_dev.dv_parent, &mi->mi_xi[next]);
    569  1.19   hannken 		(void)BUFQ_GET(&mi->mi_resq);
    570   1.1     ragge 	}
    571   1.1     ragge }
    572   1.1     ragge 
    573   1.1     ragge void
    574  1.12     ragge mscp_dgo(mi, mxi)
    575   1.1     ragge 	struct mscp_softc *mi;
    576  1.12     ragge 	struct mscp_xi *mxi;
    577   1.1     ragge {
    578   1.1     ragge 	volatile int i;
    579   1.1     ragge 	struct	mscp *mp;
    580   1.1     ragge 
    581   1.9     ragge 	/*
    582   1.9     ragge 	 * Fill in the MSCP packet and move the buffer to the I/O wait queue.
    583   1.9     ragge 	 */
    584  1.12     ragge 	mp = mxi->mxi_mp;
    585  1.12     ragge 	mp->mscp_seq.seq_buffer = mxi->mxi_dmam->dm_segs[0].ds_addr;
    586   1.1     ragge 
    587   1.6     ragge 	*mp->mscp_addr |= MSCP_OWN | MSCP_INT;
    588  1.12     ragge 	i = READ_IP;
    589   1.1     ragge }
    590   1.1     ragge 
    591   1.6     ragge #ifdef DIAGNOSTIC
    592   1.1     ragge /*
    593   1.1     ragge  * Dump the entire contents of an MSCP packet in hex.  Mainly useful
    594   1.1     ragge  * for debugging....
    595   1.1     ragge  */
    596   1.1     ragge void
    597   1.1     ragge mscp_hexdump(mp)
    598  1.15  augustss 	struct mscp *mp;
    599   1.1     ragge {
    600  1.15  augustss 	long *p = (long *) mp;
    601  1.15  augustss 	int i = mp->mscp_msglen;
    602   1.1     ragge 
    603   1.1     ragge 	if (i > 256)		/* sanity */
    604   1.1     ragge 		i = 256;
    605   1.1     ragge 	i /= sizeof (*p);	/* ASSUMES MULTIPLE OF sizeof(long) */
    606   1.1     ragge 	while (--i >= 0)
    607   1.5  christos 		printf("0x%x ", (int)*p++);
    608   1.5  christos 	printf("\n");
    609   1.1     ragge }
    610   1.6     ragge #endif
    611   1.1     ragge 
    612   1.1     ragge /*
    613   1.1     ragge  * MSCP error reporting
    614   1.1     ragge  */
    615   1.1     ragge 
    616   1.1     ragge /*
    617   1.1     ragge  * Messages for the various subcodes.
    618   1.1     ragge  */
    619   1.1     ragge static char unknown_msg[] = "unknown subcode";
    620   1.1     ragge 
    621   1.1     ragge /*
    622   1.1     ragge  * Subcodes for Success (0)
    623   1.1     ragge  */
    624   1.1     ragge static char *succ_msgs[] = {
    625   1.1     ragge 	"normal",		/* 0 */
    626   1.1     ragge 	"spin down ignored",	/* 1 = Spin-Down Ignored */
    627   1.1     ragge 	"still connected",	/* 2 = Still Connected */
    628   1.1     ragge 	unknown_msg,
    629   1.1     ragge 	"dup. unit #",		/* 4 = Duplicate Unit Number */
    630   1.1     ragge 	unknown_msg,
    631   1.1     ragge 	unknown_msg,
    632   1.1     ragge 	unknown_msg,
    633   1.1     ragge 	"already online",	/* 8 = Already Online */
    634   1.1     ragge 	unknown_msg,
    635   1.1     ragge 	unknown_msg,
    636   1.1     ragge 	unknown_msg,
    637   1.1     ragge 	unknown_msg,
    638   1.1     ragge 	unknown_msg,
    639   1.1     ragge 	unknown_msg,
    640   1.1     ragge 	unknown_msg,
    641   1.1     ragge 	"still online",		/* 16 = Still Online */
    642   1.1     ragge };
    643   1.1     ragge 
    644   1.1     ragge /*
    645   1.1     ragge  * Subcodes for Invalid Command (1)
    646   1.1     ragge  */
    647   1.1     ragge static char *icmd_msgs[] = {
    648   1.1     ragge 	"invalid msg length",	/* 0 = Invalid Message Length */
    649   1.1     ragge };
    650   1.1     ragge 
    651   1.1     ragge /*
    652   1.1     ragge  * Subcodes for Command Aborted (2)
    653   1.1     ragge  */
    654   1.1     ragge /* none known */
    655   1.1     ragge 
    656   1.1     ragge /*
    657   1.1     ragge  * Subcodes for Unit Offline (3)
    658   1.1     ragge  */
    659   1.1     ragge static char *offl_msgs[] = {
    660   1.1     ragge 	"unknown drive",	/* 0 = Unknown, or online to other ctlr */
    661   1.1     ragge 	"not mounted",		/* 1 = Unmounted, or RUN/STOP at STOP */
    662   1.1     ragge 	"inoperative",		/* 2 = Unit Inoperative */
    663   1.1     ragge 	unknown_msg,
    664   1.1     ragge 	"duplicate",		/* 4 = Duplicate Unit Number */
    665   1.1     ragge 	unknown_msg,
    666   1.1     ragge 	unknown_msg,
    667   1.1     ragge 	unknown_msg,
    668   1.1     ragge 	"in diagnosis",		/* 8 = Disabled by FS or diagnostic */
    669   1.1     ragge };
    670   1.1     ragge 
    671   1.1     ragge /*
    672   1.1     ragge  * Subcodes for Unit Available (4)
    673   1.1     ragge  */
    674   1.1     ragge /* none known */
    675   1.1     ragge 
    676   1.1     ragge /*
    677   1.1     ragge  * Subcodes for Media Format Error (5)
    678   1.1     ragge  */
    679   1.1     ragge static char *media_fmt_msgs[] = {
    680   1.1     ragge 	"fct unread - edc",	/* 0 = FCT unreadable */
    681   1.1     ragge 	"invalid sector header",/* 1 = Invalid Sector Header */
    682   1.1     ragge 	"not 512 sectors",	/* 2 = Not 512 Byte Sectors */
    683   1.1     ragge 	"not formatted",	/* 3 = Not Formatted */
    684   1.1     ragge 	"fct ecc",		/* 4 = FCT ECC */
    685   1.1     ragge };
    686   1.1     ragge 
    687   1.1     ragge /*
    688   1.1     ragge  * Subcodes for Write Protected (6)
    689   1.1     ragge  * N.B.:  Code 6 subcodes are 7 bits higher than other subcodes
    690   1.1     ragge  * (i.e., bits 12-15).
    691   1.1     ragge  */
    692   1.1     ragge static char *wrprot_msgs[] = {
    693   1.1     ragge 	unknown_msg,
    694   1.1     ragge 	"software",		/* 1 = Software Write Protect */
    695   1.1     ragge 	"hardware",		/* 2 = Hardware Write Protect */
    696   1.1     ragge };
    697   1.1     ragge 
    698   1.1     ragge /*
    699   1.1     ragge  * Subcodes for Compare Error (7)
    700   1.1     ragge  */
    701   1.1     ragge /* none known */
    702   1.1     ragge 
    703   1.1     ragge /*
    704   1.1     ragge  * Subcodes for Data Error (8)
    705   1.1     ragge  */
    706   1.1     ragge static char *data_msgs[] = {
    707   1.1     ragge 	"forced error",		/* 0 = Forced Error (software) */
    708   1.1     ragge 	unknown_msg,
    709   1.1     ragge 	"header compare",	/* 2 = Header Compare Error */
    710   1.1     ragge 	"sync timeout",		/* 3 = Sync Timeout Error */
    711   1.1     ragge 	unknown_msg,
    712   1.1     ragge 	unknown_msg,
    713   1.1     ragge 	unknown_msg,
    714   1.1     ragge 	"uncorrectable ecc",	/* 7 = Uncorrectable ECC */
    715   1.1     ragge 	"1 symbol ecc",		/* 8 = 1 bit ECC */
    716   1.1     ragge 	"2 symbol ecc",		/* 9 = 2 bit ECC */
    717   1.1     ragge 	"3 symbol ecc",		/* 10 = 3 bit ECC */
    718   1.1     ragge 	"4 symbol ecc",		/* 11 = 4 bit ECC */
    719   1.1     ragge 	"5 symbol ecc",		/* 12 = 5 bit ECC */
    720   1.1     ragge 	"6 symbol ecc",		/* 13 = 6 bit ECC */
    721   1.1     ragge 	"7 symbol ecc",		/* 14 = 7 bit ECC */
    722   1.1     ragge 	"8 symbol ecc",		/* 15 = 8 bit ECC */
    723   1.1     ragge };
    724   1.1     ragge 
    725   1.1     ragge /*
    726   1.1     ragge  * Subcodes for Host Buffer Access Error (9)
    727   1.1     ragge  */
    728   1.1     ragge static char *host_buffer_msgs[] = {
    729   1.1     ragge 	unknown_msg,
    730   1.1     ragge 	"odd xfer addr",	/* 1 = Odd Transfer Address */
    731   1.1     ragge 	"odd xfer count",	/* 2 = Odd Transfer Count */
    732   1.1     ragge 	"non-exist. memory",	/* 3 = Non-Existent Memory */
    733   1.1     ragge 	"memory parity",	/* 4 = Memory Parity Error */
    734   1.1     ragge };
    735   1.1     ragge 
    736   1.1     ragge /*
    737   1.1     ragge  * Subcodes for Controller Error (10)
    738   1.1     ragge  */
    739   1.1     ragge static char *cntlr_msgs[] = {
    740   1.1     ragge 	unknown_msg,
    741   1.1     ragge 	"serdes overrun",	/* 1 = Serialiser/Deserialiser Overrun */
    742   1.1     ragge 	"edc",			/* 2 = Error Detection Code? */
    743   1.1     ragge 	"inconsistant internal data struct",/* 3 = Internal Error */
    744   1.1     ragge };
    745   1.1     ragge 
    746   1.1     ragge /*
    747   1.1     ragge  * Subcodes for Drive Error (11)
    748   1.1     ragge  */
    749   1.1     ragge static char *drive_msgs[] = {
    750   1.1     ragge 	unknown_msg,
    751   1.1     ragge 	"sdi command timeout",	/* 1 = SDI Command Timeout */
    752   1.1     ragge 	"ctlr detected protocol",/* 2 = Controller Detected Protocol Error */
    753   1.1     ragge 	"positioner",		/* 3 = Positioner Error */
    754   1.1     ragge 	"lost rd/wr ready",	/* 4 = Lost R/W Ready Error */
    755   1.1     ragge 	"drive clock dropout",	/* 5 = Lost Drive Clock */
    756   1.1     ragge 	"lost recvr ready",	/* 6 = Lost Receiver Ready */
    757   1.9     ragge 	"drive detected error", /* 7 = Drive Error */
    758   1.1     ragge 	"ctlr detected pulse or parity",/* 8 = Pulse or Parity Error */
    759   1.1     ragge };
    760   1.1     ragge 
    761   1.1     ragge /*
    762   1.1     ragge  * The following table correlates message codes with the
    763   1.1     ragge  * decoding strings.
    764   1.1     ragge  */
    765   1.1     ragge struct code_decode {
    766   1.1     ragge 	char	*cdc_msg;
    767   1.1     ragge 	int	cdc_nsubcodes;
    768   1.1     ragge 	char	**cdc_submsgs;
    769   1.1     ragge } code_decode[] = {
    770   1.9     ragge #define SC(m)	sizeof (m) / sizeof (m[0]), m
    771   1.1     ragge 	{"success",			SC(succ_msgs)},
    772   1.1     ragge 	{"invalid command",		SC(icmd_msgs)},
    773   1.1     ragge 	{"command aborted",		0, 0},
    774   1.1     ragge 	{"unit offline",		SC(offl_msgs)},
    775   1.1     ragge 	{"unit available",		0, 0},
    776   1.1     ragge 	{"media format error",		SC(media_fmt_msgs)},
    777   1.1     ragge 	{"write protected",		SC(wrprot_msgs)},
    778   1.1     ragge 	{"compare error",		0, 0},
    779   1.1     ragge 	{"data error",			SC(data_msgs)},
    780   1.1     ragge 	{"host buffer access error",	SC(host_buffer_msgs)},
    781   1.1     ragge 	{"controller error",		SC(cntlr_msgs)},
    782   1.1     ragge 	{"drive error",			SC(drive_msgs)},
    783   1.1     ragge #undef SC
    784   1.1     ragge };
    785   1.1     ragge 
    786   1.1     ragge /*
    787   1.1     ragge  * Print the decoded error event from an MSCP error datagram.
    788   1.1     ragge  */
    789   1.1     ragge void
    790   1.1     ragge mscp_printevent(mp)
    791   1.1     ragge 	struct mscp *mp;
    792   1.1     ragge {
    793  1.15  augustss 	int event = mp->mscp_event;
    794  1.15  augustss 	struct code_decode *cdc;
    795   1.1     ragge 	int c, sc;
    796   1.1     ragge 	char *cm, *scm;
    797   1.1     ragge 
    798   1.1     ragge 	/*
    799   1.1     ragge 	 * The code is the lower six bits of the event number (aka
    800   1.1     ragge 	 * status).  If that is 6 (write protect), the subcode is in
    801   1.1     ragge 	 * bits 12-15; otherwise, it is in bits 5-11.
    802   1.1     ragge 	 * I WONDER WHAT THE OTHER BITS ARE FOR.  IT SURE WOULD BE
    803   1.1     ragge 	 * NICE IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
    804   1.1     ragge 	 */
    805   1.1     ragge 	c = event & M_ST_MASK;
    806   1.1     ragge 	sc = (c != 6 ? event >> 5 : event >> 12) & 0x7ff;
    807   1.1     ragge 	if (c >= sizeof code_decode / sizeof code_decode[0])
    808   1.1     ragge 		cm = "- unknown code", scm = "??";
    809   1.1     ragge 	else {
    810   1.1     ragge 		cdc = &code_decode[c];
    811   1.1     ragge 		cm = cdc->cdc_msg;
    812   1.1     ragge 		if (sc >= cdc->cdc_nsubcodes)
    813   1.1     ragge 			scm = unknown_msg;
    814   1.1     ragge 		else
    815   1.1     ragge 			scm = cdc->cdc_submsgs[sc];
    816   1.1     ragge 	}
    817   1.5  christos 	printf(" %s (%s) (code %d, subcode %d)\n", cm, scm, c, sc);
    818   1.1     ragge }
    819   1.1     ragge 
    820   1.2     ragge static char *codemsg[16] = {
    821   1.2     ragge 	"lbn", "code 1", "code 2", "code 3",
    822   1.2     ragge 	"code 4", "code 5", "rbn", "code 7",
    823   1.2     ragge 	"code 8", "code 9", "code 10", "code 11",
    824   1.2     ragge 	"code 12", "code 13", "code 14", "code 15"
    825   1.2     ragge };
    826   1.1     ragge /*
    827   1.1     ragge  * Print the code and logical block number for an error packet.
    828   1.1     ragge  * THIS IS PROBABLY PECULIAR TO DISK DRIVES.  IT SURE WOULD BE
    829   1.1     ragge  * NICE IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
    830   1.1     ragge  */
    831   1.2     ragge int
    832   1.2     ragge mscp_decodeerror(name, mp, mi)
    833   1.1     ragge 	char *name;
    834  1.15  augustss 	struct mscp *mp;
    835   1.2     ragge 	struct mscp_softc *mi;
    836   1.1     ragge {
    837   1.2     ragge 	int issoft;
    838   1.2     ragge 	/*
    839   1.2     ragge 	 * We will get three sdi errors of type 11 after autoconfig
    840   1.2     ragge 	 * is finished; depending of searching for non-existing units.
    841   1.2     ragge 	 * How can we avoid this???
    842   1.2     ragge 	 */
    843   1.2     ragge 	if (((mp->mscp_event & M_ST_MASK) == 11) && (mi->mi_ierr++ < 3))
    844   1.2     ragge 		return 1;
    845   1.1     ragge 	/*
    846   1.1     ragge 	 * For bad blocks, mp->mscp_erd.erd_hdr identifies a code and
    847   1.1     ragge 	 * the logical block number.  Code 0 is a regular block; code 6
    848   1.1     ragge 	 * is a replacement block.  The remaining codes are currently
    849   1.1     ragge 	 * undefined.  The code is in the upper four bits of the header
    850   1.1     ragge 	 * (bits 0-27 are the lbn).
    851   1.1     ragge 	 */
    852   1.2     ragge 	issoft = mp->mscp_flags & (M_LF_SUCC | M_LF_CONT);
    853   1.1     ragge #define BADCODE(h)	(codemsg[(unsigned)(h) >> 28])
    854   1.1     ragge #define BADLBN(h)	((h) & 0xfffffff)
    855   1.1     ragge 
    856   1.5  christos 	printf("%s: drive %d %s error datagram%s:", name, mp->mscp_unit,
    857   1.1     ragge 		issoft ? "soft" : "hard",
    858   1.1     ragge 		mp->mscp_flags & M_LF_CONT ? " (continuing)" : "");
    859   1.1     ragge 	switch (mp->mscp_format & 0377) {
    860   1.1     ragge 
    861   1.1     ragge 	case M_FM_CTLRERR:	/* controller error */
    862   1.1     ragge 		break;
    863   1.1     ragge 
    864   1.1     ragge 	case M_FM_BUSADDR:	/* host memory access error */
    865   1.5  christos 		printf(" memory addr 0x%x:", (int)mp->mscp_erd.erd_busaddr);
    866   1.1     ragge 		break;
    867   1.1     ragge 
    868   1.1     ragge 	case M_FM_DISKTRN:
    869   1.5  christos 		printf(" unit %d: level %d retry %d, %s %d:",
    870   1.1     ragge 			mp->mscp_unit,
    871   1.1     ragge 			mp->mscp_erd.erd_level, mp->mscp_erd.erd_retry,
    872   1.1     ragge 			BADCODE(mp->mscp_erd.erd_hdr),
    873   1.1     ragge 			(int)BADLBN(mp->mscp_erd.erd_hdr));
    874   1.1     ragge 		break;
    875   1.1     ragge 
    876   1.1     ragge 	case M_FM_SDI:
    877   1.5  christos 		printf(" unit %d: %s %d:", mp->mscp_unit,
    878   1.1     ragge 			BADCODE(mp->mscp_erd.erd_hdr),
    879   1.1     ragge 			(int)BADLBN(mp->mscp_erd.erd_hdr));
    880   1.1     ragge 		break;
    881   1.1     ragge 
    882   1.1     ragge 	case M_FM_SMLDSK:
    883   1.5  christos 		printf(" unit %d: small disk error, cyl %d:",
    884   1.1     ragge 			mp->mscp_unit, mp->mscp_erd.erd_sdecyl);
    885   1.1     ragge 		break;
    886   1.1     ragge 
    887   1.2     ragge 	case M_FM_TAPETRN:
    888   1.5  christos 		printf(" unit %d: tape transfer error, grp 0x%x event 0%o:",
    889   1.2     ragge 		    mp->mscp_unit, mp->mscp_erd.erd_sdecyl, mp->mscp_event);
    890   1.2     ragge 		break;
    891   1.2     ragge 
    892   1.2     ragge 	case M_FM_STIERR:
    893   1.5  christos 		printf(" unit %d: STI error, event 0%o:", mp->mscp_unit,
    894   1.2     ragge 		    mp->mscp_event);
    895   1.2     ragge 		break;
    896   1.2     ragge 
    897   1.1     ragge 	default:
    898   1.5  christos 		printf(" unit %d: unknown error, format 0x%x:",
    899   1.1     ragge 			mp->mscp_unit, mp->mscp_format);
    900   1.1     ragge 	}
    901   1.1     ragge 	mscp_printevent(mp);
    902   1.2     ragge 	return 0;
    903   1.1     ragge #undef BADCODE
    904   1.1     ragge #undef BADLBN
    905   1.1     ragge }
    906