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