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