diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-11-01 17:24:27 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-11-01 17:24:27 +0000 |
commit | e212fbadbc34f7ed1ab354d9bd79e59a2b4b7b35 (patch) | |
tree | 86ef0eb901ab533c8f61eabe273e0f3affb335fd | |
parent | e317feac43ad76b3760199a0a9f69bb632a26ee7 (diff) |
xy and xd drivers from chuck
-rw-r--r-- | sys/arch/sun3/dev/xd.c | 2370 | ||||
-rw-r--r-- | sys/arch/sun3/dev/xdreg.h | 424 | ||||
-rw-r--r-- | sys/arch/sun3/dev/xdvar.h | 167 | ||||
-rw-r--r-- | sys/arch/sun3/dev/xio.h | 65 | ||||
-rw-r--r-- | sys/arch/sun3/dev/xy.c | 2130 | ||||
-rw-r--r-- | sys/arch/sun3/dev/xyreg.h | 227 | ||||
-rw-r--r-- | sys/arch/sun3/dev/xyvar.h | 168 |
7 files changed, 5551 insertions, 0 deletions
diff --git a/sys/arch/sun3/dev/xd.c b/sys/arch/sun3/dev/xd.c new file mode 100644 index 00000000000..314cea1bb02 --- /dev/null +++ b/sys/arch/sun3/dev/xd.c @@ -0,0 +1,2370 @@ +/* $NetBSD: xd.c,v 1.1 1995/10/30 20:58:17 gwr Exp $ */ + +/* + * + * Copyright (c) 1995 Charles D. Cranor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles D. Cranor. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * + * x d . c x y l o g i c s 7 5 3 / 7 0 5 3 v m e / s m d d r i v e r + * + * author: Chuck Cranor <chuck@ccrc.wustl.edu> + * id: $Id: xd.c,v 1.1 1995/11/01 17:24:22 deraadt Exp $ + * started: 27-Feb-95 + * references: [1] Xylogics Model 753 User's Manual + * part number: 166-753-001, Revision B, May 21, 1988. + * "Your Partner For Performance" + * [2] other NetBSD disk device drivers + * + * Special thanks go to Scott E. Campbell of Xylogics, Inc. for taking + * the time to answer some of my questions about the 753/7053. + * + * note: the 753 and the 7053 are programmed the same way, but are + * different sizes. the 753 is a 6U VME card, while the 7053 is a 9U + * VME card (found in many VME based suns). + */ + +#undef XDC_DEBUG /* full debug */ +#define XDC_DIAG /* extra sanity checks */ +#if defined(DIAGNOSTIC) && !defined(XDC_DIAG) +#define XDC_DIAG /* link in with master DIAG option */ +#endif + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/conf.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <sys/buf.h> +#include <sys/uio.h> +#include <sys/malloc.h> +#include <sys/device.h> +#include <sys/disklabel.h> +#include <sys/disk.h> +#include <sys/syslog.h> +#include <sys/dkbad.h> +#include <vm/vm.h> +#include <vm/vm_kern.h> + +#include <machine/autoconf.h> +#include <machine/sun_disklabel.h> +#include <machine/dvma.h> + +#include <sun3/dev/xdreg.h> +#include <sun3/dev/xdvar.h> +#include <sun3/dev/xio.h> + +/* + * macros + */ + +/* + * XDC_TWAIT: add iorq "N" to tail of SC's wait queue + */ +#define XDC_TWAIT(SC, N) { \ + (SC)->waitq[(SC)->waitend] = (N); \ + (SC)->waitend = ((SC)->waitend + 1) % XDC_MAXIOPB; \ + (SC)->nwait++; \ +} + +/* + * XDC_HWAIT: add iorq "N" to head of SC's wait queue + */ +#define XDC_HWAIT(SC, N) { \ + (SC)->waithead = ((SC)->waithead - 1) % XDC_MAXIOPB; \ + (SC)->waitq[(SC)->waithead] = (N); \ + (SC)->nwait++; \ +} + +/* + * XDC_GET_WAITER: gets the first request waiting on the waitq + * and removes it (so it can be submitted) + */ +#define XDC_GET_WAITER(XDCSC, RQ) { \ + (RQ) = (XDCSC)->waitq[(XDCSC)->waithead]; \ + (XDCSC)->waithead = ((XDCSC)->waithead + 1) % XDC_MAXIOPB; \ + xdcsc->nwait--; \ +} + +/* + * XDC_FREE: add iorq "N" to SC's free list + */ +#define XDC_FREE(SC, N) { \ + (SC)->freereq[(SC)->nfree++] = (N); \ + (SC)->reqs[N].mode = 0; \ + if ((SC)->nfree == 1) wakeup(&(SC)->nfree); \ +} + + +/* + * XDC_RQALLOC: allocate an iorq off the free list (assume nfree > 0). + */ +#define XDC_RQALLOC(XDCSC) (XDCSC)->freereq[--((XDCSC)->nfree)] + +/* + * XDC_GO: start iopb ADDR (DVMA addr in a u_long) on XDC + */ +#define XDC_GO(XDC, ADDR) { \ + (XDC)->xdc_iopbaddr0 = ((ADDR) & 0xff); \ + (ADDR) = ((ADDR) >> 8); \ + (XDC)->xdc_iopbaddr1 = ((ADDR) & 0xff); \ + (ADDR) = ((ADDR) >> 8); \ + (XDC)->xdc_iopbaddr2 = ((ADDR) & 0xff); \ + (ADDR) = ((ADDR) >> 8); \ + (XDC)->xdc_iopbaddr3 = (ADDR); \ + (XDC)->xdc_iopbamod = XDC_ADDRMOD; \ + (XDC)->xdc_csr |= XDC_ADDIOPB; /* go! */ \ +} + +/* + * XDC_WAIT: wait for XDC's csr "BITS" to come on in "TIME". + * LCV is a counter. If it goes to zero then we timed out. + */ +#define XDC_WAIT(XDC, LCV, TIME, BITS) { \ + (LCV) = (TIME); \ + while ((LCV) > 0) { \ + if ((XDC)->xdc_csr & (BITS)) break; \ + (LCV) = (LCV) - 1; \ + DELAY(1); \ + } \ +} + +/* + * XDC_DONE: don't need IORQ, get error code and free (done after xdc_cmd) + */ +#define XDC_DONE(SC,RQ,ER) { \ + if ((RQ) == XD_ERR_FAIL) { \ + (ER) = (RQ); \ + } else { \ + if ((SC)->ndone-- == XDC_SUBWAITLIM) \ + wakeup(&(SC)->ndone); \ + (ER) = (SC)->reqs[RQ].errno; \ + XDC_FREE((SC), (RQ)); \ + } \ +} + +/* + * XDC_ADVANCE: advance iorq's pointers by a number of sectors + */ +#define XDC_ADVANCE(IORQ, N) { \ + if (N) { \ + (IORQ)->sectcnt -= (N); \ + (IORQ)->blockno += (N); \ + (IORQ)->dbuf += ((N)*XDFM_BPS); \ + } \ +} + +/* + * note - addresses you can sleep on: + * [1] & of xd_softc's "state" (waiting for a chance to attach a drive) + * [2] & of xdc_softc's "nfree" (waiting for a free iorq/iopb) + * [3] & of xdc_softc's "ndone" (waiting for number of done iorq/iopb's + * to drop below XDC_SUBWAITLIM) + * [4] & an iorq (waiting for an XD_SUB_WAIT iorq to finish) + */ + + +/* + * function prototypes + * "xdc_*" functions are internal, all others are external interfaces + */ + +/* internals */ +int xdc_cmd __P((struct xdc_softc *, int, int, int, int, int, char *, int)); +char *xdc_e2str __P((int)); +int xdc_error __P((struct xdc_softc *, struct xd_iorq *, + struct xd_iopb *, int, int)); +int xdc_ioctlcmd __P((struct xd_softc *, dev_t dev, struct xd_iocmd *)); +void xdc_perror __P((struct xd_iorq *, struct xd_iopb *, int)); +int xdc_piodriver __P((struct xdc_softc *, int, int)); +int xdc_remove_iorq __P((struct xdc_softc *)); +int xdc_reset __P((struct xdc_softc *, int, int, int, struct xd_softc *)); +inline void xdc_rqinit __P((struct xd_iorq *, struct xdc_softc *, + struct xd_softc *, int, u_long, int, + caddr_t, struct buf *)); +void xdc_rqtopb __P((struct xd_iorq *, struct xd_iopb *, int, int)); +int xdc_start __P((struct xdc_softc *, int)); +int xdc_startbuf __P((struct xdc_softc *, struct xd_softc *, struct buf *)); +int xdc_submit_iorq __P((struct xdc_softc *, int, int)); +void xdc_tick __P((void *)); +int xdc_xdreset __P((struct xdc_softc *, struct xd_softc *)); + +/* machine interrupt hook */ +int xdcintr __P((void *)); + +/* {b,c}devsw */ +int xdclose __P((dev_t, int, int)); +int xddump __P((dev_t)); +int xdioctl __P((dev_t, u_long, caddr_t, int, struct proc *)); +int xdopen __P((dev_t, int, int)); +int xdread __P((dev_t, struct uio *)); +int xdwrite __P((dev_t, struct uio *)); +int xdsize __P((dev_t)); +void xdstrategy __P((struct buf *)); + +/* autoconf */ +int xdcmatch __P((struct device *, void *, void *)); +void xdcattach __P((struct device *, struct device *, void *)); +int xdmatch __P((struct device *, void *, void *)); +void xdattach __P((struct device *, struct device *, void *)); + +static void xddummystrat __P((struct buf *)); +int xdgetdisklabel __P((struct xd_softc *, void *)); + +/* + * cfdrivers: device driver interface to autoconfig + */ + +struct cfdriver xdccd = { + NULL, "xdc", xdcmatch, xdcattach, DV_DULL, sizeof(struct xdc_softc) +}; + +struct cfdriver xdcd = { + NULL, "xd", xdmatch, xdattach, DV_DISK, sizeof(struct xd_softc) +}; + +struct xdc_attach_args { /* this is the "aux" args to xdattach */ + int driveno; /* unit number */ + char *dvmabuf; /* scratch buffer for reading disk label */ + int fullmode; /* submit mode */ + int booting; /* are we booting or not? */ +}; + +/* + * dkdriver + */ + +struct dkdriver xddkdriver = {xdstrategy}; + +/* + * start: disk label fix code (XXX) + */ + +static void *xd_labeldata; + +static void +xddummystrat(bp) + struct buf *bp; +{ + if (bp->b_bcount != XDFM_BPS) + panic("xddummystrat"); + bcopy(xd_labeldata, bp->b_un.b_addr, XDFM_BPS); + bp->b_flags |= B_DONE; + bp->b_flags &= ~B_BUSY; +} + +int +xdgetdisklabel(xd, b) + struct xd_softc *xd; + void *b; +{ + char *err; + struct sun_disklabel *sdl; + + /* We already have the label data in `b'; setup for dummy strategy */ + xd_labeldata = b; + + /* Required parameter for readdisklabel() */ + xd->sc_dk.dk_label.d_secsize = XDFM_BPS; + + err = readdisklabel(MAKEDISKDEV(0, xd->sc_dev.dv_unit, RAW_PART), + xddummystrat, + &xd->sc_dk.dk_label, &xd->sc_dk.dk_cpulabel); + if (err) { + printf("%s: %s\n", xd->sc_dev.dv_xname, err); + return(XD_ERR_FAIL); + } + + /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */ + sdl = (struct sun_disklabel *)xd->sc_dk.dk_cpulabel.cd_block; + if (sdl->sl_magic == SUN_DKMAGIC) + xd->pcyl = sdl->sl_pcyl; + else { + printf("%s: WARNING: no `pcyl' in disk label.\n", + xd->sc_dev.dv_xname); + xd->pcyl = xd->sc_dk.dk_label.d_ncylinders + + xd->sc_dk.dk_label.d_acylinders; + printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n", + xd->sc_dev.dv_xname, xd->pcyl); + } + + xd->ncyl = xd->sc_dk.dk_label.d_ncylinders; + xd->acyl = xd->sc_dk.dk_label.d_acylinders; + xd->nhead = xd->sc_dk.dk_label.d_ntracks; + xd->nsect = xd->sc_dk.dk_label.d_nsectors; + xd->sectpercyl = xd->nhead * xd->nsect; + xd->sc_dk.dk_label.d_secsize = XDFM_BPS; /* not handled by + * sun->bsd */ + return(XD_ERR_AOK); +} + +/* + * end: disk label fix code (XXX) + */ + +/* + * a u t o c o n f i g f u n c t i o n s + */ + +/* + * xdcmatch: determine if xdc is present or not. we do a + * soft reset to detect the xdc. + */ + +int xdcmatch(parent, match, aux) + struct device *parent; + void *match, *aux; +{ + struct cfdata *cf = match; + struct confargs *ca = aux; + int x; + + if (ca->ca_bustype != BUS_VME32) + return (0); + + /* Default interrupt priority always splbio==2 */ + if (ca->ca_intpri == -1) + ca->ca_intpri = 2; + + x = bus_peek(ca->ca_bustype, ca->ca_paddr + 11, 1); + if (x == -1) + return (0); + + return (1); +} + +/* + * xdcattach: attach controller + */ +void +xdcattach(parent, self, aux) + struct device *parent, *self; + void *aux; + +{ + struct xdc_softc *xdc = (void *) self; + struct confargs *ca = aux; + struct xdc_attach_args xa; + int lcv, rqno, err, pri; + struct xd_iopb_ctrl *ctl; + + /* get addressing and intr level stuff from autoconfig and load it + * into our xdc_softc. */ + + xdc->xdc = (struct xdc *) + bus_mapin(ca->ca_bustype, ca->ca_paddr, sizeof(struct xdc)); + xdc->ipl = ca->ca_intpri; + xdc->vector = ca->ca_intvec; + + for (lcv = 0; lcv < XDC_MAXDEV; lcv++) + xdc->sc_drives[lcv] = (struct xd_softc *) 0; + + /* allocate and zero buffers + * + * note: we simplify the code by allocating the max number of iopbs and + * iorq's up front. thus, we avoid linked lists and the costs + * associated with them in exchange for wasting a little memory. */ + + xdc->iopbase = (struct xd_iopb *) + dvma_malloc(XDC_MAXIOPB * sizeof(struct xd_iopb)); /* KVA */ + bzero(xdc->iopbase, XDC_MAXIOPB * sizeof(struct xd_iopb)); + xdc->dvmaiopb = (struct xd_iopb *) + dvma_kvtopa((long) xdc->iopbase, BUS_VME32); + xdc->reqs = (struct xd_iorq *) + malloc(XDC_MAXIOPB * sizeof(struct xd_iorq), M_DEVBUF, M_NOWAIT); + bzero(xdc->reqs, XDC_MAXIOPB * sizeof(struct xd_iorq)); + if (xdc->reqs == NULL) + panic("xdc malloc"); + + /* init free list, iorq to iopb pointers, and non-zero fields in the + * iopb which never change. */ + + for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) { + xdc->reqs[lcv].iopb = &xdc->iopbase[lcv]; + xdc->freereq[lcv] = lcv; + xdc->iopbase[lcv].fixd = 1; /* always the same */ + xdc->iopbase[lcv].naddrmod = XDC_ADDRMOD; /* always the same */ + xdc->iopbase[lcv].intr_vec = xdc->vector; /* always the same */ + } + xdc->nfree = XDC_MAXIOPB; + xdc->nrun = 0; + xdc->waithead = xdc->waitend = xdc->nwait = 0; + xdc->ndone = 0; + + /* init queue of waiting bufs */ + + xdc->sc_wq.b_active = 0; + xdc->sc_wq.b_actf = 0; + xdc->sc_wq.b_actb = &xdc->sc_wq.b_actf; + + /* + * section 7 of the manual tells us how to init the controller: + * - read controller parameters (6/0) + * - write controller parameters (5/0) + */ + + /* read controller parameters and insure we have a 753/7053 */ + + rqno = xdc_cmd(xdc, XDCMD_RDP, XDFUN_CTL, 0, 0, 0, 0, XD_SUB_POLL); + if (rqno == XD_ERR_FAIL) { + printf(": couldn't read controller params\n"); + return; /* shouldn't ever happen */ + } + ctl = (struct xd_iopb_ctrl *) & xdc->iopbase[rqno]; + if (ctl->ctype != XDCT_753) { + if (xdc->reqs[rqno].errno) + printf(": %s: ", xdc_e2str(xdc->reqs[rqno].errno)); + printf(": doesn't identify as a 753/7053\n"); + XDC_DONE(xdc, rqno, err); + return; + } + printf(": Xylogics 753/7053, PROM=%x.%02x.%02x\n", + ctl->eprom_partno, ctl->eprom_lvl, ctl->eprom_rev); + XDC_DONE(xdc, rqno, err); + + /* now write controller parameters (xdc_cmd sets all params for us) */ + + rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_CTL, 0, 0, 0, 0, XD_SUB_POLL); + XDC_DONE(xdc, rqno, err); + if (err) { + printf("%s: controller config error: %s\n", + xdc->sc_dev.dv_xname, xdc_e2str(err)); + return; + } + + /* link in interrupt with higher level software */ + isr_add_vectored(xdcintr, (void *)xdc, + ca->ca_intpri, ca->ca_intvec); + evcnt_attach(&xdc->sc_dev, "intr", &xdc->sc_intrcnt); + + /* now we must look for disks using autoconfig */ + xa.dvmabuf = (char *) dvma_malloc(XDFM_BPS); + xa.fullmode = XD_SUB_POLL; + xa.booting = 1; + + for (xa.driveno = 0; xa.driveno < XDC_MAXDEV; xa.driveno++) + (void) config_found(self, (void *) &xa, NULL); + + dvma_free(xa.dvmabuf, XDFM_BPS); + + /* start the watchdog clock */ + timeout(xdc_tick, xdc, XDC_TICKCNT); +} + +/* + * xdmatch: probe for disk. + * + * note: we almost always say disk is present. this allows us to + * spin up and configure a disk after the system is booted (we can + * call xdattach!). + */ +int +xdmatch(parent, match, aux) + struct device *parent; + void *match, *aux; + +{ + struct xdc_softc *xdc = (void *) parent; + struct cfdata *cf = match; + struct xdc_attach_args *xa = aux; + + /* looking for autoconf wildcard or exact match */ + + if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != xa->driveno) + return 0; + + return 1; + +} + +/* + * xdattach: attach a disk. this can be called from autoconf and also + * from xdopen/xdstrategy. + */ +void +xdattach(parent, self, aux) + struct device *parent, *self; + void *aux; + +{ + struct xd_softc *xd = (void *) self; + struct xdc_softc *xdc = (void *) parent; + struct xdc_attach_args *xa = aux; + int rqno, err, spt, mb, blk, lcv, fmode, s, newstate; + struct xd_iopb_drive *driopb; + struct dkbad *dkb; + struct bootpath *bp; + + /* if booting, init the xd_softc */ + + if (xa->booting) { + xd->state = XD_DRIVE_UNKNOWN; /* to start */ + xd->flags = 0; + xd->parent = xdc; + } + xd->xd_drive = xa->driveno; + fmode = xa->fullmode; + xdc->sc_drives[xa->driveno] = xd; + + /* if not booting, make sure we are the only process in the attach for + * this drive. if locked out, sleep on it. */ + + if (!xa->booting) { + s = splbio(); + while (xd->state == XD_DRIVE_ATTACHING) { + if (tsleep(&xd->state, PRIBIO, "xdattach", 0)) { + splx(s); + return; + } + } + printf("%s at %s", + xd->sc_dev.dv_xname, + xd->parent->sc_dev.dv_xname); + } + /* we now have control */ + + xd->state = XD_DRIVE_ATTACHING; + newstate = XD_DRIVE_UNKNOWN; + + /* first try and reset the drive */ + + rqno = xdc_cmd(xdc, XDCMD_RST, 0, xd->xd_drive, 0, 0, 0, fmode); + XDC_DONE(xdc, rqno, err); + if (err == XD_ERR_NRDY) { + printf(" drive %d: off-line\n", xa->driveno); + goto done; + } + if (err) { + printf(": ERROR 0x%02x (%s)\n", err, xdc_e2str(err)); + goto done; + } + printf(" drive %d: ready\n", xa->driveno); + + /* now set format parameters */ + + rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_FMT, xd->xd_drive, 0, 0, 0, fmode); + XDC_DONE(xdc, rqno, err); + if (err) { + printf("%s: write format parameters failed: %s\n", + xd->sc_dev.dv_xname, xdc_e2str(err)); + goto done; + } + + /* get drive parameters */ + rqno = xdc_cmd(xdc, XDCMD_RDP, XDFUN_DRV, xd->xd_drive, 0, 0, 0, fmode); + if (rqno != XD_ERR_FAIL) { + driopb = (struct xd_iopb_drive *) & xdc->iopbase[rqno]; + spt = driopb->sectpertrk; + } + XDC_DONE(xdc, rqno, err); + if (err) { + printf("%s: read drive parameters failed: %s\n", + xd->sc_dev.dv_xname, xdc_e2str(err)); + goto done; + } + + /* + * now set drive parameters (to semi-bogus values) so we can read the + * disk label. + */ + xd->pcyl = xd->ncyl = 1; + xd->acyl = 0; + xd->nhead = 1; + xd->nsect = 1; + xd->sectpercyl = 1; + for (lcv = 0; lcv < 126; lcv++) /* init empty bad144 table */ + xd->dkb.bt_bad[lcv].bt_cyl = xd->dkb.bt_bad[lcv].bt_trksec = 0xffff; + rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_DRV, xd->xd_drive, 0, 0, 0, fmode); + XDC_DONE(xdc, rqno, err); + if (err) { + printf("%s: write drive parameters failed: %s\n", + xd->sc_dev.dv_xname, xdc_e2str(err)); + goto done; + } + + /* read disk label */ + rqno = xdc_cmd(xdc, XDCMD_RD, 0, xd->xd_drive, 0, 1, + xa->dvmabuf, fmode); + XDC_DONE(xdc, rqno, err); + if (err) { + printf("%s: reading disk label failed: %s\n", + xd->sc_dev.dv_xname, xdc_e2str(err)); + goto done; + } + newstate = XD_DRIVE_NOLABEL; + + xd->hw_spt = spt; + if (xdgetdisklabel(xd, xa->dvmabuf) != XD_ERR_AOK) + goto done; + + /* inform the user of what is up */ + printf("%s: <%s>, pcyl %d, hw_spt %d\n", + xd->sc_dev.dv_xname, + xa->dvmabuf, xd->pcyl, spt); + mb = xd->ncyl * (xd->nhead * xd->nsect) / (1048576 / XDFM_BPS); + printf("%s: %dMB, %d cyl, %d head, %d sec, %d bytes/sec\n", + xd->sc_dev.dv_xname, mb, + xd->ncyl, xd->nhead, xd->nsect, XDFM_BPS); + + /* now set the real drive parameters! */ + + rqno = xdc_cmd(xdc, XDCMD_WRP, XDFUN_DRV, xd->xd_drive, 0, 0, 0, fmode); + XDC_DONE(xdc, rqno, err); + if (err) { + printf("%s: write real drive parameters failed: %s\n", + xd->sc_dev.dv_xname, xdc_e2str(err)); + goto done; + } + newstate = XD_DRIVE_ONLINE; + + /* + * read bad144 table. this table resides on the first sector of the + * last track of the disk (i.e. second cyl of "acyl" area). + */ + + blk = (xd->ncyl + xd->acyl - 1) * (xd->nhead * xd->nsect) + /* last cyl */ + (xd->nhead - 1) * xd->nsect; /* last head */ + rqno = xdc_cmd(xdc, XDCMD_RD, 0, xd->xd_drive, blk, 1, xa->dvmabuf, fmode); + XDC_DONE(xdc, rqno, err); + if (err) { + printf("%s: reading bad144 failed: %s\n", + xd->sc_dev.dv_xname, xdc_e2str(err)); + goto done; + } + + /* check dkbad for sanity */ + dkb = (struct dkbad *) xa->dvmabuf; + for (lcv = 0; lcv < 126; lcv++) { + if ((dkb->bt_bad[lcv].bt_cyl == 0xffff || + dkb->bt_bad[lcv].bt_cyl == 0) && + dkb->bt_bad[lcv].bt_trksec == 0xffff) + continue; /* blank */ + if (dkb->bt_bad[lcv].bt_cyl >= xd->ncyl) + break; + if ((dkb->bt_bad[lcv].bt_trksec >> 8) >= xd->nhead) + break; + if ((dkb->bt_bad[lcv].bt_trksec & 0xff) >= xd->nsect) + break; + } + if (lcv != 126) { + printf("%s: warning: invalid bad144 sector!\n", + xd->sc_dev.dv_xname); + } else { + bcopy(xa->dvmabuf, &xd->dkb, XDFM_BPS); + } + + if (xa->booting) { + xd->sc_dk.dk_driver = &xddkdriver; /* link in dkdriver */ + } + + /* XXX - Where is this and what does it do? -gwr */ + dk_establish(&xd->sc_dk, &xd->sc_dev); + +done: + xd->state = newstate; + if (!xa->booting) { + wakeup(&xd->state); + splx(s); + } +} + +/* + * end of autoconfig functions + */ + +/* + * { b , c } d e v s w f u n c t i o n s + */ + +/* + * xdclose: close device + */ +int +xdclose(dev, flag, fmt) + dev_t dev; + int flag, fmt; + +{ + struct xd_softc *xd = xdcd.cd_devs[DISKUNIT(dev)]; + int part = DISKPART(dev); + + /* clear mask bits */ + + switch (fmt) { + case S_IFCHR: + xd->sc_dk.dk_copenmask &= ~(1 << part); + break; + case S_IFBLK: + xd->sc_dk.dk_bopenmask &= ~(1 << part); + break; + } + xd->sc_dk.dk_openmask = xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask; + + return 0; +} + +/* + * xddump: crash dump system + */ +int +xddump(dev) + dev_t dev; + +{ + int unit, part; + struct xd_softc *xd; + + unit = DISKUNIT(dev); + if (unit >= xdcd.cd_ndevs) + return ENXIO; + part = DISKPART(dev); + + xd = xdcd.cd_devs[unit]; + + printf("%s%c: crash dump not supported (yet)\n", + xd->sc_dev.dv_xname, 'a' + part); + + return ENXIO; + + /* outline: globals: "dumplo" == sector number of partition to start + * dump at (convert to physical sector with partition table) + * "dumpsize" == size of dump in clicks "physmem" == size of physical + * memory (clicks, ctob() to get bytes) (normal case: dumpsize == + * physmem) + * + * dump a copy of physical memory to the dump device starting at sector + * "dumplo" in the swap partition (make sure > 0). map in pages as + * we go. use polled I/O. + * + * XXX how to handle NON_CONTIG? */ + +} + +/* + * xdioctl: ioctls on XD drives. based on ioctl's of other netbsd disks. + */ +int +xdioctl(dev, command, addr, flag, p) + dev_t dev; + u_long command; + caddr_t addr; + int flag; + struct proc *p; + +{ + struct xd_softc *xd; + struct xd_iocmd *xio; + int error, s, unit; + + unit = DISKUNIT(dev); + + if (unit >= xdcd.cd_ndevs || (xd = xdcd.cd_devs[unit]) == NULL) + return (ENXIO); + + /* switch on ioctl type */ + + switch (command) { + case DIOCSBAD: /* set bad144 info */ + if ((flag & FWRITE) == 0) + return EBADF; + s = splbio(); + bcopy(addr, &xd->dkb, sizeof(xd->dkb)); + splx(s); + return 0; + + case DIOCGDINFO: /* get disk label */ + bcopy(&xd->sc_dk.dk_label, addr, sizeof(struct disklabel)); + return 0; + + case DIOCGPART: /* get partition info */ + ((struct partinfo *) addr)->disklab = &xd->sc_dk.dk_label; + ((struct partinfo *) addr)->part = + &xd->sc_dk.dk_label.d_partitions[DISKPART(dev)]; + return 0; + + case DIOCSDINFO: /* set disk label */ + if ((flag & FWRITE) == 0) + return EBADF; + error = setdisklabel(&xd->sc_dk.dk_label, + (struct disklabel *) addr, /* xd->sc_dk.dk_openmask : */ 0, + &xd->sc_dk.dk_cpulabel); + if (error == 0) { + if (xd->state == XD_DRIVE_NOLABEL) + xd->state = XD_DRIVE_ONLINE; + } + return error; + + case DIOCWLABEL: /* change write status of disk label */ + if ((flag & FWRITE) == 0) + return EBADF; + if (*(int *) addr) + xd->flags |= XD_WLABEL; + else + xd->flags &= ~XD_WLABEL; + return 0; + + case DIOCWDINFO: /* write disk label */ + if ((flag & FWRITE) == 0) + return EBADF; + error = setdisklabel(&xd->sc_dk.dk_label, + (struct disklabel *) addr, /* xd->sc_dk.dk_openmask : */ 0, + &xd->sc_dk.dk_cpulabel); + if (error == 0) { + if (xd->state == XD_DRIVE_NOLABEL) + xd->state = XD_DRIVE_ONLINE; + + /* Simulate opening partition 0 so write succeeds. */ + xd->sc_dk.dk_openmask |= (1 << 0); + error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART), + xdstrategy, &xd->sc_dk.dk_label, + &xd->sc_dk.dk_cpulabel); + xd->sc_dk.dk_openmask = + xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask; + } + return error; + + case DIOSXDCMD: + xio = (struct xd_iocmd *) addr; + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return (error); + return (xdc_ioctlcmd(xd, dev, xio)); + + default: + return ENOTTY; + } +} +/* + * xdopen: open drive + */ + +int +xdopen(dev, flag, fmt) + dev_t dev; + int flag, fmt; + +{ + int unit, part; + struct xd_softc *xd; + struct xdc_attach_args xa; + + /* first, could it be a valid target? */ + + unit = DISKUNIT(dev); + if (unit >= xdcd.cd_ndevs || (xd = xdcd.cd_devs[unit]) == NULL) + return (ENXIO); + part = DISKPART(dev); + + /* do we need to attach the drive? */ + + if (xd->state == XD_DRIVE_UNKNOWN) { + xa.driveno = xd->xd_drive; + xa.dvmabuf = (char *) dvma_malloc(XDFM_BPS); + xa.fullmode = XD_SUB_WAIT; + xa.booting = 0; + xdattach((struct device *) xd->parent, (struct device *) xd, &xa); + dvma_free(xa.dvmabuf, XDFM_BPS); + if (xd->state == XD_DRIVE_UNKNOWN) { + return (EIO); + } + } + /* check for partition */ + + if (part != RAW_PART && + (part >= xd->sc_dk.dk_label.d_npartitions || + xd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + return (ENXIO); + } + /* set open masks */ + + switch (fmt) { + case S_IFCHR: + xd->sc_dk.dk_copenmask |= (1 << part); + break; + case S_IFBLK: + xd->sc_dk.dk_bopenmask |= (1 << part); + break; + } + xd->sc_dk.dk_openmask = xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask; + + return 0; +} + +int +xdread(dev, uio) + dev_t dev; + struct uio *uio; +{ + + return (physio(xdstrategy, NULL, dev, B_READ, minphys, uio)); +} + +int +xdwrite(dev, uio) + dev_t dev; + struct uio *uio; +{ + + return (physio(xdstrategy, NULL, dev, B_WRITE, minphys, uio)); +} + + +/* + * xdsize: return size of a partition for a dump + */ + +int +xdsize(dev) + dev_t dev; + +{ + struct xd_softc *xdsc; + int unit, part, size; + + /* valid unit? try an open */ + + if (xdopen(dev, 0, S_IFBLK) != 0) + return (-1); + + /* do it */ + + xdsc = xdcd.cd_devs[DISKUNIT(dev)]; + part = DISKPART(dev); + if (xdsc->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + size = -1; /* only give valid size for swap partitions */ + else + size = xdsc->sc_dk.dk_label.d_partitions[part].p_size; + if (xdclose(dev, 0, S_IFBLK) != 0) + return -1; + return size; +} +/* + * xdstrategy: buffering system interface to xd. + */ + +void +xdstrategy(bp) + struct buf *bp; + +{ + struct xd_softc *xd; + struct xdc_softc *parent; + struct buf *wq; + int s, unit; + struct xdc_attach_args xa; + + unit = DISKUNIT(bp->b_dev); + + /* check for live device */ + + if (unit >= xdcd.cd_ndevs || (xd = xdcd.cd_devs[unit]) == 0 || + bp->b_blkno < 0 || + (bp->b_bcount % xd->sc_dk.dk_label.d_secsize) != 0) { + bp->b_error = EINVAL; + goto bad; + } + /* do we need to attach the drive? */ + + if (xd->state == XD_DRIVE_UNKNOWN) { + xa.driveno = xd->xd_drive; + xa.dvmabuf = (char *) dvma_malloc(XDFM_BPS); + xa.fullmode = XD_SUB_WAIT; + xa.booting = 0; + xdattach((struct device *)xd->parent, (struct device *)xd, &xa); + dvma_free(xa.dvmabuf, XDFM_BPS); + if (xd->state == XD_DRIVE_UNKNOWN) { + bp->b_error = EIO; + goto bad; + } + } + if (xd->state != XD_DRIVE_ONLINE && DISKPART(bp->b_dev) != RAW_PART) { + /* no I/O to unlabeled disks, unless raw partition */ + bp->b_error = EIO; + goto bad; + } + /* short circuit zero length request */ + + if (bp->b_bcount == 0) + goto done; + + /* check bounds with label (disksubr.c). Determine the size of the + * transfer, and make sure it is within the boundaries of the + * partition. Adjust transfer if needed, and signal errors or early + * completion. */ + + if (bounds_check_with_label(bp, &xd->sc_dk.dk_label, + (xd->flags & XD_WLABEL) != 0) <= 0) + goto done; + + /* + * now we know we have a valid buf structure that we need to do I/O + * on. + * + * note that we don't disksort because the controller has a sorting + * algorithm built into the hardware. + */ + + s = splbio(); /* protect the queues */ + + /* first, give jobs in front of us a chance */ + + parent = xd->parent; + while (parent->nfree > 0 && parent->sc_wq.b_actf) + if (xdc_startbuf(parent, NULL, NULL) != XD_ERR_AOK) + break; + + /* if there are no free iorq's, then we just queue and return. the + * buffs will get picked up later by xdcintr(). */ + + if (parent->nfree == 0) { + wq = &xd->parent->sc_wq; + bp->b_actf = 0; + bp->b_actb = wq->b_actb; + *wq->b_actb = bp; + wq->b_actb = &bp->b_actf; + splx(s); + return; + } + /* now we have free iopb's and we are at splbio... start 'em up */ + + if (xdc_startbuf(parent, xd, bp) != XD_ERR_AOK) { + return; + } + /* done! */ + + splx(s); + return; + +bad: /* tells upper layers we have an error */ + bp->b_flags |= B_ERROR; +done: /* tells upper layers we are done with this + * buf */ + bp->b_resid = bp->b_bcount; + biodone(bp); +} +/* + * end of {b,c}devsw functions + */ + +/* + * i n t e r r u p t f u n c t i o n + * + * xdcintr: hardware interrupt. + */ +int +xdcintr(v) + void *v; + +{ + struct xdc_softc *xdcsc = v; + struct xd_softc *xd; + struct buf *bp; + + /* kick the event counter */ + + xdcsc->sc_intrcnt.ev_count++; + + /* remove as many done IOPBs as possible */ + + xdc_remove_iorq(xdcsc); + + /* start any iorq's already waiting */ + + xdc_start(xdcsc, XDC_MAXIOPB); + + /* fill up any remaining iorq's with queue'd buffers */ + + while (xdcsc->nfree > 0 && xdcsc->sc_wq.b_actf) + if (xdc_startbuf(xdcsc, NULL, NULL) != XD_ERR_AOK) + break; + + return (1); +} +/* + * end of interrupt function + */ + +/* + * i n t e r n a l f u n c t i o n s + */ + +/* + * xdc_rqinit: fill out the fields of an I/O request + */ + +inline void +xdc_rqinit(rq, xdc, xd, md, blk, cnt, db, bp) + struct xd_iorq *rq; + struct xdc_softc *xdc; + struct xd_softc *xd; + int md; + u_long blk; + int cnt; + caddr_t db; + struct buf *bp; +{ + rq->xdc = xdc; + rq->xd = xd; + rq->ttl = XDC_MAXTTL + 10; + rq->mode = md; + rq->tries = rq->errno = rq->lasterror = 0; + rq->blockno = blk; + rq->sectcnt = cnt; + rq->dbuf = rq->dbufbase = db; + rq->buf = bp; +} +/* + * xdc_rqtopb: load up an IOPB based on an iorq + */ + +void +xdc_rqtopb(iorq, iopb, cmd, subfun) + struct xd_iorq *iorq; + struct xd_iopb *iopb; + int cmd, subfun; + +{ + u_long block, dp; + + /* standard stuff */ + + iopb->errs = iopb->done = 0; + iopb->comm = cmd; + iopb->errno = iopb->status = 0; + iopb->subfun = subfun; + if (iorq->xd) + iopb->unit = iorq->xd->xd_drive; + else + iopb->unit = 0; + + /* check for alternate IOPB format */ + + if (cmd == XDCMD_WRP) { + switch (subfun) { + case XDFUN_CTL:{ + struct xd_iopb_ctrl *ctrl = + (struct xd_iopb_ctrl *) iopb; + iopb->lll = 0; + iopb->intl = (XD_STATE(iorq->mode) == XD_SUB_POLL) + ? 0 + : iorq->xdc->ipl; + ctrl->param_a = XDPA_TMOD | XDPA_DACF; + ctrl->param_b = XDPB_ROR | XDPB_TDT_3_2USEC; + ctrl->param_c = XDPC_OVS | XDPC_COP | XDPC_ASR | + XDPC_RBC | XDPC_ECC2; + ctrl->throttle = XDC_THROTTLE; +#ifdef sparc + if (cputyp == CPU_SUN4 && cpumod == SUN4_300) + ctrl->delay = XDC_DELAY_4_300; + else + ctrl->delay = XDC_DELAY_SPARC; +#endif +#ifdef sun3 + ctrl->delay = XDC_DELAY_SUN3; +#endif + break; + } + case XDFUN_DRV:{ + struct xd_iopb_drive *drv = + (struct xd_iopb_drive *)iopb; + /* we assume that the disk label has the right + * info */ + if (XD_STATE(iorq->mode) == XD_SUB_POLL) + drv->dparam_ipl = (XDC_DPARAM << 3); + else + drv->dparam_ipl = (XDC_DPARAM << 3) | + iorq->xdc->ipl; + drv->maxsect = iorq->xd->nsect - 1; + drv->maxsector = drv->maxsect; + /* note: maxsector != maxsect only if you are + * doing cyl sparing */ + drv->headoff = 0; + drv->maxcyl = iorq->xd->pcyl - 1; + drv->maxhead = iorq->xd->nhead - 1; + break; + } + case XDFUN_FMT:{ + struct xd_iopb_format *form = + (struct xd_iopb_format *) iopb; + if (XD_STATE(iorq->mode) == XD_SUB_POLL) + form->interleave_ipl = (XDC_INTERLEAVE << 3); + else + form->interleave_ipl = (XDC_INTERLEAVE << 3) | + iorq->xdc->ipl; + form->field1 = XDFM_FIELD1; + form->field2 = XDFM_FIELD2; + form->field3 = XDFM_FIELD3; + form->field4 = XDFM_FIELD4; + form->bytespersec = XDFM_BPS; + form->field6 = XDFM_FIELD6; + form->field7 = XDFM_FIELD7; + break; + } + } + } else { + + /* normal IOPB case (harmless to RDP command) */ + + iopb->lll = 0; + iopb->intl = (XD_STATE(iorq->mode) == XD_SUB_POLL) + ? 0 + : iorq->xdc->ipl; + iopb->sectcnt = iorq->sectcnt; + block = iorq->blockno; + if (iorq->xd == NULL || block == 0) { + iopb->sectno = iopb->headno = iopb->cylno = 0; + } else { + iopb->sectno = block % iorq->xd->nsect; + block = block / iorq->xd->nsect; + iopb->headno = block % iorq->xd->nhead; + block = block / iorq->xd->nhead; + iopb->cylno = block; + } + dp = dvma_kvtopa((long)iorq->dbuf, BUS_VME32); + iopb->daddr = dp = (iorq->dbuf == NULL) ? 0 : dp; + iopb->addrmod = XDC_ADDRMOD; + } +} + +/* + * xdc_cmd: front end for POLL'd and WAIT'd commands. Returns rqno. + * If you've already got an IORQ, you can call submit directly (currently + * there is no need to do this). NORM requests are handled seperately. + */ +int +xdc_cmd(xdcsc, cmd, subfn, unit, block, scnt, dptr, fullmode) + struct xdc_softc *xdcsc; + int cmd, subfn, unit, block, scnt; + char *dptr; + int fullmode; + +{ + int rqno, submode = XD_STATE(fullmode), retry; + u_long dp; + struct xd_iorq *iorq; + struct xd_iopb *iopb; + + /* get iorq/iopb */ + switch (submode) { + case XD_SUB_POLL: + while (xdcsc->nfree == 0) { + if (xdc_piodriver(xdcsc, 0, 1) != XD_ERR_AOK) + return (XD_ERR_FAIL); + } + break; + case XD_SUB_WAIT: + retry = 1; + while (retry) { + while (xdcsc->nfree == 0) { + if (tsleep(&xdcsc->nfree, PRIBIO, "xdnfree", 0)) + return (XD_ERR_FAIL); + } + while (xdcsc->ndone > XDC_SUBWAITLIM) { + if (tsleep(&xdcsc->ndone, PRIBIO, "xdsubwait", 0)) + return (XD_ERR_FAIL); + } + if (xdcsc->nfree) + retry = 0; /* got it */ + } + break; + default: + return (XD_ERR_FAIL); /* illegal */ + } + if (xdcsc->nfree == 0) + panic("xdcmd nfree"); + rqno = XDC_RQALLOC(xdcsc); + iorq = &xdcsc->reqs[rqno]; + iopb = iorq->iopb; + + + /* init iorq/iopb */ + + xdc_rqinit(iorq, xdcsc, + (unit == XDC_NOUNIT) ? NULL : xdcsc->sc_drives[unit], + fullmode, block, scnt, dptr, NULL); + + /* load IOPB from iorq */ + + xdc_rqtopb(iorq, iopb, cmd, subfn); + + /* submit it for processing */ + + xdc_submit_iorq(xdcsc, rqno, fullmode); /* error code will be in iorq */ + + return (rqno); +} +/* + * xdc_startbuf + * start a buffer running, assumes nfree > 0 + */ + +int +xdc_startbuf(xdcsc, xdsc, bp) + struct xdc_softc *xdcsc; + struct xd_softc *xdsc; + struct buf *bp; + +{ + int rqno, partno; + struct xd_iorq *iorq; + struct xd_iopb *iopb; + struct buf *wq; + u_long block, dp; + caddr_t dbuf; + + if (!xdcsc->nfree) + panic("xdc_startbuf free"); + rqno = XDC_RQALLOC(xdcsc); + iorq = &xdcsc->reqs[rqno]; + iopb = iorq->iopb; + + /* get buf */ + + if (bp == NULL) { + bp = xdcsc->sc_wq.b_actf; + if (!bp) + panic("xdc_startbuf bp"); + wq = bp->b_actf; + if (wq) + wq->b_actb = bp->b_actb; + else + xdcsc->sc_wq.b_actb = bp->b_actb; + *bp->b_actb = wq; + xdsc = xdcsc->sc_drives[DISKUNIT(bp->b_dev)]; + } + partno = DISKPART(bp->b_dev); +#ifdef XDC_DEBUG + printf("xdc_startbuf: %s%c: %s block %d\n", xdsc->sc_dev.dv_xname, + 'a' + partno, (bp->b_flags & B_READ) ? "read" : "write", bp->b_blkno); + printf("xdc_startbuf: b_bcount %d, b_data 0x%x\n", + bp->b_bcount, bp->b_data); +#endif + + /* + * load request. we have to calculate the correct block number based + * on partition info. + * + * also, note that there are two kinds of buf structures, those with + * B_PHYS set and those without B_PHYS. if B_PHYS is set, then it is + * a raw I/O (to a cdevsw) and we are doing I/O directly to the users' + * buffer which has already been mapped into DVMA space. (Not on sun3) + * However, if B_PHYS is not set, then the buffer is a normal system + * buffer which does *not* live in DVMA space. In that case we call + * dvma_mapin to map it into DVMA space so we can do the DMA to it. + * + * in cases where we do a dvma_mapin, note that iorq points to the buffer + * as mapped into DVMA space, where as the bp->b_data points to its + * non-DVMA mapping. + * + * XXX - On the sun3, B_PHYS does NOT mean the buffer is mapped + * into dvma space, only that it was remapped into the kernel. + * We ALWAYS have to remap the kernel buf into DVMA space. + * (It is done inexpensively, using whole segments!) + */ + + block = bp->b_blkno + ((partno == RAW_PART) ? 0 : + xdsc->sc_dk.dk_label.d_partitions[partno].p_offset); + + dbuf = dvma_mapin(bp->b_data, bp->b_bcount); + if (dbuf == NULL) { /* out of DVMA space */ + printf("%s: warning: out of DVMA space\n", xdcsc->sc_dev.dv_xname); + XDC_FREE(xdcsc, rqno); + wq = &xdcsc->sc_wq; /* put at end of queue */ + bp->b_actf = 0; + bp->b_actb = wq->b_actb; + *wq->b_actb = bp; + wq->b_actb = &bp->b_actf; + return (XD_ERR_FAIL); /* XXX: need some sort of + * call-back scheme here? */ + } + + /* init iorq and load iopb from it */ + + xdc_rqinit(iorq, xdcsc, xdsc, XD_SUB_NORM | XD_MODE_VERBO, block, + bp->b_bcount / XDFM_BPS, dbuf, bp); + + xdc_rqtopb(iorq, iopb, (bp->b_flags & B_READ) ? XDCMD_RD : XDCMD_WR, 0); + + /* now submit [note that xdc_submit_iorq can never fail on NORM reqs] */ + + xdc_submit_iorq(xdcsc, rqno, XD_SUB_NORM); + return (XD_ERR_AOK); +} + + +/* + * xdc_submit_iorq: submit an iorq for processing. returns XD_ERR_AOK + * if ok. if it fail returns an error code. type is XD_SUB_*. + * + * note: caller frees iorq in all cases except NORM + * + * return value: + * NORM: XD_AOK (req pending), XD_FAIL (couldn't submit request) + * WAIT: XD_AOK (success), <error-code> (failed) + * POLL: <same as WAIT> + * NOQ : <same as NORM> + * + * there are three sources for i/o requests: + * [1] xdstrategy: normal block I/O, using "struct buf" system. + * [2] autoconfig/crash dump: these are polled I/O requests, no interrupts. + * [3] open/ioctl: these are I/O requests done in the context of a process, + * and the process should block until they are done. + * + * software state is stored in the iorq structure. each iorq has an + * iopb structure. the hardware understands the iopb structure. + * every command must go through an iopb. a 7053 can only handle + * XDC_MAXIOPB (31) active iopbs at one time. iopbs are allocated in + * DVMA space at boot up time. what happens if we run out of iopb's? + * for i/o type [1], the buffers are queued at the "buff" layer and + * picked up later by the interrupt routine. for case [2] the + * programmed i/o driver is called with a special flag that says + * return when one iopb is free. for case [3] the process can sleep + * on the iorq free list until some iopbs are avaliable. + */ + + +int +xdc_submit_iorq(xdcsc, iorqno, type) + struct xdc_softc *xdcsc; + int iorqno; + int type; + +{ + u_long iopbaddr; + struct xd_iorq *iorq = &xdcsc->reqs[iorqno]; + +#ifdef XDC_DEBUG + printf("xdc_submit_iorq(%s, no=%d, type=%d)\n", xdcsc->sc_dev.dv_xname, + iorqno, type); +#endif + + /* first check and see if controller is busy */ + if (xdcsc->xdc->xdc_csr & XDC_ADDING) { +#ifdef XDC_DEBUG + printf("xdc_submit_iorq: XDC not ready (ADDING)\n"); +#endif + if (type == XD_SUB_NOQ) + return (XD_ERR_FAIL); /* failed */ + XDC_TWAIT(xdcsc, iorqno); /* put at end of waitq */ + switch (type) { + case XD_SUB_NORM: + return XD_ERR_AOK; /* success */ + case XD_SUB_WAIT: + while (iorq->iopb->done == 0) { + sleep(iorq, PRIBIO); + } + return (iorq->errno); + case XD_SUB_POLL: + return (xdc_piodriver(xdcsc, iorqno, 0)); + default: + panic("xdc_submit_iorq adding"); + } + } +#ifdef XDC_DEBUG + { + u_char *rio = (u_char *) iorq->iopb; + int sz = sizeof(struct xd_iopb), lcv; + printf("%s: aio #%d [", + xdcsc->sc_dev.dv_xname, iorq - xdcsc->reqs); + for (lcv = 0; lcv < sz; lcv++) + printf(" %02x", rio[lcv]); + printf("]\n"); + } +#endif /* XDC_DEBUG */ + + /* controller not busy, start command */ + iopbaddr = dvma_kvtopa((long) iorq->iopb, BUS_VME32); + XDC_GO(xdcsc->xdc, iopbaddr); /* go! */ + xdcsc->nrun++; + /* command now running, wrap it up */ + switch (type) { + case XD_SUB_NORM: + case XD_SUB_NOQ: + return (XD_ERR_AOK); /* success */ + case XD_SUB_WAIT: + while (iorq->iopb->done == 0) { + sleep(iorq, PRIBIO); + } + return (iorq->errno); + case XD_SUB_POLL: + return (xdc_piodriver(xdcsc, iorqno, 0)); + default: + panic("xdc_submit_iorq wrap up"); + } + panic("xdc_submit_iorq"); + return 0; /* not reached */ +} + + +/* + * xdc_piodriver + * + * programmed i/o driver. this function takes over the computer + * and drains off all i/o requests. it returns the status of the iorq + * the caller is interesting in. if freeone is true, then it returns + * when there is a free iorq. + */ +int +xdc_piodriver(xdcsc, iorqno, freeone) + struct xdc_softc *xdcsc; + char iorqno; + int freeone; + +{ + int nreset = 0; + int retval = 0; + u_long count; + struct xdc *xdc = xdcsc->xdc; +#ifdef XDC_DEBUG + printf("xdc_piodriver(%s, %d, freeone=%d)\n", xdcsc->sc_dev.dv_xname, + iorqno, freeone); +#endif + + while (xdcsc->nwait || xdcsc->nrun) { +#ifdef XDC_DEBUG + printf("xdc_piodriver: wait=%d, run=%d\n", + xdcsc->nwait, xdcsc->nrun); +#endif + XDC_WAIT(xdc, count, XDC_MAXTIME, (XDC_REMIOPB | XDC_F_ERROR)); +#ifdef XDC_DEBUG + printf("xdc_piodriver: done wait with count = %d\n", count); +#endif + /* we expect some progress soon */ + if (count == 0 && nreset >= 2) { + xdc_reset(xdcsc, 0, XD_RSET_ALL, XD_ERR_FAIL, 0); +#ifdef XDC_DEBUG + printf("xdc_piodriver: timeout\n"); +#endif + return (XD_ERR_FAIL); + } + if (count == 0) { + if (xdc_reset(xdcsc, 0, + (nreset++ == 0) ? XD_RSET_NONE : iorqno, + XD_ERR_FAIL, + 0) == XD_ERR_FAIL) + return (XD_ERR_FAIL); /* flushes all but POLL + * requests, resets */ + continue; + } + xdc_remove_iorq(xdcsc); /* could resubmit request */ + if (freeone) { + if (xdcsc->nrun < XDC_MAXIOPB) { +#ifdef XDC_DEBUG + printf("xdc_piodriver: done: one free\n"); +#endif + return (XD_ERR_AOK); + } + continue; /* don't xdc_start */ + } + xdc_start(xdcsc, XDC_MAXIOPB); + } + + /* get return value */ + + retval = xdcsc->reqs[iorqno].errno; + +#ifdef XDC_DEBUG + printf("xdc_piodriver: done, retval = 0x%x (%s)\n", + xdcsc->reqs[iorqno].errno, xdc_e2str(xdcsc->reqs[iorqno].errno)); +#endif + + /* now that we've drained everything, start up any bufs that have + * queued */ + + while (xdcsc->nfree > 0 && xdcsc->sc_wq.b_actf) + if (xdc_startbuf(xdcsc, NULL, NULL) != XD_ERR_AOK) + break; + + return (retval); +} + +/* + * xdc_reset: reset one drive. NOTE: assumes xdc was just reset. + * we steal iopb[0] for this, but we put it back when we are done. + */ +int +xdc_xdreset(xdcsc, xdsc) + struct xdc_softc *xdcsc; + struct xd_softc *xdsc; + +{ + struct xd_iopb tmpiopb; + u_long addr; + int del; + bcopy(xdcsc->iopbase, &tmpiopb, sizeof(tmpiopb)); + bzero(xdcsc->iopbase, sizeof(tmpiopb)); + xdcsc->iopbase->comm = XDCMD_RST; + xdcsc->iopbase->unit = xdsc->xd_drive; + addr = (u_long) xdcsc->dvmaiopb; + XDC_GO(xdcsc->xdc, addr); /* go! */ + XDC_WAIT(xdcsc->xdc, del, XDC_RESETUSEC, XDC_REMIOPB); + if (del <= 0 || xdcsc->iopbase->errs) { + printf("%s: off-line: %s\n", xdcsc->sc_dev.dv_xname, + xdc_e2str(xdcsc->iopbase->errno)); + xdcsc->xdc->xdc_csr = XDC_RESET; + XDC_WAIT(xdcsc->xdc, del, XDC_RESETUSEC, XDC_RESET); + if (del <= 0) + panic("xdc_reset"); + } else { + xdcsc->xdc->xdc_csr |= XDC_CLRRIO; /* clear RIO */ + } + bcopy(&tmpiopb, xdcsc->iopbase, sizeof(tmpiopb)); +} + + +/* + * xdc_reset: reset everything: requests are marked as errors except + * a polled request (which is resubmitted) + */ +int +xdc_reset(xdcsc, quiet, blastmode, error, xdsc) + struct xdc_softc *xdcsc; + int quiet, blastmode, error; + struct xd_softc *xdsc; + +{ + int del = 0, lcv, poll = -1, retval = XD_ERR_AOK; + int oldfree = xdcsc->nfree; + struct xd_iorq *iorq; + + /* soft reset hardware */ + + if (!quiet) + printf("%s: soft reset\n", xdcsc->sc_dev.dv_xname); + xdcsc->xdc->xdc_csr = XDC_RESET; + XDC_WAIT(xdcsc->xdc, del, XDC_RESETUSEC, XDC_RESET); + if (del <= 0) { + blastmode = XD_RSET_ALL; /* dead, flush all requests */ + retval = XD_ERR_FAIL; + } + if (xdsc) + xdc_xdreset(xdcsc, xdsc); + + /* fix queues based on "blast-mode" */ + + for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) { + iorq = &xdcsc->reqs[lcv]; + + if (XD_STATE(iorq->mode) != XD_SUB_POLL && + XD_STATE(iorq->mode) != XD_SUB_WAIT && + XD_STATE(iorq->mode) != XD_SUB_NORM) + /* is it active? */ + continue; + + xdcsc->nrun--; /* it isn't running any more */ + if (blastmode == XD_RSET_ALL || blastmode != lcv) { + /* failed */ + iorq->errno = error; + xdcsc->iopbase[lcv].done = xdcsc->iopbase[lcv].errs = 1; + switch (XD_STATE(iorq->mode)) { + case XD_SUB_NORM: + iorq->buf->b_error = EIO; + iorq->buf->b_flags |= B_ERROR; + iorq->buf->b_resid = + iorq->sectcnt * XDFM_BPS; + /* Sun3: map/unmap regardless of B_PHYS */ + dvma_mapout(iorq->dbufbase, + iorq->buf->b_bcount); + biodone(iorq->buf); + XDC_FREE(xdcsc, lcv); /* add to free list */ + break; + case XD_SUB_WAIT: + wakeup(iorq); + case XD_SUB_POLL: + xdcsc->ndone++; + iorq->mode = XD_NEWSTATE(iorq->mode, XD_SUB_DONE); + break; + } + + } else { + + /* resubmit, put at front of wait queue */ + XDC_HWAIT(xdcsc, lcv); + } + } + + /* + * now, if stuff is waiting, start it. + * since we just reset it should go + */ + xdc_start(xdcsc, XDC_MAXIOPB); + + /* ok, we did it */ + if (oldfree == 0 && xdcsc->nfree) + wakeup(&xdcsc->nfree); + +#ifdef XDC_DIAG + del = xdcsc->nwait + xdcsc->nrun + xdcsc->nfree + xdcsc->ndone; + if (del != XDC_MAXIOPB) + printf("%s: diag: xdc_reset miscount (%d should be %d)!\n", + xdcsc->sc_dev.dv_xname, del, XDC_MAXIOPB); + else + if (xdcsc->ndone > XDC_MAXIOPB - XDC_SUBWAITLIM) + printf("%s: diag: lots of done jobs (%d)\n", + xdcsc->sc_dev.dv_xname, xdcsc->ndone); +#endif + printf("RESET DONE\n"); + return (retval); +} +/* + * xdc_start: start all waiting buffers + */ + +int +xdc_start(xdcsc, maxio) + struct xdc_softc *xdcsc; + int maxio; + +{ + int rqno; + while (maxio && xdcsc->nwait && + (xdcsc->xdc->xdc_csr & XDC_ADDING) == 0) { + XDC_GET_WAITER(xdcsc, rqno); /* note: rqno is an "out" + * param */ + if (xdc_submit_iorq(xdcsc, rqno, XD_SUB_NOQ) != XD_ERR_AOK) + panic("xdc_start"); /* should never happen */ + maxio--; + } +} +/* + * xdc_remove_iorq: remove "done" IOPB's. + */ + +int +xdc_remove_iorq(xdcsc) + struct xdc_softc *xdcsc; + +{ + int errno, rqno, comm, errs; + struct xdc *xdc = xdcsc->xdc; + u_long addr; + struct xd_iopb *iopb; + struct xd_iorq *iorq; + struct buf *bp; + + if (xdc->xdc_csr & XDC_F_ERROR) { + /* + * FATAL ERROR: should never happen under normal use. This + * error is so bad, you can't even tell which IOPB is bad, so + * we dump them all. + */ + errno = xdc->xdc_f_err; + printf("%s: fatal error 0x%02x: %s\n", xdcsc->sc_dev.dv_xname, + errno, xdc_e2str(errno)); + if (xdc_reset(xdcsc, 0, XD_RSET_ALL, errno, 0) != XD_ERR_AOK) { + printf("%s: soft reset failed!\n", + xdcsc->sc_dev.dv_xname); + panic("xdc_remove_iorq: controller DEAD"); + } + return (XD_ERR_AOK); + } + + /* + * get iopb that is done + * + * hmm... I used to read the address of the done IOPB off the VME + * registers and calculate the rqno directly from that. that worked + * until I started putting a load on the controller. when loaded, i + * would get interrupts but neither the REMIOPB or F_ERROR bits would + * be set, even after DELAY'ing a while! later on the timeout + * routine would detect IOPBs that were marked "running" but their + * "done" bit was set. rather than dealing directly with this + * problem, it is just easier to look at all running IOPB's for the + * done bit. + */ + if (xdc->xdc_csr & XDC_REMIOPB) { + xdc->xdc_csr |= XDC_CLRRIO; + } + + for (rqno = 0; rqno < XDC_MAXIOPB; rqno++) { + iorq = &xdcsc->reqs[rqno]; + if (iorq->mode == 0 || XD_STATE(iorq->mode) == XD_SUB_DONE) + continue; /* free, or done */ + iopb = &xdcsc->iopbase[rqno]; + if (iopb->done == 0) + continue; /* not done yet */ + +#ifdef XDC_DEBUG + { + u_char *rio = (u_char *) iopb; + int sz = sizeof(struct xd_iopb), lcv; + printf("%s: rio #%d [", xdcsc->sc_dev.dv_xname, rqno); + for (lcv = 0; lcv < sz; lcv++) + printf(" %02x", rio[lcv]); + printf("]\n"); + } +#endif /* XDC_DEBUG */ + + xdcsc->nrun--; + + comm = iopb->comm; + errs = iopb->errs; + + if (errs) + iorq->errno = iopb->errno; + else + iorq->errno = 0; + + /* handle non-fatal errors */ + + if (errs && + xdc_error(xdcsc, iorq, iopb, rqno, comm) == XD_ERR_AOK) + continue; /* AOK: we resubmitted it */ + + + /* this iorq is now done (hasn't been restarted or anything) */ + + if ((iorq->mode & XD_MODE_VERBO) && iorq->lasterror) + xdc_perror(iorq, iopb, 0); + + /* now, if read/write check to make sure we got all the data + * we needed. (this may not be the case if we got an error in + * the middle of a multisector request). */ + + if ((iorq->mode & XD_MODE_B144) != 0 && errs == 0 && + (comm == XDCMD_RD || comm == XDCMD_WR)) { + /* we just successfully processed a bad144 sector + * note: if we are in bad 144 mode, the pointers have + * been advanced already (see above) and are pointing + * at the bad144 sector. to exit bad144 mode, we + * must advance the pointers 1 sector and issue a new + * request if there are still sectors left to process + * + */ + XDC_ADVANCE(iorq, 1); /* advance 1 sector */ + + /* exit b144 mode */ + iorq->mode = iorq->mode & (~XD_MODE_B144); + + if (iorq->sectcnt) { /* more to go! */ + iorq->lasterror = iorq->errno = iopb->errno = 0; + iopb->errs = iopb->done = 0; + iorq->tries = 0; + iopb->sectcnt = iorq->sectcnt; + iopb->cylno = iorq->blockno / + iorq->xd->sectpercyl; + iopb->headno = + (iorq->blockno / iorq->xd->nhead) % + iorq->xd->nhead; + iopb->sectno = iorq->blockno % XDFM_BPS; + iopb->daddr = + dvma_kvtopa((long)iorq->dbuf, BUS_VME32); + XDC_HWAIT(xdcsc, rqno); + xdc_start(xdcsc, 1); /* resubmit */ + continue; + } + } + /* final cleanup, totally done with this request */ + + switch (XD_STATE(iorq->mode)) { + case XD_SUB_NORM: + bp = iorq->buf; + if (errs) { + bp->b_error = EIO; + bp->b_flags |= B_ERROR; + bp->b_resid = iorq->sectcnt * XDFM_BPS; + } else { + bp->b_resid = 0; /* done */ + } + /* Sun3: map/unmap regardless of B_PHYS */ + dvma_mapout(iorq->dbufbase, + iorq->buf->b_bcount); + XDC_FREE(xdcsc, rqno); + biodone(bp); + break; + case XD_SUB_WAIT: + iorq->mode = XD_NEWSTATE(iorq->mode, XD_SUB_DONE); + xdcsc->ndone++; + wakeup(iorq); + break; + case XD_SUB_POLL: + iorq->mode = XD_NEWSTATE(iorq->mode, XD_SUB_DONE); + xdcsc->ndone++; + break; + } + } + + return (XD_ERR_AOK); +} + +/* + * xdc_perror: print error. + * - if still_trying is true: we got an error, retried and got a + * different error. in that case lasterror is the old error, + * and errno is the new one. + * - if still_trying is not true, then if we ever had an error it + * is in lasterror. also, if iorq->errno == 0, then we recovered + * from that error (otherwise iorq->errno == iorq->lasterror). + */ +void +xdc_perror(iorq, iopb, still_trying) + struct xd_iorq *iorq; + struct xd_iopb *iopb; + int still_trying; + +{ + + int error = iorq->lasterror; + + printf("%s", (iorq->xd) ? + iorq->xd->sc_dev.dv_xname : + iorq->xdc->sc_dev.dv_xname); + if (iorq->buf) + printf("%c: ", 'a' + DISKPART(iorq->buf->b_dev)); + if (iopb->comm == XDCMD_RD || iopb->comm == XDCMD_WR) + printf("%s %d/%d/%d: ", + (iopb->comm == XDCMD_RD) ? "read" : "write", + iopb->cylno, iopb->headno, iopb->sectno); + printf("%s", xdc_e2str(error)); + + if (still_trying) + printf(" [still trying, new error=%s]", xdc_e2str(iorq->errno)); + else + if (iorq->errno == 0) + printf(" [recovered in %d tries]", iorq->tries); + + printf("\n"); +} + +/* + * xdc_error: non-fatal error encountered... recover. + * return AOK if resubmitted, return FAIL if this iopb is done + */ +int +xdc_error(xdcsc, iorq, iopb, rqno, comm) + struct xdc_softc *xdcsc; + struct xd_iorq *iorq; + struct xd_iopb *iopb; + int rqno, comm; + +{ + int errno = iorq->errno; + int erract = errno & XD_ERA_MASK; + int oldmode, advance, i; + + if (erract == XD_ERA_RSET) { /* some errors require a reset */ + oldmode = iorq->mode; + iorq->mode = XD_SUB_DONE | (~XD_SUB_MASK & oldmode); + xdcsc->ndone++; + /* make xdc_start ignore us */ + xdc_reset(xdcsc, 1, XD_RSET_NONE, errno, iorq->xd); + iorq->mode = oldmode; + xdcsc->ndone--; + } + /* check for read/write to a sector in bad144 table if bad: redirect + * request to bad144 area */ + + if ((comm == XDCMD_RD || comm == XDCMD_WR) && + (iorq->mode & XD_MODE_B144) == 0) { + advance = iorq->sectcnt - iopb->sectcnt; + XDC_ADVANCE(iorq, advance); + if ((i = isbad(&iorq->xd->dkb, iorq->blockno / iorq->xd->sectpercyl, + (iorq->blockno / iorq->xd->nsect) % iorq->xd->nhead, + iorq->blockno % iorq->xd->nsect)) != -1) { + iorq->mode |= XD_MODE_B144; /* enter bad144 mode & + * redirect */ + iopb->errno = iopb->done = iopb->errs = 0; + iopb->sectcnt = 1; + iopb->cylno = (iorq->xd->ncyl + iorq->xd->acyl) - 2; + /* second to last acyl */ + i = iorq->xd->sectpercyl - 1 - i; /* follow bad144 + * standard */ + iopb->headno = i / iorq->xd->nhead; + iopb->sectno = i % iorq->xd->nhead; + XDC_HWAIT(xdcsc, rqno); + xdc_start(xdcsc, 1); /* resubmit */ + return (XD_ERR_AOK); /* recovered! */ + } + } + + /* + * it isn't a bad144 sector, must be real error! see if we can retry + * it? + */ + if ((iorq->mode & XD_MODE_VERBO) && iorq->lasterror) + xdc_perror(iorq, iopb, 1); /* inform of error state + * change */ + iorq->lasterror = errno; + + if ((erract == XD_ERA_RSET || erract == XD_ERA_HARD) + && iorq->tries < XDC_MAXTRIES) { /* retry? */ + iorq->tries++; + iorq->errno = iopb->errno = iopb->done = iopb->errs = 0; + XDC_HWAIT(xdcsc, rqno); + xdc_start(xdcsc, 1); /* restart */ + return (XD_ERR_AOK); /* recovered! */ + } + + /* failed to recover from this error */ + return (XD_ERR_FAIL); +} + +/* + * xdc_tick: make sure xd is still alive and ticking (err, kicking). + */ +void +xdc_tick(arg) + void *arg; + +{ + struct xdc_softc *xdcsc = arg; + int lcv, s, reset = 0; +#ifdef XDC_DIAG + int wait, run, free, done, whd; + u_char fqc[XDC_MAXIOPB], wqc[XDC_MAXIOPB], mark[XDC_MAXIOPB]; + s = splbio(); + wait = xdcsc->nwait; + run = xdcsc->nrun; + free = xdcsc->nfree; + done = xdcsc->ndone; + bcopy(xdcsc->waitq, wqc, sizeof(wqc)); + bcopy(xdcsc->freereq, fqc, sizeof(fqc)); + splx(s); + if (wait + run + free + done != XDC_MAXIOPB) { + printf("%s: diag: IOPB miscount (got w/f/r/d %d/%d/%d/%d, wanted %d)\n", + xdcsc->sc_dev.dv_xname, wait, free, run, done, XDC_MAXIOPB); + bzero(mark, sizeof(mark)); + printf("FREE: "); + for (lcv = free; lcv > 0; lcv--) { + printf("%d ", fqc[lcv - 1]); + mark[fqc[lcv - 1]] = 1; + } + printf("\nWAIT: "); + lcv = wait; + while (lcv > 0) { + printf("%d ", wqc[whd]); + mark[wqc[whd]] = 1; + whd = (whd + 1) % XDC_MAXIOPB; + lcv--; + } + printf("\n"); + for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) { + if (mark[lcv] == 0) + printf("MARK: running %d: mode %d done %d errs %d errno 0x%x ttl %d buf %x\n", + lcv, xdcsc->reqs[lcv].mode, + xdcsc->iopbase[lcv].done, + xdcsc->iopbase[lcv].errs, + xdcsc->iopbase[lcv].errno, + xdcsc->reqs[lcv].ttl, xdcsc->reqs[lcv].buf); + } + } else + if (done > XDC_MAXIOPB - XDC_SUBWAITLIM) + printf("%s: diag: lots of done jobs (%d)\n", + xdcsc->sc_dev.dv_xname, done); + +#endif +#ifdef XDC_DEBUG + printf("%s: tick: csr 0x%x, w/f/r/d %d/%d/%d/%d\n", + xdcsc->sc_dev.dv_xname, + xdcsc->xdc->xdc_csr, xdcsc->nwait, xdcsc->nfree, xdcsc->nrun, + xdcsc->ndone); + for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) { + if (xdcsc->reqs[lcv].mode) + printf("running %d: mode %d done %d errs %d errno 0x%x\n", + lcv, + xdcsc->reqs[lcv].mode, xdcsc->iopbase[lcv].done, + xdcsc->iopbase[lcv].errs, xdcsc->iopbase[lcv].errno); + } +#endif + + /* reduce ttl for each request if one goes to zero, reset xdc */ + s = splbio(); + for (lcv = 0; lcv < XDC_MAXIOPB; lcv++) { + if (xdcsc->reqs[lcv].mode == 0 || + XD_STATE(xdcsc->reqs[lcv].mode) == XD_SUB_DONE) + continue; + xdcsc->reqs[lcv].ttl--; + if (xdcsc->reqs[lcv].ttl == 0) + reset = 1; + } + if (reset) { + printf("%s: watchdog timeout\n", xdcsc->sc_dev.dv_xname); + xdc_reset(xdcsc, 0, XD_RSET_NONE, XD_ERR_FAIL, NULL); + } + splx(s); + + /* until next time */ + + timeout(xdc_tick, xdcsc, XDC_TICKCNT); +} + +/* + * xdc_ioctlcmd: this function provides a user level interface to the + * controller via ioctl. this allows "format" programs to be written + * in user code, and is also useful for some debugging. we return + * an error code. called at user priority. + */ +int +xdc_ioctlcmd(xd, dev, xio) + struct xd_softc *xd; + dev_t dev; + struct xd_iocmd *xio; + +{ + int s, err, rqno, dummy; + caddr_t dvmabuf = NULL; + struct xdc_softc *xdcsc; + + /* check sanity of requested command */ + + switch (xio->cmd) { + + case XDCMD_NOP: /* no op: everything should be zero */ + if (xio->subfn || xio->dptr || xio->dlen || + xio->block || xio->sectcnt) + return (EINVAL); + break; + + case XDCMD_RD: /* read / write sectors (up to XD_IOCMD_MAXS) */ + case XDCMD_WR: + if (xio->subfn || xio->sectcnt > XD_IOCMD_MAXS || + xio->sectcnt * XDFM_BPS != xio->dlen || xio->dptr == NULL) + return (EINVAL); + break; + + case XDCMD_SK: /* seek: doesn't seem useful to export this */ + return (EINVAL); + + case XDCMD_WRP: /* write parameters */ + return (EINVAL);/* not useful, except maybe drive + * parameters... but drive parameters should + * go via disklabel changes */ + + case XDCMD_RDP: /* read parameters */ + if (xio->subfn != XDFUN_DRV || + xio->dlen || xio->block || xio->dptr) + return (EINVAL); /* allow read drive params to + * get hw_spt */ + xio->sectcnt = xd->hw_spt; /* we already know the answer */ + return (0); + break; + + case XDCMD_XRD: /* extended read/write */ + case XDCMD_XWR: + + switch (xio->subfn) { + + case XDFUN_THD:/* track headers */ + if (xio->sectcnt != xd->hw_spt || + (xio->block % xd->nsect) != 0 || + xio->dlen != XD_IOCMD_HSZ * xd->hw_spt || + xio->dptr == NULL) + return (EINVAL); + xio->sectcnt = 0; + break; + + case XDFUN_FMT:/* NOTE: also XDFUN_VFY */ + if (xio->cmd == XDCMD_XRD) + return (EINVAL); /* no XDFUN_VFY */ + if (xio->sectcnt || xio->dlen || + (xio->block % xd->nsect) != 0 || xio->dptr) + return (EINVAL); + break; + + case XDFUN_HDR:/* header, header verify, data, data ECC */ + return (EINVAL); /* not yet */ + + case XDFUN_DM: /* defect map */ + case XDFUN_DMX:/* defect map (alternate location) */ + if (xio->sectcnt || xio->dlen != XD_IOCMD_DMSZ || + (xio->block % xd->nsect) != 0 || xio->dptr == NULL) + return (EINVAL); + break; + + default: + return (EINVAL); + } + break; + + case XDCMD_TST: /* diagnostics */ + return (EINVAL); + + default: + return (EINVAL);/* ??? */ + } + + /* create DVMA buffer for request if needed */ + + if (xio->dlen) { + dvmabuf = dvma_malloc(xio->dlen); + if (xio->cmd == XDCMD_WR || xio->cmd == XDCMD_XWR) { + if (err = copyin(xio->dptr, dvmabuf, xio->dlen)) { + dvma_free(dvmabuf, xio->dlen); + return (err); + } + } + } + /* do it! */ + + err = 0; + xdcsc = xd->parent; + s = splbio(); + rqno = xdc_cmd(xdcsc, xio->cmd, xio->subfn, xd->xd_drive, xio->block, + xio->sectcnt, dvmabuf, XD_SUB_WAIT); + if (rqno == XD_ERR_FAIL) { + err = EIO; + goto done; + } + xio->errno = xdcsc->reqs[rqno].errno; + xio->tries = xdcsc->reqs[rqno].tries; + XDC_DONE(xdcsc, rqno, dummy); + + if (xio->cmd == XDCMD_RD || xio->cmd == XDCMD_XRD) + err = copyout(dvmabuf, xio->dptr, xio->dlen); + +done: + splx(s); + if (dvmabuf) + dvma_free(dvmabuf, xio->dlen); + return (err); +} + +/* + * xdc_e2str: convert error code number into an error string + */ +char * +xdc_e2str(no) + int no; +{ + switch (no) { + case XD_ERR_FAIL: + return ("Software fatal error"); + case XD_ERR_AOK: + return ("Successful completion"); + case XD_ERR_ICYL: + return ("Illegal cylinder address"); + case XD_ERR_IHD: + return ("Illegal head address"); + case XD_ERR_ISEC: + return ("Illgal sector address"); + case XD_ERR_CZER: + return ("Count zero"); + case XD_ERR_UIMP: + return ("Unimplemented command"); + case XD_ERR_IF1: + return ("Illegal field length 1"); + case XD_ERR_IF2: + return ("Illegal field length 2"); + case XD_ERR_IF3: + return ("Illegal field length 3"); + case XD_ERR_IF4: + return ("Illegal field length 4"); + case XD_ERR_IF5: + return ("Illegal field length 5"); + case XD_ERR_IF6: + return ("Illegal field length 6"); + case XD_ERR_IF7: + return ("Illegal field length 7"); + case XD_ERR_ISG: + return ("Illegal scatter/gather length"); + case XD_ERR_ISPT: + return ("Not enough sectors per track"); + case XD_ERR_ALGN: + return ("Next IOPB address alignment error"); + case XD_ERR_SGAL: + return ("Scatter/gather address alignment error"); + case XD_ERR_SGEC: + return ("Scatter/gather with auto-ECC"); + case XD_ERR_SECC: + return ("Soft ECC corrected"); + case XD_ERR_SIGN: + return ("ECC ignored"); + case XD_ERR_ASEK: + return ("Auto-seek retry recovered"); + case XD_ERR_RTRY: + return ("Soft retry recovered"); + case XD_ERR_HECC: + return ("Hard data ECC"); + case XD_ERR_NHDR: + return ("Header not found"); + case XD_ERR_NRDY: + return ("Drive not ready"); + case XD_ERR_TOUT: + return ("Operation timeout"); + case XD_ERR_VTIM: + return ("VMEDMA timeout"); + case XD_ERR_DSEQ: + return ("Disk sequencer error"); + case XD_ERR_HDEC: + return ("Header ECC error"); + case XD_ERR_RVFY: + return ("Read verify"); + case XD_ERR_VFER: + return ("Fatail VMEDMA error"); + case XD_ERR_VBUS: + return ("VMEbus error"); + case XD_ERR_DFLT: + return ("Drive faulted"); + case XD_ERR_HECY: + return ("Header error/cyliner"); + case XD_ERR_HEHD: + return ("Header error/head"); + case XD_ERR_NOCY: + return ("Drive not on-cylinder"); + case XD_ERR_SEEK: + return ("Seek error"); + case XD_ERR_ILSS: + return ("Illegal sector size"); + case XD_ERR_SEC: + return ("Soft ECC"); + case XD_ERR_WPER: + return ("Write-protect error"); + case XD_ERR_IRAM: + return ("IRAM self test failure"); + case XD_ERR_MT3: + return ("Maintenance test 3 failure (DSKCEL RAM)"); + case XD_ERR_MT4: + return ("Maintenance test 4 failure (header shift reg)"); + case XD_ERR_MT5: + return ("Maintenance test 5 failure (VMEDMA regs)"); + case XD_ERR_MT6: + return ("Maintenance test 6 failure (REGCEL chip)"); + case XD_ERR_MT7: + return ("Maintenance test 7 failure (buffer parity)"); + case XD_ERR_MT8: + return ("Maintenance test 8 failure (disk FIFO)"); + case XD_ERR_IOCK: + return ("IOPB checksum miscompare"); + case XD_ERR_IODM: + return ("IOPB DMA fatal"); + case XD_ERR_IOAL: + return ("IOPB address alignment error"); + case XD_ERR_FIRM: + return ("Firmware error"); + case XD_ERR_MMOD: + return ("Illegal maintenance mode test number"); + case XD_ERR_ACFL: + return ("ACFAIL asserted"); + default: + return ("Unknown error"); + } +} diff --git a/sys/arch/sun3/dev/xdreg.h b/sys/arch/sun3/dev/xdreg.h new file mode 100644 index 00000000000..22397999eda --- /dev/null +++ b/sys/arch/sun3/dev/xdreg.h @@ -0,0 +1,424 @@ +/* $NetBSD: xdreg.h,v 1.1 1995/10/30 20:58:18 gwr Exp $ */ + +/* + * + * Copyright (c) 1995 Charles D. Cranor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles D. Cranor. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * x d r e g . h + * + * this file contains the description of the Xylogics 753/7053's hardware + * data structures. + * + * author: Chuck Cranor <chuck@ccrc.wustl.edu> + */ + +#define XDC_MAXDEV 4 /* max devices per controller */ +#define XDC_RESETUSEC 1000000 /* max time for xdc reset (page 21 says 1sec) */ +#define XDC_MAXIOPB 31 /* max number of iopbs that can be active */ +#define XDC_MAXTIME 4*1000000 /* four seconds before we give up and reset */ +#define XDC_MAXTRIES 4 /* max number of times to retry an operation */ +#define XDC_THROTTLE 32 /* dma throttle */ +#define XDC_INTERLEAVE 0 /* interleave (for format param) */ +#define XDC_DPARAM 0 /* dparam (drive param) XDDP_EC32 or 0 */ + +/* + * xdc device interface + * (lives in VME address space) + */ + +struct xdc { + volatile u_char filler0; + volatile u_char xdc_iopbaddr0; /* iopb byte 0 (LSB) */ + volatile u_char filler1; + volatile u_char xdc_iopbaddr1; /* iopb byte 1 */ + volatile u_char filler2; + volatile u_char xdc_iopbaddr2; /* iopb byte 2 */ + volatile u_char filler3; + volatile u_char xdc_iopbaddr3; /* iopb byte 3 (MSB) */ + volatile u_char filler4; + volatile u_char xdc_iopbamod; /* iopb address modifier */ + volatile u_char filler5; + volatile u_char xdc_csr; /* control and status register */ + volatile u_char filler6; + volatile u_char xdc_f_err; /* fatal error register */ +}; + +/* + * xdc_iopbamod: addressing modes + * When doing DMA, if the maximum address of the buffer is greater than + * 24 bits then you must use the 32 bit mode. Note that on many systems + * (e.g. sun-4/300) DVMA space is smaller than 24 bits, so there is no + * need for the 32 bit mode. However, the 32-bit mode hooks are in + * the driver in case it ever gets ported to an environment that needs it. + */ + +#define XDC_ADDRMOD 0x3d /* standard address modifer, 24 bit max */ +#define XDC_ADDRMOD32 0x0d /* 32 bit version above */ + +/* + * xdc_csr + */ + +#define XDC_RMAINTMD 0x80 /* reserved maintenance mode (write) */ +#define XDC_BUSY 0x80 /* busy (read) */ +#define XDC_F_ERROR 0x40 /* fatal error (read) */ +#define XDC_MAINTMOD 0x20 /* maintenance mode (read/write) */ +#define XDC_RESET 0x08 /* soft reset (read/write) */ +#define XDC_ADDIOPB 0x04 /* add iopb/add pending (write) */ +#define XDC_ADDING 0x04 /* iopb add is pending (read) */ +#define XDC_CLRRIO 0x02 /* clear RIO (remove iopb) request (write) */ +#define XDC_REMIOPB 0x02 /* remove iopb (read) */ +#define XDC_RBUSYSEM 0x01 /* register busy semaphore (read/write) */ + +/* + * Input/Output Parameter Block (iopb) + * + * all controller commands are done via iopb's. to start a command you + * must do this: + * [1] allocate space in DVMA space for the iopb + * [2] fill out all the fields of the iopb + * [3] check to see if controller can accept an iopb (XDC_ADDING bit clear) + * [4] put the DVMA address of the iopb in the xdc registers (in vme space) + * [5] set the XDC_ADDIOPB bit in the xdc csr + * [6] <command started> + * + * when the controller is done with a command it may interrupt (if you + * ask it to) and it will set the XDC_REMIOPB bit in the csr. the address + * of the finished iopb will be in the xdc registers. after that is + * read, set the XDC_CLRRIO to clear the iopb out of memory. + * + * the format of the iopb is described in section 4 of the manual. + */ + +struct xd_iopb { + /* section 4.1.1: byte 0 */ + volatile u_char errs:1; /* error summary bit, only valid if + "done" is set. must clear "done" + and "errs" bits before starting an + operation */ + volatile u_char done:1; /* "done" bit */ + volatile u_char chen:1; /* chain enable, "next iopb" is valid, + note xd returns one iopb at a time */ + volatile u_char sgm:1; /* scatter/gather mode */ + volatile u_char comm:4; /* command number (see table 4-2) */ +#define XDCMD_NOP 0x0 /* no-op */ +#define XDCMD_WR 0x1 /* write */ +#define XDCMD_RD 0x2 /* read */ +#define XDCMD_SK 0x3 /* seek */ +#define XDCMD_RST 0x4 /* drive reset */ +#define XDCMD_WRP 0x5 /* write params */ +#define XDCMD_RDP 0x6 /* read params */ +#define XDCMD_XWR 0x7 /* extended write */ +#define XDCMD_XRD 0x8 /* extended read */ +#define XDCMD_TST 0x9 /* diagnostic tests */ + /* 0xa to 0xf are reserved */ + /* section 4.1.2: byte 1 */ + volatile u_char errno; /* status byte 1 (non-zero if error) */ + /* section 4.1.3: byte 2 */ + volatile u_char status; /* status byte 2 (see below) */ +#define XDST_SR 0x40 /* slipped revolution */ +#define XDST_CSE 0x20 /* count sectors executed */ +#define XDST_WRPT 0x10 /* write protected drive */ +#define XDST_DFLT 0x08 /* disk fault */ +#define XDST_SKER 0x04 /* seek error: >max, or timeout */ +#define XDST_ONCL 0x02 /* on-cylinder */ +#define XDST_DRDY 0x01 /* drive is ready! */ + /* section 4.1.4: byte 3 */ + volatile u_char istat; /* internal status: reserved for xylogics */ + /* section 4.1.5: byte 4 */ + volatile u_char subfun; /* sub-function of command (see below) */ +#define XDFUN_R 0x00 /* XDCMD_SK: report current addr */ +#define XDFUN_SR 0x01 /* XDCMD_SK: seek and report addr */ +#define XDFUN_SRI 0x02 /* XDCMD_SK: start seek, report comp imm */ +#define XDFUN_CTL 0x00 /* XDCMD_{WRP,RDP}: controller params */ +#define XDFUN_DRV 0x80 /* XDCMD_{WRP,RDP}: drive params */ +#define XDFUN_FMT 0x81 /* XDCMD_{WRP,RDP}: format params,XWR form.*/ +#define XDFUN_STX 0xa0 /* XDCMD_RDP: read drive status extended */ +#define XDFUN_THD 0x80 /* XDCMD_{XWR,XRD}: track headers */ +#define XDFUN_VFY 0x81 /* XDCMD_XRD: verify data */ +#define XDFUN_HDR 0x82 /* XDCMD_{XWR,XRD}: header, verify,data, ecc*/ +#define XDFUN_DM 0xa0 /* XDCMD_{XWR,XRD}: defect map */ +#define XDFUN_DMX 0xa1 /* XDCMD_{XWR,XRD}: defect map extended */ + /* section 4.1.6: byte 5 */ + volatile u_char fixd:1; /* fixed media (vs removeable) */ + volatile u_char reserved1:4; /* reserved */ + volatile u_char unit:3; /* unit number */ + /* note: 6 to 13 are overloaded (see below) */ + /* section 4.1.7: byte 6 */ + volatile u_char lll:5; /* linked list length */ + volatile u_char intl:3; /* interrupt level */ + /* section 4.1.8: byte 7 */ + volatile u_char intr_vec; /* interrupt vector */ + /* section 4.1.9: bytes 8 and 9 */ + volatile u_short sectcnt; /* sector count (# to xfer) */ + /* section 4.1.10: byte a and b */ + volatile u_short cylno; /* cylinder number */ + /* section 4.1.11: byte c */ + volatile u_char headno; /* head number */ + /* section 4.1.12: byte d */ + volatile u_char sectno; /* sector number */ + /* section 4.1.13: byte e */ + volatile u_char addrmod; /* addr modifier (bits 7,6 must be zero) */ + /* section 4.1.14: byte f */ + volatile u_char naddrmod; /* next (in chain) address iobp ad. modifer */ + /* section 4.1.15: bytes 0x10 to 0x13 */ + volatile u_long daddr; /* DMA data address */ + /* section 4.1.16: bytes 0x14 to 0x17 */ + volatile u_long nextiopb; /* next iopb (in chain) address */ + /* section 4.1.17: bytes 0x18, 0x19 */ + volatile u_short cksum; /* iopb checksum */ + /* section 4.1.18: bytes 0x1a, 0x1b */ + volatile u_short eccpattern; /* ECC pattern word (ecc mode 0) */ + /* section 4.1.19: bytes 0x1c, 0x1d */ + volatile u_short eccoffword; /* ECC offset word (ecc mode 0) */ +}; + +/* + * some commands overload bytes 6 to 0x13 of the iopb with different meanings. + * these commands include: + * section 4.2: controller parameters + * section 4.3: drive parameters + * sectino 4.4: format parameters + * + * note that the commands that overload the iopb are not part of the + * "critical data path" of the driver. so, we handle them by defining + * alternate iopb structures for these commands... it only costs us an + * extra pointer. + */ + +/* + * controller parameters iopb: redefines bytes: 8 -> 0xe, 0x10 -> 0x13 + */ + +struct xd_iopb_ctrl { + volatile u_char same[8]; /* same as xd_iopb */ + /* section 4.2.1: byte 8 */ + volatile u_char param_a; /* param A (see below) */ +#define XDPA_AUD 0x80 /* auto-update iopb fields when cmd done */ +#define XDPA_TMOD 0x40 /* long-word transfer mode (vs word) */ +#define XDPA_DACF 0x20 /* ignore vme ACFAIL signal */ +#define XDPA_ICS 0x10 /* checksum check (adds 100usec per xfer) */ +#define XDPA_EDT 0x08 /* enable on-board DMA timeout timer */ +#define XDPA_NPRM 0x04 /* enable VME non-priv request mode */ + /* rest must be zero */ + /* section 4.2.2: byte 9 */ + volatile u_char param_b; /* param B (see below) */ +#define XDPB_TDT 0xc0 /* throttle dead time (see 8.11, below) */ +#define XDPB_ROR 0x10 /* release on request */ +#define XDPB_DRA 0x01 /* disable read ahead */ + /* TDT values: */ +#define XDPB_TDT_0USEC 0x00 /* no TDT */ +#define XDPB_TDT_3_2USEC 0x40 /* 3.2 usec */ +#define XDPB_TDT_6_4USEC 0x80 /* 6.4 usec */ +#define XDPB_TDT_12_8USEC 0xc0 /* 12.8 usec */ + /* section 4.2.3: byte a */ + volatile u_char param_c; /* param C (see below) */ +#define XDPC_OVS 0x80 /* over-lapped seek */ +#define XDPC_COP 0x40 /* command optimiziation (elevator alg.) */ +#define XDPC_ASR 0x10 /* auto-seek retry */ +#define XDPC_RBC 0x04 /* retry before correction if ECC error */ +#define XDPC_ECCM 0x03 /* ECC mode (0, 1, and 2) */ +#define XDPC_ECC0 0x00 /* ECC mode 0 */ +#define XDPC_ECC1 0x01 /* ECC mode 1 */ +#define XDPC_ECC2 0x02 /* ECC mode 2 */ + /* section 4.2.4: byte b */ + volatile u_char throttle; /* max dma xfers per master (0==256) */ + /* section 4.2.5: byte c */ + volatile u_char eprom_lvl; /* EPROM release level */ + volatile u_char delay; /* delay (see note below) */ + /* section 4.2.6: byte e */ + volatile u_char ctype; /* controller type */ +#define XDCT_753 0x53 /* xylogic 753/7053 */ + volatile u_char same2; /* byte f: same as xd_iopb */ + /* section 4.2.7: byte 0x10, 0x11 */ + volatile u_short eprom_partno; /* eprom part number */ + /* section 4.2.8: byte 12 */ + volatile u_char eprom_rev; /* eprom revision number */ +}; + +/* + * Note on byte 0xd ("delay"): This byte is not documented in the + * Xylogics manual. However, I contacted Xylogics and found out what + * it does. The controller sorts read commands into groups of + * contiguous sectors. After it processes a group of contiguous + * sectors rather than immediately going on to the next group of + * contiguous sectors, the controller can delay for a certain amount + * of time in hopes of getting another cluster of reads in the same + * area of the disk (thus avoiding a long seek). Byte 0xd controls + * how long it waits before giving up and going on and doing the next + * contiguous cluster. + * + * it is unclear what unit the delay is in, but it looks like sun + * uses the value "20" for sun3's, and "0" for sparc, except for the + * 4/300 (where it is "4"). [see /sys/sundev/xd_conf.c on any 4.1.3 + * machine for how sun configures its controller...] + */ + +#define XDC_DELAY_SUN3 20 +#define XDC_DELAY_4_300 4 +#define XDC_DELAY_SPARC 0 + +/* + * drive parameters iopb: redefines bytes: 6, 8, 9, a, b, c, d, e + */ + +struct xd_iopb_drive { + volatile u_char same[6]; /* same as xd_iopb */ + /* section 4.3.1: byte 6 */ + volatile u_char dparam_ipl; /* drive params | interrupt level */ +#define XDDP_EC32 0x10 /* 32 bit ECC mode */ + volatile u_char same1; /* byte 7: same */ + /* section 4.3.2: byte 8 */ + volatile u_char maxsect; /* max sector/last head (<= byte d) */ + /* section 4.3.3: byte 9 */ + volatile u_char headoff; /* head offset */ + /* section 4.3.4: bytes 0xa, 0xb */ + volatile u_short maxcyl; /* max cyl (zero based!) */ + /* section 4.3.5: byte 0xc */ + volatile u_char maxhead; /* max head (zero based!) */ + /* section 4.3.6: byte 0xd */ + volatile u_char maxsector; /* max sector of disk (zero based!) */ + /* section 4.3.7: byte 0xe */ + volatile u_char sectpertrk; /* sectors per track, not zero base, no runt*/ +}; + +/* + * format parameters iopb: redefines bytes: 6, 8, 9, a, b, c, d, 0x10, 0x11 + */ + +struct xd_iopb_format { + volatile u_char same[6]; /* smae as xd_iopb */ + /* section 4.4.1: byte 6 */ + volatile u_char interleave_ipl;/* (interleave << 4) | interupt level */ + /* interleave ratio 1:1 to 16:1 */ + volatile u_char same1; /* byte 7: same */ + /* section 4.4.2: byte 8 */ + volatile u_char field1; /* >= 1, xylogic says should be 1 */ +#define XDFM_FIELD1 0x01 /* xylogic value */ + /* section 4.4.3: byte 9 */ + volatile u_char field2; /* >0, field1+field2 <= 255 */ +#define XDFM_FIELD2 0x0a /* xylogic value */ + /* section 4.4.4: byte a */ + volatile u_char field3; /* >= field1+field2 */ +#define XDFM_FIELD3 0x1b /* xylogic value */ + /* section 4.4.5: byte b */ + volatile u_char field4; /* field4 */ +#define XDFM_FIELD4 0x14 /* xylogic value */ + /* section 4.4.6: bytes 0xc, 0xd */ + volatile u_short bytespersec; /* bytes per sector */ +#define XDFM_BPS 0x200 /* must be 512! */ + volatile u_char same2[2]; /* bytes e, f */ + /* section 4.4.7: byte 0x10 */ + volatile u_char field6; /* field 6 */ +#define XDFM_FIELD6 0x0a /* xylogic value */ + /* section 4.4.8: byte 0x11 */ + volatile u_char field7; /* field 7, >= 1 */ +#define XDFM_FIELD7 0x03 /* xylogic value */ +}; + + +/* + * errors: errors come from either the fatal error register or the + * iopb + */ + +#define XD_ERA_MASK 0xf0 /* error action mask */ +#define XD_ERA_PROG 0x10 /* program error */ +#define XD_ERA_PRG2 0x20 /* program error */ +#define XD_ERA_SOFT 0x30 /* soft error: we recovered */ +#define XD_ERA_HARD 0x40 /* hard error: retry */ +#define XD_ERA_RSET 0x60 /* hard error: reset, then retry */ +#define XD_ERA_WPRO 0x90 /* write protected */ + +/* software error codes */ +#define XD_ERR_FAIL 0xff /* general total failure */ +/* no error */ +#define XD_ERR_AOK 0x00 /* success */ +/* non-retryable programming error */ +#define XD_ERR_ICYL 0x10 /* illegal cyl */ +#define XD_ERR_IHD 0x11 /* illegal head */ +#define XD_ERR_ISEC 0x12 /* illegal sector */ +#define XD_ERR_CZER 0x13 /* count zero */ +#define XD_ERR_UIMP 0x14 /* unknown command */ +#define XD_ERR_IF1 0x15 /* illegal field 1 */ +#define XD_ERR_IF2 0x16 /* illegal field 2 */ +#define XD_ERR_IF3 0x17 /* illegal field 3 */ +#define XD_ERR_IF4 0x18 /* illegal field 4 */ +#define XD_ERR_IF5 0x19 /* illegal field 5 */ +#define XD_ERR_IF6 0x1a /* illegal field 6 */ +#define XD_ERR_IF7 0x1b /* illegal field 7 */ +#define XD_ERR_ISG 0x1c /* illegal scatter/gather */ +#define XD_ERR_ISPT 0x1d /* not enough sectors per track */ +#define XD_ERR_ALGN 0x1e /* next iopb allignment error */ +#define XD_ERR_SGAL 0x1f /* scatter gather address alignment error */ +#define XD_ERR_SGEC 0x20 /* scatter gather with auto ECC */ +/* successfully recovered soft errors */ +#define XD_ERR_SECC 0x30 /* soft ecc corrected */ +#define XD_ERR_SIGN 0x31 /* ecc ignored */ +#define XD_ERR_ASEK 0x32 /* auto-seek retry recovered */ +#define XD_ERR_RTRY 0x33 /* soft retry recovered */ +/* hard errors: please retry */ +#define XD_ERR_HECC 0x40 /* hard data ECC */ +#define XD_ERR_NHDR 0x41 /* header not found */ +#define XD_ERR_NRDY 0x42 /* drive not ready */ +#define XD_ERR_TOUT 0x43 /* timeout */ +#define XD_ERR_VTIM 0x44 /* VME DMA timeout */ +#define XD_ERR_DSEQ 0x45 /* disk sequencer error */ +#define XD_ERR_HDEC 0x48 /* header ECC error */ +#define XD_ERR_RVFY 0x49 /* ready verify */ +#define XD_ERR_VFER 0x4a /* fatal VME DMA error */ +#define XD_ERR_VBUS 0x4b /* VME bus error */ +/* hard error: reset and retry */ +#define XD_ERR_DFLT 0x60 /* drive fault */ +#define XD_ERR_HECY 0x61 /* header error/cyl */ +#define XD_ERR_HEHD 0x62 /* header error/head */ +#define XD_ERR_NOCY 0x63 /* not on cylinder */ +#define XD_ERR_SEEK 0x64 /* seek error */ +/* fatal hardware error */ +#define XD_ERR_ILSS 0x70 /* illegal sector size */ +/* misc */ +#define XD_ERR_SEC 0x80 /* soft ecc */ +/* requires manual intervention */ +#define XD_ERR_WPER 0x90 /* write protected */ +/* FATAL errors */ +#define XD_ERR_IRAM 0xe1 /* IRAM self test failed */ +#define XD_ERR_MT3 0xe3 /* maint test 3 failed (DSKCEL RAM) */ +#define XD_ERR_MT4 0xe4 /* maint test 4 failed (Header shift reg) */ +#define XD_ERR_MT5 0xe5 /* maint test 5 failed (VMEDMA regs) */ +#define XD_ERR_MT6 0xe6 /* maint test 6 failed (REGCEL chip) */ +#define XD_ERR_MT7 0xe7 /* maint test 7 failed (buff. parity) */ +#define XD_ERR_MT8 0xe8 /* maint test 8 failed (fifo) */ +#define XD_ERR_IOCK 0xf0 /* iopb checksume miscompare */ +#define XD_ERR_IODM 0xf1 /* iopb dma fatal */ +#define XD_ERR_IOAL 0xf2 /* iopb allignment error */ +#define XD_ERR_FIRM 0xf3 /* firmware error n*/ +#define XD_ERR_MMOD 0xf5 /* illegal maint mode test number */ +#define XD_ERR_ACFL 0xf6 /* ACFAIL asserted */ diff --git a/sys/arch/sun3/dev/xdvar.h b/sys/arch/sun3/dev/xdvar.h new file mode 100644 index 00000000000..918c22d1f3d --- /dev/null +++ b/sys/arch/sun3/dev/xdvar.h @@ -0,0 +1,167 @@ +/* $NetBSD: xdvar.h,v 1.1 1995/10/30 20:58:19 gwr Exp $ */ + +/* + * + * Copyright (c) 1995 Charles D. Cranor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles D. Cranor. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * x d v a r . h + * + * this file defines the software structure we use to control the + * 753/7053. + * + * author: Chuck Cranor <chuck@ccrc.wustl.edu> + */ + +/* + * i/o request: wrapper for hardware's iopb data structure + */ + +struct xd_iorq { + struct xd_iopb *iopb; /* address of matching iopb */ + struct xdc_softc *xdc; /* who we are working with */ + struct xd_softc *xd; /* which disk */ + int ttl; /* time to live */ + int mode; /* current mode (state+other data) */ + int tries; /* number of times we have tried it */ + int errno; /* error number if we fail */ + int lasterror; /* last error we got */ + int blockno; /* starting block no for this xfer */ + int sectcnt; /* number of sectors in xfer */ + char *dbuf; /* KVA of data buffer (advances) */ + char *dbufbase; /* base of dbuf */ + struct buf *buf; /* for NORM */ +}; + +/* + * state + */ + +#define XD_SUB_MASK 0xf0 /* mask bits for state */ +#define XD_SUB_FREE 0x00 /* free */ +#define XD_SUB_NORM 0x10 /* normal I/O request */ +#define XD_SUB_WAIT 0x20 /* normal I/O request in the + context of a process */ +#define XD_SUB_POLL 0x30 /* polled mode */ +#define XD_SUB_DONE 0x40 /* not active, but can't be free'd yet */ +#define XD_SUB_NOQ 0x50 /* don't queue, just submit (internal) */ + +#define XD_STATE(X) ((X) & XD_SUB_MASK) /* extract state from mode */ +#define XD_NEWSTATE(OLD, NEW) (((OLD) & ~XD_SUB_MASK) |(NEW)) /* new state */ + + +/* + * other mode data + */ + +#define XD_MODE_VERBO 0x08 /* print error messages */ +#define XD_MODE_B144 0x04 /* handling a bad144 sector */ + + +/* + * software timers and flags + */ + +#define XDC_SUBWAITLIM 4 /* max number of "done" IOPBs there can be + where we still allow a SUB_WAIT command */ +#define XDC_TICKCNT (5*hz) /* call xdc_tick on this interval (5 sec) */ +#define XDC_MAXTTL 2 /* max number of xd ticks to live */ +#define XDC_NOUNIT (-1) /* for xdcmd: no unit number */ + +/* + * a "xd_softc" structure contains per-disk state info. + */ + +struct xd_softc { + struct device sc_dev; /* device struct, reqd by autoconf */ + struct dkdevice sc_dk; /* dkdevice: hook for iostat */ + struct xdc_softc *parent; /* parent */ + u_short flags; /* flags */ + u_short state; /* device state */ + int xd_drive; /* unit number */ + /* geometry */ + u_short ncyl, acyl, pcyl; /* number of cyl's */ + u_short sectpercyl; /* nhead*nsect */ + u_char nhead; /* number of heads */ + u_char nsect; /* number of sectors per track */ + u_char hw_spt; /* as above, but includes spare sectors */ + struct dkbad dkb; /* bad144 sectors */ +}; + + +/* + * flags + */ + +#define XD_WLABEL 0x0001 /* write label */ +/* + * state + */ + +#define XD_DRIVE_UNKNOWN 0 /* never talked to it */ +#define XD_DRIVE_ATTACHING 1 /* attach in progress */ +#define XD_DRIVE_NOLABEL 2 /* drive on-line, no label */ +#define XD_DRIVE_ONLINE 3 /* drive is on-line */ + +/* + * a "xdc_softc" structure contains per-disk-controller state info, + * including a list of active controllers. + */ + +struct xdc_softc { + struct device sc_dev; /* device struct, reqd by autoconf */ + struct evcnt sc_intrcnt; /* event counter (for vmstat -i) */ + + struct xdc *xdc; /* vaddr of vme registers */ + + struct xd_softc *sc_drives[XDC_MAXDEV]; /* drives on this controller */ + int ipl; /* interrupt level */ + int vector; /* interrupt vector */ + + struct xd_iorq *reqs; /* i/o requests */ + struct xd_iopb *iopbase; /* iopb base addr (maps iopb->iorq) */ + struct xd_iopb *dvmaiopb; /* iopb base in DVMA space, not kvm */ + struct buf sc_wq; /* queue'd IOPBs for this controller */ + char freereq[XDC_MAXIOPB]; /* free list (stack) */ + char waitq[XDC_MAXIOPB]; /* wait queue */ + char nfree; /* number of iopbs free */ + char nrun; /* number running */ + char nwait; /* number of waiting iopbs */ + char ndone; /* number of done IORQs */ + char waithead; /* head of queue */ + char waitend; /* end of queue */ +}; + +/* + * reset blast modes + */ + +#define XD_RSET_NONE (-1) /* restart all requests */ +#define XD_RSET_ALL (-2) /* don't restart anything */ diff --git a/sys/arch/sun3/dev/xio.h b/sys/arch/sun3/dev/xio.h new file mode 100644 index 00000000000..d1f03a25e52 --- /dev/null +++ b/sys/arch/sun3/dev/xio.h @@ -0,0 +1,65 @@ +/* $NetBSD: xio.h,v 1.1 1995/10/30 20:58:20 gwr Exp $ */ + +/* + * + * Copyright (c) 1995 Charles D. Cranor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles D. Cranor. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * x i o . h + * + * this file defines the software structure we use to ioctl the + * 753/7053. this interface isn't set in stone and may (or may not) + * need adjustment. + * + * author: Chuck Cranor <chuck@ccrc.wustl.edu> + */ + +/* + * xylogic ioctl interface + */ + +struct xd_iocmd { + u_char cmd; /* in: command number */ + u_char subfn; /* in: subfunction number */ + u_char errno; /* out: error number */ + u_char tries; /* out: number of tries */ + u_short sectcnt; /* in,out: sector count (hw_spt on read drive param) */ + u_short dlen; /* in: length of data buffer (good sanity check) */ + u_long block; /* in: block number */ + caddr_t dptr; /* in: data buffer to do I/O from */ +}; + +#ifndef DIOSXDCMD +#define DIOSXDCMD _IOWR('x', 101, struct xd_iocmd) /* do xd command */ +#endif + +#define XD_IOCMD_MAXS 16 /* max number of sectors you can do */ +#define XD_IOCMD_HSZ 4 /* size of one header */ +#define XD_IOCMD_DMSZ 24 /* defect map size */ diff --git a/sys/arch/sun3/dev/xy.c b/sys/arch/sun3/dev/xy.c new file mode 100644 index 00000000000..4895fd1ce9d --- /dev/null +++ b/sys/arch/sun3/dev/xy.c @@ -0,0 +1,2130 @@ +/* $NetBSD: xy.c,v 1.1 1995/10/30 20:58:21 gwr Exp $ */ + +/* + * + * Copyright (c) 1995 Charles D. Cranor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles D. Cranor. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * + * 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 + * + * author: Chuck Cranor <chuck@ccrc.wustl.edu> + * id: $Id: xy.c,v 1.1 1995/11/01 17:24:25 deraadt Exp $ + * started: 14-Sep-95 + * references: [1] Xylogics Model 753 User's Manual + * part number: 166-753-001, Revision B, May 21, 1988. + * "Your Partner For Performance" + * [2] other NetBSD disk device drivers + * [3] Xylogics Model 450 User's Manual + * part number: 166-017-001, Revision B, 1983. + * [4] Addendum to Xylogics Model 450 Disk Controller User's + * Manual, Jan. 1985. + * [5] The 451 Controller, Rev. B3, September 2, 1986. + * [6] David Jones <dej@achilles.net>'s unfinished 450/451 driver + * + */ + +#undef XYC_DEBUG /* full debug */ +#undef XYC_DIAG /* extra sanity checks */ +#if defined(DIAGNOSTIC) && !defined(XYC_DIAG) +#define XYC_DIAG /* link in with master DIAG option */ +#endif + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/conf.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <sys/buf.h> +#include <sys/uio.h> +#include <sys/malloc.h> +#include <sys/device.h> +#include <sys/disklabel.h> +#include <sys/disk.h> +#include <sys/syslog.h> +#include <sys/dkbad.h> +#include <vm/vm.h> +#include <vm/vm_kern.h> + +#include <machine/autoconf.h> +#include <machine/sun_disklabel.h> +#include <machine/dvma.h> + +#include <sun3/dev/xyreg.h> +#include <sun3/dev/xyvar.h> +#include <sun3/dev/xio.h> + +/* + * macros + */ + +/* + * XYC_GO: start iopb ADDR (DVMA addr in a u_long) on XYC + */ +#define XYC_GO(XYC, ADDR) { \ + (XYC)->xyc_addr_lo = ((ADDR) & 0xff); \ + (ADDR) = ((ADDR) >> 8); \ + (XYC)->xyc_addr_hi = ((ADDR) & 0xff); \ + (ADDR) = ((ADDR) >> 8); \ + (XYC)->xyc_reloc_lo = ((ADDR) & 0xff); \ + (ADDR) = ((ADDR) >> 8); \ + (XYC)->xyc_reloc_hi = (ADDR); \ + (XYC)->xyc_csr |= XYC_GBSY; /* go! */ \ +} + +/* + * XYC_DONE: don't need IORQ, get error code and free (done after xyc_cmd) + */ + +#define XYC_DONE(SC,ER) { \ + if ((ER) == XY_ERR_AOK) { \ + (ER) = (SC)->ciorq->errno; \ + (SC)->ciorq->mode = XY_SUB_FREE; \ + wakeup((SC)->ciorq); \ + } \ + } + +/* + * XYC_ADVANCE: advance iorq's pointers by a number of sectors + */ + +#define XYC_ADVANCE(IORQ, N) { \ + if (N) { \ + (IORQ)->sectcnt -= (N); \ + (IORQ)->blockno += (N); \ + (IORQ)->dbuf += ((N)*XYFM_BPS); \ + } \ +} + +/* + * note - addresses you can sleep on: + * [1] & of xy_softc's "state" (waiting for a chance to attach a drive) + * [2] & an iorq (waiting for an XY_SUB_WAIT iorq to finish) + */ + + +/* + * function prototypes + * "xyc_*" functions are internal, all others are external interfaces + */ + +/* internals */ +struct xy_iopb *xyc_chain __P((struct xyc_softc *, struct xy_iorq *)); +int xyc_cmd __P((struct xyc_softc *, int, int, int, int, int, char *, int)); +char *xyc_e2str __P((int)); +int xyc_entoact __P((int)); +int xyc_error __P((struct xyc_softc *, struct xy_iorq *, + struct xy_iopb *, int)); +int xyc_ioctlcmd __P((struct xy_softc *, dev_t dev, struct xd_iocmd *)); +void xyc_perror __P((struct xy_iorq *, struct xy_iopb *, int)); +int xyc_piodriver __P((struct xyc_softc *, struct xy_iorq *)); +int xyc_remove_iorq __P((struct xyc_softc *)); +int xyc_reset __P((struct xyc_softc *, int, struct xy_iorq *, int, + struct xy_softc *)); +inline void xyc_rqinit __P((struct xy_iorq *, struct xyc_softc *, + struct xy_softc *, int, u_long, int, + caddr_t, struct buf *)); +void xyc_rqtopb __P((struct xy_iorq *, struct xy_iopb *, int, int)); +int xyc_start __P((struct xyc_softc *, struct xy_iorq *)); +int xyc_startbuf __P((struct xyc_softc *, struct xy_softc *, struct buf *)); +int xyc_submit_iorq __P((struct xyc_softc *, struct xy_iorq *, int)); +void xyc_tick __P((void *)); +int xyc_unbusy __P((struct xyc *, int)); +int xyc_xyreset __P((struct xyc_softc *, struct xy_softc *)); + +/* machine interrupt hook */ +int xycintr __P((void *)); + +/* {b,c}devsw */ +int xyclose __P((dev_t, int, int)); +int xydump __P((dev_t)); +int xyioctl __P((dev_t, u_long, caddr_t, int, struct proc *)); +int xyopen __P((dev_t, int, int)); +int xyread __P((dev_t, struct uio *)); +int xywrite __P((dev_t, struct uio *)); +int xysize __P((dev_t)); +void xystrategy __P((struct buf *)); + +/* autoconf */ +int xycmatch __P((struct device *, void *, void *)); +void xycattach __P((struct device *, struct device *, void *)); +int xymatch __P((struct device *, void *, void *)); +void xyattach __P((struct device *, struct device *, void *)); + +static void xydummystrat __P((struct buf *)); +int xygetdisklabel __P((struct xy_softc *, void *)); + +/* + * cfdrivers: device driver interface to autoconfig + */ + +struct cfdriver xyccd = { + NULL, "xyc", xycmatch, xycattach, DV_DULL, sizeof(struct xyc_softc) +}; + +struct cfdriver xycd = { + NULL, "xy", xymatch, xyattach, DV_DISK, sizeof(struct xy_softc) +}; + +struct xyc_attach_args { /* this is the "aux" args to xyattach */ + int driveno; /* unit number */ + char *dvmabuf; /* scratch buffer for reading disk label */ + int fullmode; /* submit mode */ + int booting; /* are we booting or not? */ +}; + +/* + * dkdriver + */ + +struct dkdriver xydkdriver = { xystrategy }; + +/* + * start: disk label fix code (XXX) + */ + +static void *xy_labeldata; + +static void +xydummystrat(bp) + struct buf *bp; +{ + if (bp->b_bcount != XYFM_BPS) + panic("xydummystrat"); + bcopy(xy_labeldata, bp->b_un.b_addr, XYFM_BPS); + bp->b_flags |= B_DONE; + bp->b_flags &= ~B_BUSY; +} + +int +xygetdisklabel(xy, b) + struct xy_softc *xy; + void *b; +{ + char *err; + struct sun_disklabel *sdl; + + /* We already have the label data in `b'; setup for dummy strategy */ + xy_labeldata = b; + + /* Required parameter for readdisklabel() */ + xy->sc_dk.dk_label.d_secsize = XYFM_BPS; + + err = readdisklabel(MAKEDISKDEV(0, xy->sc_dev.dv_unit, RAW_PART), + xydummystrat, + &xy->sc_dk.dk_label, &xy->sc_dk.dk_cpulabel); + if (err) { + printf("%s: %s\n", xy->sc_dev.dv_xname, err); + return(XY_ERR_FAIL); + } + + /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */ + sdl = (struct sun_disklabel *)xy->sc_dk.dk_cpulabel.cd_block; + if (sdl->sl_magic == SUN_DKMAGIC) + xy->pcyl = sdl->sl_pcyl; + else { + printf("%s: WARNING: no `pcyl' in disk label.\n", + xy->sc_dev.dv_xname); + xy->pcyl = xy->sc_dk.dk_label.d_ncylinders + + xy->sc_dk.dk_label.d_acylinders; + printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n", + xy->sc_dev.dv_xname, xy->pcyl); + } + + xy->ncyl = xy->sc_dk.dk_label.d_ncylinders; + xy->acyl = xy->sc_dk.dk_label.d_acylinders; + xy->nhead = xy->sc_dk.dk_label.d_ntracks; + xy->nsect = xy->sc_dk.dk_label.d_nsectors; + xy->sectpercyl = xy->nhead * xy->nsect; + xy->sc_dk.dk_label.d_secsize = XYFM_BPS; /* not handled by + * sun->bsd */ + return(XY_ERR_AOK); +} + +/* + * end: disk label fix code (XXX) + */ + +/* + * a u t o c o n f i g f u n c t i o n s + */ + +/* + * xycmatch: determine if xyc is present or not. we do a + * soft reset to detect the xyc. + */ + +int xycmatch(parent, match, aux) + struct device *parent; + void *match, *aux; +{ + struct cfdata *cf = match; + struct confargs *ca = aux; + int x; + + if (ca->ca_bustype != BUS_VME16) + return (0); + + /* Default interrupt priority always splbio==2 */ + if (ca->ca_intpri == -1) + ca->ca_intpri = 2; + + x = bus_peek(ca->ca_bustype, ca->ca_paddr + 5, 1); + if (x == -1) + return (0); + + return (1); +} + +/* + * xycattach: attach controller + */ +void +xycattach(parent, self, aux) + struct device *parent, *self; + void *aux; + +{ + struct xyc_softc *xyc = (void *) self; + struct confargs *ca = aux; + struct xyc_attach_args xa; + int lcv, err, pri, res, pbsz; + void *tmp, *tmp2; + u_long ultmp; + + /* get addressing and intr level stuff from autoconfig and load it + * into our xyc_softc. */ + + xyc->xyc = (struct xyc *) + bus_mapin(ca->ca_bustype, ca->ca_paddr, sizeof(struct xyc)); + xyc->ipl = ca->ca_intpri; + xyc->vector = ca->ca_intvec; + xyc->no_ols = 0; /* XXX should be from config */ + + for (lcv = 0; lcv < XYC_MAXDEV; lcv++) + xyc->sc_drives[lcv] = (struct xy_softc *) 0; + + /* + * allocate and zero buffers + * check boundaries of the KVA's ... all IOPBs must reside in + * the same 64K region. + */ + + pbsz = XYC_MAXIOPB * sizeof(struct xy_iopb); + tmp = tmp2 = (struct xy_iopb *) dvma_malloc(pbsz); /* KVA */ + ultmp = (u_long) tmp; + if ((ultmp & 0xffff0000) != ((ultmp + pbsz) & 0xffff0000)) { + tmp = (struct xy_iopb *) dvma_malloc(pbsz); /* retry! */ + dvma_free(tmp2, pbsz); + ultmp = (u_long) tmp; + if ((ultmp & 0xffff0000) != ((ultmp + pbsz) & 0xffff0000)) { + printf("%s: can't alloc IOPB mem in 64K\n", + xyc->sc_dev.dv_xname); + return; + } + } + xyc->iopbase = tmp; + bzero(xyc->iopbase, pbsz); + xyc->dvmaiopb = (struct xy_iopb *) + dvma_kvtopa((long) xyc->iopbase, BUS_VME16); + xyc->reqs = (struct xy_iorq *) + malloc(XYC_MAXIOPB * sizeof(struct xy_iorq), M_DEVBUF, M_NOWAIT); + bzero(xyc->reqs, XYC_MAXIOPB * sizeof(struct xy_iorq)); + if (xyc->reqs == NULL) + panic("xyc malloc"); + + /* + * init iorq to iopb pointers, and non-zero fields in the + * iopb which never change. + */ + + for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) { + xyc->xy_chain[lcv] = NULL; + xyc->reqs[lcv].iopb = &xyc->iopbase[lcv]; + xyc->iopbase[lcv].asr = 1; /* always the same */ + xyc->iopbase[lcv].eef = 1; /* always the same */ + xyc->iopbase[lcv].ecm = XY_ECM; /* always the same */ + xyc->iopbase[lcv].aud = 1; /* always the same */ + xyc->iopbase[lcv].relo = 1; /* always the same */ + xyc->iopbase[lcv].thro = XY_THRO;/* always the same */ + } + xyc->ciorq = &xyc->reqs[XYC_CTLIOPB]; /* short hand name */ + xyc->ciopb = &xyc->iopbase[XYC_CTLIOPB]; /* short hand name */ + xyc->xy_hand = 0; + + /* read controller parameters and insure we have a 450/451 */ + + err = xyc_cmd(xyc, XYCMD_ST, 0, 0, 0, 0, 0, XY_SUB_POLL); + res = xyc->ciopb->ctyp; + XYC_DONE(xyc, err); + if (res != XYCT_450) { + if (err) + printf(": %s: ", xyc_e2str(err)); + printf(": doesn't identify as a 450/451\n"); + return; + } + printf(": Xylogics 450/451"); + if (xyc->no_ols) + printf(" [OLS disabled]"); /* 450 doesn't overlap seek right */ + printf("\n"); + if (err) { + printf("%s: error: %s\n", xyc->sc_dev.dv_xname, + xyc_e2str(err)); + return; + } + if ((xyc->xyc->xyc_csr & XYC_ADRM) == 0) { + printf("%s: 24 bit addressing turned off\n", + xyc->sc_dev.dv_xname); + printf("please set hardware jumpers JM1-JM2=in, JM3-JM4=out\n"); + printf("to enable 24 bit mode and this driver\n"); + return; + } + + /* link in interrupt with higher level software */ + isr_add_vectored(xycintr, (void *)xyc, + ca->ca_intpri, ca->ca_intvec); + evcnt_attach(&xyc->sc_dev, "intr", &xyc->sc_intrcnt); + + /* now we must look for disks using autoconfig */ + xa.dvmabuf = (char *) dvma_malloc(XYFM_BPS); + xa.fullmode = XY_SUB_POLL; + xa.booting = 1; + + for (xa.driveno = 0; xa.driveno < XYC_MAXDEV; xa.driveno++) + (void) config_found(self, (void *) &xa, NULL); + + dvma_free(xa.dvmabuf, XYFM_BPS); + + /* start the watchdog clock */ + timeout(xyc_tick, xyc, XYC_TICKCNT); +} + +/* + * xymatch: probe for disk. + * + * note: we almost always say disk is present. this allows us to + * spin up and configure a disk after the system is booted (we can + * call xyattach!). + */ +int +xymatch(parent, match, aux) + struct device *parent; + void *match, *aux; + +{ + struct xyc_softc *xyc = (void *) parent; + struct cfdata *cf = match; + struct xyc_attach_args *xa = aux; + + /* looking for autoconf wildcard or exact match */ + + if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != xa->driveno) + return 0; + + return 1; + +} + +/* + * xyattach: attach a disk. this can be called from autoconf and also + * from xyopen/xystrategy. + */ +void +xyattach(parent, self, aux) + struct device *parent, *self; + void *aux; + +{ + struct xy_softc *xy = (void *) self, *oxy; + struct xyc_softc *xyc = (void *) parent; + struct xyc_attach_args *xa = aux; + int res, err, spt, mb, blk, lcv, fmode, s, newstate; + struct dkbad *dkb; + struct bootpath *bp; + + /* if booting, init the xy_softc */ + + if (xa->booting) { + xy->state = XY_DRIVE_UNKNOWN; /* to start */ + xy->flags = 0; + xy->parent = xyc; + + /* init queue of waiting bufs */ + + xy->xyq.b_active = 0; + xy->xyq.b_actf = 0; + xy->xyq.b_actb = &xy->xyq.b_actf; /* XXX b_actb: not used? */ + + xy->xyrq = &xyc->reqs[xa->driveno]; + + } + xy->xy_drive = xa->driveno; + fmode = xa->fullmode; + xyc->sc_drives[xa->driveno] = xy; + + /* if not booting, make sure we are the only process in the attach for + * this drive. if locked out, sleep on it. */ + + if (!xa->booting) { + s = splbio(); + while (xy->state == XY_DRIVE_ATTACHING) { + if (tsleep(&xy->state, PRIBIO, "xyattach", 0)) { + splx(s); + return; + } + } + printf("%s at %s", + xy->sc_dev.dv_xname, xy->parent->sc_dev.dv_xname); + } + /* we now have control */ + + xy->state = XY_DRIVE_ATTACHING; + newstate = XY_DRIVE_UNKNOWN; + + /* first try and reset the drive */ + + err = xyc_cmd(xyc, XYCMD_RST, 0, xy->xy_drive, 0, 0, 0, fmode); + XYC_DONE(xyc, err); + if (err == XY_ERR_DNRY) { + printf(" drive %d: off-line\n", xa->driveno); + goto done; + } + if (err) { + printf(": ERROR 0x%02x (%s)\n", err, xyc_e2str(err)); + goto done; + } + printf(" drive %d: ready", xa->driveno); + + /* + * now set drive parameters (to semi-bogus values) so we can read the + * disk label. + */ + xy->pcyl = xy->ncyl = 1; + xy->acyl = 0; + xy->nhead = 1; + xy->nsect = 1; + xy->sectpercyl = 1; + for (lcv = 0; lcv < 126; lcv++) /* init empty bad144 table */ + xy->dkb.bt_bad[lcv].bt_cyl = + xy->dkb.bt_bad[lcv].bt_trksec = 0xffff; + + /* read disk label */ + for (xy->drive_type = 0 ; xy->drive_type <= XYC_MAXDT ; + xy->drive_type++) { + err = xyc_cmd(xyc, XYCMD_RD, 0, xy->xy_drive, 0, 1, + xa->dvmabuf, fmode); + XYC_DONE(xyc, err); + if (err == XY_ERR_AOK) break; + } + + if (err != XY_ERR_AOK) { + printf("\n%s: reading disk label failed: %s\n", + xy->sc_dev.dv_xname, xyc_e2str(err)); + goto done; + } + printf(" (drive type %d)\n", xy->drive_type); + + newstate = XY_DRIVE_NOLABEL; + + xy->hw_spt = spt = 0; /* XXX needed ? */ + if (xygetdisklabel(xy, xa->dvmabuf) != XY_ERR_AOK) + goto done; + + /* inform the user of what is up */ + printf("%s: <%s>, pcyl %d\n", xy->sc_dev.dv_xname, + xa->dvmabuf, xy->pcyl); + mb = xy->ncyl * (xy->nhead * xy->nsect) / (1048576 / XYFM_BPS); + printf("%s: %dMB, %d cyl, %d head, %d sec, %d bytes/sec\n", + xy->sc_dev.dv_xname, mb, xy->ncyl, xy->nhead, xy->nsect, + XYFM_BPS); + + /* + * 450/451 stupidity: the drive type is encoded into the format + * of the disk. the drive type in the IOPB must match the drive + * type in the format, or you will not be able to do I/O to the + * disk (you get header not found errors). if you have two drives + * of different sizes that have the same drive type in their + * formatting then you are out of luck. + * + * this problem was corrected in the 753/7053. + */ + + for (lcv = 0 ; lcv < XYC_MAXDEV ; lcv++) { + oxy = xyc->sc_drives[lcv]; + if (oxy == NULL || oxy == xy) continue; + if (oxy->drive_type != xy->drive_type) continue; + if (xy->nsect != oxy->nsect || xy->pcyl != oxy->pcyl || + xy->nhead != oxy->nhead) { + printf("%s: %s and %s must be the same size!\n", + xyc->sc_dev.dv_xname, xy->sc_dev.dv_xname, + oxy->sc_dev.dv_xname); + panic("xy drive size mismatch"); + } + } + + + /* now set the real drive parameters! */ + + blk = (xy->nsect - 1) + + ((xy->nhead - 1) * xy->nsect) + + ((xy->pcyl - 1) * xy->nsect * xy->nhead); + err = xyc_cmd(xyc, XYCMD_SDS, 0, xy->xy_drive, blk, 0, 0, fmode); + XYC_DONE(xyc, err); + if (err) { + printf("%s: write drive size failed: %s\n", + xy->sc_dev.dv_xname, xyc_e2str(err)); + goto done; + } + newstate = XY_DRIVE_ONLINE; + + /* + * read bad144 table. this table resides on the first sector of the + * last track of the disk (i.e. second cyl of "acyl" area). + */ + + blk = (xy->ncyl + xy->acyl - 1) * (xy->nhead * xy->nsect) + + /* last cyl */ + (xy->nhead - 1) * xy->nsect; /* last head */ + err = xyc_cmd(xyc, XYCMD_RD, 0, xy->xy_drive, blk, 1, + xa->dvmabuf, fmode); + XYC_DONE(xyc, err); + if (err) { + printf("%s: reading bad144 failed: %s\n", + xy->sc_dev.dv_xname, xyc_e2str(err)); + goto done; + } + + /* check dkbad for sanity */ + dkb = (struct dkbad *) xa->dvmabuf; + for (lcv = 0; lcv < 126; lcv++) { + if ((dkb->bt_bad[lcv].bt_cyl == 0xffff || + dkb->bt_bad[lcv].bt_cyl == 0) && + dkb->bt_bad[lcv].bt_trksec == 0xffff) + continue; /* blank */ + if (dkb->bt_bad[lcv].bt_cyl >= xy->ncyl) + break; + if ((dkb->bt_bad[lcv].bt_trksec >> 8) >= xy->nhead) + break; + if ((dkb->bt_bad[lcv].bt_trksec & 0xff) >= xy->nsect) + break; + } + if (lcv != 126) { + printf("%s: warning: invalid bad144 sector!\n", + xy->sc_dev.dv_xname); + } else { + bcopy(xa->dvmabuf, &xy->dkb, XYFM_BPS); + } + + if (xa->booting) { + xy->sc_dk.dk_driver = &xydkdriver; /* link in dkdriver */ + } + + dk_establish(&xy->sc_dk, &xy->sc_dev); + +done: + xy->state = newstate; + if (!xa->booting) { + wakeup(&xy->state); + splx(s); + } +} + +/* + * end of autoconfig functions + */ + +/* + * { b , c } d e v s w f u n c t i o n s + */ + +/* + * xyclose: close device + */ +int +xyclose(dev, flag, fmt) + dev_t dev; + int flag, fmt; + +{ + struct xy_softc *xy = xycd.cd_devs[DISKUNIT(dev)]; + int part = DISKPART(dev); + + /* clear mask bits */ + + switch (fmt) { + case S_IFCHR: + xy->sc_dk.dk_copenmask &= ~(1 << part); + break; + case S_IFBLK: + xy->sc_dk.dk_bopenmask &= ~(1 << part); + break; + } + xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask; + + return 0; +} + +/* + * xydump: crash dump system + */ +int +xydump(dev) + dev_t dev; + +{ + int unit, part; + struct xy_softc *xy; + + unit = DISKUNIT(dev); + if (unit >= xycd.cd_ndevs) + return ENXIO; + part = DISKPART(dev); + + xy = xycd.cd_devs[unit]; + + printf("%s%c: crash dump not supported (yet)\n", xy->sc_dev.dv_xname, + 'a' + part); + + return ENXIO; + + /* outline: globals: "dumplo" == sector number of partition to start + * dump at (convert to physical sector with partition table) + * "dumpsize" == size of dump in clicks "physmem" == size of physical + * memory (clicks, ctob() to get bytes) (normal case: dumpsize == + * physmem) + * + * dump a copy of physical memory to the dump device starting at sector + * "dumplo" in the swap partition (make sure > 0). map in pages as + * we go. use polled I/O. + * + * XXX how to handle NON_CONTIG? */ + +} + +/* + * xyioctl: ioctls on XY drives. based on ioctl's of other netbsd disks. + */ +int +xyioctl(dev, command, addr, flag, p) + dev_t dev; + u_long command; + caddr_t addr; + int flag; + struct proc *p; + +{ + struct xy_softc *xy; + struct xd_iocmd *xio; + int error, s, unit; + + unit = DISKUNIT(dev); + + if (unit >= xycd.cd_ndevs || (xy = xycd.cd_devs[unit]) == NULL) + return (ENXIO); + + /* switch on ioctl type */ + + switch (command) { + case DIOCSBAD: /* set bad144 info */ + if ((flag & FWRITE) == 0) + return EBADF; + s = splbio(); + bcopy(addr, &xy->dkb, sizeof(xy->dkb)); + splx(s); + return 0; + + case DIOCGDINFO: /* get disk label */ + bcopy(&xy->sc_dk.dk_label, addr, sizeof(struct disklabel)); + return 0; + + case DIOCGPART: /* get partition info */ + ((struct partinfo *) addr)->disklab = &xy->sc_dk.dk_label; + ((struct partinfo *) addr)->part = + &xy->sc_dk.dk_label.d_partitions[DISKPART(dev)]; + return 0; + + case DIOCSDINFO: /* set disk label */ + if ((flag & FWRITE) == 0) + return EBADF; + error = setdisklabel(&xy->sc_dk.dk_label, + (struct disklabel *) addr, /* xy->sc_dk.dk_openmask : */ 0, + &xy->sc_dk.dk_cpulabel); + if (error == 0) { + if (xy->state == XY_DRIVE_NOLABEL) + xy->state = XY_DRIVE_ONLINE; + } + return error; + + case DIOCWLABEL: /* change write status of disk label */ + if ((flag & FWRITE) == 0) + return EBADF; + if (*(int *) addr) + xy->flags |= XY_WLABEL; + else + xy->flags &= ~XY_WLABEL; + return 0; + + case DIOCWDINFO: /* write disk label */ + if ((flag & FWRITE) == 0) + return EBADF; + error = setdisklabel(&xy->sc_dk.dk_label, + (struct disklabel *) addr, /* xy->sc_dk.dk_openmask : */ 0, + &xy->sc_dk.dk_cpulabel); + if (error == 0) { + if (xy->state == XY_DRIVE_NOLABEL) + xy->state = XY_DRIVE_ONLINE; + + /* Simulate opening partition 0 so write succeeds. */ + xy->sc_dk.dk_openmask |= (1 << 0); + error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART), + xystrategy, &xy->sc_dk.dk_label, + &xy->sc_dk.dk_cpulabel); + xy->sc_dk.dk_openmask = + xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask; + } + return error; + + case DIOSXDCMD: + xio = (struct xd_iocmd *) addr; + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) + return (error); + return (xyc_ioctlcmd(xy, dev, xio)); + + default: + return ENOTTY; + } +} + +/* + * xyopen: open drive + */ + +int +xyopen(dev, flag, fmt) + dev_t dev; + int flag, fmt; + +{ + int unit, part; + struct xy_softc *xy; + struct xyc_attach_args xa; + + /* first, could it be a valid target? */ + + unit = DISKUNIT(dev); + if (unit >= xycd.cd_ndevs || (xy = xycd.cd_devs[unit]) == NULL) + return (ENXIO); + part = DISKPART(dev); + + /* do we need to attach the drive? */ + + if (xy->state == XY_DRIVE_UNKNOWN) { + xa.driveno = xy->xy_drive; + xa.dvmabuf = (char *) dvma_malloc(XYFM_BPS); + xa.fullmode = XY_SUB_WAIT; + xa.booting = 0; + xyattach((struct device *) xy->parent, + (struct device *) xy, &xa); + dvma_free(xa.dvmabuf, XYFM_BPS); + if (xy->state == XY_DRIVE_UNKNOWN) { + return (EIO); + } + } + /* check for partition */ + + if (part != RAW_PART && + (part >= xy->sc_dk.dk_label.d_npartitions || + xy->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + return (ENXIO); + } + /* set open masks */ + + switch (fmt) { + case S_IFCHR: + xy->sc_dk.dk_copenmask |= (1 << part); + break; + case S_IFBLK: + xy->sc_dk.dk_bopenmask |= (1 << part); + break; + } + xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask; + + return 0; +} + +int +xyread(dev, uio) + dev_t dev; + struct uio *uio; +{ + + return (physio(xystrategy, NULL, dev, B_READ, minphys, uio)); +} + +int +xywrite(dev, uio) + dev_t dev; + struct uio *uio; +{ + + return (physio(xystrategy, NULL, dev, B_WRITE, minphys, uio)); +} + + +/* + * xysize: return size of a partition for a dump + */ + +int +xysize(dev) + dev_t dev; + +{ + struct xy_softc *xysc; + int unit, part, size; + + /* valid unit? try an open */ + + if (xyopen(dev, 0, S_IFBLK) != 0) + return (-1); + + /* do it */ + + xysc = xycd.cd_devs[DISKUNIT(dev)]; + part = DISKPART(dev); + if (xysc->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + size = -1; /* only give valid size for swap partitions */ + else + size = xysc->sc_dk.dk_label.d_partitions[part].p_size; + if (xyclose(dev, 0, S_IFBLK) != 0) + return -1; + return size; +} + +/* + * xystrategy: buffering system interface to xy. + */ + +void +xystrategy(bp) + struct buf *bp; + +{ + struct xy_softc *xy; + struct xyc_softc *parent; + struct buf *wq; + int s, unit; + struct xyc_attach_args xa; + + unit = DISKUNIT(bp->b_dev); + + /* check for live device */ + + if (unit >= xycd.cd_ndevs || (xy = xycd.cd_devs[unit]) == 0 || + bp->b_blkno < 0 || + (bp->b_bcount % xy->sc_dk.dk_label.d_secsize) != 0) { + bp->b_error = EINVAL; + goto bad; + } + /* do we need to attach the drive? */ + + if (xy->state == XY_DRIVE_UNKNOWN) { + xa.driveno = xy->xy_drive; + xa.dvmabuf = (char *) dvma_malloc(XYFM_BPS); + xa.fullmode = XY_SUB_WAIT; + xa.booting = 0; + xyattach((struct device *)xy->parent, (struct device *)xy, &xa); + dvma_free(xa.dvmabuf, XYFM_BPS); + if (xy->state == XY_DRIVE_UNKNOWN) { + bp->b_error = EIO; + goto bad; + } + } + if (xy->state != XY_DRIVE_ONLINE && DISKPART(bp->b_dev) != RAW_PART) { + /* no I/O to unlabeled disks, unless raw partition */ + bp->b_error = EIO; + goto bad; + } + /* short circuit zero length request */ + + if (bp->b_bcount == 0) + goto done; + + /* check bounds with label (disksubr.c). Determine the size of the + * transfer, and make sure it is within the boundaries of the + * partition. Adjust transfer if needed, and signal errors or early + * completion. */ + + if (bounds_check_with_label(bp, &xy->sc_dk.dk_label, + (xy->flags & XY_WLABEL) != 0) <= 0) + goto done; + + /* + * now we know we have a valid buf structure that we need to do I/O + * on. + */ + + s = splbio(); /* protect the queues */ + + disksort(&xy->xyq, bp); + + /* start 'em up */ + + xyc_start(xy->parent, NULL); + + /* done! */ + + splx(s); + return; + +bad: /* tells upper layers we have an error */ + bp->b_flags |= B_ERROR; +done: /* tells upper layers we are done with this + * buf */ + bp->b_resid = bp->b_bcount; + biodone(bp); +} +/* + * end of {b,c}devsw functions + */ + +/* + * i n t e r r u p t f u n c t i o n + * + * xycintr: hardware interrupt. + */ +int +xycintr(v) + void *v; + +{ + struct xyc_softc *xycsc = v; + struct xy_softc *xy; + struct buf *bp; + + /* kick the event counter */ + + xycsc->sc_intrcnt.ev_count++; + + /* remove as many done IOPBs as possible */ + + xyc_remove_iorq(xycsc); + + /* start any iorq's already waiting */ + + xyc_start(xycsc, NULL); + + return (1); +} +/* + * end of interrupt function + */ + +/* + * i n t e r n a l f u n c t i o n s + */ + +/* + * xyc_rqinit: fill out the fields of an I/O request + */ + +inline void +xyc_rqinit(rq, xyc, xy, md, blk, cnt, db, bp) + struct xy_iorq *rq; + struct xyc_softc *xyc; + struct xy_softc *xy; + int md; + u_long blk; + int cnt; + caddr_t db; + struct buf *bp; +{ + rq->xyc = xyc; + rq->xy = xy; + rq->ttl = XYC_MAXTTL + 10; + rq->mode = md; + rq->tries = rq->errno = rq->lasterror = 0; + rq->blockno = blk; + rq->sectcnt = cnt; + rq->dbuf = rq->dbufbase = db; + rq->buf = bp; +} + +/* + * xyc_rqtopb: load up an IOPB based on an iorq + */ + +void +xyc_rqtopb(iorq, iopb, cmd, subfun) + struct xy_iorq *iorq; + struct xy_iopb *iopb; + int cmd, subfun; + +{ + u_long block, dp; + + /* normal IOPB case, standard stuff */ + + /* chain bit handled later */ + iopb->ien = (XY_STATE(iorq->mode) == XY_SUB_POLL) ? 0 : 1; + iopb->com = cmd; + iopb->errno = 0; + iopb->errs = 0; + iopb->done = 0; + if (iorq->xy) { + iopb->unit = iorq->xy->xy_drive; + iopb->dt = iorq->xy->drive_type; + } else { + iopb->unit = 0; + iopb->dt = 0; + } + block = iorq->blockno; + if (iorq->xy == NULL || block == 0) { + iopb->sect = iopb->head = iopb->cyl = 0; + } else { + iopb->sect = block % iorq->xy->nsect; + block = block / iorq->xy->nsect; + iopb->head = block % iorq->xy->nhead; + block = block / iorq->xy->nhead; + iopb->cyl = block; + } + iopb->scnt = iorq->sectcnt; + dp = dvma_kvtopa((long)iorq->dbuf, BUS_VME16); + if (iorq->dbuf == NULL) { + iopb->dataa = 0; + iopb->datar = 0; + } else { + iopb->dataa = (dp & 0xffff); + iopb->datar = ((dp & 0xff0000) >> 16); + } + iopb->subfn = subfun; +} + + +/* + * xyc_unbusy: wait for the xyc to go unbusy, or timeout. + */ + +int +xyc_unbusy(xyc, del) + +struct xyc *xyc; +int del; + +{ + while (del-- > 0) { + if ((xyc->xyc_csr & XYC_GBSY) == 0) + break; + DELAY(1); + } + return(del == 0 ? XY_ERR_FAIL : XY_ERR_AOK); +} + +/* + * xyc_cmd: front end for POLL'd and WAIT'd commands. Returns 0 or error. + * note that NORM requests are handled seperately. + */ +int +xyc_cmd(xycsc, cmd, subfn, unit, block, scnt, dptr, fullmode) + struct xyc_softc *xycsc; + int cmd, subfn, unit, block, scnt; + char *dptr; + int fullmode; + +{ + int submode = XY_STATE(fullmode), retry; + u_long dp; + struct xy_iorq *iorq = xycsc->ciorq; + struct xy_iopb *iopb = xycsc->ciopb; + + /* + * is someone else using the control iopq wait for it if we can + */ +start: + if (submode == XY_SUB_WAIT && XY_STATE(iorq->mode) != XY_SUB_FREE) { + if (tsleep(iorq, PRIBIO, "xyc_cmd", 0)) + return(XY_ERR_FAIL); + goto start; + } + + if (XY_STATE(iorq->mode) != XY_SUB_FREE) { + DELAY(1000000); /* XY_SUB_POLL: steal the iorq */ + iorq->mode = XY_SUB_FREE; + printf("%s: stole control iopb\n", xycsc->sc_dev.dv_xname); + } + + /* init iorq/iopb */ + + xyc_rqinit(iorq, xycsc, + (unit == XYC_NOUNIT) ? NULL : xycsc->sc_drives[unit], + fullmode, block, scnt, dptr, NULL); + + /* load IOPB from iorq */ + + xyc_rqtopb(iorq, iopb, cmd, subfn); + + /* submit it for processing */ + + xyc_submit_iorq(xycsc, iorq, fullmode); /* error code will be in iorq */ + + return(XY_ERR_AOK); +} + +/* + * xyc_startbuf + * start a buffer for running + */ + +int +xyc_startbuf(xycsc, xysc, bp) + struct xyc_softc *xycsc; + struct xy_softc *xysc; + struct buf *bp; + +{ + int partno; + struct xy_iorq *iorq; + struct xy_iopb *iopb; + u_long block, dp; + caddr_t dbuf; + + iorq = xysc->xyrq; + iopb = iorq->iopb; + + /* get buf */ + + if (bp == NULL) + panic("xyc_startbuf null buf"); + + partno = DISKPART(bp->b_dev); +#ifdef XYC_DEBUG + printf("xyc_startbuf: %s%c: %s block %d\n", xysc->sc_dev.dv_xname, + 'a' + partno, (bp->b_flags & B_READ) ? "read" : "write", bp->b_blkno); + printf("xyc_startbuf: b_bcount %d, b_data 0x%x\n", + bp->b_bcount, bp->b_data); +#endif + + /* + * load request. we have to calculate the correct block number based + * on partition info. + * + * also, note that there are two kinds of buf structures, those with + * B_PHYS set and those without B_PHYS. if B_PHYS is set, then it is + * a raw I/O (to a cdevsw) and we are doing I/O directly to the users' + * buffer which has already been mapped into DVMA space. (Not on sun3) + * However, if B_PHYS is not set, then the buffer is a normal system + * buffer which does *not* live in DVMA space. In that case we call + * dvma_mapin to map it into DVMA space so we can do the DMA to it. + * + * in cases where we do a dvma_mapin, note that iorq points to the buffer + * as mapped into DVMA space, where as the bp->b_data points to its + * non-DVMA mapping. + * + * XXX - On the sun3, B_PHYS does NOT mean the buffer is mapped + * into dvma space, only that it was remapped into the kernel. + * We ALWAYS have to remap the kernel buf into DVMA space. + * (It is done inexpensively, using whole segments!) + */ + + block = bp->b_blkno + ((partno == RAW_PART) ? 0 : + xysc->sc_dk.dk_label.d_partitions[partno].p_offset); + + dbuf = dvma_mapin(bp->b_data, bp->b_bcount); + if (dbuf == NULL) { /* out of DVMA space */ + printf("%s: warning: out of DVMA space\n", + xycsc->sc_dev.dv_xname); + return (XY_ERR_FAIL); /* XXX: need some sort of + * call-back scheme here? */ + } + + /* init iorq and load iopb from it */ + + xyc_rqinit(iorq, xycsc, xysc, XY_SUB_NORM | XY_MODE_VERBO, block, + bp->b_bcount / XYFM_BPS, dbuf, bp); + + xyc_rqtopb(iorq, iopb, (bp->b_flags & B_READ) ? XYCMD_RD : XYCMD_WR, 0); + + return (XY_ERR_AOK); +} + + +/* + * xyc_submit_iorq: submit an iorq for processing. returns XY_ERR_AOK + * if ok. if it fail returns an error code. type is XY_SUB_*. + * + * note: caller frees iorq in all cases except NORM + * + * return value: + * NORM: XY_AOK (req pending), XY_FAIL (couldn't submit request) + * WAIT: XY_AOK (success), <error-code> (failed) + * POLL: <same as WAIT> + * NOQ : <same as NORM> + * + * there are three sources for i/o requests: + * [1] xystrategy: normal block I/O, using "struct buf" system. + * [2] autoconfig/crash dump: these are polled I/O requests, no interrupts. + * [3] open/ioctl: these are I/O requests done in the context of a process, + * and the process should block until they are done. + * + * software state is stored in the iorq structure. each iorq has an + * iopb structure. the hardware understands the iopb structure. + * every command must go through an iopb. a 450 handles one iopb at a + * time, where as a 451 can take them in chains. [the 450 claims it + * can handle chains, but is appears to be buggy...] iopb are allocated + * in DVMA space at boot up time. each disk gets one iopb, and the + * controller gets one (for POLL and WAIT commands). what happens if + * the iopb is busy? for i/o type [1], the buffers are queued at the + * "buff" layer and * picked up later by the interrupt routine. for case + * [2] we can only be blocked if there is a WAIT type I/O request being + * run. since this can only happen when we are crashing, we wait a sec + * and then steal the IOPB. for case [3] the process can sleep + * on the iorq free list until some iopbs are avaliable. + */ + + +int +xyc_submit_iorq(xycsc, iorq, type) + struct xyc_softc *xycsc; + struct xy_iorq *iorq; + int type; + +{ + struct xy_iopb *iopb; + u_long iopbaddr; + +#ifdef XYC_DEBUG + printf("xyc_submit_iorq(%s, addr=0x%x, type=%d)\n", + xycsc->sc_dev.dv_xname, iorq, type); +#endif + + /* first check and see if controller is busy */ + if ((xycsc->xyc->xyc_csr & XYC_GBSY) != 0) { +#ifdef XYC_DEBUG + printf("xyc_submit_iorq: XYC not ready (BUSY)\n"); +#endif + if (type == XY_SUB_NOQ) + return (XY_ERR_FAIL); /* failed */ + switch (type) { + case XY_SUB_NORM: + return XY_ERR_AOK; /* success */ + case XY_SUB_WAIT: + while (iorq->iopb->done == 0) { + sleep(iorq, PRIBIO); + } + return (iorq->errno); + case XY_SUB_POLL: /* steal controller */ + iopbaddr = xycsc->xyc->xyc_rsetup; /* RESET */ + if (xyc_unbusy(xycsc->xyc,XYC_RESETUSEC) == XY_ERR_FAIL) + panic("xyc_submit_iorq: stuck xyc"); + printf("%s: stole controller\n", + xycsc->sc_dev.dv_xname); + break; + default: + panic("xyc_submit_iorq adding"); + } + } + + iopb = xyc_chain(xycsc, iorq); /* build chain */ + if (iopb == NULL) { /* nothing doing? */ + if (type == XY_SUB_NORM || type == XY_SUB_NOQ) + return(XY_ERR_AOK); + panic("xyc_submit_iorq: xyc_chain failed!\n"); + } + iopbaddr = dvma_kvtopa((long) iopb, BUS_VME16); + + XYC_GO(xycsc->xyc, iopbaddr); + + /* command now running, wrap it up */ + switch (type) { + case XY_SUB_NORM: + case XY_SUB_NOQ: + return (XY_ERR_AOK); /* success */ + case XY_SUB_WAIT: + while (iorq->iopb->done == 0) { + sleep(iorq, PRIBIO); + } + return (iorq->errno); + case XY_SUB_POLL: + return (xyc_piodriver(xycsc, iorq)); + default: + panic("xyc_submit_iorq wrap up"); + } + panic("xyc_submit_iorq"); + return 0; /* not reached */ +} + + +/* + * xyc_chain: build a chain. return dvma address of first element in + * the chain. iorq != NULL: means we only want that item on the chain. + */ + +struct xy_iopb * +xyc_chain(xycsc, iorq) + +struct xyc_softc *xycsc; +struct xy_iorq *iorq; + +{ + int togo, chain, hand; + struct xy_iopb *iopb, *prev_iopb; + bzero(xycsc->xy_chain, sizeof(xycsc->xy_chain)); + + /* + * promote control IOPB to the top + */ + if (iorq == NULL) { + if ((XY_STATE(xycsc->reqs[XYC_CTLIOPB].mode) == XY_SUB_POLL || + XY_STATE(xycsc->reqs[XYC_CTLIOPB].mode) == XY_SUB_WAIT) && + xycsc->iopbase[XYC_CTLIOPB].done == 0) + iorq = &xycsc->reqs[XYC_CTLIOPB]; + } + /* + * special case: if iorq != NULL then we have a POLL or WAIT request. + * we let these take priority and do them first. + */ + if (iorq) { + xycsc->xy_chain[0] = iorq; + iorq->iopb->chen = 0; + return(iorq->iopb); + } + + /* + * NORM case: do round robin and maybe chain (if allowed and possible) + */ + + chain = 0; + hand = xycsc->xy_hand; + xycsc->xy_hand = (xycsc->xy_hand + 1) % XYC_MAXIOPB; + + for (togo = XYC_MAXIOPB ; togo > 0 ; togo--, hand = (hand + 1) % XYC_MAXIOPB){ + + if (XY_STATE(xycsc->reqs[hand].mode) != XY_SUB_NORM || + xycsc->iopbase[hand].done) + continue; /* not ready-for-i/o */ + + xycsc->xy_chain[chain] = &xycsc->reqs[hand]; + iopb = xycsc->xy_chain[chain]->iopb; + iopb->chen = 0; + if (chain != 0) { /* adding a link to a chain? */ + prev_iopb = xycsc->xy_chain[chain-1]->iopb; + prev_iopb->chen = 1; + prev_iopb->nxtiopb = 0xffff & + dvma_kvtopa((long) iopb, BUS_VME16); + } else { /* head of chain */ + iorq = xycsc->xy_chain[chain]; + } + chain++; + if (xycsc->no_ols) break; /* quit if chaining dis-allowed */ + } + return(iorq ? iorq->iopb : NULL); +} + +/* + * xyc_piodriver + * + * programmed i/o driver. this function takes over the computer + * and drains off the polled i/o request. it returns the status of the iorq + * the caller is interesting in. + */ +int +xyc_piodriver(xycsc, iorq) + struct xyc_softc *xycsc; + struct xy_iorq *iorq; + +{ + int nreset = 0; + int retval = 0; + u_long res; + struct xyc *xyc = xycsc->xyc; +#ifdef XYC_DEBUG + printf("xyc_piodriver(%s, 0x%x)\n", xycsc->sc_dev.dv_xname, iorq); +#endif + + while (iorq->iopb->done == 0) { + + res = xyc_unbusy(xycsc->xyc, XYC_MAXTIME); + + /* we expect some progress soon */ + if (res == XY_ERR_FAIL && nreset >= 2) { + xyc_reset(xycsc, 0, XY_RSET_ALL, XY_ERR_FAIL, 0); +#ifdef XYC_DEBUG + printf("xyc_piodriver: timeout\n"); +#endif + return (XY_ERR_FAIL); + } + if (res == XY_ERR_FAIL) { + if (xyc_reset(xycsc, 0, + (nreset++ == 0) ? XY_RSET_NONE : iorq, + XY_ERR_FAIL, + 0) == XY_ERR_FAIL) + return (XY_ERR_FAIL); /* flushes all but POLL + * requests, resets */ + continue; + } + + xyc_remove_iorq(xycsc); /* may resubmit request */ + + if (iorq->iopb->done == 0) + xyc_start(xycsc, iorq); + } + + /* get return value */ + + retval = iorq->errno; + +#ifdef XYC_DEBUG + printf("xyc_piodriver: done, retval = 0x%x (%s)\n", + iorq->errno, xyc_e2str(iorq->errno)); +#endif + + /* start up any bufs that have queued */ + + xyc_start(xycsc, NULL); + + return (retval); +} + +/* + * xyc_xyreset: reset one drive. NOTE: assumes xyc was just reset. + * we steal iopb[XYC_CTLIOPB] for this, but we put it back when we are done. + */ +int +xyc_xyreset(xycsc, xysc) + struct xyc_softc *xycsc; + struct xy_softc *xysc; + +{ + struct xy_iopb tmpiopb; + u_long addr; + int del; + bcopy(xycsc->ciopb, &tmpiopb, sizeof(tmpiopb)); + xycsc->ciopb->chen = xycsc->ciopb->done = xycsc->ciopb->errs = 0; + xycsc->ciopb->ien = 0; + xycsc->ciopb->com = XYCMD_RST; + xycsc->ciopb->unit = xysc->xy_drive; + addr = dvma_kvtopa((long) xycsc->ciopb, BUS_VME16); + + XYC_GO(xycsc->xyc, addr); + + del = XYC_RESETUSEC; + while (del > 0) { + if ((xycsc->xyc->xyc_csr & XYC_GBSY) == 0) break; + DELAY(1); + del--; + } + + if (del <= 0 || xycsc->ciopb->errs) { + printf("%s: off-line: %s\n", xycsc->sc_dev.dv_xname, + xyc_e2str(xycsc->ciopb->errno)); + del = xycsc->xyc->xyc_rsetup; + if (xyc_unbusy(xycsc->xyc, XYC_RESETUSEC) == XY_ERR_FAIL) + panic("xyc_reset"); + } else { + xycsc->xyc->xyc_csr |= XYC_IPND; /* clear IPND */ + } + bcopy(&tmpiopb, xycsc->ciopb, sizeof(tmpiopb)); +} + + +/* + * xyc_reset: reset everything: requests are marked as errors except + * a polled request (which is resubmitted) + */ +int +xyc_reset(xycsc, quiet, blastmode, error, xysc) + struct xyc_softc *xycsc; + int quiet, error; + struct xy_iorq *blastmode; + struct xy_softc *xysc; + +{ + int del = 0, lcv, poll = -1, retval = XY_ERR_AOK; + struct xy_iorq *iorq; + + /* soft reset hardware */ + + if (!quiet) + printf("%s: soft reset\n", xycsc->sc_dev.dv_xname); + del = xycsc->xyc->xyc_rsetup; + del = xyc_unbusy(xycsc->xyc, XYC_RESETUSEC); + if (del == XY_ERR_FAIL) { + blastmode = XY_RSET_ALL; /* dead, flush all requests */ + retval = XY_ERR_FAIL; + } + if (xysc) + xyc_xyreset(xycsc, xysc); + + /* fix queues based on "blast-mode" */ + + for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) { + iorq = &xycsc->reqs[lcv]; + + if (XY_STATE(iorq->mode) != XY_SUB_POLL && + XY_STATE(iorq->mode) != XY_SUB_WAIT && + XY_STATE(iorq->mode) != XY_SUB_NORM) + /* is it active? */ + continue; + + if (blastmode == XY_RSET_ALL || + blastmode != iorq) { + /* failed */ + iorq->errno = error; + xycsc->iopbase[lcv].done = xycsc->iopbase[lcv].errs = 1; + switch (XY_STATE(iorq->mode)) { + case XY_SUB_NORM: + iorq->buf->b_error = EIO; + iorq->buf->b_flags |= B_ERROR; + iorq->buf->b_resid = + iorq->sectcnt * XYFM_BPS; + /* Sun3: map/unmap regardless of B_PHYS */ + dvma_mapout(iorq->dbufbase, + iorq->buf->b_bcount); + iorq->xy->xyq.b_actf = + iorq->buf->b_actf; + biodone(iorq->buf); + iorq->mode = XY_SUB_FREE; + break; + case XY_SUB_WAIT: + wakeup(iorq); + case XY_SUB_POLL: + iorq->mode = + XY_NEWSTATE(iorq->mode, XY_SUB_DONE); + break; + } + + } else { + + /* resubmit, no need to do anything here */ + } + } + + /* + * now, if stuff is waiting, start it. + * since we just reset it should go + */ + xyc_start(xycsc, NULL); + + return (retval); +} + +/* + * xyc_start: start waiting buffers + */ + +int +xyc_start(xycsc, iorq) + struct xyc_softc *xycsc; + struct xy_iorq *iorq; + +{ + int lcv; + struct xy_softc *xy; + + if (iorq == NULL) { + for (lcv = 0; lcv < XYC_MAXDEV ; lcv++) { + if ((xy = xycsc->sc_drives[lcv]) == NULL) continue; + if (xy->xyq.b_actf == NULL) continue; + if (xy->xyrq->mode != XY_SUB_FREE) continue; + xyc_startbuf(xycsc, xy, xy->xyq.b_actf); + } + } + xyc_submit_iorq(xycsc, iorq, XY_SUB_NOQ); +} + +/* + * xyc_remove_iorq: remove "done" IOPB's. + */ + +int +xyc_remove_iorq(xycsc) + struct xyc_softc *xycsc; + +{ + int errno, rq, comm, errs; + struct xyc *xyc = xycsc->xyc; + u_long addr; + struct xy_iopb *iopb; + struct xy_iorq *iorq; + struct buf *bp; + + if (xyc->xyc_csr & XYC_DERR) { + /* + * DOUBLE ERROR: should never happen under normal use. This + * error is so bad, you can't even tell which IOPB is bad, so + * we dump them all. + */ + errno = XY_ERR_DERR; + printf("%s: DOUBLE ERROR!\n", xycsc->sc_dev.dv_xname); + if (xyc_reset(xycsc, 0, XY_RSET_ALL, errno, 0) != XY_ERR_AOK) { + printf("%s: soft reset failed!\n", + xycsc->sc_dev.dv_xname); + panic("xyc_remove_iorq: controller DEAD"); + } + return (XY_ERR_AOK); + } + + /* + * get iopb that is done, loop down the chain + */ + + if (xyc->xyc_csr & XYC_ERR) { + xyc->xyc_csr |= XYC_ERR; /* clear error condition */ + } + if (xyc->xyc_csr & XYC_IPND) { + xyc->xyc_csr |= XYC_IPND; /* clear interrupt */ + } + + for (rq = 0; rq < XYC_MAXIOPB; rq++) { + iorq = xycsc->xy_chain[rq]; + if (iorq == NULL) break; /* done ! */ + if (iorq->mode == 0 || XY_STATE(iorq->mode) == XY_SUB_DONE) + continue; /* free, or done */ + iopb = iorq->iopb; + if (iopb->done == 0) + continue; /* not done yet */ + + comm = iopb->com; + errs = iopb->errs; + + if (errs) + iorq->errno = iopb->errno; + else + iorq->errno = 0; + + /* handle non-fatal errors */ + + if (errs && + xyc_error(xycsc, iorq, iopb, comm) == XY_ERR_AOK) + continue; /* AOK: we resubmitted it */ + + + /* this iorq is now done (hasn't been restarted or anything) */ + + if ((iorq->mode & XY_MODE_VERBO) && iorq->lasterror) + xyc_perror(iorq, iopb, 0); + + /* now, if read/write check to make sure we got all the data + * we needed. (this may not be the case if we got an error in + * the middle of a multisector request). */ + + if ((iorq->mode & XY_MODE_B144) != 0 && errs == 0 && + (comm == XYCMD_RD || comm == XYCMD_WR)) { + /* we just successfully processed a bad144 sector + * note: if we are in bad 144 mode, the pointers have + * been advanced already (see above) and are pointing + * at the bad144 sector. to exit bad144 mode, we + * must advance the pointers 1 sector and issue a new + * request if there are still sectors left to process + * + */ + XYC_ADVANCE(iorq, 1); /* advance 1 sector */ + + /* exit b144 mode */ + iorq->mode = iorq->mode & (~XY_MODE_B144); + + if (iorq->sectcnt) { /* more to go! */ + iorq->lasterror = iorq->errno = iopb->errno = 0; + iopb->errs = iopb->done = 0; + iorq->tries = 0; + iopb->scnt = iorq->sectcnt; + iopb->cyl = iorq->blockno / + iorq->xy->sectpercyl; + iopb->head = + (iorq->blockno / iorq->xy->nhead) % + iorq->xy->nhead; + iopb->sect = iorq->blockno % XYFM_BPS; + addr = dvma_kvtopa((long) iorq->dbuf, BUS_VME16); + iopb->dataa = (addr & 0xffff); + iopb->datar = ((addr & 0xff0000) >> 16); + /* will resubit at end */ + continue; + } + } + /* final cleanup, totally done with this request */ + + switch (XY_STATE(iorq->mode)) { + case XY_SUB_NORM: + bp = iorq->buf; + if (errs) { + bp->b_error = EIO; + bp->b_flags |= B_ERROR; + bp->b_resid = iorq->sectcnt * XYFM_BPS; + } else { + bp->b_resid = 0; /* done */ + } + /* Sun3: map/unmap regardless of B_PHYS */ + dvma_mapout(iorq->dbufbase, + iorq->buf->b_bcount); + iorq->mode = XY_SUB_FREE; + iorq->xy->xyq.b_actf = bp->b_actf; + biodone(bp); + break; + case XY_SUB_WAIT: + iorq->mode = XY_NEWSTATE(iorq->mode, XY_SUB_DONE); + wakeup(iorq); + break; + case XY_SUB_POLL: + iorq->mode = XY_NEWSTATE(iorq->mode, XY_SUB_DONE); + break; + } + } + + return (XY_ERR_AOK); +} + +/* + * xyc_perror: print error. + * - if still_trying is true: we got an error, retried and got a + * different error. in that case lasterror is the old error, + * and errno is the new one. + * - if still_trying is not true, then if we ever had an error it + * is in lasterror. also, if iorq->errno == 0, then we recovered + * from that error (otherwise iorq->errno == iorq->lasterror). + */ +void +xyc_perror(iorq, iopb, still_trying) + struct xy_iorq *iorq; + struct xy_iopb *iopb; + int still_trying; + +{ + + int error = iorq->lasterror; + + printf("%s", (iorq->xy) ? iorq->xy->sc_dev.dv_xname + : iorq->xyc->sc_dev.dv_xname); + if (iorq->buf) + printf("%c: ", 'a' + DISKPART(iorq->buf->b_dev)); + if (iopb->com == XYCMD_RD || iopb->com == XYCMD_WR) + printf("%s %d/%d/%d: ", + (iopb->com == XYCMD_RD) ? "read" : "write", + iopb->cyl, iopb->head, iopb->sect); + printf("%s", xyc_e2str(error)); + + if (still_trying) + printf(" [still trying, new error=%s]", xyc_e2str(iorq->errno)); + else + if (iorq->errno == 0) + printf(" [recovered in %d tries]", iorq->tries); + + printf("\n"); +} + +/* + * xyc_error: non-fatal error encountered... recover. + * return AOK if resubmitted, return FAIL if this iopb is done + */ +int +xyc_error(xycsc, iorq, iopb, comm) + struct xyc_softc *xycsc; + struct xy_iorq *iorq; + struct xy_iopb *iopb; + int comm; + +{ + int errno = iorq->errno; + int erract = xyc_entoact(errno); + int oldmode, advance, i; + + if (erract == XY_ERA_RSET) { /* some errors require a reset */ + oldmode = iorq->mode; + iorq->mode = XY_SUB_DONE | (~XY_SUB_MASK & oldmode); + /* make xyc_start ignore us */ + xyc_reset(xycsc, 1, XY_RSET_NONE, errno, iorq->xy); + iorq->mode = oldmode; + } + /* check for read/write to a sector in bad144 table if bad: redirect + * request to bad144 area */ + + if ((comm == XYCMD_RD || comm == XYCMD_WR) && + (iorq->mode & XY_MODE_B144) == 0) { + advance = iorq->sectcnt - iopb->scnt; + XYC_ADVANCE(iorq, advance); + if ((i = isbad(&iorq->xy->dkb, iorq->blockno / iorq->xy->sectpercyl, + (iorq->blockno / iorq->xy->nsect) % iorq->xy->nhead, + iorq->blockno % iorq->xy->nsect)) != -1) { + iorq->mode |= XY_MODE_B144; /* enter bad144 mode & + * redirect */ + iopb->errno = iopb->done = iopb->errs = 0; + iopb->scnt = 1; + iopb->cyl = (iorq->xy->ncyl + iorq->xy->acyl) - 2; + /* second to last acyl */ + i = iorq->xy->sectpercyl - 1 - i; /* follow bad144 + * standard */ + iopb->head = i / iorq->xy->nhead; + iopb->sect = i % iorq->xy->nhead; + /* will resubmit when we come out of remove_iorq */ + return (XY_ERR_AOK); /* recovered! */ + } + } + + /* + * it isn't a bad144 sector, must be real error! see if we can retry + * it? + */ + if ((iorq->mode & XY_MODE_VERBO) && iorq->lasterror) + xyc_perror(iorq, iopb, 1); /* inform of error state + * change */ + iorq->lasterror = errno; + + if ((erract == XY_ERA_RSET || erract == XY_ERA_HARD) + && iorq->tries < XYC_MAXTRIES) { /* retry? */ + iorq->tries++; + iorq->errno = iopb->errno = iopb->done = iopb->errs = 0; + /* will resubmit at end of remove_iorq */ + return (XY_ERR_AOK); /* recovered! */ + } + + /* failed to recover from this error */ + return (XY_ERR_FAIL); +} + +/* + * xyc_tick: make sure xy is still alive and ticking (err, kicking). + */ +void +xyc_tick(arg) + void *arg; + +{ + struct xyc_softc *xycsc = arg; + int lcv, s, reset = 0; + + /* reduce ttl for each request if one goes to zero, reset xyc */ + s = splbio(); + for (lcv = 0; lcv < XYC_MAXIOPB; lcv++) { + if (xycsc->reqs[lcv].mode == 0 || + XY_STATE(xycsc->reqs[lcv].mode) == XY_SUB_DONE) + continue; + xycsc->reqs[lcv].ttl--; + if (xycsc->reqs[lcv].ttl == 0) + reset = 1; + } + if (reset) { + printf("%s: watchdog timeout\n", xycsc->sc_dev.dv_xname); + xyc_reset(xycsc, 0, XY_RSET_NONE, XY_ERR_FAIL, NULL); + } + splx(s); + + /* until next time */ + + timeout(xyc_tick, xycsc, XYC_TICKCNT); +} + +/* + * xyc_ioctlcmd: this function provides a user level interface to the + * controller via ioctl. this allows "format" programs to be written + * in user code, and is also useful for some debugging. we return + * an error code. called at user priority. + * + * XXX missing a few commands (see the 7053 driver for ideas) + */ +int +xyc_ioctlcmd(xy, dev, xio) + struct xy_softc *xy; + dev_t dev; + struct xd_iocmd *xio; + +{ + int s, err, rqno, dummy; + caddr_t dvmabuf = NULL; + struct xyc_softc *xycsc; + + /* check sanity of requested command */ + + switch (xio->cmd) { + + case XYCMD_NOP: /* no op: everything should be zero */ + if (xio->subfn || xio->dptr || xio->dlen || + xio->block || xio->sectcnt) + return (EINVAL); + break; + + case XYCMD_RD: /* read / write sectors (up to XD_IOCMD_MAXS) */ + case XYCMD_WR: + if (xio->subfn || xio->sectcnt > XD_IOCMD_MAXS || + xio->sectcnt * XYFM_BPS != xio->dlen || xio->dptr == NULL) + return (EINVAL); + break; + + case XYCMD_SK: /* seek: doesn't seem useful to export this */ + return (EINVAL); + + break; + + default: + return (EINVAL);/* ??? */ + } + + /* create DVMA buffer for request if needed */ + + if (xio->dlen) { + dvmabuf = dvma_malloc(xio->dlen); + if (xio->cmd == XYCMD_WR) { + if (err = copyin(xio->dptr, dvmabuf, xio->dlen)) { + dvma_free(dvmabuf, xio->dlen); + return (err); + } + } + } + /* do it! */ + + err = 0; + xycsc = xy->parent; + s = splbio(); + rqno = xyc_cmd(xycsc, xio->cmd, xio->subfn, xy->xy_drive, xio->block, + xio->sectcnt, dvmabuf, XY_SUB_WAIT); + if (rqno == XY_ERR_FAIL) { + err = EIO; + goto done; + } + xio->errno = xycsc->ciorq->errno; + xio->tries = xycsc->ciorq->tries; + XYC_DONE(xycsc, dummy); + + if (xio->cmd == XYCMD_RD) + err = copyout(dvmabuf, xio->dptr, xio->dlen); + +done: + splx(s); + if (dvmabuf) + dvma_free(dvmabuf, xio->dlen); + return (err); +} + +/* + * xyc_e2str: convert error code number into an error string + */ +char * +xyc_e2str(no) + int no; +{ + switch (no) { + case XY_ERR_FAIL: + return ("Software fatal error"); + case XY_ERR_DERR: + return ("DOUBLE ERROR"); + case XY_ERR_AOK: + return ("Successful completion"); + case XY_ERR_IPEN: + return("Interrupt pending"); + case XY_ERR_BCFL: + return("Busy conflict"); + case XY_ERR_TIMO: + return("Operation timeout"); + case XY_ERR_NHDR: + return("Header not found"); + case XY_ERR_HARD: + return("Hard ECC error"); + case XY_ERR_ICYL: + return("Illegal cylinder address"); + case XY_ERR_ISEC: + return("Illegal sector address"); + case XY_ERR_SMAL: + return("Last sector too small"); + case XY_ERR_SACK: + return("Slave ACK error (non-existent memory)"); + case XY_ERR_CHER: + return("Cylinder and head/header error"); + case XY_ERR_SRTR: + return("Auto-seek retry successful"); + case XY_ERR_WPRO: + return("Write-protect error"); + case XY_ERR_UIMP: + return("Unimplemented command"); + case XY_ERR_DNRY: + return("Drive not ready"); + case XY_ERR_SZER: + return("Sector count zero"); + case XY_ERR_DFLT: + return("Drive faulted"); + case XY_ERR_ISSZ: + return("Illegal sector size"); + case XY_ERR_SLTA: + return("Self test A"); + case XY_ERR_SLTB: + return("Self test B"); + case XY_ERR_SLTC: + return("Self test C"); + case XY_ERR_SOFT: + return("Soft ECC error"); + case XY_ERR_SFOK: + return("Soft ECC error recovered"); + case XY_ERR_IHED: + return("Illegal head"); + case XY_ERR_DSEQ: + return("Disk sequencer error"); + case XY_ERR_SEEK: + return("Seek error"); + default: + return ("Unknown error"); + } +} + +int +xyc_entoact(errno) + +int errno; + +{ + switch (errno) { + case XY_ERR_FAIL: case XY_ERR_DERR: case XY_ERR_IPEN: + case XY_ERR_BCFL: case XY_ERR_ICYL: case XY_ERR_ISEC: + case XY_ERR_UIMP: case XY_ERR_SZER: case XY_ERR_ISSZ: + case XY_ERR_SLTA: case XY_ERR_SLTB: case XY_ERR_SLTC: + case XY_ERR_IHED: case XY_ERR_SACK: case XY_ERR_SMAL: + + return(XY_ERA_PROG); /* program error ! */ + + case XY_ERR_TIMO: case XY_ERR_NHDR: case XY_ERR_HARD: + case XY_ERR_DNRY: case XY_ERR_CHER: case XY_ERR_SEEK: + case XY_ERR_SOFT: + + return(XY_ERA_HARD); /* hard error, retry */ + + case XY_ERR_DFLT: case XY_ERR_DSEQ: + + return(XY_ERA_RSET); /* hard error reset */ + + case XY_ERR_SRTR: case XY_ERR_SFOK: case XY_ERR_AOK: + + return(XY_ERA_SOFT); /* an FYI error */ + + case XY_ERR_WPRO: + + return(XY_ERA_WPRO); /* write protect */ + } + + return(XY_ERA_PROG); /* ??? */ +} diff --git a/sys/arch/sun3/dev/xyreg.h b/sys/arch/sun3/dev/xyreg.h new file mode 100644 index 00000000000..b6591e51a37 --- /dev/null +++ b/sys/arch/sun3/dev/xyreg.h @@ -0,0 +1,227 @@ +/* $NetBSD: xyreg.h,v 1.1 1995/10/30 20:58:22 gwr Exp $ */ + +/* + * + * Copyright (c) 1995 Charles D. Cranor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles D. Cranor. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * x y r e g . h + * + * this file contains the description of the Xylogics 450/451's hardware + * data structures. + * + * author: Chuck Cranor <chuck@ccrc.wustl.edu> + */ + +#define XYC_MAXDEV 2 /* max devices per controller */ +#define XYC_CTLIOPB XYC_MAXDEV /* controller's iopb */ +#define XYC_RESETUSEC 1000000 /* max time for xyc reset (same as xdc?) */ +#define XYC_MAXIOPB (XYC_MAXDEV+1) + /* max number of iopbs that can be active */ +#define XYC_MAXTIME 4*1000000 /* four seconds before we give up and reset */ +#define XYC_MAXTRIES 4 /* max number of times to retry an operation */ +#define XYC_INTERLEAVE 1 /* interleave (from disk label?) */ +#define XYFM_BPS 0x200 /* must be 512! */ + +/* + * xyc device interface + * (lives in VME address space) [note: bytes are swapped!] + */ + +struct xyc { + volatile u_char xyc_reloc_hi; /* iopb relocation (low byte) */ + volatile u_char xyc_reloc_lo; /* iopb relocation (high byte) */ + volatile u_char xyc_addr_hi; /* iopb address (low byte) */ + volatile u_char xyc_addr_lo; /* iopb address (high byte) */ + volatile u_char xyc_rsetup; /* reset/update reg */ + volatile u_char xyc_csr; /* control and status register */ +}; + +/* + * xyc_csr + */ + +#define XYC_GBSY 0x80 /* go/busy */ +#define XYC_ERR 0x40 /* error */ +#define XYC_DERR 0x20 /* double error! */ +#define XYC_IPND 0x10 /* interrupt pending */ +#define XYC_ADRM 0x08 /* 24-bit addressing */ +#define XYC_AREQ 0x04 /* attention request */ +#define XYC_AACK 0x02 /* attention ack. */ +#define XYC_DRDY 0x01 /* drive ready */ + +/* + * Input/Output Parameter Block (iopb) + * + * all controller commands are done via iopb's. to start a command you + * must do this: + * [1] allocate space in DVMA space for the iopb + * [2] fill out all the fields of the iopb + * [3] if the controller isn't busy, start the iopb by loading the address + * and reloc in the xyc's registers and setting the "go" bit [done] + * [4] controller busy: set AREQ bit, and wait for AACK bit. + * add iopb to the chain, and clear AREQ to resume I/O + * + * when the controller is done with a command it may interrupt (if you + * ask it to) and it will set the XYC_IPND bit in the csr. clear + * the interrupt by writing one to this bit. + * + * the format of the iopb is described in section 2.4 of the manual. + * note that it is byte-swapped on the sun. + */ + +struct xy_iopb { + /* section 2.4.2: byte 1 */ + volatile u_char resv1:1; /* reserved */ + volatile u_char iei:1; /* interrupt on each IOPB done */ + volatile u_char ierr:1; /* interrupt on error (no effect on 450) */ + volatile u_char hdp:1; /* hold dual port drive */ + volatile u_char asr:1; /* autoseek retry */ + volatile u_char eef:1; /* enable extended fn. (overlap seek) */ + volatile u_char ecm:2; /* ECC correction mode */ +#define XY_ECM 2 /* use mode 2 (see section 2.4.2) */ + /* section 2.4.1: byte 0 */ + volatile u_char aud:1; /* auto-update iopb */ + volatile u_char relo:1; /* enable multibus relocation (>16bit addrs)*/ + volatile u_char chen:1; /* chain enable, "next iopb" is valid */ + volatile u_char ien:1; /* interrupt enable */ + volatile u_char com:4; /* command */ +#define XYCMD_NOP 0x0 /* no-op */ +#define XYCMD_WR 0x1 /* write */ +#define XYCMD_RD 0x2 /* read */ +#define XYCMD_WTH 0x3 /* write track headers */ +#define XYCMD_RTH 0x4 /* read track headers */ +#define XYCMD_SK 0x5 /* seek */ +#define XYCMD_RST 0x6 /* drive reset */ +#define XYCMD_WFM 0x7 /* write format */ +#define XYCMD_RDH 0x8 /* read header, data, and ECC */ +#define XYCMD_RDS 0x9 /* read drive status */ +#define XYCMD_WRH 0xa /* write header, data, and ECC */ +#define XYCMD_SDS 0xb /* set drive size */ +#define XYCMD_ST 0xc /* self test */ +#define XYCMD_R 0xd /* reserved */ +#define XYCMD_MBL 0xe /* maint. buffer load */ +#define XYCMD_MBD 0xf /* main. buffer dump */ + /* section 2.4.4: byte 3 */ + volatile u_char errno; /* error or completion code */ + /* section 2.4.3: byte 2 */ + volatile u_char errs:1; /* error summary bit */ + volatile u_char resv2:2; /* reserved */ + volatile u_char ctyp:3; /* controller type */ +#define XYCT_450 1 /* the 450 controller */ + volatile u_char resv3:1; /* reserved */ + volatile u_char done:1; /* done! */ + /* section 2.4.6: byte 5 */ + volatile u_char dt:2; /* drive type */ +#define XYC_MAXDT 3 /* largest drive type possible */ + volatile u_char resv4:4; /* reserved */ + volatile u_char unit:2; /* unit # */ + /* section 2.4.5: byte 4 */ + volatile u_char bw:1; /* byte(1)/word(0) xfer size */ + volatile u_char intlv:4; /* interleave factor (0=1:1, 1=2:1, etc.) */ + volatile u_char thro:3; /* dma throttle (0=2,1=4,2=8, etc...) */ +#define XY_THRO 4 /* 4 == 32 dma cycles */ + /* section 2.4.8: byte 7 */ + volatile u_char sect; /* sector # */ + /* section 2.4.7: byte 6 */ + volatile u_char head; /* head # */ + /* section 2.4.9: byte 8,9 */ + volatile u_short cyl; /* cyl # */ + /* section 2.4.10: byte a,b */ + volatile u_short scnt; /* sector count, also drive status */ +#define xy_dr_status scnt +#define XYS_ONCL 0x80 /* on-cylinder (active LOW) */ +#define XYS_DRDY 0x40 /* drive ready (active LOW) */ +#define XYS_WRPT 0x20 /* write protect */ +#define XYS_DPB 0x10 /* dual-port busy */ +#define XYS_SKER 0x08 /* hard seek error */ +#define XYS_DFLT 0x04 /* disk fault */ + /* section 2.4.11: byte c,d */ + volatile u_short dataa; /* data address */ + /* section 2.4.12: byte e,f */ + volatile u_short datar; /* data relocation pointer */ + /* section 2.4.14: byte 11 */ + volatile u_char subfn; /* sub-function */ + /* section 2.4.13: byte 10 */ + volatile u_char hoff; /* head offset for fixed/removeable drives */ + /* section 2.4.15: byte 12,13 */ + volatile u_short nxtiopb; /* next iopb address (same relocation) */ + /* section 2.4.16: byte 14,15 */ + volatile u_short eccpat; /* ecc pattern */ + /* section 2.4.17: byte 16,17 */ + volatile u_short eccaddr; /* ecc address */ +}; + + +/* + * errors (section 2.4.4.1) + */ + +/* software error codes */ +#define XY_ERR_FAIL 0xff /* general total failure */ +#define XY_ERR_DERR 0xfe /* double error */ +/* no error */ +#define XY_ERR_AOK 0x00 /* success */ + +#define XY_ERR_IPEN 0x01 /* interrupt pending */ +#define XY_ERR_BCFL 0x03 /* busy conflict */ +#define XY_ERR_TIMO 0x04 /* operation timeout */ +#define XY_ERR_NHDR 0x05 /* header not found */ +#define XY_ERR_HARD 0x06 /* hard ECC error */ +#define XY_ERR_ICYL 0x07 /* illegal cylinder address */ +#define XY_ERR_ISEC 0x0a /* illegal sector address */ +#define XY_ERR_SMAL 0x0d /* last sector too small */ +#define XY_ERR_SACK 0x0e /* slave ACK error (non-existent memory) */ +#define XY_ERR_CHER 0x12 /* cylinder and head/header error */ +#define XY_ERR_SRTR 0x13 /* auto-seek retry successful */ +#define XY_ERR_WPRO 0x14 /* write-protect error */ +#define XY_ERR_UIMP 0x15 /* unimplemented command */ +#define XY_ERR_DNRY 0x16 /* drive not ready */ +#define XY_ERR_SZER 0x17 /* sector count zero */ +#define XY_ERR_DFLT 0x18 /* drive faulted */ +#define XY_ERR_ISSZ 0x19 /* illegal sector size */ +#define XY_ERR_SLTA 0x1a /* self test a */ +#define XY_ERR_SLTB 0x1b /* self test b */ +#define XY_ERR_SLTC 0x1c /* self test c */ +#define XY_ERR_SOFT 0x1e /* soft ECC error */ +#define XY_ERR_SFOK 0x1f /* soft ECC error recovered */ +#define XY_ERR_IHED 0x20 /* illegal head */ +#define XY_ERR_DSEQ 0x21 /* disk sequencer error */ +#define XY_ERR_SEEK 0x25 /* seek error */ + + +/* error actions */ +#define XY_ERA_PROG 0x10 /* program error: quit */ +#define XY_ERA_SOFT 0x30 /* soft error: we recovered */ +#define XY_ERA_HARD 0x40 /* hard error: retry */ +#define XY_ERA_RSET 0x60 /* hard error: reset, then retry */ +#define XY_ERA_WPRO 0x90 /* write protected */ + + diff --git a/sys/arch/sun3/dev/xyvar.h b/sys/arch/sun3/dev/xyvar.h new file mode 100644 index 00000000000..02fe755dc72 --- /dev/null +++ b/sys/arch/sun3/dev/xyvar.h @@ -0,0 +1,168 @@ +/* $NetBSD: xyvar.h,v 1.1 1995/10/30 20:58:23 gwr Exp $ */ + +/* + * + * Copyright (c) 1995 Charles D. Cranor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles D. Cranor. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * x y v a r . h + * + * this file defines the software structure we use to control the + * 450/451. + * + * author: Chuck Cranor <chuck@ccrc.wustl.edu> + */ + +/* + * i/o request: wrapper for hardware's iopb data structure + */ + +struct xy_iorq { + struct xy_iopb *iopb; /* address of matching iopb */ + struct xyc_softc *xyc; /* who we are working with */ + struct xy_softc *xy; /* which disk */ + int ttl; /* time to live */ + int mode; /* current mode (state+other data) */ + int tries; /* number of times we have tried it */ + int errno; /* error number if we fail */ + int lasterror; /* last error we got */ + int blockno; /* starting block no for this xfer */ + int sectcnt; /* number of sectors in xfer */ + char *dbuf; /* KVA of data buffer (advances) */ + char *dbufbase; /* base of dbuf */ + struct buf *buf; /* for NORM */ +}; + +/* + * state + */ + +#define XY_SUB_MASK 0xf0 /* mask bits for state */ +#define XY_SUB_FREE 0x00 /* free */ +#define XY_SUB_NORM 0x10 /* normal I/O request */ +#define XY_SUB_WAIT 0x20 /* normal I/O request in the + context of a process */ +#define XY_SUB_POLL 0x30 /* polled mode */ +#define XY_SUB_DONE 0x40 /* not active, but can't be free'd yet */ +#define XY_SUB_NOQ 0x50 /* don't queue, just submit (internal) */ + +#define XY_STATE(X) ((X) & XY_SUB_MASK) /* extract state from mode */ +#define XY_NEWSTATE(OLD, NEW) (((OLD) & ~XY_SUB_MASK) |(NEW)) /* new state */ + + +/* + * other mode data + */ + +#define XY_MODE_VERBO 0x08 /* print error messages */ +#define XY_MODE_B144 0x04 /* handling a bad144 sector */ + + +/* + * software timers and flags + */ + +#define XYC_SUBWAITLIM 4 /* max number of "done" IOPBs there can be + where we still allow a SUB_WAIT command */ +#define XYC_TICKCNT (5*hz) /* call xyc_tick on this interval (5 sec) */ +#define XYC_MAXTTL 2 /* max number of xy ticks to live */ +#define XYC_NOUNIT (-1) /* for xycmd: no unit number */ + +/* + * a "xy_softc" structure contains per-disk state info. + */ + +struct xy_softc { + struct device sc_dev; /* device struct, reqd by autoconf */ + struct dkdevice sc_dk; /* dkdevice: hook for iostat */ + struct xyc_softc *parent; /* parent */ + u_short flags; /* flags */ + u_short state; /* device state */ + int xy_drive; /* unit number */ + int drive_type; /* drive type (as per disk) */ + /* geometry */ + u_short ncyl, acyl, pcyl; /* number of cyl's */ + u_short sectpercyl; /* nhead*nsect */ + u_char nhead; /* number of heads */ + u_char nsect; /* number of sectors per track */ + u_char hw_spt; /* as above, but includes spare sectors */ + struct xy_iorq *xyrq; /* this disk's ioreq structure */ + struct buf xyq; /* queue'd I/O requests */ + struct dkbad dkb; /* bad144 sectors */ +}; + +/* + * flags + */ + +#define XY_WLABEL 0x0001 /* write label */ +/* + * state + */ + +#define XY_DRIVE_UNKNOWN 0 /* never talked to it */ +#define XY_DRIVE_ATTACHING 1 /* attach in progress */ +#define XY_DRIVE_NOLABEL 2 /* drive on-line, no label */ +#define XY_DRIVE_ONLINE 3 /* drive is on-line */ + +/* + * a "xyc_softc" structure contains per-disk-controller state info, + * including a list of active controllers. + */ + +struct xyc_softc { + struct device sc_dev; /* device struct, reqd by autoconf */ + struct evcnt sc_intrcnt; /* event counter (for vmstat -i) */ + + struct xyc *xyc; /* vaddr of vme registers */ + + struct xy_softc *sc_drives[XYC_MAXDEV]; /* drives on this controller */ + int ipl; /* interrupt level */ + int vector; /* interrupt vector */ + + struct xy_iorq *reqs; /* i/o requests */ + struct xy_iopb *iopbase; /* iopb base addr (maps iopb->iorq) */ + struct xy_iopb *dvmaiopb; /* iopb base in DVMA space, not kvm */ + + struct xy_iorq *ciorq; /* controller's iorq */ + struct xy_iopb *ciopb; /* controller's iopb */ + + int xy_hand; /* hand */ + struct xy_iorq *xy_chain[XYC_MAXIOPB]; + /* current chain */ + int no_ols; /* disable overlap seek for stupid 450s */ +}; + +/* + * reset blast modes + */ + +#define XY_RSET_NONE (struct xy_iorq *)(-1) /* restart all requests */ +#define XY_RSET_ALL (struct xy_iorq *)(-2) /* don't restart anything */ |