Home | History | Annotate | Line # | Download | only in vme
xy.c revision 1.50
      1 /*	$NetBSD: xy.c,v 1.50 2003/06/29 09:56:32 darrenr Exp $	*/
      2 
      3 /*
      4  *
      5  * Copyright (c) 1995 Charles D. Cranor
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *      This product includes software developed by Charles D. Cranor.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 /*
     35  *
     36  * x y . c   x y l o g i c s   4 5 0 / 4 5 1   s m d   d r i v e r
     37  *
     38  * author: Chuck Cranor <chuck (at) ccrc.wustl.edu>
     39  * started: 14-Sep-95
     40  * references: [1] Xylogics Model 753 User's Manual
     41  *                 part number: 166-753-001, Revision B, May 21, 1988.
     42  *                 "Your Partner For Performance"
     43  *             [2] other NetBSD disk device drivers
     44  *	       [3] Xylogics Model 450 User's Manual
     45  *		   part number: 166-017-001, Revision B, 1983.
     46  *	       [4] Addendum to Xylogics Model 450 Disk Controller User's
     47  *			Manual, Jan. 1985.
     48  *	       [5] The 451 Controller, Rev. B3, September 2, 1986.
     49  *	       [6] David Jones <dej (at) achilles.net>'s unfinished 450/451 driver
     50  *
     51  */
     52 
     53 #include <sys/cdefs.h>
     54 __KERNEL_RCSID(0, "$NetBSD: xy.c,v 1.50 2003/06/29 09:56:32 darrenr Exp $");
     55 
     56 #undef XYC_DEBUG		/* full debug */
     57 #undef XYC_DIAG			/* extra sanity checks */
     58 #if defined(DIAGNOSTIC) && !defined(XYC_DIAG)
     59 #define XYC_DIAG		/* link in with master DIAG option */
     60 #endif
     61 
     62 #include <sys/param.h>
     63 #include <sys/proc.h>
     64 #include <sys/systm.h>
     65 #include <sys/kernel.h>
     66 #include <sys/file.h>
     67 #include <sys/stat.h>
     68 #include <sys/ioctl.h>
     69 #include <sys/buf.h>
     70 #include <sys/uio.h>
     71 #include <sys/malloc.h>
     72 #include <sys/device.h>
     73 #include <sys/disklabel.h>
     74 #include <sys/disk.h>
     75 #include <sys/syslog.h>
     76 #include <sys/dkbad.h>
     77 #include <sys/conf.h>
     78 
     79 #include <machine/bus.h>
     80 #include <machine/intr.h>
     81 
     82 #if defined(__sparc__) || defined(sun3)
     83 #include <dev/sun/disklabel.h>
     84 #endif
     85 
     86 #include <dev/vme/vmereg.h>
     87 #include <dev/vme/vmevar.h>
     88 
     89 #include <dev/vme/xyreg.h>
     90 #include <dev/vme/xyvar.h>
     91 #include <dev/vme/xio.h>
     92 
     93 #include "locators.h"
     94 
     95 /*
     96  * macros
     97  */
     98 
     99 /*
    100  * XYC_GO: start iopb ADDR (DVMA addr in a u_long) on XYC
    101  */
    102 #define XYC_GO(XYC, ADDR) { \
    103 	(XYC)->xyc_addr_lo = ((ADDR) & 0xff); \
    104 	(ADDR) = ((ADDR) >> 8); \
    105 	(XYC)->xyc_addr_hi = ((ADDR) & 0xff); \
    106 	(ADDR) = ((ADDR) >> 8); \
    107 	(XYC)->xyc_reloc_lo = ((ADDR) & 0xff); \
    108 	(ADDR) = ((ADDR) >> 8); \
    109 	(XYC)->xyc_reloc_hi = (ADDR); \
    110 	(XYC)->xyc_csr = XYC_GBSY; /* go! */ \
    111 }
    112 
    113 /*
    114  * XYC_DONE: don't need IORQ, get error code and free (done after xyc_cmd)
    115  */
    116 
    117 #define XYC_DONE(SC,ER) { \
    118 	if ((ER) == XY_ERR_AOK) { \
    119 		(ER) = (SC)->ciorq->errno; \
    120 		(SC)->ciorq->mode = XY_SUB_FREE; \
    121 		wakeup((SC)->ciorq); \
    122 	} \
    123 	}
    124 
    125 /*
    126  * XYC_ADVANCE: advance iorq's pointers by a number of sectors
    127  */
    128 
    129 #define XYC_ADVANCE(IORQ, N) { \
    130 	if (N) { \
    131 		(IORQ)->sectcnt -= (N); \
    132 		(IORQ)->blockno += (N); \
    133 		(IORQ)->dbuf += ((N)*XYFM_BPS); \
    134 	} \
    135 }
    136 
    137 /*
    138  * note - addresses you can sleep on:
    139  *   [1] & of xy_softc's "state" (waiting for a chance to attach a drive)
    140  *   [2] & an iorq (waiting for an XY_SUB_WAIT iorq to finish)
    141  */
    142 
    143 
    144 /*
    145  * function prototypes
    146  * "xyc_*" functions are internal, all others are external interfaces
    147  */
    148 
    149 extern int pil_to_vme[];	/* from obio.c */
    150 
    151 /* internals */
    152 struct xy_iopb *xyc_chain __P((struct xyc_softc *, struct xy_iorq *));
    153 int	xyc_cmd __P((struct xyc_softc *, int, int, int, int, int, char *, int));
    154 char   *xyc_e2str __P((int));
    155 int	xyc_entoact __P((int));
    156 int	xyc_error __P((struct xyc_softc *, struct xy_iorq *,
    157 		   struct xy_iopb *, int));
    158 int	xyc_ioctlcmd __P((struct xy_softc *, dev_t dev, struct xd_iocmd *));
    159 void	xyc_perror __P((struct xy_iorq *, struct xy_iopb *, int));
    160 int	xyc_piodriver __P((struct xyc_softc *, struct xy_iorq *));
    161 int	xyc_remove_iorq __P((struct xyc_softc *));
    162 int	xyc_reset __P((struct xyc_softc *, int, struct xy_iorq *, int,
    163 			struct xy_softc *));
    164 inline void xyc_rqinit __P((struct xy_iorq *, struct xyc_softc *,
    165 			    struct xy_softc *, int, u_long, int,
    166 			    caddr_t, struct buf *));
    167 void	xyc_rqtopb __P((struct xy_iorq *, struct xy_iopb *, int, int));
    168 void	xyc_start __P((struct xyc_softc *, struct xy_iorq *));
    169 int	xyc_startbuf __P((struct xyc_softc *, struct xy_softc *, struct buf *));
    170 int	xyc_submit_iorq __P((struct xyc_softc *, struct xy_iorq *, int));
    171 void	xyc_tick __P((void *));
    172 int	xyc_unbusy __P((struct xyc *, int));
    173 void	xyc_xyreset __P((struct xyc_softc *, struct xy_softc *));
    174 int	xy_dmamem_alloc(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
    175 			int *, bus_size_t, caddr_t *, bus_addr_t *);
    176 void	xy_dmamem_free(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
    177 			int, bus_size_t, caddr_t);
    178 
    179 /* machine interrupt hook */
    180 int	xycintr __P((void *));
    181 
    182 /* autoconf */
    183 int	xycmatch __P((struct device *, struct cfdata *, void *));
    184 void	xycattach __P((struct device *, struct device *, void *));
    185 int	xymatch __P((struct device *, struct cfdata *, void *));
    186 void	xyattach __P((struct device *, struct device *, void *));
    187 static	int xyc_probe __P((void *, bus_space_tag_t, bus_space_handle_t));
    188 
    189 static	void xydummystrat __P((struct buf *));
    190 int	xygetdisklabel __P((struct xy_softc *, void *));
    191 
    192 /*
    193  * cfattach's: device driver interface to autoconfig
    194  */
    195 
    196 CFATTACH_DECL(xyc, sizeof(struct xyc_softc),
    197     xycmatch, xycattach, NULL, NULL);
    198 
    199 CFATTACH_DECL(xy, sizeof(struct xy_softc),
    200     xymatch, xyattach, NULL, NULL);
    201 
    202 extern struct cfdriver xy_cd;
    203 
    204 dev_type_open(xyopen);
    205 dev_type_close(xyclose);
    206 dev_type_read(xyread);
    207 dev_type_write(xywrite);
    208 dev_type_ioctl(xyioctl);
    209 dev_type_strategy(xystrategy);
    210 dev_type_dump(xydump);
    211 dev_type_size(xysize);
    212 
    213 const struct bdevsw xy_bdevsw = {
    214 	xyopen, xyclose, xystrategy, xyioctl, xydump, xysize, D_DISK
    215 };
    216 
    217 const struct cdevsw xy_cdevsw = {
    218 	xyopen, xyclose, xyread, xywrite, xyioctl,
    219 	nostop, notty, nopoll, nommap, nokqfilter, D_DISK
    220 };
    221 
    222 struct xyc_attach_args {	/* this is the "aux" args to xyattach */
    223 	int	driveno;	/* unit number */
    224 	int	fullmode;	/* submit mode */
    225 	int	booting;	/* are we booting or not? */
    226 };
    227 
    228 /*
    229  * dkdriver
    230  */
    231 
    232 struct dkdriver xydkdriver = { xystrategy };
    233 
    234 /*
    235  * start: disk label fix code (XXX)
    236  */
    237 
    238 static void *xy_labeldata;
    239 
    240 static void
    241 xydummystrat(bp)
    242 	struct buf *bp;
    243 {
    244 	if (bp->b_bcount != XYFM_BPS)
    245 		panic("xydummystrat");
    246 	bcopy(xy_labeldata, bp->b_data, XYFM_BPS);
    247 	bp->b_flags |= B_DONE;
    248 	bp->b_flags &= ~B_BUSY;
    249 }
    250 
    251 int
    252 xygetdisklabel(xy, b)
    253 	struct xy_softc *xy;
    254 	void *b;
    255 {
    256 	const char *err;
    257 #if defined(__sparc__) || defined(sun3)
    258 	struct sun_disklabel *sdl;
    259 #endif
    260 
    261 	/* We already have the label data in `b'; setup for dummy strategy */
    262 	xy_labeldata = b;
    263 
    264 	/* Required parameter for readdisklabel() */
    265 	xy->sc_dk.dk_label->d_secsize = XYFM_BPS;
    266 
    267 	err = readdisklabel(MAKEDISKDEV(0, xy->sc_dev.dv_unit, RAW_PART),
    268 					xydummystrat,
    269 				xy->sc_dk.dk_label, xy->sc_dk.dk_cpulabel);
    270 	if (err) {
    271 		printf("%s: %s\n", xy->sc_dev.dv_xname, err);
    272 		return(XY_ERR_FAIL);
    273 	}
    274 
    275 #if defined(__sparc__) || defined(sun3)
    276 	/* Ok, we have the label; fill in `pcyl' if there's SunOS magic */
    277 	sdl = (struct sun_disklabel *)xy->sc_dk.dk_cpulabel->cd_block;
    278 	if (sdl->sl_magic == SUN_DKMAGIC) {
    279 		xy->pcyl = sdl->sl_pcylinders;
    280 	} else
    281 #endif
    282 	{
    283 		printf("%s: WARNING: no `pcyl' in disk label.\n",
    284 			xy->sc_dev.dv_xname);
    285 		xy->pcyl = xy->sc_dk.dk_label->d_ncylinders +
    286 			xy->sc_dk.dk_label->d_acylinders;
    287 		printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n",
    288 		xy->sc_dev.dv_xname, xy->pcyl);
    289 	}
    290 
    291 	xy->ncyl = xy->sc_dk.dk_label->d_ncylinders;
    292 	xy->acyl = xy->sc_dk.dk_label->d_acylinders;
    293 	xy->nhead = xy->sc_dk.dk_label->d_ntracks;
    294 	xy->nsect = xy->sc_dk.dk_label->d_nsectors;
    295 	xy->sectpercyl = xy->nhead * xy->nsect;
    296 	xy->sc_dk.dk_label->d_secsize = XYFM_BPS; /* not handled by
    297                                           	  * sun->bsd */
    298 	return(XY_ERR_AOK);
    299 }
    300 
    301 /*
    302  * end: disk label fix code (XXX)
    303  */
    304 
    305 /*
    306  * Shorthand for allocating, mapping and loading a DMA buffer
    307  */
    308 int
    309 xy_dmamem_alloc(tag, map, seg, nsegp, len, kvap, dmap)
    310 	bus_dma_tag_t		tag;
    311 	bus_dmamap_t		map;
    312 	bus_dma_segment_t	*seg;
    313 	int			*nsegp;
    314 	bus_size_t		len;
    315 	caddr_t			*kvap;
    316 	bus_addr_t		*dmap;
    317 {
    318 	int nseg;
    319 	int error;
    320 
    321 	if ((error = bus_dmamem_alloc(tag, len, 0, 0,
    322 				      seg, 1, &nseg, BUS_DMA_NOWAIT)) != 0) {
    323 		return (error);
    324 	}
    325 
    326 	if ((error = bus_dmamem_map(tag, seg, nseg,
    327 				    len, kvap,
    328 				    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    329 		bus_dmamem_free(tag, seg, nseg);
    330 		return (error);
    331 	}
    332 
    333 	if ((error = bus_dmamap_load(tag, map, *kvap, len, NULL,
    334 				     BUS_DMA_NOWAIT)) != 0) {
    335 		bus_dmamem_unmap(tag, *kvap, len);
    336 		bus_dmamem_free(tag, seg, nseg);
    337 		return (error);
    338 	}
    339 
    340 	*dmap = map->dm_segs[0].ds_addr;
    341 	*nsegp = nseg;
    342 	return (0);
    343 }
    344 
    345 void
    346 xy_dmamem_free(tag, map, seg, nseg, len, kva)
    347 	bus_dma_tag_t		tag;
    348 	bus_dmamap_t		map;
    349 	bus_dma_segment_t	*seg;
    350 	int			nseg;
    351 	bus_size_t		len;
    352 	caddr_t			kva;
    353 {
    354 
    355 	bus_dmamap_unload(tag, map);
    356 	bus_dmamem_unmap(tag, kva, len);
    357 	bus_dmamem_free(tag, seg, nseg);
    358 }
    359 
    360 
    361 /*
    362  * a u t o c o n f i g   f u n c t i o n s
    363  */
    364 
    365 /*
    366  * xycmatch: determine if xyc is present or not.   we do a
    367  * soft reset to detect the xyc.
    368  */
    369 int
    370 xyc_probe(arg, tag, handle)
    371 	void *arg;
    372 	bus_space_tag_t tag;
    373 	bus_space_handle_t handle;
    374 {
    375 	struct xyc *xyc = (void *)handle; /* XXX */
    376 
    377 	return ((xyc_unbusy(xyc, XYC_RESETUSEC) != XY_ERR_FAIL) ? 0 : EIO);
    378 }
    379 
    380 int xycmatch(parent, cf, aux)
    381 	struct device *parent;
    382 	struct cfdata *cf;
    383 	void *aux;
    384 {
    385 	struct vme_attach_args	*va = aux;
    386 	vme_chipset_tag_t	ct = va->va_vct;
    387 	vme_am_t		mod;
    388 	int error;
    389 
    390 	mod = VME_AM_A16 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
    391 	if (vme_space_alloc(ct, va->r[0].offset, sizeof(struct xyc), mod))
    392 		return (0);
    393 
    394 	error = vme_probe(ct, va->r[0].offset, sizeof(struct xyc),
    395 			  mod, VME_D16, xyc_probe, 0);
    396 	vme_space_free(va->va_vct, va->r[0].offset, sizeof(struct xyc), mod);
    397 
    398 	return (error == 0);
    399 }
    400 
    401 /*
    402  * xycattach: attach controller
    403  */
    404 void
    405 xycattach(parent, self, aux)
    406 	struct device *parent, *self;
    407 	void   *aux;
    408 
    409 {
    410 	struct xyc_softc	*xyc = (void *) self;
    411 	struct vme_attach_args	*va = aux;
    412 	vme_chipset_tag_t	ct = va->va_vct;
    413 	bus_space_tag_t		bt;
    414 	bus_space_handle_t	bh;
    415 	vme_intr_handle_t	ih;
    416 	vme_am_t		mod;
    417 	struct xyc_attach_args	xa;
    418 	int			lcv, res, error;
    419 	bus_dma_segment_t	seg;
    420 	int			rseg;
    421 	vme_mapresc_t resc;
    422 
    423 	/* get addressing and intr level stuff from autoconfig and load it
    424 	 * into our xyc_softc. */
    425 
    426 	mod = VME_AM_A16 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
    427 
    428 	if (vme_space_alloc(ct, va->r[0].offset, sizeof(struct xyc), mod))
    429 		panic("xyc: vme alloc");
    430 
    431 	if (vme_space_map(ct, va->r[0].offset, sizeof(struct xyc),
    432 			  mod, VME_D16, 0, &bt, &bh, &resc) != 0)
    433 		panic("xyc: vme_map");
    434 
    435 	xyc->xyc = (struct xyc *) bh; /* XXX */
    436 	xyc->ipl = va->ilevel;
    437 	xyc->vector = va->ivector;
    438 	xyc->no_ols = 0; /* XXX should be from config */
    439 
    440 	for (lcv = 0; lcv < XYC_MAXDEV; lcv++)
    441 		xyc->sc_drives[lcv] = (struct xy_softc *) 0;
    442 
    443 	/*
    444 	 * allocate and zero buffers
    445 	 * check boundaries of the KVA's ... all IOPBs must reside in
    446  	 * the same 64K region.
    447 	 */
    448 
    449 	/* Get DMA handle for misc. transfers */
    450 	if ((error = vme_dmamap_create(
    451 				ct,		/* VME chip tag */
    452 				MAXPHYS,	/* size */
    453 				VME_AM_A24,	/* address modifier */
    454 				VME_D16,	/* data size */
    455 				0,		/* swap */
    456 				1,		/* nsegments */
    457 				MAXPHYS,	/* maxsegsz */
    458 				0,		/* boundary */
    459 				BUS_DMA_NOWAIT,
    460 				&xyc->reqs[lcv].dmamap)) != 0) {
    461 
    462 		printf("%s: DMA buffer map create error %d\n",
    463 			xyc->sc_dev.dv_xname, error);
    464 		return;
    465 	}
    466 
    467 	/* Get DMA handle for mapping iorq descriptors */
    468 	if ((error = vme_dmamap_create(
    469 				ct,		/* VME chip tag */
    470 				XYC_MAXIOPB * sizeof(struct xy_iopb),
    471 				VME_AM_A24,	/* address modifier */
    472 				VME_D16,	/* data size */
    473 				0,		/* swap */
    474 				1,		/* nsegments */
    475 				XYC_MAXIOPB * sizeof(struct xy_iopb),
    476 				64*1024,	/* boundary */
    477 				BUS_DMA_NOWAIT,
    478 				&xyc->iopmap)) != 0) {
    479 
    480 		printf("%s: DMA buffer map create error %d\n",
    481 			xyc->sc_dev.dv_xname, error);
    482 		return;
    483 	}
    484 
    485 	/* Get DMA buffer for iorq descriptors */
    486 	if ((error = xy_dmamem_alloc(xyc->dmatag, xyc->iopmap, &seg, &rseg,
    487 				     XYC_MAXIOPB * sizeof(struct xy_iopb),
    488 				     (caddr_t *)&xyc->iopbase,
    489 				     (bus_addr_t *)&xyc->dvmaiopb)) != 0) {
    490 		printf("%s: DMA buffer alloc error %d\n",
    491 			xyc->sc_dev.dv_xname, error);
    492 		return;
    493 	}
    494 
    495 	bzero(xyc->iopbase, XYC_MAXIOPB * sizeof(struct xy_iopb));
    496 
    497 	xyc->reqs = (struct xy_iorq *)
    498 	    malloc(XYC_MAXIOPB * sizeof(struct xy_iorq),
    499 	    M_DEVBUF, M_NOWAIT|M_ZERO);
    500 	if (xyc->reqs == NULL)
    501 		panic("xyc malloc");
    502 
    503 	/*
    504 	 * init iorq to iopb pointers, and non-zero fields in the
    505 	 * iopb which never change.
    506 	 */
    507 
    508 	for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) {
    509 		xyc->xy_chain[lcv] = NULL;
    510 		xyc->reqs[lcv].iopb = &xyc->iopbase[lcv];
    511 		xyc->reqs[lcv].dmaiopb = &xyc->dvmaiopb[lcv];
    512 		xyc->iopbase[lcv].asr = 1;	/* always the same */
    513 		xyc->iopbase[lcv].eef = 1;	/* always the same */
    514 		xyc->iopbase[lcv].ecm = XY_ECM;	/* always the same */
    515 		xyc->iopbase[lcv].aud = 1;	/* always the same */
    516 		xyc->iopbase[lcv].relo = 1;	/* always the same */
    517 		xyc->iopbase[lcv].thro = XY_THRO;/* always the same */
    518 
    519 		if ((error = vme_dmamap_create(
    520 				ct,		/* VME chip tag */
    521 				MAXPHYS,	/* size */
    522 				VME_AM_A24,	/* address modifier */
    523 				VME_D16,	/* data size */
    524 				0,		/* swap */
    525 				1,		/* nsegments */
    526 				MAXPHYS,	/* maxsegsz */
    527 				0,		/* boundary */
    528 				BUS_DMA_NOWAIT,
    529 				&xyc->reqs[lcv].dmamap)) != 0) {
    530 
    531 			printf("%s: DMA buffer map create error %d\n",
    532 				xyc->sc_dev.dv_xname, error);
    533 			return;
    534 		}
    535 	}
    536 	xyc->ciorq = &xyc->reqs[XYC_CTLIOPB];    /* short hand name */
    537 	xyc->ciopb = &xyc->iopbase[XYC_CTLIOPB]; /* short hand name */
    538 	xyc->xy_hand = 0;
    539 
    540 	/* read controller parameters and insure we have a 450/451 */
    541 
    542 	error = xyc_cmd(xyc, XYCMD_ST, 0, 0, 0, 0, 0, XY_SUB_POLL);
    543 	res = xyc->ciopb->ctyp;
    544 	XYC_DONE(xyc, error);
    545 	if (res != XYCT_450) {
    546 		if (error)
    547 			printf(": %s: ", xyc_e2str(error));
    548 		printf(": doesn't identify as a 450/451\n");
    549 		return;
    550 	}
    551 	printf(": Xylogics 450/451");
    552 	if (xyc->no_ols)
    553 		printf(" [OLS disabled]"); /* 450 doesn't overlap seek right */
    554 	printf("\n");
    555 	if (error) {
    556 		printf("%s: error: %s\n", xyc->sc_dev.dv_xname,
    557 				xyc_e2str(error));
    558 		return;
    559 	}
    560 	if ((xyc->xyc->xyc_csr & XYC_ADRM) == 0) {
    561 		printf("%s: 24 bit addressing turned off\n",
    562 			xyc->sc_dev.dv_xname);
    563 		printf("please set hardware jumpers JM1-JM2=in, JM3-JM4=out\n");
    564 		printf("to enable 24 bit mode and this driver\n");
    565 		return;
    566 	}
    567 
    568 	/* link in interrupt with higher level software */
    569 	vme_intr_map(ct, va->ilevel, va->ivector, &ih);
    570 	vme_intr_establish(ct, ih, IPL_BIO, xycintr, xyc);
    571 	evcnt_attach_dynamic(&xyc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    572 	    xyc->sc_dev.dv_xname, "intr");
    573 
    574 	callout_init(&xyc->sc_tick_ch);
    575 
    576 	/* now we must look for disks using autoconfig */
    577 	xa.fullmode = XY_SUB_POLL;
    578 	xa.booting = 1;
    579 
    580 	for (xa.driveno = 0; xa.driveno < XYC_MAXDEV; xa.driveno++)
    581 		(void) config_found(self, (void *) &xa, NULL);
    582 
    583 	/* start the watchdog clock */
    584 	callout_reset(&xyc->sc_tick_ch, XYC_TICKCNT, xyc_tick, xyc);
    585 
    586 }
    587 
    588 /*
    589  * xymatch: probe for disk.
    590  *
    591  * note: we almost always say disk is present.   this allows us to
    592  * spin up and configure a disk after the system is booted (we can
    593  * call xyattach!).
    594  */
    595 int
    596 xymatch(parent, cf, aux)
    597 	struct device *parent;
    598 	struct cfdata *cf;
    599 	void *aux;
    600 {
    601 	struct xyc_attach_args *xa = aux;
    602 
    603 	/* looking for autoconf wildcard or exact match */
    604 
    605 	if (cf->cf_loc[XYCCF_DRIVE] != XYCCF_DRIVE_DEFAULT &&
    606 	    cf->cf_loc[XYCCF_DRIVE] != xa->driveno)
    607 		return 0;
    608 
    609 	return 1;
    610 
    611 }
    612 
    613 /*
    614  * xyattach: attach a disk.   this can be called from autoconf and also
    615  * from xyopen/xystrategy.
    616  */
    617 void
    618 xyattach(parent, self, aux)
    619 	struct device *parent, *self;
    620 	void   *aux;
    621 
    622 {
    623 	struct xy_softc *xy = (void *) self, *oxy;
    624 	struct xyc_softc *xyc = (void *) parent;
    625 	struct xyc_attach_args *xa = aux;
    626 	int     spt, mb, blk, lcv, fmode, s = 0, newstate;
    627 	struct dkbad *dkb;
    628 	int			rseg, error;
    629 	bus_dma_segment_t	seg;
    630 	caddr_t			dmaddr;
    631 	caddr_t			buf;
    632 
    633 	/*
    634 	 * Always re-initialize the disk structure.  We want statistics
    635 	 * to start with a clean slate.
    636 	 */
    637 	bzero(&xy->sc_dk, sizeof(xy->sc_dk));
    638 	xy->sc_dk.dk_driver = &xydkdriver;
    639 	xy->sc_dk.dk_name = xy->sc_dev.dv_xname;
    640 
    641 	/* if booting, init the xy_softc */
    642 
    643 	if (xa->booting) {
    644 		xy->state = XY_DRIVE_UNKNOWN;	/* to start */
    645 		xy->flags = 0;
    646 		xy->parent = xyc;
    647 
    648 		/* init queue of waiting bufs */
    649 
    650 		bufq_alloc(&xy->xyq, BUFQ_DISKSORT|BUFQ_SORT_RAWBLOCK);
    651 
    652 		xy->xyrq = &xyc->reqs[xa->driveno];
    653 
    654 	}
    655 	xy->xy_drive = xa->driveno;
    656 	fmode = xa->fullmode;
    657 	xyc->sc_drives[xa->driveno] = xy;
    658 
    659 	/* if not booting, make sure we are the only process in the attach for
    660 	 * this drive.   if locked out, sleep on it. */
    661 
    662 	if (!xa->booting) {
    663 		s = splbio();
    664 		while (xy->state == XY_DRIVE_ATTACHING) {
    665 			if (tsleep(&xy->state, PRIBIO, "xyattach", 0)) {
    666 				splx(s);
    667 				return;
    668 			}
    669 		}
    670 		printf("%s at %s",
    671 			xy->sc_dev.dv_xname, xy->parent->sc_dev.dv_xname);
    672 	}
    673 
    674 	/* we now have control */
    675 	xy->state = XY_DRIVE_ATTACHING;
    676 	newstate = XY_DRIVE_UNKNOWN;
    677 
    678 	buf = NULL;
    679 	if ((error = xy_dmamem_alloc(xyc->dmatag, xyc->auxmap, &seg, &rseg,
    680 				     XYFM_BPS,
    681 				     (caddr_t *)&buf,
    682 				     (bus_addr_t *)&dmaddr)) != 0) {
    683 		printf("%s: DMA buffer alloc error %d\n",
    684 			xyc->sc_dev.dv_xname, error);
    685 		return;
    686 	}
    687 
    688 	/* first try and reset the drive */
    689 	error = xyc_cmd(xyc, XYCMD_RST, 0, xy->xy_drive, 0, 0, 0, fmode);
    690 	XYC_DONE(xyc, error);
    691 	if (error == XY_ERR_DNRY) {
    692 		printf(" drive %d: off-line\n", xa->driveno);
    693 		goto done;
    694 	}
    695 	if (error) {
    696 		printf(": ERROR 0x%02x (%s)\n", error, xyc_e2str(error));
    697 		goto done;
    698 	}
    699 	printf(" drive %d: ready", xa->driveno);
    700 
    701 	/*
    702 	 * now set drive parameters (to semi-bogus values) so we can read the
    703 	 * disk label.
    704 	 */
    705 	xy->pcyl = xy->ncyl = 1;
    706 	xy->acyl = 0;
    707 	xy->nhead = 1;
    708 	xy->nsect = 1;
    709 	xy->sectpercyl = 1;
    710 	for (lcv = 0; lcv < 126; lcv++)	/* init empty bad144 table */
    711 		xy->dkb.bt_bad[lcv].bt_cyl =
    712 			xy->dkb.bt_bad[lcv].bt_trksec = 0xffff;
    713 
    714 	/* read disk label */
    715 	for (xy->drive_type = 0 ; xy->drive_type <= XYC_MAXDT ;
    716 						xy->drive_type++) {
    717 		error = xyc_cmd(xyc, XYCMD_RD, 0, xy->xy_drive, 0, 1,
    718 						dmaddr, fmode);
    719 		XYC_DONE(xyc, error);
    720 		if (error == XY_ERR_AOK) break;
    721 	}
    722 
    723 	if (error != XY_ERR_AOK) {
    724 		printf("\n%s: reading disk label failed: %s\n",
    725 			xy->sc_dev.dv_xname, xyc_e2str(error));
    726 		goto done;
    727 	}
    728 	printf(" (drive type %d)\n", xy->drive_type);
    729 
    730 	newstate = XY_DRIVE_NOLABEL;
    731 
    732 	xy->hw_spt = spt = 0; /* XXX needed ? */
    733 	/* Attach the disk: must be before getdisklabel to malloc label */
    734 	disk_attach(&xy->sc_dk);
    735 
    736 	if (xygetdisklabel(xy, buf) != XY_ERR_AOK)
    737 		goto done;
    738 
    739 	/* inform the user of what is up */
    740 	printf("%s: <%s>, pcyl %d\n", xy->sc_dev.dv_xname,
    741 		buf, xy->pcyl);
    742 	mb = xy->ncyl * (xy->nhead * xy->nsect) / (1048576 / XYFM_BPS);
    743 	printf("%s: %dMB, %d cyl, %d head, %d sec, %d bytes/sec\n",
    744 		xy->sc_dev.dv_xname, mb, xy->ncyl, xy->nhead, xy->nsect,
    745 		XYFM_BPS);
    746 
    747 	/*
    748 	 * 450/451 stupidity: the drive type is encoded into the format
    749 	 * of the disk.   the drive type in the IOPB must match the drive
    750 	 * type in the format, or you will not be able to do I/O to the
    751 	 * disk (you get header not found errors).  if you have two drives
    752 	 * of different sizes that have the same drive type in their
    753 	 * formatting then you are out of luck.
    754 	 *
    755 	 * this problem was corrected in the 753/7053.
    756 	 */
    757 
    758 	for (lcv = 0 ; lcv < XYC_MAXDEV ; lcv++) {
    759 		oxy = xyc->sc_drives[lcv];
    760 		if (oxy == NULL || oxy == xy) continue;
    761 		if (oxy->drive_type != xy->drive_type) continue;
    762 		if (xy->nsect != oxy->nsect || xy->pcyl != oxy->pcyl ||
    763 			xy->nhead != oxy->nhead) {
    764 			printf("%s: %s and %s must be the same size!\n",
    765 				xyc->sc_dev.dv_xname, xy->sc_dev.dv_xname,
    766 				oxy->sc_dev.dv_xname);
    767 			panic("xy drive size mismatch");
    768 		}
    769 	}
    770 
    771 
    772 	/* now set the real drive parameters! */
    773 
    774 	blk = (xy->nsect - 1) +
    775 		((xy->nhead - 1) * xy->nsect) +
    776 		((xy->pcyl - 1) * xy->nsect * xy->nhead);
    777 	error = xyc_cmd(xyc, XYCMD_SDS, 0, xy->xy_drive, blk, 0, 0, fmode);
    778 	XYC_DONE(xyc, error);
    779 	if (error) {
    780 		printf("%s: write drive size failed: %s\n",
    781 			xy->sc_dev.dv_xname, xyc_e2str(error));
    782 		goto done;
    783 	}
    784 	newstate = XY_DRIVE_ONLINE;
    785 
    786 	/*
    787 	 * read bad144 table. this table resides on the first sector of the
    788 	 * last track of the disk (i.e. second cyl of "acyl" area).
    789 	 */
    790 
    791 	blk = (xy->ncyl + xy->acyl - 1) * (xy->nhead * xy->nsect) +
    792 								/* last cyl */
    793 	    (xy->nhead - 1) * xy->nsect;	/* last head */
    794 	error = xyc_cmd(xyc, XYCMD_RD, 0, xy->xy_drive, blk, 1,
    795 						dmaddr, fmode);
    796 	XYC_DONE(xyc, error);
    797 	if (error) {
    798 		printf("%s: reading bad144 failed: %s\n",
    799 			xy->sc_dev.dv_xname, xyc_e2str(error));
    800 		goto done;
    801 	}
    802 
    803 	/* check dkbad for sanity */
    804 	dkb = (struct dkbad *) buf;
    805 	for (lcv = 0; lcv < 126; lcv++) {
    806 		if ((dkb->bt_bad[lcv].bt_cyl == 0xffff ||
    807 				dkb->bt_bad[lcv].bt_cyl == 0) &&
    808 		     dkb->bt_bad[lcv].bt_trksec == 0xffff)
    809 			continue;	/* blank */
    810 		if (dkb->bt_bad[lcv].bt_cyl >= xy->ncyl)
    811 			break;
    812 		if ((dkb->bt_bad[lcv].bt_trksec >> 8) >= xy->nhead)
    813 			break;
    814 		if ((dkb->bt_bad[lcv].bt_trksec & 0xff) >= xy->nsect)
    815 			break;
    816 	}
    817 	if (lcv != 126) {
    818 		printf("%s: warning: invalid bad144 sector!\n",
    819 			xy->sc_dev.dv_xname);
    820 	} else {
    821 		bcopy(buf, &xy->dkb, XYFM_BPS);
    822 	}
    823 
    824 done:
    825 	if (buf != NULL) {
    826 		xy_dmamem_free(xyc->dmatag, xyc->auxmap,
    827 				&seg, rseg, XYFM_BPS, buf);
    828 	}
    829 
    830 	xy->state = newstate;
    831 	if (!xa->booting) {
    832 		wakeup(&xy->state);
    833 		splx(s);
    834 	}
    835 }
    836 
    837 /*
    838  * end of autoconfig functions
    839  */
    840 
    841 /*
    842  * { b , c } d e v s w   f u n c t i o n s
    843  */
    844 
    845 /*
    846  * xyclose: close device
    847  */
    848 int
    849 xyclose(dev, flag, fmt, l)
    850 	dev_t   dev;
    851 	int     flag, fmt;
    852 	struct lwp *l;
    853 
    854 {
    855 	struct xy_softc *xy = xy_cd.cd_devs[DISKUNIT(dev)];
    856 	int     part = DISKPART(dev);
    857 
    858 	/* clear mask bits */
    859 
    860 	switch (fmt) {
    861 	case S_IFCHR:
    862 		xy->sc_dk.dk_copenmask &= ~(1 << part);
    863 		break;
    864 	case S_IFBLK:
    865 		xy->sc_dk.dk_bopenmask &= ~(1 << part);
    866 		break;
    867 	}
    868 	xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask;
    869 
    870 	return 0;
    871 }
    872 
    873 /*
    874  * xydump: crash dump system
    875  */
    876 int
    877 xydump(dev, blkno, va, size)
    878 	dev_t dev;
    879 	daddr_t blkno;
    880 	caddr_t va;
    881 	size_t size;
    882 {
    883 	int     unit, part;
    884 	struct xy_softc *xy;
    885 
    886 	unit = DISKUNIT(dev);
    887 	if (unit >= xy_cd.cd_ndevs)
    888 		return ENXIO;
    889 	part = DISKPART(dev);
    890 
    891 	xy = xy_cd.cd_devs[unit];
    892 
    893 	printf("%s%c: crash dump not supported (yet)\n", xy->sc_dev.dv_xname,
    894 	    'a' + part);
    895 
    896 	return ENXIO;
    897 
    898 	/* outline: globals: "dumplo" == sector number of partition to start
    899 	 * dump at (convert to physical sector with partition table)
    900 	 * "dumpsize" == size of dump in clicks "physmem" == size of physical
    901 	 * memory (clicks, ctob() to get bytes) (normal case: dumpsize ==
    902 	 * physmem)
    903 	 *
    904 	 * dump a copy of physical memory to the dump device starting at sector
    905 	 * "dumplo" in the swap partition (make sure > 0).   map in pages as
    906 	 * we go.   use polled I/O.
    907 	 *
    908 	 * XXX how to handle NON_CONTIG? */
    909 
    910 }
    911 
    912 /*
    913  * xyioctl: ioctls on XY drives.   based on ioctl's of other netbsd disks.
    914  */
    915 int
    916 xyioctl(dev, command, addr, flag, l)
    917 	dev_t   dev;
    918 	u_long  command;
    919 	caddr_t addr;
    920 	int     flag;
    921 	struct lwp *l;
    922 
    923 {
    924 	struct proc *p = l->l_proc;
    925 	struct xy_softc *xy;
    926 	struct xd_iocmd *xio;
    927 	int     error, s, unit;
    928 #ifdef __HAVE_OLD_DISKLABEL
    929 	struct disklabel newlabel;
    930 #endif
    931 	struct disklabel *lp;
    932 
    933 	unit = DISKUNIT(dev);
    934 
    935 	if (unit >= xy_cd.cd_ndevs || (xy = xy_cd.cd_devs[unit]) == NULL)
    936 		return (ENXIO);
    937 
    938 	/* switch on ioctl type */
    939 
    940 	switch (command) {
    941 	case DIOCSBAD:		/* set bad144 info */
    942 		if ((flag & FWRITE) == 0)
    943 			return EBADF;
    944 		s = splbio();
    945 		bcopy(addr, &xy->dkb, sizeof(xy->dkb));
    946 		splx(s);
    947 		return 0;
    948 
    949 	case DIOCGDINFO:	/* get disk label */
    950 		bcopy(xy->sc_dk.dk_label, addr, sizeof(struct disklabel));
    951 		return 0;
    952 #ifdef __HAVE_OLD_DISKLABEL
    953 	case ODIOCGDINFO:
    954 		newlabel = *(xy->sc_dk.dk_label);
    955 		if (newlabel.d_npartitions > OLDMAXPARTITIONS)
    956 			return ENOTTY;
    957 		memcpy(addr, &newlabel, sizeof (struct olddisklabel));
    958 		return 0;
    959 #endif
    960 
    961 	case DIOCGPART:	/* get partition info */
    962 		((struct partinfo *) addr)->disklab = xy->sc_dk.dk_label;
    963 		((struct partinfo *) addr)->part =
    964 		    &xy->sc_dk.dk_label->d_partitions[DISKPART(dev)];
    965 		return 0;
    966 
    967 	case DIOCSDINFO:	/* set disk label */
    968 #ifdef __HAVE_OLD_DISKLABEL
    969 	case ODIOCSDINFO:
    970 		if (command == ODIOCSDINFO) {
    971 			memset(&newlabel, 0, sizeof newlabel);
    972 			memcpy(&newlabel, addr, sizeof (struct olddisklabel));
    973 			lp = &newlabel;
    974 		} else
    975 #endif
    976 		lp = (struct disklabel *)addr;
    977 
    978 		if ((flag & FWRITE) == 0)
    979 			return EBADF;
    980 		error = setdisklabel(xy->sc_dk.dk_label,
    981 		    lp, /* xy->sc_dk.dk_openmask : */ 0,
    982 		    xy->sc_dk.dk_cpulabel);
    983 		if (error == 0) {
    984 			if (xy->state == XY_DRIVE_NOLABEL)
    985 				xy->state = XY_DRIVE_ONLINE;
    986 		}
    987 		return error;
    988 
    989 	case DIOCWLABEL:	/* change write status of disk label */
    990 		if ((flag & FWRITE) == 0)
    991 			return EBADF;
    992 		if (*(int *) addr)
    993 			xy->flags |= XY_WLABEL;
    994 		else
    995 			xy->flags &= ~XY_WLABEL;
    996 		return 0;
    997 
    998 	case DIOCWDINFO:	/* write disk label */
    999 #ifdef __HAVE_OLD_DISKLABEL
   1000 	case ODIOCWDINFO:
   1001 		if (command == ODIOCWDINFO) {
   1002 			memset(&newlabel, 0, sizeof newlabel);
   1003 			memcpy(&newlabel, addr, sizeof (struct olddisklabel));
   1004 			lp = &newlabel;
   1005 		} else
   1006 #endif
   1007 		lp = (struct disklabel *)addr;
   1008 
   1009 		if ((flag & FWRITE) == 0)
   1010 			return EBADF;
   1011 		error = setdisklabel(xy->sc_dk.dk_label,
   1012 		    lp, /* xy->sc_dk.dk_openmask : */ 0,
   1013 		    xy->sc_dk.dk_cpulabel);
   1014 		if (error == 0) {
   1015 			if (xy->state == XY_DRIVE_NOLABEL)
   1016 				xy->state = XY_DRIVE_ONLINE;
   1017 
   1018 			/* Simulate opening partition 0 so write succeeds. */
   1019 			xy->sc_dk.dk_openmask |= (1 << 0);
   1020 			error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART),
   1021 			    xystrategy, xy->sc_dk.dk_label,
   1022 			    xy->sc_dk.dk_cpulabel);
   1023 			xy->sc_dk.dk_openmask =
   1024 			    xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask;
   1025 		}
   1026 		return error;
   1027 
   1028 	case DIOSXDCMD:
   1029 		xio = (struct xd_iocmd *) addr;
   1030 		if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
   1031 			return (error);
   1032 		return (xyc_ioctlcmd(xy, dev, xio));
   1033 
   1034 	default:
   1035 		return ENOTTY;
   1036 	}
   1037 }
   1038 
   1039 /*
   1040  * xyopen: open drive
   1041  */
   1042 
   1043 int
   1044 xyopen(dev, flag, fmt, l)
   1045 	dev_t   dev;
   1046 	int     flag, fmt;
   1047 	struct lwp *l;
   1048 {
   1049 	int     unit, part;
   1050 	struct xy_softc *xy;
   1051 	struct xyc_attach_args xa;
   1052 
   1053 	/* first, could it be a valid target? */
   1054 
   1055 	unit = DISKUNIT(dev);
   1056 	if (unit >= xy_cd.cd_ndevs || (xy = xy_cd.cd_devs[unit]) == NULL)
   1057 		return (ENXIO);
   1058 	part = DISKPART(dev);
   1059 
   1060 	/* do we need to attach the drive? */
   1061 
   1062 	if (xy->state == XY_DRIVE_UNKNOWN) {
   1063 		xa.driveno = xy->xy_drive;
   1064 		xa.fullmode = XY_SUB_WAIT;
   1065 		xa.booting = 0;
   1066 		xyattach((struct device *) xy->parent,
   1067 						(struct device *) xy, &xa);
   1068 		if (xy->state == XY_DRIVE_UNKNOWN) {
   1069 			return (EIO);
   1070 		}
   1071 	}
   1072 	/* check for partition */
   1073 
   1074 	if (part != RAW_PART &&
   1075 	    (part >= xy->sc_dk.dk_label->d_npartitions ||
   1076 		xy->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
   1077 		return (ENXIO);
   1078 	}
   1079 	/* set open masks */
   1080 
   1081 	switch (fmt) {
   1082 	case S_IFCHR:
   1083 		xy->sc_dk.dk_copenmask |= (1 << part);
   1084 		break;
   1085 	case S_IFBLK:
   1086 		xy->sc_dk.dk_bopenmask |= (1 << part);
   1087 		break;
   1088 	}
   1089 	xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask;
   1090 
   1091 	return 0;
   1092 }
   1093 
   1094 int
   1095 xyread(dev, uio, flags)
   1096 	dev_t   dev;
   1097 	struct uio *uio;
   1098 	int flags;
   1099 {
   1100 
   1101 	return (physio(xystrategy, NULL, dev, B_READ, minphys, uio));
   1102 }
   1103 
   1104 int
   1105 xywrite(dev, uio, flags)
   1106 	dev_t   dev;
   1107 	struct uio *uio;
   1108 	int flags;
   1109 {
   1110 
   1111 	return (physio(xystrategy, NULL, dev, B_WRITE, minphys, uio));
   1112 }
   1113 
   1114 
   1115 /*
   1116  * xysize: return size of a partition for a dump
   1117  */
   1118 
   1119 int
   1120 xysize(dev)
   1121 	dev_t   dev;
   1122 
   1123 {
   1124 	struct xy_softc *xysc;
   1125 	int     unit, part, size, omask;
   1126 
   1127 	/* valid unit? */
   1128 	unit = DISKUNIT(dev);
   1129 	if (unit >= xy_cd.cd_ndevs || (xysc = xy_cd.cd_devs[unit]) == NULL)
   1130 		return (-1);
   1131 
   1132 	part = DISKPART(dev);
   1133 	omask = xysc->sc_dk.dk_openmask & (1 << part);
   1134 
   1135 	if (omask == 0 && xyopen(dev, 0, S_IFBLK, NULL) != 0)
   1136 		return (-1);
   1137 
   1138 	/* do it */
   1139 	if (xysc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
   1140 		size = -1;	/* only give valid size for swap partitions */
   1141 	else
   1142 		size = xysc->sc_dk.dk_label->d_partitions[part].p_size *
   1143 		    (xysc->sc_dk.dk_label->d_secsize / DEV_BSIZE);
   1144 	if (omask == 0 && xyclose(dev, 0, S_IFBLK, NULL) != 0)
   1145 		return (-1);
   1146 	return (size);
   1147 }
   1148 
   1149 /*
   1150  * xystrategy: buffering system interface to xy.
   1151  */
   1152 
   1153 void
   1154 xystrategy(bp)
   1155 	struct buf *bp;
   1156 
   1157 {
   1158 	struct xy_softc *xy;
   1159 	int     s, unit;
   1160 	struct xyc_attach_args xa;
   1161 	struct disklabel *lp;
   1162 	daddr_t blkno;
   1163 
   1164 	unit = DISKUNIT(bp->b_dev);
   1165 
   1166 	/* check for live device */
   1167 
   1168 	if (unit >= xy_cd.cd_ndevs || (xy = xy_cd.cd_devs[unit]) == 0 ||
   1169 	    bp->b_blkno < 0 ||
   1170 	    (bp->b_bcount % xy->sc_dk.dk_label->d_secsize) != 0) {
   1171 		bp->b_error = EINVAL;
   1172 		goto bad;
   1173 	}
   1174 	/* do we need to attach the drive? */
   1175 
   1176 	if (xy->state == XY_DRIVE_UNKNOWN) {
   1177 		xa.driveno = xy->xy_drive;
   1178 		xa.fullmode = XY_SUB_WAIT;
   1179 		xa.booting = 0;
   1180 		xyattach((struct device *)xy->parent, (struct device *)xy, &xa);
   1181 		if (xy->state == XY_DRIVE_UNKNOWN) {
   1182 			bp->b_error = EIO;
   1183 			goto bad;
   1184 		}
   1185 	}
   1186 	if (xy->state != XY_DRIVE_ONLINE && DISKPART(bp->b_dev) != RAW_PART) {
   1187 		/* no I/O to unlabeled disks, unless raw partition */
   1188 		bp->b_error = EIO;
   1189 		goto bad;
   1190 	}
   1191 	/* short circuit zero length request */
   1192 
   1193 	if (bp->b_bcount == 0)
   1194 		goto done;
   1195 
   1196 	/* check bounds with label (disksubr.c).  Determine the size of the
   1197 	 * transfer, and make sure it is within the boundaries of the
   1198 	 * partition. Adjust transfer if needed, and signal errors or early
   1199 	 * completion. */
   1200 
   1201 	lp = xy->sc_dk.dk_label;
   1202 
   1203 	if (bounds_check_with_label(&xy->sc_dk, bp,
   1204 		(xy->flags & XY_WLABEL) != 0) <= 0)
   1205 		goto done;
   1206 
   1207 	/*
   1208 	 * Now convert the block number to absolute and put it in
   1209 	 * terms of the device's logical block size.
   1210 	 */
   1211 	blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
   1212 	if (DISKPART(bp->b_dev) != RAW_PART)
   1213 		blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
   1214 
   1215 	bp->b_rawblkno = blkno;
   1216 
   1217 	/*
   1218 	 * now we know we have a valid buf structure that we need to do I/O
   1219 	 * on.
   1220 	 */
   1221 	s = splbio();		/* protect the queues */
   1222 
   1223 	BUFQ_PUT(&xy->xyq, bp);
   1224 
   1225 	/* start 'em up */
   1226 
   1227 	xyc_start(xy->parent, NULL);
   1228 
   1229 	/* done! */
   1230 
   1231 	splx(s);
   1232 	return;
   1233 
   1234 bad:				/* tells upper layers we have an error */
   1235 	bp->b_flags |= B_ERROR;
   1236 done:				/* tells upper layers we are done with this
   1237 				 * buf */
   1238 	bp->b_resid = bp->b_bcount;
   1239 	biodone(bp);
   1240 }
   1241 /*
   1242  * end of {b,c}devsw functions
   1243  */
   1244 
   1245 /*
   1246  * i n t e r r u p t   f u n c t i o n
   1247  *
   1248  * xycintr: hardware interrupt.
   1249  */
   1250 int
   1251 xycintr(v)
   1252 	void   *v;
   1253 
   1254 {
   1255 	struct xyc_softc *xycsc = v;
   1256 
   1257 	/* kick the event counter */
   1258 
   1259 	xycsc->sc_intrcnt.ev_count++;
   1260 
   1261 	/* remove as many done IOPBs as possible */
   1262 
   1263 	xyc_remove_iorq(xycsc);
   1264 
   1265 	/* start any iorq's already waiting */
   1266 
   1267 	xyc_start(xycsc, NULL);
   1268 
   1269 	return (1);
   1270 }
   1271 /*
   1272  * end of interrupt function
   1273  */
   1274 
   1275 /*
   1276  * i n t e r n a l   f u n c t i o n s
   1277  */
   1278 
   1279 /*
   1280  * xyc_rqinit: fill out the fields of an I/O request
   1281  */
   1282 
   1283 inline void
   1284 xyc_rqinit(rq, xyc, xy, md, blk, cnt, db, bp)
   1285 	struct xy_iorq *rq;
   1286 	struct xyc_softc *xyc;
   1287 	struct xy_softc *xy;
   1288 	int     md;
   1289 	u_long  blk;
   1290 	int     cnt;
   1291 	caddr_t db;
   1292 	struct buf *bp;
   1293 {
   1294 	rq->xyc = xyc;
   1295 	rq->xy = xy;
   1296 	rq->ttl = XYC_MAXTTL + 10;
   1297 	rq->mode = md;
   1298 	rq->tries = rq->errno = rq->lasterror = 0;
   1299 	rq->blockno = blk;
   1300 	rq->sectcnt = cnt;
   1301 	rq->dbuf = db;
   1302 	rq->buf = bp;
   1303 }
   1304 
   1305 /*
   1306  * xyc_rqtopb: load up an IOPB based on an iorq
   1307  */
   1308 
   1309 void
   1310 xyc_rqtopb(iorq, iopb, cmd, subfun)
   1311 	struct xy_iorq *iorq;
   1312 	struct xy_iopb *iopb;
   1313 	int     cmd, subfun;
   1314 
   1315 {
   1316 	u_long  block, dp;
   1317 
   1318 	/* normal IOPB case, standard stuff */
   1319 
   1320 	/* chain bit handled later */
   1321 	iopb->ien = (XY_STATE(iorq->mode) == XY_SUB_POLL) ? 0 : 1;
   1322 	iopb->com = cmd;
   1323 	iopb->errno = 0;
   1324 	iopb->errs = 0;
   1325 	iopb->done = 0;
   1326 	if (iorq->xy) {
   1327 		iopb->unit = iorq->xy->xy_drive;
   1328 		iopb->dt = iorq->xy->drive_type;
   1329 	} else {
   1330 		iopb->unit = 0;
   1331 		iopb->dt = 0;
   1332 	}
   1333 	block = iorq->blockno;
   1334 	if (iorq->xy == NULL || block == 0) {
   1335 		iopb->sect = iopb->head = iopb->cyl = 0;
   1336 	} else {
   1337 		iopb->sect = block % iorq->xy->nsect;
   1338 		block = block / iorq->xy->nsect;
   1339 		iopb->head = block % iorq->xy->nhead;
   1340 		block = block / iorq->xy->nhead;
   1341 		iopb->cyl = block;
   1342 	}
   1343 	iopb->scnt = iorq->sectcnt;
   1344 	dp = (u_long) iorq->dbuf;
   1345 	if (iorq->dbuf == NULL) {
   1346 		iopb->dataa = 0;
   1347 		iopb->datar = 0;
   1348 	} else {
   1349 		iopb->dataa = (dp & 0xffff);
   1350 		iopb->datar = ((dp & 0xff0000) >> 16);
   1351 	}
   1352 	iopb->subfn = subfun;
   1353 }
   1354 
   1355 
   1356 /*
   1357  * xyc_unbusy: wait for the xyc to go unbusy, or timeout.
   1358  */
   1359 
   1360 int
   1361 xyc_unbusy(xyc, del)
   1362 
   1363 struct xyc *xyc;
   1364 int del;
   1365 
   1366 {
   1367 	while (del-- > 0) {
   1368 		if ((xyc->xyc_csr & XYC_GBSY) == 0)
   1369 			break;
   1370 		DELAY(1);
   1371 	}
   1372 	return(del == 0 ? XY_ERR_FAIL : XY_ERR_AOK);
   1373 }
   1374 
   1375 /*
   1376  * xyc_cmd: front end for POLL'd and WAIT'd commands.  Returns 0 or error.
   1377  * note that NORM requests are handled separately.
   1378  */
   1379 int
   1380 xyc_cmd(xycsc, cmd, subfn, unit, block, scnt, dptr, fullmode)
   1381 	struct xyc_softc *xycsc;
   1382 	int     cmd, subfn, unit, block, scnt;
   1383 	char   *dptr;
   1384 	int     fullmode;
   1385 
   1386 {
   1387 	int     submode = XY_STATE(fullmode);
   1388 	struct xy_iorq *iorq = xycsc->ciorq;
   1389 	struct xy_iopb *iopb = xycsc->ciopb;
   1390 
   1391 	/*
   1392 	 * is someone else using the control iopq wait for it if we can
   1393 	 */
   1394 start:
   1395 	if (submode == XY_SUB_WAIT && XY_STATE(iorq->mode) != XY_SUB_FREE) {
   1396 		if (tsleep(iorq, PRIBIO, "xyc_cmd", 0))
   1397                                 return(XY_ERR_FAIL);
   1398 		goto start;
   1399 	}
   1400 
   1401 	if (XY_STATE(iorq->mode) != XY_SUB_FREE) {
   1402 		DELAY(1000000);		/* XY_SUB_POLL: steal the iorq */
   1403 		iorq->mode = XY_SUB_FREE;
   1404 		printf("%s: stole control iopb\n", xycsc->sc_dev.dv_xname);
   1405 	}
   1406 
   1407 	/* init iorq/iopb */
   1408 
   1409 	xyc_rqinit(iorq, xycsc,
   1410 	    (unit == XYC_NOUNIT) ? NULL : xycsc->sc_drives[unit],
   1411 	    fullmode, block, scnt, dptr, NULL);
   1412 
   1413 	/* load IOPB from iorq */
   1414 
   1415 	xyc_rqtopb(iorq, iopb, cmd, subfn);
   1416 
   1417 	/* submit it for processing */
   1418 
   1419 	xyc_submit_iorq(xycsc, iorq, fullmode);	/* error code will be in iorq */
   1420 
   1421 	return(XY_ERR_AOK);
   1422 }
   1423 
   1424 /*
   1425  * xyc_startbuf
   1426  * start a buffer for running
   1427  */
   1428 
   1429 int
   1430 xyc_startbuf(xycsc, xysc, bp)
   1431 	struct xyc_softc *xycsc;
   1432 	struct xy_softc *xysc;
   1433 	struct buf *bp;
   1434 
   1435 {
   1436 	int     partno, error;
   1437 	struct xy_iorq *iorq;
   1438 	struct xy_iopb *iopb;
   1439 	u_long  block;
   1440 
   1441 	iorq = xysc->xyrq;
   1442 	iopb = iorq->iopb;
   1443 
   1444 	/* get buf */
   1445 
   1446 	if (bp == NULL)
   1447 		panic("xyc_startbuf null buf");
   1448 
   1449 	partno = DISKPART(bp->b_dev);
   1450 #ifdef XYC_DEBUG
   1451 	printf("xyc_startbuf: %s%c: %s block %d\n", xysc->sc_dev.dv_xname,
   1452 	    'a' + partno, (bp->b_flags & B_READ) ? "read" : "write", bp->b_blkno);
   1453 	printf("xyc_startbuf: b_bcount %d, b_data 0x%x\n",
   1454 	    bp->b_bcount, bp->b_data);
   1455 #endif
   1456 
   1457 	/*
   1458 	 * load request.
   1459 	 *
   1460 	 * note that iorq points to the buffer as mapped into DVMA space,
   1461 	 * where as the bp->b_data points to its non-DVMA mapping.
   1462 	 */
   1463 
   1464 	block = bp->b_rawblkno;
   1465 
   1466 	error = bus_dmamap_load(xycsc->dmatag, iorq->dmamap,
   1467 			bp->b_data, bp->b_bcount, 0, BUS_DMA_NOWAIT);
   1468 	if (error != 0) {
   1469 		printf("%s: warning: cannot load DMA map\n",
   1470 			xycsc->sc_dev.dv_xname);
   1471 		return (XY_ERR_FAIL);	/* XXX: need some sort of
   1472 					 * call-back scheme here? */
   1473 	}
   1474 
   1475 	bus_dmamap_sync(xycsc->dmatag, iorq->dmamap, 0,
   1476 			iorq->dmamap->dm_mapsize, (bp->b_flags & B_READ)
   1477 				? BUS_DMASYNC_PREREAD
   1478 				: BUS_DMASYNC_PREWRITE);
   1479 
   1480 	/* init iorq and load iopb from it */
   1481 	xyc_rqinit(iorq, xycsc, xysc, XY_SUB_NORM | XY_MODE_VERBO, block,
   1482 		   bp->b_bcount / XYFM_BPS,
   1483 		   (caddr_t)(u_long)iorq->dmamap->dm_segs[0].ds_addr,
   1484 		   bp);
   1485 
   1486 	xyc_rqtopb(iorq, iopb, (bp->b_flags & B_READ) ? XYCMD_RD : XYCMD_WR, 0);
   1487 
   1488 	/* Instrumentation. */
   1489 	disk_busy(&xysc->sc_dk);
   1490 
   1491 	return (XY_ERR_AOK);
   1492 }
   1493 
   1494 
   1495 /*
   1496  * xyc_submit_iorq: submit an iorq for processing.  returns XY_ERR_AOK
   1497  * if ok.  if it fail returns an error code.  type is XY_SUB_*.
   1498  *
   1499  * note: caller frees iorq in all cases except NORM
   1500  *
   1501  * return value:
   1502  *   NORM: XY_AOK (req pending), XY_FAIL (couldn't submit request)
   1503  *   WAIT: XY_AOK (success), <error-code> (failed)
   1504  *   POLL: <same as WAIT>
   1505  *   NOQ : <same as NORM>
   1506  *
   1507  * there are three sources for i/o requests:
   1508  * [1] xystrategy: normal block I/O, using "struct buf" system.
   1509  * [2] autoconfig/crash dump: these are polled I/O requests, no interrupts.
   1510  * [3] open/ioctl: these are I/O requests done in the context of a process,
   1511  *                 and the process should block until they are done.
   1512  *
   1513  * software state is stored in the iorq structure.  each iorq has an
   1514  * iopb structure.  the hardware understands the iopb structure.
   1515  * every command must go through an iopb.  a 450 handles one iopb at a
   1516  * time, where as a 451 can take them in chains.  [the 450 claims it
   1517  * can handle chains, but is appears to be buggy...]   iopb are allocated
   1518  * in DVMA space at boot up time.  each disk gets one iopb, and the
   1519  * controller gets one (for POLL and WAIT commands).  what happens if
   1520  * the iopb is busy?  for i/o type [1], the buffers are queued at the
   1521  * "buff" layer and * picked up later by the interrupt routine.  for case
   1522  * [2] we can only be blocked if there is a WAIT type I/O request being
   1523  * run.   since this can only happen when we are crashing, we wait a sec
   1524  * and then steal the IOPB.  for case [3] the process can sleep
   1525  * on the iorq free list until some iopbs are avaliable.
   1526  */
   1527 
   1528 
   1529 int
   1530 xyc_submit_iorq(xycsc, iorq, type)
   1531 	struct xyc_softc *xycsc;
   1532 	struct xy_iorq *iorq;
   1533 	int     type;
   1534 
   1535 {
   1536 	struct xy_iopb *dmaiopb;
   1537 
   1538 #ifdef XYC_DEBUG
   1539 	printf("xyc_submit_iorq(%s, addr=0x%x, type=%d)\n",
   1540 		xycsc->sc_dev.dv_xname, iorq, type);
   1541 #endif
   1542 
   1543 	/* first check and see if controller is busy */
   1544 	if ((xycsc->xyc->xyc_csr & XYC_GBSY) != 0) {
   1545 #ifdef XYC_DEBUG
   1546 		printf("xyc_submit_iorq: XYC not ready (BUSY)\n");
   1547 #endif
   1548 		if (type == XY_SUB_NOQ)
   1549 			return (XY_ERR_FAIL);	/* failed */
   1550 		switch (type) {
   1551 		case XY_SUB_NORM:
   1552 			return XY_ERR_AOK;	/* success */
   1553 		case XY_SUB_WAIT:
   1554 			while (iorq->iopb->done == 0) {
   1555 				(void) tsleep(iorq, PRIBIO, "xyciorq", 0);
   1556 			}
   1557 			return (iorq->errno);
   1558 		case XY_SUB_POLL:		/* steal controller */
   1559 			(void)xycsc->xyc->xyc_rsetup; /* RESET */
   1560 			if (xyc_unbusy(xycsc->xyc,XYC_RESETUSEC) == XY_ERR_FAIL)
   1561 				panic("xyc_submit_iorq: stuck xyc");
   1562 			printf("%s: stole controller\n",
   1563 				xycsc->sc_dev.dv_xname);
   1564 			break;
   1565 		default:
   1566 			panic("xyc_submit_iorq adding");
   1567 		}
   1568 	}
   1569 
   1570 	dmaiopb = xyc_chain(xycsc, iorq);	 /* build chain */
   1571 	if (dmaiopb == NULL) { /* nothing doing? */
   1572 		if (type == XY_SUB_NORM || type == XY_SUB_NOQ)
   1573 			return(XY_ERR_AOK);
   1574 		panic("xyc_submit_iorq: xyc_chain failed!");
   1575 	}
   1576 
   1577 	XYC_GO(xycsc->xyc, (u_long)dmaiopb);
   1578 
   1579 	/* command now running, wrap it up */
   1580 	switch (type) {
   1581 	case XY_SUB_NORM:
   1582 	case XY_SUB_NOQ:
   1583 		return (XY_ERR_AOK);	/* success */
   1584 	case XY_SUB_WAIT:
   1585 		while (iorq->iopb->done == 0) {
   1586 			(void) tsleep(iorq, PRIBIO, "xyciorq", 0);
   1587 		}
   1588 		return (iorq->errno);
   1589 	case XY_SUB_POLL:
   1590 		return (xyc_piodriver(xycsc, iorq));
   1591 	default:
   1592 		panic("xyc_submit_iorq wrap up");
   1593 	}
   1594 	panic("xyc_submit_iorq");
   1595 	return 0;	/* not reached */
   1596 }
   1597 
   1598 
   1599 /*
   1600  * xyc_chain: build a chain.  return dvma address of first element in
   1601  * the chain.   iorq != NULL: means we only want that item on the chain.
   1602  */
   1603 
   1604 struct xy_iopb *
   1605 xyc_chain(xycsc, iorq)
   1606 	struct xyc_softc *xycsc;
   1607 	struct xy_iorq *iorq;
   1608 
   1609 {
   1610 	int togo, chain, hand;
   1611 
   1612 	bzero(xycsc->xy_chain, sizeof(xycsc->xy_chain));
   1613 
   1614 	/*
   1615 	 * promote control IOPB to the top
   1616 	 */
   1617 	if (iorq == NULL) {
   1618 		if ((XY_STATE(xycsc->reqs[XYC_CTLIOPB].mode) == XY_SUB_POLL ||
   1619 		     XY_STATE(xycsc->reqs[XYC_CTLIOPB].mode) == XY_SUB_WAIT) &&
   1620 		     xycsc->iopbase[XYC_CTLIOPB].done == 0)
   1621 			iorq = &xycsc->reqs[XYC_CTLIOPB];
   1622 	}
   1623 
   1624 	/*
   1625 	 * special case: if iorq != NULL then we have a POLL or WAIT request.
   1626 	 * we let these take priority and do them first.
   1627 	 */
   1628 	if (iorq) {
   1629 		xycsc->xy_chain[0] = iorq;
   1630 		iorq->iopb->chen = 0;
   1631 		return(iorq->dmaiopb);
   1632 	}
   1633 
   1634 	/*
   1635 	 * NORM case: do round robin and maybe chain (if allowed and possible)
   1636 	 */
   1637 	chain = 0;
   1638 	hand = xycsc->xy_hand;
   1639 	xycsc->xy_hand = (xycsc->xy_hand + 1) % XYC_MAXIOPB;
   1640 
   1641 	for (togo = XYC_MAXIOPB; togo > 0;
   1642 	     togo--, hand = (hand + 1) % XYC_MAXIOPB) {
   1643 		struct xy_iopb *iopb, *prev_iopb, *dmaiopb;
   1644 
   1645 		if (XY_STATE(xycsc->reqs[hand].mode) != XY_SUB_NORM ||
   1646 		    xycsc->iopbase[hand].done)
   1647 			continue;   /* not ready-for-i/o */
   1648 
   1649 		xycsc->xy_chain[chain] = &xycsc->reqs[hand];
   1650 		iopb = xycsc->xy_chain[chain]->iopb;
   1651 		iopb->chen = 0;
   1652 		if (chain != 0) {
   1653 			/* adding a link to a chain */
   1654 			prev_iopb = xycsc->xy_chain[chain-1]->iopb;
   1655 			prev_iopb->chen = 1;
   1656 			dmaiopb = xycsc->xy_chain[chain]->dmaiopb;
   1657 			prev_iopb->nxtiopb = ((u_long)dmaiopb) & 0xffff;
   1658 		} else {
   1659 			/* head of chain */
   1660 			iorq = xycsc->xy_chain[chain];
   1661 		}
   1662 		chain++;
   1663 
   1664 		/* quit if chaining dis-allowed */
   1665 		if (xycsc->no_ols)
   1666 			break;
   1667 	}
   1668 
   1669 	return(iorq ? iorq->dmaiopb : NULL);
   1670 }
   1671 
   1672 /*
   1673  * xyc_piodriver
   1674  *
   1675  * programmed i/o driver.   this function takes over the computer
   1676  * and drains off the polled i/o request.   it returns the status of the iorq
   1677  * the caller is interesting in.
   1678  */
   1679 int
   1680 xyc_piodriver(xycsc, iorq)
   1681 	struct xyc_softc *xycsc;
   1682 	struct xy_iorq  *iorq;
   1683 
   1684 {
   1685 	int     nreset = 0;
   1686 	int     retval = 0;
   1687 	u_long  res;
   1688 #ifdef XYC_DEBUG
   1689 	printf("xyc_piodriver(%s, 0x%x)\n", xycsc->sc_dev.dv_xname, iorq);
   1690 #endif
   1691 
   1692 	while (iorq->iopb->done == 0) {
   1693 
   1694 		res = xyc_unbusy(xycsc->xyc, XYC_MAXTIME);
   1695 
   1696 		/* we expect some progress soon */
   1697 		if (res == XY_ERR_FAIL && nreset >= 2) {
   1698 			xyc_reset(xycsc, 0, XY_RSET_ALL, XY_ERR_FAIL, 0);
   1699 #ifdef XYC_DEBUG
   1700 			printf("xyc_piodriver: timeout\n");
   1701 #endif
   1702 			return (XY_ERR_FAIL);
   1703 		}
   1704 		if (res == XY_ERR_FAIL) {
   1705 			if (xyc_reset(xycsc, 0,
   1706 				      (nreset++ == 0) ? XY_RSET_NONE : iorq,
   1707 				      XY_ERR_FAIL,
   1708 				      0) == XY_ERR_FAIL)
   1709 				return (XY_ERR_FAIL);	/* flushes all but POLL
   1710 							 * requests, resets */
   1711 			continue;
   1712 		}
   1713 
   1714 		xyc_remove_iorq(xycsc);	 /* may resubmit request */
   1715 
   1716 		if (iorq->iopb->done == 0)
   1717 			xyc_start(xycsc, iorq);
   1718 	}
   1719 
   1720 	/* get return value */
   1721 
   1722 	retval = iorq->errno;
   1723 
   1724 #ifdef XYC_DEBUG
   1725 	printf("xyc_piodriver: done, retval = 0x%x (%s)\n",
   1726 	    iorq->errno, xyc_e2str(iorq->errno));
   1727 #endif
   1728 
   1729 	/* start up any bufs that have queued */
   1730 
   1731 	xyc_start(xycsc, NULL);
   1732 
   1733 	return (retval);
   1734 }
   1735 
   1736 /*
   1737  * xyc_xyreset: reset one drive.   NOTE: assumes xyc was just reset.
   1738  * we steal iopb[XYC_CTLIOPB] for this, but we put it back when we are done.
   1739  */
   1740 void
   1741 xyc_xyreset(xycsc, xysc)
   1742 	struct xyc_softc *xycsc;
   1743 	struct xy_softc *xysc;
   1744 
   1745 {
   1746 	struct xy_iopb tmpiopb;
   1747 	struct xy_iopb *iopb;
   1748 	int     del;
   1749 
   1750 	iopb = xycsc->ciopb;
   1751 
   1752 	/* Save contents */
   1753 	bcopy(iopb, &tmpiopb, sizeof(struct xy_iopb));
   1754 
   1755 	iopb->chen = iopb->done = iopb->errs = 0;
   1756 	iopb->ien = 0;
   1757 	iopb->com = XYCMD_RST;
   1758 	iopb->unit = xysc->xy_drive;
   1759 
   1760 	XYC_GO(xycsc->xyc, (u_long)xycsc->ciorq->dmaiopb);
   1761 
   1762 	del = XYC_RESETUSEC;
   1763 	while (del > 0) {
   1764 		if ((xycsc->xyc->xyc_csr & XYC_GBSY) == 0)
   1765 			break;
   1766 		DELAY(1);
   1767 		del--;
   1768 	}
   1769 
   1770 	if (del <= 0 || iopb->errs) {
   1771 		printf("%s: off-line: %s\n", xycsc->sc_dev.dv_xname,
   1772 		    xyc_e2str(iopb->errno));
   1773 		del = xycsc->xyc->xyc_rsetup;
   1774 		if (xyc_unbusy(xycsc->xyc, XYC_RESETUSEC) == XY_ERR_FAIL)
   1775 			panic("xyc_reset");
   1776 	} else {
   1777 		xycsc->xyc->xyc_csr = XYC_IPND;	/* clear IPND */
   1778 	}
   1779 
   1780 	/* Restore contents */
   1781 	bcopy(&tmpiopb, iopb, sizeof(struct xy_iopb));
   1782 }
   1783 
   1784 
   1785 /*
   1786  * xyc_reset: reset everything: requests are marked as errors except
   1787  * a polled request (which is resubmitted)
   1788  */
   1789 int
   1790 xyc_reset(xycsc, quiet, blastmode, error, xysc)
   1791 	struct xyc_softc *xycsc;
   1792 	int     quiet, error;
   1793 	struct xy_iorq *blastmode;
   1794 	struct xy_softc *xysc;
   1795 
   1796 {
   1797 	int     del = 0, lcv, retval = XY_ERR_AOK;
   1798 
   1799 	/* soft reset hardware */
   1800 
   1801 	if (!quiet)
   1802 		printf("%s: soft reset\n", xycsc->sc_dev.dv_xname);
   1803 	del = xycsc->xyc->xyc_rsetup;
   1804 	del = xyc_unbusy(xycsc->xyc, XYC_RESETUSEC);
   1805 	if (del == XY_ERR_FAIL) {
   1806 		blastmode = XY_RSET_ALL;	/* dead, flush all requests */
   1807 		retval = XY_ERR_FAIL;
   1808 	}
   1809 	if (xysc)
   1810 		xyc_xyreset(xycsc, xysc);
   1811 
   1812 	/* fix queues based on "blast-mode" */
   1813 
   1814 	for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) {
   1815 		register struct xy_iorq *iorq = &xycsc->reqs[lcv];
   1816 
   1817 		if (XY_STATE(iorq->mode) != XY_SUB_POLL &&
   1818 		    XY_STATE(iorq->mode) != XY_SUB_WAIT &&
   1819 		    XY_STATE(iorq->mode) != XY_SUB_NORM)
   1820 			/* is it active? */
   1821 			continue;
   1822 
   1823 		if (blastmode == XY_RSET_ALL ||
   1824 				blastmode != iorq) {
   1825 			/* failed */
   1826 			iorq->errno = error;
   1827 			xycsc->iopbase[lcv].done = xycsc->iopbase[lcv].errs = 1;
   1828 			switch (XY_STATE(iorq->mode)) {
   1829 			case XY_SUB_NORM:
   1830 			    iorq->buf->b_error = EIO;
   1831 			    iorq->buf->b_flags |= B_ERROR;
   1832 			    iorq->buf->b_resid = iorq->sectcnt * XYFM_BPS;
   1833 
   1834 			    bus_dmamap_sync(xycsc->dmatag, iorq->dmamap, 0,
   1835 					iorq->dmamap->dm_mapsize,
   1836 					(iorq->buf->b_flags & B_READ)
   1837 						? BUS_DMASYNC_POSTREAD
   1838 						: BUS_DMASYNC_POSTWRITE);
   1839 
   1840 			    bus_dmamap_unload(xycsc->dmatag, iorq->dmamap);
   1841 
   1842 			    (void)BUFQ_GET(&iorq->xy->xyq);
   1843 			    disk_unbusy(&xycsc->reqs[lcv].xy->sc_dk,
   1844 				(xycsc->reqs[lcv].buf->b_bcount -
   1845 				xycsc->reqs[lcv].buf->b_resid),
   1846 				(xycsc->reqs[lcv].buf->b_flags & B_READ));
   1847 			    biodone(iorq->buf);
   1848 			    iorq->mode = XY_SUB_FREE;
   1849 			    break;
   1850 			case XY_SUB_WAIT:
   1851 			    wakeup(iorq);
   1852 			case XY_SUB_POLL:
   1853 			    iorq->mode =
   1854 				XY_NEWSTATE(iorq->mode, XY_SUB_DONE);
   1855 			    break;
   1856 			}
   1857 
   1858 		} else {
   1859 
   1860 			/* resubmit, no need to do anything here */
   1861 		}
   1862 	}
   1863 
   1864 	/*
   1865 	 * now, if stuff is waiting, start it.
   1866 	 * since we just reset it should go
   1867 	 */
   1868 	xyc_start(xycsc, NULL);
   1869 
   1870 	return (retval);
   1871 }
   1872 
   1873 /*
   1874  * xyc_start: start waiting buffers
   1875  */
   1876 
   1877 void
   1878 xyc_start(xycsc, iorq)
   1879 	struct xyc_softc *xycsc;
   1880 	struct xy_iorq *iorq;
   1881 
   1882 {
   1883 	int lcv;
   1884 	struct xy_softc *xy;
   1885 
   1886 	if (iorq == NULL) {
   1887 		for (lcv = 0; lcv < XYC_MAXDEV ; lcv++) {
   1888 			if ((xy = xycsc->sc_drives[lcv]) == NULL) continue;
   1889 			if (BUFQ_PEEK(&xy->xyq) == NULL) continue;
   1890 			if (xy->xyrq->mode != XY_SUB_FREE) continue;
   1891 			xyc_startbuf(xycsc, xy, BUFQ_PEEK(&xy->xyq));
   1892 		}
   1893 	}
   1894 	xyc_submit_iorq(xycsc, iorq, XY_SUB_NOQ);
   1895 }
   1896 
   1897 /*
   1898  * xyc_remove_iorq: remove "done" IOPB's.
   1899  */
   1900 
   1901 int
   1902 xyc_remove_iorq(xycsc)
   1903 	struct xyc_softc *xycsc;
   1904 
   1905 {
   1906 	int     errno, rq, comm, errs;
   1907 	struct xyc *xyc = xycsc->xyc;
   1908 	u_long  addr;
   1909 	struct xy_iopb *iopb;
   1910 	struct xy_iorq *iorq;
   1911 	struct buf *bp;
   1912 
   1913 	if (xyc->xyc_csr & XYC_DERR) {
   1914 		/*
   1915 		 * DOUBLE ERROR: should never happen under normal use. This
   1916 		 * error is so bad, you can't even tell which IOPB is bad, so
   1917 		 * we dump them all.
   1918 		 */
   1919 		errno = XY_ERR_DERR;
   1920 		printf("%s: DOUBLE ERROR!\n", xycsc->sc_dev.dv_xname);
   1921 		if (xyc_reset(xycsc, 0, XY_RSET_ALL, errno, 0) != XY_ERR_AOK) {
   1922 			printf("%s: soft reset failed!\n",
   1923 				xycsc->sc_dev.dv_xname);
   1924 			panic("xyc_remove_iorq: controller DEAD");
   1925 		}
   1926 		return (XY_ERR_AOK);
   1927 	}
   1928 
   1929 	/*
   1930 	 * get iopb that is done, loop down the chain
   1931 	 */
   1932 
   1933 	if (xyc->xyc_csr & XYC_ERR) {
   1934 		xyc->xyc_csr = XYC_ERR; /* clear error condition */
   1935 	}
   1936 	if (xyc->xyc_csr & XYC_IPND) {
   1937 		xyc->xyc_csr = XYC_IPND; /* clear interrupt */
   1938 	}
   1939 
   1940 	for (rq = 0; rq < XYC_MAXIOPB; rq++) {
   1941 		iorq = xycsc->xy_chain[rq];
   1942 		if (iorq == NULL) break; /* done ! */
   1943 		if (iorq->mode == 0 || XY_STATE(iorq->mode) == XY_SUB_DONE)
   1944 			continue;	/* free, or done */
   1945 		iopb = iorq->iopb;
   1946 		if (iopb->done == 0)
   1947 			continue;	/* not done yet */
   1948 
   1949 		comm = iopb->com;
   1950 		errs = iopb->errs;
   1951 
   1952 		if (errs)
   1953 			iorq->errno = iopb->errno;
   1954 		else
   1955 			iorq->errno = 0;
   1956 
   1957 		/* handle non-fatal errors */
   1958 
   1959 		if (errs &&
   1960 		    xyc_error(xycsc, iorq, iopb, comm) == XY_ERR_AOK)
   1961 			continue;	/* AOK: we resubmitted it */
   1962 
   1963 
   1964 		/* this iorq is now done (hasn't been restarted or anything) */
   1965 
   1966 		if ((iorq->mode & XY_MODE_VERBO) && iorq->lasterror)
   1967 			xyc_perror(iorq, iopb, 0);
   1968 
   1969 		/* now, if read/write check to make sure we got all the data
   1970 		 * we needed. (this may not be the case if we got an error in
   1971 		 * the middle of a multisector request).   */
   1972 
   1973 		if ((iorq->mode & XY_MODE_B144) != 0 && errs == 0 &&
   1974 		    (comm == XYCMD_RD || comm == XYCMD_WR)) {
   1975 			/* we just successfully processed a bad144 sector
   1976 			 * note: if we are in bad 144 mode, the pointers have
   1977 			 * been advanced already (see above) and are pointing
   1978 			 * at the bad144 sector.   to exit bad144 mode, we
   1979 			 * must advance the pointers 1 sector and issue a new
   1980 			 * request if there are still sectors left to process
   1981 			 *
   1982 			 */
   1983 			XYC_ADVANCE(iorq, 1);	/* advance 1 sector */
   1984 
   1985 			/* exit b144 mode */
   1986 			iorq->mode = iorq->mode & (~XY_MODE_B144);
   1987 
   1988 			if (iorq->sectcnt) {	/* more to go! */
   1989 				iorq->lasterror = iorq->errno = iopb->errno = 0;
   1990 				iopb->errs = iopb->done = 0;
   1991 				iorq->tries = 0;
   1992 				iopb->scnt = iorq->sectcnt;
   1993 				iopb->cyl = iorq->blockno /
   1994 						iorq->xy->sectpercyl;
   1995 				iopb->head =
   1996 					(iorq->blockno / iorq->xy->nhead) %
   1997 						iorq->xy->nhead;
   1998 				iopb->sect = iorq->blockno % XYFM_BPS;
   1999 				addr = (u_long) iorq->dbuf;
   2000 				iopb->dataa = (addr & 0xffff);
   2001 				iopb->datar = ((addr & 0xff0000) >> 16);
   2002 				/* will resubit at end */
   2003 				continue;
   2004 			}
   2005 		}
   2006 		/* final cleanup, totally done with this request */
   2007 
   2008 		switch (XY_STATE(iorq->mode)) {
   2009 		case XY_SUB_NORM:
   2010 			bp = iorq->buf;
   2011 			if (errs) {
   2012 				bp->b_error = EIO;
   2013 				bp->b_flags |= B_ERROR;
   2014 				bp->b_resid = iorq->sectcnt * XYFM_BPS;
   2015 			} else {
   2016 				bp->b_resid = 0;	/* done */
   2017 			}
   2018 			bus_dmamap_sync(xycsc->dmatag, iorq->dmamap, 0,
   2019 					iorq->dmamap->dm_mapsize,
   2020 					(iorq->buf->b_flags & B_READ)
   2021 						? BUS_DMASYNC_POSTREAD
   2022 						: BUS_DMASYNC_POSTWRITE);
   2023 
   2024 			bus_dmamap_unload(xycsc->dmatag, iorq->dmamap);
   2025 
   2026 			(void)BUFQ_GET(&iorq->xy->xyq);
   2027 			disk_unbusy(&iorq->xy->sc_dk,
   2028 			    (bp->b_bcount - bp->b_resid),
   2029 			    (bp->b_flags & B_READ));
   2030 			iorq->mode = XY_SUB_FREE;
   2031 			biodone(bp);
   2032 			break;
   2033 		case XY_SUB_WAIT:
   2034 			iorq->mode = XY_NEWSTATE(iorq->mode, XY_SUB_DONE);
   2035 			wakeup(iorq);
   2036 			break;
   2037 		case XY_SUB_POLL:
   2038 			iorq->mode = XY_NEWSTATE(iorq->mode, XY_SUB_DONE);
   2039 			break;
   2040 		}
   2041 	}
   2042 
   2043 	return (XY_ERR_AOK);
   2044 }
   2045 
   2046 /*
   2047  * xyc_perror: print error.
   2048  * - if still_trying is true: we got an error, retried and got a
   2049  *   different error.  in that case lasterror is the old error,
   2050  *   and errno is the new one.
   2051  * - if still_trying is not true, then if we ever had an error it
   2052  *   is in lasterror. also, if iorq->errno == 0, then we recovered
   2053  *   from that error (otherwise iorq->errno == iorq->lasterror).
   2054  */
   2055 void
   2056 xyc_perror(iorq, iopb, still_trying)
   2057 	struct xy_iorq *iorq;
   2058 	struct xy_iopb *iopb;
   2059 	int     still_trying;
   2060 
   2061 {
   2062 
   2063 	int     error = iorq->lasterror;
   2064 
   2065 	printf("%s", (iorq->xy) ? iorq->xy->sc_dev.dv_xname
   2066 	    : iorq->xyc->sc_dev.dv_xname);
   2067 	if (iorq->buf)
   2068 		printf("%c: ", 'a' + DISKPART(iorq->buf->b_dev));
   2069 	if (iopb->com == XYCMD_RD || iopb->com == XYCMD_WR)
   2070 		printf("%s %d/%d/%d: ",
   2071 			(iopb->com == XYCMD_RD) ? "read" : "write",
   2072 			iopb->cyl, iopb->head, iopb->sect);
   2073 	printf("%s", xyc_e2str(error));
   2074 
   2075 	if (still_trying)
   2076 		printf(" [still trying, new error=%s]", xyc_e2str(iorq->errno));
   2077 	else
   2078 		if (iorq->errno == 0)
   2079 			printf(" [recovered in %d tries]", iorq->tries);
   2080 
   2081 	printf("\n");
   2082 }
   2083 
   2084 /*
   2085  * xyc_error: non-fatal error encountered... recover.
   2086  * return AOK if resubmitted, return FAIL if this iopb is done
   2087  */
   2088 int
   2089 xyc_error(xycsc, iorq, iopb, comm)
   2090 	struct xyc_softc *xycsc;
   2091 	struct xy_iorq *iorq;
   2092 	struct xy_iopb *iopb;
   2093 	int     comm;
   2094 
   2095 {
   2096 	int     errno = iorq->errno;
   2097 	int     erract = xyc_entoact(errno);
   2098 	int     oldmode, advance;
   2099 #ifdef __sparc__
   2100 	int i;
   2101 #endif
   2102 
   2103 	if (erract == XY_ERA_RSET) {	/* some errors require a reset */
   2104 		oldmode = iorq->mode;
   2105 		iorq->mode = XY_SUB_DONE | (~XY_SUB_MASK & oldmode);
   2106 		/* make xyc_start ignore us */
   2107 		xyc_reset(xycsc, 1, XY_RSET_NONE, errno, iorq->xy);
   2108 		iorq->mode = oldmode;
   2109 	}
   2110 	/* check for read/write to a sector in bad144 table if bad: redirect
   2111 	 * request to bad144 area */
   2112 
   2113 	if ((comm == XYCMD_RD || comm == XYCMD_WR) &&
   2114 	    (iorq->mode & XY_MODE_B144) == 0) {
   2115 		advance = iorq->sectcnt - iopb->scnt;
   2116 		XYC_ADVANCE(iorq, advance);
   2117 #ifdef __sparc__
   2118 		if ((i = isbad(&iorq->xy->dkb, iorq->blockno / iorq->xy->sectpercyl,
   2119 			    (iorq->blockno / iorq->xy->nsect) % iorq->xy->nhead,
   2120 			    iorq->blockno % iorq->xy->nsect)) != -1) {
   2121 			iorq->mode |= XY_MODE_B144;	/* enter bad144 mode &
   2122 							 * redirect */
   2123 			iopb->errno = iopb->done = iopb->errs = 0;
   2124 			iopb->scnt = 1;
   2125 			iopb->cyl = (iorq->xy->ncyl + iorq->xy->acyl) - 2;
   2126 			/* second to last acyl */
   2127 			i = iorq->xy->sectpercyl - 1 - i;	/* follow bad144
   2128 								 * standard */
   2129 			iopb->head = i / iorq->xy->nhead;
   2130 			iopb->sect = i % iorq->xy->nhead;
   2131 			/* will resubmit when we come out of remove_iorq */
   2132 			return (XY_ERR_AOK);	/* recovered! */
   2133 		}
   2134 #endif
   2135 	}
   2136 
   2137 	/*
   2138 	 * it isn't a bad144 sector, must be real error! see if we can retry
   2139 	 * it?
   2140 	 */
   2141 	if ((iorq->mode & XY_MODE_VERBO) && iorq->lasterror)
   2142 		xyc_perror(iorq, iopb, 1);	/* inform of error state
   2143 						 * change */
   2144 	iorq->lasterror = errno;
   2145 
   2146 	if ((erract == XY_ERA_RSET || erract == XY_ERA_HARD)
   2147 	    && iorq->tries < XYC_MAXTRIES) {	/* retry? */
   2148 		iorq->tries++;
   2149 		iorq->errno = iopb->errno = iopb->done = iopb->errs = 0;
   2150 		/* will resubmit at end of remove_iorq */
   2151 		return (XY_ERR_AOK);	/* recovered! */
   2152 	}
   2153 
   2154 	/* failed to recover from this error */
   2155 	return (XY_ERR_FAIL);
   2156 }
   2157 
   2158 /*
   2159  * xyc_tick: make sure xy is still alive and ticking (err, kicking).
   2160  */
   2161 void
   2162 xyc_tick(arg)
   2163 	void   *arg;
   2164 
   2165 {
   2166 	struct xyc_softc *xycsc = arg;
   2167 	int     lcv, s, reset = 0;
   2168 
   2169 	/* reduce ttl for each request if one goes to zero, reset xyc */
   2170 	s = splbio();
   2171 	for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) {
   2172 		if (xycsc->reqs[lcv].mode == 0 ||
   2173 		    XY_STATE(xycsc->reqs[lcv].mode) == XY_SUB_DONE)
   2174 			continue;
   2175 		xycsc->reqs[lcv].ttl--;
   2176 		if (xycsc->reqs[lcv].ttl == 0)
   2177 			reset = 1;
   2178 	}
   2179 	if (reset) {
   2180 		printf("%s: watchdog timeout\n", xycsc->sc_dev.dv_xname);
   2181 		xyc_reset(xycsc, 0, XY_RSET_NONE, XY_ERR_FAIL, NULL);
   2182 	}
   2183 	splx(s);
   2184 
   2185 	/* until next time */
   2186 
   2187 	callout_reset(&xycsc->sc_tick_ch, XYC_TICKCNT, xyc_tick, xycsc);
   2188 }
   2189 
   2190 /*
   2191  * xyc_ioctlcmd: this function provides a user level interface to the
   2192  * controller via ioctl.   this allows "format" programs to be written
   2193  * in user code, and is also useful for some debugging.   we return
   2194  * an error code.   called at user priority.
   2195  *
   2196  * XXX missing a few commands (see the 7053 driver for ideas)
   2197  */
   2198 int
   2199 xyc_ioctlcmd(xy, dev, xio)
   2200 	struct xy_softc *xy;
   2201 	dev_t   dev;
   2202 	struct xd_iocmd *xio;
   2203 
   2204 {
   2205 	int     s, rqno, dummy = 0;
   2206 	caddr_t dvmabuf = NULL, buf = NULL;
   2207 	struct xyc_softc *xycsc;
   2208 	int			rseg, error;
   2209 	bus_dma_segment_t	seg;
   2210 
   2211 	/* check sanity of requested command */
   2212 
   2213 	switch (xio->cmd) {
   2214 
   2215 	case XYCMD_NOP:	/* no op: everything should be zero */
   2216 		if (xio->subfn || xio->dptr || xio->dlen ||
   2217 		    xio->block || xio->sectcnt)
   2218 			return (EINVAL);
   2219 		break;
   2220 
   2221 	case XYCMD_RD:		/* read / write sectors (up to XD_IOCMD_MAXS) */
   2222 	case XYCMD_WR:
   2223 		if (xio->subfn || xio->sectcnt > XD_IOCMD_MAXS ||
   2224 		    xio->sectcnt * XYFM_BPS != xio->dlen || xio->dptr == NULL)
   2225 			return (EINVAL);
   2226 		break;
   2227 
   2228 	case XYCMD_SK:		/* seek: doesn't seem useful to export this */
   2229 		return (EINVAL);
   2230 
   2231 		break;
   2232 
   2233 	default:
   2234 		return (EINVAL);/* ??? */
   2235 	}
   2236 
   2237 	xycsc = xy->parent;
   2238 
   2239 	/* create DVMA buffer for request if needed */
   2240 	if (xio->dlen) {
   2241 		if ((error = xy_dmamem_alloc(xycsc->dmatag, xycsc->auxmap,
   2242 					     &seg, &rseg,
   2243 					     xio->dlen, &buf,
   2244 					     (bus_addr_t *)&dvmabuf)) != 0) {
   2245 			return (error);
   2246 		}
   2247 
   2248 		if (xio->cmd == XYCMD_WR) {
   2249 			if ((error = copyin(xio->dptr, buf, xio->dlen)) != 0) {
   2250 				bus_dmamem_unmap(xycsc->dmatag, buf, xio->dlen);
   2251 				bus_dmamem_free(xycsc->dmatag, &seg, rseg);
   2252 				return (error);
   2253 			}
   2254 		}
   2255 	}
   2256 	/* do it! */
   2257 
   2258 	error = 0;
   2259 	s = splbio();
   2260 	rqno = xyc_cmd(xycsc, xio->cmd, xio->subfn, xy->xy_drive, xio->block,
   2261 	    xio->sectcnt, dvmabuf, XY_SUB_WAIT);
   2262 	if (rqno == XY_ERR_FAIL) {
   2263 		error = EIO;
   2264 		goto done;
   2265 	}
   2266 	xio->errno = xycsc->ciorq->errno;
   2267 	xio->tries = xycsc->ciorq->tries;
   2268 	XYC_DONE(xycsc, dummy);
   2269 
   2270 	if (xio->cmd == XYCMD_RD)
   2271 		error = copyout(buf, xio->dptr, xio->dlen);
   2272 
   2273 done:
   2274 	splx(s);
   2275 	if (dvmabuf) {
   2276 		xy_dmamem_free(xycsc->dmatag, xycsc->auxmap, &seg, rseg,
   2277 				xio->dlen, buf);
   2278 	}
   2279 	return (error);
   2280 }
   2281 
   2282 /*
   2283  * xyc_e2str: convert error code number into an error string
   2284  */
   2285 char *
   2286 xyc_e2str(no)
   2287 	int     no;
   2288 {
   2289 	switch (no) {
   2290 	case XY_ERR_FAIL:
   2291 		return ("Software fatal error");
   2292 	case XY_ERR_DERR:
   2293 		return ("DOUBLE ERROR");
   2294 	case XY_ERR_AOK:
   2295 		return ("Successful completion");
   2296 	case XY_ERR_IPEN:
   2297 		return("Interrupt pending");
   2298 	case XY_ERR_BCFL:
   2299 		return("Busy conflict");
   2300 	case XY_ERR_TIMO:
   2301 		return("Operation timeout");
   2302 	case XY_ERR_NHDR:
   2303 		return("Header not found");
   2304 	case XY_ERR_HARD:
   2305 		return("Hard ECC error");
   2306 	case XY_ERR_ICYL:
   2307 		return("Illegal cylinder address");
   2308 	case XY_ERR_ISEC:
   2309 		return("Illegal sector address");
   2310 	case XY_ERR_SMAL:
   2311 		return("Last sector too small");
   2312 	case XY_ERR_SACK:
   2313 		return("Slave ACK error (non-existent memory)");
   2314 	case XY_ERR_CHER:
   2315 		return("Cylinder and head/header error");
   2316 	case XY_ERR_SRTR:
   2317 		return("Auto-seek retry successful");
   2318 	case XY_ERR_WPRO:
   2319 		return("Write-protect error");
   2320 	case XY_ERR_UIMP:
   2321 		return("Unimplemented command");
   2322 	case XY_ERR_DNRY:
   2323 		return("Drive not ready");
   2324 	case XY_ERR_SZER:
   2325 		return("Sector count zero");
   2326 	case XY_ERR_DFLT:
   2327 		return("Drive faulted");
   2328 	case XY_ERR_ISSZ:
   2329 		return("Illegal sector size");
   2330 	case XY_ERR_SLTA:
   2331 		return("Self test A");
   2332 	case XY_ERR_SLTB:
   2333 		return("Self test B");
   2334 	case XY_ERR_SLTC:
   2335 		return("Self test C");
   2336 	case XY_ERR_SOFT:
   2337 		return("Soft ECC error");
   2338 	case XY_ERR_SFOK:
   2339 		return("Soft ECC error recovered");
   2340 	case XY_ERR_IHED:
   2341 		return("Illegal head");
   2342 	case XY_ERR_DSEQ:
   2343 		return("Disk sequencer error");
   2344 	case XY_ERR_SEEK:
   2345 		return("Seek error");
   2346 	default:
   2347 		return ("Unknown error");
   2348 	}
   2349 }
   2350 
   2351 int
   2352 xyc_entoact(errno)
   2353 
   2354 int errno;
   2355 
   2356 {
   2357   switch (errno) {
   2358     case XY_ERR_FAIL:	case XY_ERR_DERR:	case XY_ERR_IPEN:
   2359     case XY_ERR_BCFL:	case XY_ERR_ICYL:	case XY_ERR_ISEC:
   2360     case XY_ERR_UIMP:	case XY_ERR_SZER:	case XY_ERR_ISSZ:
   2361     case XY_ERR_SLTA:	case XY_ERR_SLTB:	case XY_ERR_SLTC:
   2362     case XY_ERR_IHED:	case XY_ERR_SACK:	case XY_ERR_SMAL:
   2363 
   2364 	return(XY_ERA_PROG); /* program error ! */
   2365 
   2366     case XY_ERR_TIMO:	case XY_ERR_NHDR:	case XY_ERR_HARD:
   2367     case XY_ERR_DNRY:	case XY_ERR_CHER:	case XY_ERR_SEEK:
   2368     case XY_ERR_SOFT:
   2369 
   2370 	return(XY_ERA_HARD); /* hard error, retry */
   2371 
   2372     case XY_ERR_DFLT:	case XY_ERR_DSEQ:
   2373 
   2374 	return(XY_ERA_RSET); /* hard error reset */
   2375 
   2376     case XY_ERR_SRTR:	case XY_ERR_SFOK:	case XY_ERR_AOK:
   2377 
   2378 	return(XY_ERA_SOFT); /* an FYI error */
   2379 
   2380     case XY_ERR_WPRO:
   2381 
   2382 	return(XY_ERA_WPRO); /* write protect */
   2383   }
   2384 
   2385   return(XY_ERA_PROG); /* ??? */
   2386 }
   2387