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