From 59b29023fdc43dd7b8cabafc48e29dd581ca6354 Mon Sep 17 00:00:00 2001 From: ragge Date: Sun, 13 May 2001 15:32:40 +0000 Subject: [PATCH] Update the TS11 driver to useable state. Thanks to Michael Kukat for providing a machine to test this driver. --- sys/dev/qbus/ts.c | 1339 +++++++++++++++--------------------------- sys/dev/qbus/tsreg.h | 24 +- 2 files changed, 494 insertions(+), 869 deletions(-) diff --git a/sys/dev/qbus/ts.c b/sys/dev/qbus/ts.c index 1ffc7344fbbb..2b25302dd115 100644 --- a/sys/dev/qbus/ts.c +++ b/sys/dev/qbus/ts.c @@ -1,4 +1,4 @@ -/* $NetBSD: ts.c,v 1.1 2001/05/13 15:30:10 ragge Exp $ */ +/* $NetBSD: ts.c,v 1.2 2001/05/13 15:32:40 ragge Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -69,52 +69,13 @@ * should be TS11 compatible (untested) */ -#define TS11_COMPAT /* don't use extended features provided by TS05 */ - -#ifdef NEED_18BIT -#define TS_UBAFLAGS UBA_NEED16 -#else -#define TS_UBAFLAGS 0 -#endif - -#define ENABLE_ESS -#define ENABLE_END - -#define ENABLE_EAI /* enable Attention-Interrupts */ -#undef ENABLE_EAI - -#define ENABLE_ERI /* Enable Release Buffer Interrupts */ -#undef ENABLE_ERI - -#ifdef DEBUG -int tsdebug = 1; -# define debug(x) if (tsdebug > 0) {DELAY(2000); printf x; DELAY(3000);} -# define debug10(x) if (tsdebug > 9) printf x -#else -# define debug(x) /* just ignore it */ -# define debug10(x) /* just ignore it */ -#endif - -#ifdef TRACE -int tstrace = 1; -# define trace(x) if (tstrace > 0) {DELAY(2000); printf x; DELAY(3000);} -#else -# define trace(x) /* just ignore it */ -#endif +#undef TSDEBUG /* - * TODO: most :-) + * TODO: * - * include uba-mapping into tsinit(); - * merge tsinit(), tsreset() and tsprobe(); - * complete tsintr(); - * add proper error/status messages - * make messages appear where they are intended to. - * check for termination-classes and appropriate actions. - * check if flags like CVC and ATTN should be used. - * look for correct handling of attentions. - * check for correct usage of retry-commands. - * ... + * Keep track of tape position so that lseek et al works. + * Use tprintf to inform the user, not the system console. */ @@ -132,28 +93,20 @@ int tstrace = 1; #include #include -#include -#include -#include -#include +#include #include #include -#include +#include -#include "opt_vax750.h" +#include "ioconf.h" -#include "ts.h" - -/* - * ts command packets and communication area (per controller) - */ struct ts { - struct tsdevice *reg; /* address of i/o-registers */ - struct tscmd cmd; /* command packet(s) */ - struct tsmsg msg; /* message packet(s) */ -} ts[NTS]; + struct cmd cmd; /* command packet */ + struct chr chr; /* characteristics packet */ + struct status status; /* status packet */ +}; /* * Software status, per controller. @@ -163,59 +116,63 @@ struct ts { struct ts_softc { struct device sc_dev; /* Autoconf ... */ struct uba_unit sc_unit; /* Struct common for UBA to talk */ - struct ts *sc_ts; /* Unibus address of uda struct */ + struct evcnt sc_intrcnt; /* Interrupt counting */ + struct ubinfo sc_ui; /* mapping info for struct ts */ + struct uba_unit sc_uu; /* Struct for UBA to communicate */ + bus_space_tag_t sc_iot; + bus_addr_t sc_ioh; + bus_dma_tag_t sc_dmat; + bus_dmamap_t sc_dmam; + volatile struct ts *sc_vts; /* Memory address of ts struct */ + struct ts *sc_bts; /* Unibus address of ts struct */ + int sc_type; /* TS11 or TS05? */ + short sc_waddr; /* Value to write to TSDB */ + struct buf_queue sc_bufq; /* pending I/O requests */ + short sc_mapped; /* Unibus map allocated ? */ - int sc_ubainfo; /* Unibus mapping info */ short sc_state; /* see below: ST_xxx */ - short sc_flags; /* see below: FL_xxx */ - short sc_lcmd; /* last command word */ short sc_rtc; /* retry count for lcmd */ - short sc_lssr; /* last status register */ - short sc_lmsgh; /* last message header */ - short sc_lxst0; /* last status word */ - short sc_cmdf; /* command flags (ack,cvc,ie) */ short sc_openf; /* lock against multiple opens */ short sc_liowf; /* last operation was write */ - int sc_micro; /* microcode revision */ - int sc_ivec; /* interrupt vector address */ - short sc_ipl; /* interrupt priority, Q-bus */ + struct buf ts_cbuf; /* internal cmd buffer (for ioctls) */ }; -void tsintr __P((int)); -int tsinit __P((struct ts_softc *)); -void tscommand __P((dev_t, int, int)); -int tsstatus __P((int)); -int tsexec __P((int, int)); -int tsstart __P((struct ts_softc *, struct buf *)); -int tswchar __P((int)); -void tsreset __P((int)); -void tsxstatus __P((struct tsmsg *)); -int tsmatch __P((struct device *, void *, void *)); -void tsattach __P((struct device *, struct device *, void *)); -void tsstrategy __P((struct buf *)); +#define XNAME sc->sc_dev.dv_xname -int tsopen __P((dev_t, int, int, struct proc *)); -int tsclose __P((dev_t, int, int, struct proc *)); -int tsioctl __P((dev_t, u_long, caddr_t, int, struct proc *)); -int tsread __P((dev_t, struct uio *)); -int tswrite __P((dev_t, struct uio *)); -int tsdump __P((dev_t, daddr_t, caddr_t, size_t)); +#define TS_WCSR(csr, val) \ + bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val) +#define TS_RCSR(csr) \ + bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr) + +#define LOWORD(x) ((int)(x) & 0xffff) +#define HIWORD(x) (((int)(x) >> 16) & 0x3f) + +#define TYPE_TS11 0 +#define TYPE_TS05 1 +#define TYPE_TU80 2 + +#define TS_INVALID 0 +#define TS_INIT 1 +#define TS_RUNNING 2 +#define TS_FASTREPOS 3 + +static void tsintr(void *); +static void tsinit(struct ts_softc *); +static void tscommand(struct ts_softc *, dev_t, int, int); +static int tsstart(struct ts_softc *, int); +static void tswchar(struct ts_softc *); +static int tsreset(struct ts_softc *); +static int tsmatch(struct device *, struct cfdata *, void *); +static void tsattach(struct device *, struct device *, void *); +static int tsready(struct uba_unit *); + +cdev_decl(ts); +bdev_decl(ts); struct cfattach ts_ca = { sizeof(struct ts_softc), tsmatch, tsattach }; -extern struct cfdriver ts_cd; - -#define ST_INVALID 0 /* uninitialized, before probe */ -#define ST_PROBE 1 /* during tsprobe(), not used */ -#define ST_SLAVE 2 /* in tsslave(), init almost complete */ -#define ST_ATTACH 3 /* during tsattach(), not used */ -#define ST_INITIALIZED 4 /* init completed, set by tsintr() */ -#define ST_RUNNING 5 -#define ST_IDLE 6 -#define ST_BUSY 7 - /* Bits in minor device */ #define TS_UNIT(dev) (minor(dev)&03) #define TS_HIDENSITY 010 @@ -224,132 +181,123 @@ extern struct cfdriver ts_cd; /* - * Since we don't have credits and thus only one operation per time, - * we don't have and don't need queues like MSCP/TMSCP use them. - * Per controller we only need one internal buffer for ioctls and - * two pointers to buffers to simulate similiar behaviour ... + * Probe for device. If found, try to raise an interrupt. */ -struct buf ts_cbuf[NTS]; /* internal cmd buffer (for ioctls) */ -struct buf *ts_wtab[NTS]; /* dummy I/O wait queue */ -#define b_ubinfo b_resid /* Unibus mapping info, per buffer */ +int +tsmatch(struct device *parent, struct cfdata *match, void *aux) +{ + struct ts_softc ssc; + struct ts_softc *sc = &ssc; + struct uba_attach_args *ua = aux; + int i; -/*----------------------------------------------------------------------*/ + sc->sc_iot = ua->ua_iot; + sc->sc_ioh = ua->ua_ioh; + sc->sc_mapped = 0; + sc->sc_dev.dv_parent = parent; + strcpy(XNAME, "ts"); + + /* Try to reset the device */ + for (i = 0; i < 3; i++) + if (tsreset(sc) == 1) + break; + + if (i == 3) + return 0; + + tsinit(sc); + tswchar(sc); /* write charact. to enable interrupts */ + /* completion of this will raise the intr. */ + + DELAY(1000000); /* Wait for interrupt */ + ubmemfree((void *)parent, &sc->sc_ui); + return 1; +} + +/* + */ +void +tsattach(struct device *parent, struct device *self, void *aux) +{ + struct uba_softc *uh = (void *)parent; + struct ts_softc *sc = (void *)self; + struct uba_attach_args *ua = aux; + int error; + char *t; + + sc->sc_iot = ua->ua_iot; + sc->sc_ioh = ua->ua_ioh; + sc->sc_dmat = ua->ua_dmat; + + sc->sc_uu.uu_softc = sc; + sc->sc_uu.uu_ready = tsready; + + tsinit(sc); /* reset and map */ + + if ((error = bus_dmamap_create(sc->sc_dmat, (64*1024), 16, (64*1024), + 0, BUS_DMA_NOWAIT, &sc->sc_dmam))) + return printf(": failed create DMA map %d\n", error); + + BUFQ_INIT(&sc->sc_bufq); + + /* + * write the characteristics (again) + */ + sc->sc_state = TS_INIT; /* tsintr() checks this ... */ + tswchar(sc); + if (tsleep(sc, PRIBIO, "tsattach", 100)) + return printf(": failed SET CHARACTERISTICS\n"); + + sc->sc_state = TS_RUNNING; + if (uh->uh_type == UBA_UBA) { + if (sc->sc_vts->status.xst2 & TS_SF_TU80) { + sc->sc_type = TYPE_TU80; + t = "TU80"; + } else { + sc->sc_type = TYPE_TS11; + t = "TS11"; + } + } else { + sc->sc_type = TYPE_TS05; + t = "TS05"; + } + + printf("\n%s: %s\n", XNAME, t); + printf("%s: rev %d, extended features %s, transport %s\n", + XNAME, (sc->sc_vts->status.xst2 & TS_SF_MCRL) >> 2, + (sc->sc_vts->status.xst2 & TS_SF_EFES ? "enabled" : "disabled"), + (TS_RCSR(TSSR) & TS_OFL ? "offline" : "online")); + + uba_intr_establish(ua->ua_icookie, ua->ua_cvec, tsintr, + sc, &sc->sc_intrcnt); + evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt, + sc->sc_dev.dv_xname, "intr"); +} /* * Initialize a TS device. Set up UBA mapping registers, * initialize data structures, what else ??? */ -int -tsinit (sc) - struct ts_softc *sc; +void +tsinit(struct ts_softc *sc) { - volatile struct tsdevice *tsregs; - int unit = sc->sc_dev.dv_unit; - struct uba_unit *uu; - - uu = &sc->sc_unit; - tsregs = (struct tsdevice *)ts[unit].reg; if (sc->sc_mapped == 0) { + /* * Map the communications area and command and message * buffer into Unibus address space. */ - sc->sc_ubainfo = uballoc((struct uba_softc *) - sc->sc_dev.dv_parent, - (caddr_t)&ts[unit], sizeof (struct ts), TS_UBAFLAGS); - sc->sc_ts = (struct ts *)(UBAI_ADDR(sc->sc_ubainfo)); + sc->sc_ui.ui_size = sizeof(struct ts); + if ((ubmemalloc((void *)sc->sc_dev.dv_parent, + &sc->sc_ui, UBA_CANTWAIT))) + return; + sc->sc_vts = (void *)sc->sc_ui.ui_vaddr; + sc->sc_bts = (void *)sc->sc_ui.ui_baddr; + sc->sc_waddr = sc->sc_ui.ui_baddr | + ((sc->sc_ui.ui_baddr >> 16) & 3); sc->sc_mapped = 1; } - - /* - * bertram: start hardware initialization ?????? - */ - - /* tsreset(unit); */ - - return (1); -} - -/* - * send a command using the default command-buffer for this unit/controller. - * If a command-word is given, then assemble a one-word command. - * other words in command-buffer are unchanged and must thus be initialized - * before calling this function. - */ -int -tsexec (ctlr, cmd) - int ctlr; - int cmd; -{ - register struct ts_softc *sc = ts_cd.cd_devs[ctlr]; - register struct tscmd *tscmdp = &ts[ctlr].cmd; - register long tscmdma = (long)&sc->sc_ts->cmd; /* mapped address */ - volatile struct tsdevice *tsreg = ts[ctlr].reg; - volatile char *dbx = ((char*)tsreg) + 3; - volatile short sr; - - sc->sc_cmdf |= TS_CF_ACK | TS_CF_IE; - tscmdp->cmdr = sc->sc_cmdf | cmd; - tscmdp->cmdr = TS_CF_ACK | TS_CF_IE | sc->sc_cmdf | cmd; - sc->sc_cmdf = 0; /* XXX */ - -#ifdef DEBUG - switch (tscmdp->cmdr & TS_CF_CMASK) { - case TS_CMD_RNF: cmdName = "Read Next (Forward)"; break; - case TS_CMD_RPR: cmdName = "Read Previous (Reverse)"; break; - case TS_CMD_WCHAR: cmdName = "Write Characteristics"; break; - case TS_CMD_WD: cmdName = "Write Data (Next)"; break; - case TS_CMD_WDR: cmdName = "Write Data (Retry)"; break; - case TS_CMD_SRF: cmdName = "Space Records Forward"; break; - case TS_CMD_SRR: cmdName = "Space Records Reverse"; break; - case TS_CMD_STMF: cmdName = "Skip Tape Marks Forward"; break; - case TS_CMD_STMR: cmdName = "Skip Tape Marks Reverse"; break; - case TS_CMD_RWND: cmdName = "Rewind"; break; - case TS_CMD_WTM: cmdName = "Write Tape Mark"; break; - case TS_CMD_WTMR: cmdName = "Write Tape Mark (Retry)"; break; - case TS_CMD_STAT: cmdName = "Get Status (END)"; break; - default: cmdName = "unexptected Command"; break; - } -#endif - - sr = tsreg->tssr; - if ((sr & TS_SSR) == 0) { /* subsystem NOT ready */ - printf ("%s%d: subsystem not ready [%x]\n", - sc->sc_dev.dv_xname, sr); - return (-1); - } - dbx = ((char*)tsreg) + 3; /* dbx is located at the fourth byte */ - *dbx = (tscmdma >> 18) & 0x0F; /* load bits 18-21 into dbx */ - - /* possible race-condition with ATTN !!! */ - - sr = tsreg->tssr; - if ((sr & TS_RMR) != 0) { /* Register modification Refused */ - printf ("ts: error writing TSDBX\n"); - return (-1); - } - /* now load bits 15-2 at pos 15-2 and bits 17,16 at pos 1,0 of TSDB */ - tsreg->tsdb = (tscmdma & 0xfffc) | ((tscmdma >> 16) & 0x03); - - /* - * wait for SSR or RMR to show up - */ - sr = tsreg->tssr; - if ((sr & TS_SSR) != 0) { /* something went wrong .. */ - if (sr & TS_RMR) { - printf ("ts: error writing TSDB (RMR)\n"); - return (-1); - } - if (sr & TS_NXM) { - printf ("ts: error writing TSDB (NXM)\n"); - return (-1); - } - printf ("ts: error 0x%x while writing TSDB\n", sr); - tsstatus (sr); - return (-1); - } - - return (0); /* completed successfully */ + tsreset(sc); } /* @@ -358,19 +306,18 @@ tsexec (ctlr, cmd) * issues the command to the controller. */ void -tscommand (dev, cmd, count) - register dev_t dev; - int cmd; - int count; +tscommand(struct ts_softc *sc, dev_t dev, int cmd, int count) { - register struct buf *bp; - register int s; + struct buf *bp; + int s; - trace (("tscommand (%d, %x, %d)\n", TS_UNIT(dev), cmd, count)); +#ifdef TSDEBUG + printf("tscommand (%x, %d)\n", cmd, count); +#endif + + bp = &sc->ts_cbuf; s = splbio(); - bp = &ts_cbuf[TS_UNIT(dev)]; - while (bp->b_flags & B_BUSY) { /* * This special check is because B_BUSY never @@ -383,7 +330,6 @@ tscommand (dev, cmd, count) /* check MOT-flag !!! */ } bp->b_flags = B_BUSY | B_READ; - splx(s); /* @@ -396,19 +342,16 @@ tscommand (dev, cmd, count) bp->b_bcount = count; bp->b_resid = cmd; bp->b_blkno = 0; - tsstrategy (bp); + tsstrategy(bp); /* * In case of rewind from close, don't wait. * This is the only case where count can be 0. */ - if (count == 0) { - debug (("tscommand: direct return, no biowait.\n")); + if (count == 0) return; - } - debug (("tscommand: calling biowait ...\n"));; - biowait (bp); + biowait(bp); if (bp->b_flags & B_WANTED) - wakeup ((caddr_t)bp); + wakeup((caddr_t)bp); bp->b_flags &= B_ERROR; } @@ -416,122 +359,46 @@ tscommand (dev, cmd, count) * Start an I/O operation on TS05 controller */ int -tsstart (sc, bp) - register struct ts_softc *sc; - register struct buf *bp; +tsstart(struct ts_softc *sc, int isloaded) { - int ctlr = sc->sc_dev.dv_unit; - volatile struct tsdevice *tsreg = ts[ctlr].reg; - register struct tscmd *tscmdp = &ts[ctlr].cmd; - register struct buf *dp; - volatile int i, itmp; - int ioctl; + struct buf *bp; int cmd; - if ((dp = ts_wtab[ctlr]) != NULL) { - /* - * There's already a command pending ... - * Either we are called by tsintr or we have missed - * something important (race condition). - */ - - /* bertram: ubarelse ??? */ - ts_wtab[ctlr] = NULL; - dp->b_flags |= B_ERROR; - biodone (dp); - - if (tsreg->tssr & TS_SC) { /* Special Condition; Error */ - log (TS_PRI, "%s: tssr 0x%x, state %d\n", - sc->sc_dev.dv_xname, tsreg->tssr, sc->sc_state); - tsinit (sc); - return (-1); - } - /* XXX */ - } + if (TAILQ_EMPTY(&sc->sc_bufq.bq_head)) + return 0; + bp = BUFQ_FIRST(&sc->sc_bufq); +#ifdef TSDEBUG + printf("buf: %p bcount %ld blkno %d\n", bp, bp->b_bcount, bp->b_blkno); +#endif /* * Check if command is an ioctl or not (ie. read or write). * If it's an ioctl then just set the flags for later use; * For other commands attempt to setup a buffer pointer. */ - if (bp == &ts_cbuf[ctlr]) { - ioctl = 1; - } else { - ioctl = 0; - - /* - * now we try to map the buffer into uba map space (???) - */ - i = TS_UBAFLAGS; - switch (vax_cputype) { - case VAX_8600: - case VAX_780: - i |= UBA_CANTWAIT; - break; - case VAX_750: - i |= sc->sc_unit.uu_ubinfo | UBA_CANTWAIT; - break; - case VAX_730: - case VAX_78032: - i |= UBA_CANTWAIT; - break; - default: - printf ("unsupported cpu %d in tsstart.\n", vax_cputype); - } /* end switch (vax_cputype) */ - - if ((i = ubasetup(sc->sc_dev.dv_parent->dv_unit, bp, i)) == 0) { - /* - * For some reasons which I don't (yet? :) understand, - * tmscp.c initiates in this situation a GET-UNIT - * command. (Because no data-buffers are neccess. ??) - */ - cmd = TS_CMD_STAT; - goto do_cmd; - return (-1); /* ??? */ - } -#if VAX750 - if (vax_cputype == VAX_750) - itmp = i & 0xfffffff; /* mask off bdp */ - else -#endif - itmp = i; - - /* XXX */ - } - - /* - * If it's an ioctl command, then assemble the command. - * The "b_resid" field holds the command-number as defined - * in - */ - if (ioctl) { + if (bp == &sc->ts_cbuf) { switch ((int)bp->b_resid) { case MTWEOF: cmd = TS_CMD_WTM; break; case MTFSF: cmd = TS_CMD_STMF; - tscmdp->cw1 = bp->b_bcount; + sc->sc_vts->cmd.cw1 = bp->b_bcount; break; case MTBSF: cmd = TS_CMD_STMR; - tscmdp->cw1 = bp->b_bcount; + sc->sc_vts->cmd.cw1 = bp->b_bcount; break; case MTFSR: cmd = TS_CMD_SRF; - tscmdp->cw1 = bp->b_bcount; + sc->sc_vts->cmd.cw1 = bp->b_bcount; break; case MTBSR: cmd = TS_CMD_SRR; - tscmdp->cw1 = bp->b_bcount; + sc->sc_vts->cmd.cw1 = bp->b_bcount; break; case MTREW: cmd = TS_CMD_RWND; -#ifndef TS11_COMPAT - if (bp->b_bcount == 0) { - cmd = TS_CMD_RWII; - } -#endif break; case MTOFFL: cmd = TS_CMD_RWUL; @@ -545,37 +412,57 @@ tsstart (sc, bp) /* Need a no-op. get status */ cmd = TS_CMD_STAT; } /* end switch (bp->b_resid) */ - } else { /* Its a read/write command (not an ioctl) */ - tscmdp->cw1 = UBAI_ADDR(i) & 0xffff; - tscmdp->cw2 = (UBAI_ADDR(i) >> 16) & 0x3f; - tscmdp->cw3 = bp->b_bcount; - - if (bp->b_flags & B_READ) { + } else { + if (isloaded == 0) { + /* + * now we try to map the buffer into uba map space (???) + */ + if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam, + bp->b_data, + bp->b_bcount, bp->b_proc, BUS_DMA_NOWAIT)) { + uba_enqueue(&sc->sc_uu); + return 0; + } + sc->sc_rtc = 0; + } + sc->sc_vts->cmd.cw1 = LOWORD(sc->sc_dmam->dm_segs[0].ds_addr); + sc->sc_vts->cmd.cw2 = HIWORD(sc->sc_dmam->dm_segs[0].ds_addr); + sc->sc_vts->cmd.cw3 = bp->b_bcount; + bp->b_error = 0; /* Used for error count */ +#ifdef TSDEBUG + printf("tsstart-1: err %d\n", bp->b_error); +#endif + if (bp->b_flags & B_READ) cmd = TS_CMD_RNF; - } - else { + else cmd = TS_CMD_WD; - } - bp->b_ubinfo = itmp; /* save mapping info */ } - /* - * Move buffer to I/O wait pseudo-queue - */ - if (ts_wtab[ctlr]) { - /* - * we are already waiting for something ... - * this should not happen, so we have a problem now. - * bertram: set error-flag and call biodone() ??? - */ - } - ts_wtab[ctlr] = bp; - /* * Now that the command-buffer is setup, give it to the controller */ -do_cmd: - return (tsexec(ctlr, cmd)); + sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | cmd; +#ifdef TSDEBUG + printf("tsstart: sending cmdr %x\n", sc->sc_vts->cmd.cmdr); +#endif + TS_WCSR(TSDB, sc->sc_waddr); +} + +/* + * Called when there are free uba resources. + */ +int +tsready(struct uba_unit *uu) +{ + struct ts_softc *sc = uu->uu_softc; + struct buf *bp = BUFQ_FIRST(&sc->sc_bufq); + + if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam, bp->b_data, + bp->b_bcount, bp->b_proc, BUS_DMA_NOWAIT)) + return 0; + + tsstart(sc, 1); + return 1; } /* @@ -583,264 +470,82 @@ do_cmd: * contents of command- and message-buffer are assembled during this * function. */ -int -tswchar (ctlr) - int ctlr; +void +tswchar(struct ts_softc *sc) { - struct ts_softc *sc = ts_cd.cd_devs[ctlr]; - volatile struct tsdevice *tsregs = ts[ctlr].reg; - volatile struct tscmd *tscmdp = &ts[ctlr].cmd; - volatile struct tsmsg *tsmsgp = &ts[ctlr].msg; - volatile unsigned int sr, ma, timeout; - /* * assemble and send "WRITE CHARACTERISTICS" command */ - ma = (long)tsmsgp; - if (ma & 0x7FC00001) { /* address must be even and 22-bit */ - printf ("invalid address 0x%0x for msg-buffer.\n", ma); - return (-1); - } - tsmsgp->hdr = ma & 0xFFFF; /* low order addr. bits */ - tsmsgp->dfl = (ma >> 16) & 0x003F; /* high order addr. bits */ - tsmsgp->rbpcr = 16; /* size of message-buffer */ - tsmsgp->xst0 = 0; /* chacacteristics mode word */ - tsmsgp->xst1 = 0; /* control word (ext.feat.) */ + sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | TS_CMD_WCHAR; + sc->sc_vts->cmd.cw1 = LOWORD(&sc->sc_bts->chr); + sc->sc_vts->cmd.cw2 = HIWORD(&sc->sc_bts->chr); + sc->sc_vts->cmd.cw3 = 010; /* size of charact.-data */ -#ifdef TS11_COMPAT - tsmsgp->rbpcr = 14; /* size of message-buffer */ - tsmsgp->xst0 = 0; /* chacacteristics mode word */ - tsmsgp->xst1 = 0; /* control word (ext.feat.) */ -#else - tsmsgp->rbpcr = 16; /* size of extended message buffer */ - tsmsgp->xst0 = 0; /* chacacteristics mode word */ - tsmsgp->xst1 = 0; /* unit-select */ - tsmsgp->xst1 |= TS_WC_HSP; /* high speed */ -#endif + sc->sc_vts->chr.sadrl = LOWORD(&sc->sc_bts->status); + sc->sc_vts->chr.sadrh = HIWORD(&sc->sc_bts->status); + sc->sc_vts->chr.onesix = (sc->sc_type == TYPE_TS05 ? 020 : 016); + sc->sc_vts->chr.chrw = TS_WC_ESS; + sc->sc_vts->chr.xchrw = TS_WCX_HSP|TS_WCX_RBUF|TS_WCX_WBUF; -#ifdef ENABLE_ESS - tsmsgp->xst0 |= TS_WC_ESS; -#ifdef ENABLE_ENB - tsmsgp->xst0 |= TS_WC_ENB; -#endif -#endif - -#ifdef ENABLE_EAI - tsmsgp->xst0 |= TS_WC_EAI; -#ifdef ENABLE_ERI - tsmsgp->xst0 |= TS_WC_ERI; -#endif -#endif - - tscmdp->cmdr = TS_CF_ACK | TS_CF_IE | TS_CMD_WCHAR; /* obsolete */ - tscmdp->cw1 = ma & 0xFFFF; - tscmdp->cw2 = (ma >> 16) & 0x003F; - tscmdp->cw3 = 10; /* size of charact.-data */ - - if (tsexec (ctlr, TS_CMD_WCHAR) < 0) { - printf ("%s: write characteristics command failed [%x]\n", - sc->sc_dev.dv_xname, tsregs->tssr); - return (-1); - } - - timeout = 1000; /* timeout in 10 seconds */ - do { - DELAY(10000); - sr = tsregs->tssr; - debug10 (("\ttssr: 0x%x\n", sr)); - if (timeout-- > 0) { - printf ("timeout during initialize."); - tsstatus (sr); - return (-1); - } - } while ((sr & TS_SSR) == 0); - tsstatus (sr); - - return (0); + TS_WCSR(TSDB, sc->sc_waddr); } /* - * + * Reset the TS11. Return 1 if failed, 0 if succeeded. */ -void -tsreset(ctlr) - int ctlr; +int +tsreset(struct ts_softc *sc) { - struct ts_softc *sc = ts_cd.cd_devs[ctlr]; - volatile struct tsdevice *tsreg = ts[ctlr].reg; - volatile unsigned int sr, timeout; + int timeout; /* * reset ctlr by writing into TSSR, then write characteristics */ - timeout = 1000; /* timeout in 10 seconds */ - tsreg->tssr = 0; /* start initialization */ - do { + timeout = 0; /* timeout in 10 seconds */ + TS_WCSR(TSSR, 0); /* start initialization */ + while ((TS_RCSR(TSSR) & TS_SSR) == 0) { DELAY(10000); - sr = tsreg->tssr; - debug10 (("\ttssr: 0x%x\n", sr)); - if (timeout-- > 0) { - if (sr != 0) - printf ("%s: timeout waiting for TS_SSR\n", - sc->sc_dev.dv_xname); - tsstatus (sr); - return; - } - } while ((sr & TS_SSR) == 0); /* wait until subsystem ready */ - tsstatus (sr); - - return; -} - -/* - * probe for device. If found, try to raise an interrupt. - * XXX - most of this should be done in the attach routine. - */ -int -tsmatch(parent, match, aux) - struct device *parent; - void *match, *aux; -{ - struct ts_softc *sc = match; - struct uba_softc *uh = (void *)parent; - struct uba_attach_args *ua = aux; - struct tsdevice *tsregs = (struct tsdevice*)ua->ua_addr; - volatile unsigned int sr, timeout, count; - int ctlr = sc->sc_dev.dv_unit; - - ts_wtab[ctlr] = NULL; - sc->sc_ts = &ts[ctlr]; - sc->sc_state = ST_PROBE; - sc->sc_flags = 0; - ts[ctlr].reg = (struct tsdevice*)ua->ua_addr; - - /* - * Set host-settable interrupt vector. - * Assign 0 to the TSSR register to start the ts-device initialization. - * The device is not really initialized at this point, this is just to - * find out if the device exists. - */ - sc->sc_ivec = (uh->uh_lastiv -= 4); - - count = 0; -again: - timeout = 1000; /* timeout in 10 seconds */ - tsregs->tssr = 0; /* start initialization */ - do { - DELAY(10000); - sr = tsregs->tssr; - debug10 (("\ttssr-1: 0x%x\n", sr)); - if (timeout-- > 0) { - if (sr != 0) /* the device exists !!! */ - printf ("%s: timeout waiting for TS_SSR\n", - sc->sc_dev.dv_xname); - tsstatus (sr); - goto bad; - } - } while ((sr & TS_SSR) == 0); /* wait until subsystem ready */ - tsstatus (sr); - - tswchar (ctlr); /* write charact. to enable interrupts */ - /* completion of this will raise the intr. */ - -#ifdef notyet - sc->sc_ipl = br = qbgetpri(); -#else - sc->sc_ipl = 0x15; -#endif - return (sizeof (struct tsdevice)); - -bad: if (++count < 3) - goto again; - -#ifdef notyet - splx(s); -#endif - return (0); -} - - -/* - * Try to find a slave (a drive) on the controller. - * Since there's only one drive per controller there's nothing to do. - * (we could check the status of the drive (online/offline/...) - */ -void -tsattach(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct ts_softc *sc = (void *)self; - int ctlr = sc->sc_dev.dv_unit; - struct tsmsg *tsmsgp = &ts[ctlr].msg; - - trace (("tsslave (%x, %x)\n", ui, reg)); - - /* - * write the characteristics (again) - * This will raise an interrupt during ST_SLAVE which indicates - * completion of initialization ... - */ - sc->sc_state = ST_SLAVE; /* tsintr() checks this ... */ - if (tswchar (ctlr) < 0) { - printf ("%s: cannot initialize", sc->sc_dev.dv_xname); + if (timeout++ > 1000) + return 0; } - sc->sc_micro = (tsmsgp->xst2 & TS_SF_MCRL) >> 2; - printf ("%s: rev %d, extended features %s, transport %s\n", - sc->sc_dev.dv_xname, sc->sc_micro, - (tsmsgp->xst2 & TS_SF_EFES ? "enabled" : "disabled"), - (ts[ctlr].reg->tssr & TS_OFL ? "offline" : "online")); - - tsinit (sc); /* must be called once, why not here ? */ + return 1; } +static void +prtstat(struct ts_softc *sc, int sr) +{ + char buf[100]; + + bitmask_snprintf(sr, TS_TSSR_BITS, buf, sizeof(buf)); + printf("%s: TSSR=%s\n", XNAME, buf); + bitmask_snprintf(sc->sc_vts->status.xst0,TS_XST0_BITS,buf,sizeof(buf)); + printf("%s: XST0=%s\n", XNAME, buf); +} /* * TSV05/TS05 interrupt routine */ -void -tsintr(ctlr) - int ctlr; +static void +tsintr(void *arg) { - register struct ts_softc *sc = ts_cd.cd_devs[ctlr]; - register struct tsmsg *tsmsgp = &ts[ctlr].msg; - register struct tscmd *tscmdp = &ts[ctlr].cmd; - volatile struct tsdevice *tsreg = ts[ctlr].reg; - struct uba_unit *um = &sc->sc_unit; - register struct buf *bp; + struct ts_softc *sc = arg; + struct buf *bp; - unsigned short sr = tsreg->tssr; /* save TSSR */ - unsigned short mh = tsmsgp->hdr; /* and msg-header */ + unsigned short sr = TS_RCSR(TSSR); /* save TSSR */ + unsigned short mh = sc->sc_vts->status.hdr; /* and msg-header */ /* clear the message header ??? */ - short ccode = tscmdp->cmdr & TS_CF_CCODE; - short cmask = tscmdp->cmdr & TS_CF_CMASK; + short ccode = sc->sc_vts->cmd.cmdr & TS_CF_CCODE; -#ifdef DEBUG +#ifdef TSDEBUG { - char bits[64]; - printf ("TSSR: %s, MSG: %x ", bitmask_snprintf(sr, - TS_TSSR_BITS, bits, sizeof(bits)), mh); - } - switch (tsmsgp->hdr & 0x001F) { - case 16: printf ("(End)"); break; - case 17: printf ("(Fail)"); break; - case 18: printf ("(Error)"); break; - case 19: printf ("(Attention)"); break; + char buf[100]; + bitmask_snprintf(sr, TS_TSSR_BITS, buf, sizeof(buf)); + printf("tsintr: sr %x mh %x\n", sr, mh); + printf("srbits: %s\n", buf); } #endif - - trace ((" tsintr (%d, %d, %d, %x)\n", uba, vector, level, ctlr)); - - if (tsmsgp->xst0 & TS_SF_VCK) - sc->sc_cmdf |= TS_CF_CVC; - -#ifdef QBA /* copied from uda.c */ - if(vax_cputype == VAX_78032) - splx(sc->sc_ipl); /* Qbus interrupt protocol is odd */ -#endif - /* * There are two different things which can (and should) be checked: * the actual (internal) state and the device's result (tssr/msg.hdr) @@ -854,32 +559,23 @@ tsintr(ctlr) */ switch (sc->sc_state) { - case ST_INVALID: + case TS_INVALID: /* * Ignore unsolicited interrupts. */ - log (LOG_WARNING, "%s: stray intr [%x,%x]\n", + log(LOG_WARNING, "%s: stray intr [%x,%x]\n", sc->sc_dev.dv_xname, sr, mh); return; - case ST_SLAVE: + case TS_INIT: /* - * this interrupt was caused by write-charact. command - * issued by tsslave() and indicates the end of the - * initialization phase. Just ignore it ... + * Init phase ready. */ - if ((sr & TS_SC) != 0 || (sr & TS_TC) != TS_TC_NORM) { - printf("%s: problem during init [%x,%x]\n", - sc->sc_dev.dv_xname, sr, mh); - /* return here ??? */ - /* break and check the error outside switch ??? */ - break; - } - sc->sc_state = ST_RUNNING; + wakeup(sc); return; - - case ST_RUNNING: + case TS_RUNNING: + case TS_FASTREPOS: /* * Here we expect interrupts indicating the end of * commands or indicating problems. @@ -889,10 +585,6 @@ tsintr(ctlr) */ break; - case ST_IDLE: - break; - - default: printf ("%s: unexpected interrupt during state %d [%x,%x]\n", sc->sc_dev.dv_xname, sc->sc_state, sr, mh); @@ -909,32 +601,17 @@ tsintr(ctlr) * Normal termination -- The operation is completed * witout incident. */ - sc->sc_state = ST_IDLE; /* XXX ??? */ - sc->sc_state = ST_RUNNING; - sc->sc_liowf = (ccode == TS_CC_WRITE); - sc->sc_rtc = 0; - if ((bp = ts_wtab[ctlr]) != NULL) { - ts_wtab[ctlr] = NULL; /* pseudo-unlink */ - - if (bp != &ts_cbuf[ctlr]) { /* no ioctl */ - ubarelse((struct uba_softc *) - sc->sc_dev.dv_parent, - (int *)&bp->b_ubinfo); -#if VAX750 - if (vax_cputype == VAX_750 && - sc->sc_unit.uu_ubinfo != 0) - ubarelse((struct uba_softc *) - sc->sc_dev.dv_parent, - &sc->sc_unit.uu_ubinfo); - /* XXX */ + if (sc->sc_state == TS_FASTREPOS) { +#ifdef TSDEBUG + printf("Fast repos interrupt\n"); #endif - } - bp->b_resid = tsmsgp->rbpcr; - debug (("tsintr: biodone(NORM) [%d,%d,%d]\n", - bp->b_resid, bp->b_bcount, tsmsgp->rbpcr)); - biodone (bp); /* bertram: ioctl ??? */ + /* Fast repos succeeded, start normal data xfer */ + sc->sc_state = TS_RUNNING; + tsstart(sc, 1); + return; } - return; + sc->sc_liowf = (ccode == TS_CC_WRITE); + break; case TS_TC_ATTN: /* @@ -953,14 +630,49 @@ tsintr(ctlr) * interest in the extended status registers include * TMK, EOT and RLL. */ - debug (("Tape Status Alert\n")); - tsxstatus (tsmsgp); - if (tsmsgp->xst0 & TS_SF_TMK) { - debug (("Tape Mark detected")); +#ifdef TSDEBUG + { + char buf[100]; + bitmask_snprintf(sc->sc_vts->status.xst0, + TS_XST0_BITS, buf, sizeof(buf)); + printf("TSA: sr %x bits %s\n", + sc->sc_vts->status.xst0, buf); } - if (tsmsgp->xst0 & TS_SF_EOT) { - debug (("End of Tape")); +#endif + if (sc->sc_vts->status.xst0 & TS_SF_TMK) { + /* Read to end-of-file. No error. */ + break; } + if (sc->sc_vts->status.xst0 & TS_SF_EOT) { + /* End of tape. Bad. */ +#ifdef TSDEBUG + printf("TS_TC_TSA: EOT\n"); +#endif + bp->b_flags |= B_ERROR; + bp->b_error = EIO; + break; + } + if (sc->sc_vts->status.xst0 & TS_SF_RLS) + break; + if (sc->sc_vts->status.xst0 & TS_SF_TMK) { +#ifdef TSDEBUG + printf(("Tape Mark detected")); +#endif + } + if (sc->sc_vts->status.xst0 & TS_SF_EOT) { +#ifdef TSDEBUG + printf(("End of Tape")); +#endif + } +#ifndef TSDEBUG + { + char buf[100]; + bitmask_snprintf(sc->sc_vts->status.xst0, + TS_XST0_BITS, buf, sizeof(buf)); + printf("TSA: sr %x bits %s\n", + sc->sc_vts->status.xst0, buf); + } +#endif break; case TS_TC_FR: @@ -969,23 +681,25 @@ tsintr(ctlr) * initiated. Bits of interest include OFL, VCK, BOT, * WLE, ILC and ILA. */ - debug (("Function reject\n")); - tsxstatus (tsmsgp); - if (sr & TS_OFL) { - printf ("tape is off-line.\n"); - break; - } - if (tsmsgp->xst0 & TS_SF_VCK) { - printf ("Volume check: repeating command ...\n"); - tsexec (ctlr, tscmdp->cmdr); - return; - } - if (tsmsgp->xst0 & TS_SF_BOT) { - printf ("bottom of tape.\n"); - } - if (tsmsgp->xst0 & TS_SF_WLE) { - printf ("Write Lock Error\n"); + if (sr & TS_OFL) + printf("tape is off-line.\n"); +#ifdef TSDEBUG + { + char buf[100]; + bitmask_snprintf(sc->sc_vts->status.xst0, + TS_XST0_BITS, buf, sizeof(buf)); + printf("FR: sr %x bits %s\n", + sc->sc_vts->status.xst0, buf); } +#endif + if (sc->sc_vts->status.xst0 & TS_SF_VCK) + printf("Volume check\n"); + if (sc->sc_vts->status.xst0 & TS_SF_BOT) + printf("Start of tape.\n"); + if (sc->sc_vts->status.xst0 & TS_SF_WLE) + printf("Write Lock Error\n"); + if (sc->sc_vts->status.xst0 & TS_SF_EOT) + printf("End of tape.\n"); break; case TS_TC_TPD: @@ -994,32 +708,25 @@ tsintr(ctlr) * what its position was when the function was initiated. * Suggested recovery procedure is to log the error and * issue the appropriate retry command. + * + * Do a fast repositioning one record back. */ - debug (("Tape position down\n")); - switch (cmask) { - case TS_CMD_RNF: /* Read Next (forward) */ - debug (("retry read forward ...\n")); - sc->sc_rtc = 1; - tsexec (ctlr, TS_CMD_RPF); - return; - case TS_CMD_RPR: /* Read Previous (Reverse) */ - debug (("retry read reverse ...\n")); - sc->sc_rtc = 1; - tsexec (ctlr, TS_CMD_RNR); - return; - case TS_CMD_WD: /* Write Data (Next) */ - debug (("retry write data ...\n")); - sc->sc_rtc = 1; - tsexec (ctlr, TS_CMD_WDR); - return; - case TS_CMD_WTM: - debug (("retry write tape mark ...\n")); - sc->sc_rtc = 1; - tsexec (ctlr, TS_CMD_WTMR); - return; - default: - debug (("TPD in command %x\n", cmask)); + sc->sc_state = TS_FASTREPOS; +#ifdef TSDEBUG + printf("TS_TC_TPD: errcnt %d\n", sc->sc_rtc); +#endif + if (sc->sc_rtc++ == 8) { + printf("%s: failed 8 retries\n", XNAME); + prtstat(sc, sr); + bp->b_flags |= B_ERROR; + bp->b_error = EIO; + break; } + sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | TS_CMD_SRR; + sc->sc_vts->cmd.cw1 = 1; + TS_WCSR(TSDB, sc->sc_waddr); + return; + break; case TS_TC_TNM: @@ -1028,16 +735,15 @@ tsintr(ctlr) * Suggested recovery procedure is to log the error and * reissue the original command. */ - printf ("Tape not moved\n"); - if (sc->sc_rtc < 3) { - sc->sc_rtc++; - /* bertram: log the error !!! */ - printf ("retrying command %x (%d)\n", - tscmdp->cmdr, sc->sc_rtc); - tsexec (ctlr, tscmdp->cmdr); - return; + if (sc->sc_rtc++ == 8) { + printf("%s: failed 8 retries\n", XNAME); + prtstat(sc, sr); + bp->b_flags |= B_ERROR; + bp->b_error = EIO; + break; } - break; + tsstart(sc, 1); + return; case TS_TC_TPL: /* @@ -1045,7 +751,9 @@ tsintr(ctlr) * No valid recovery procedures exist unless the tape * has labels or sequence numbers. */ - printf ("Tape position lost\n"); + printf("Tape position lost\n"); + bp->b_flags |= B_ERROR; + bp->b_error = EIO; break; case TS_TC_FCE: @@ -1057,36 +765,30 @@ tsintr(ctlr) * additional information on the type of fatal error. */ printf ("Fatal Controller Error\n"); + prtstat(sc, sr); + break; default: printf ("%s: error 0x%x, resetting controller\n", sc->sc_dev.dv_xname, sr & TS_TC); - tsreset (ctlr); + tsreset(sc); } + if ((bp = TAILQ_FIRST(&sc->sc_bufq.bq_head)) != NULL) { + BUFQ_REMOVE(&sc->sc_bufq, bp); - /* - * reset controller ?? call tsinit() ??? - */ - if ((bp = ts_wtab[ctlr]) != NULL) { - ts_wtab[ctlr] = NULL; /* pseudo unlink */ - - if (bp != &ts_cbuf[ctlr]) /* no ioctl */ - ubarelse((struct uba_softc *)sc->sc_dev.dv_parent, - (int *)&bp->b_ubinfo); - - if ((sr & TS_TC) != TS_TC_NORM) - bp->b_flags |= B_ERROR; - - debug (("resid:%d, count:%d, rbpcr:%d\n", - bp->b_resid, bp->b_bcount, tsmsgp->rbpcr)); - bp->b_resid = tsmsgp->rbpcr; /* XXX */ - debug (("tsintr: biodone(%x)\n", bp->b_flags)); +#ifdef TSDEBUG + printf("tsintr2: que %p\n", TAILQ_FIRST(&sc->sc_bufq.bq_head)); +#endif + if (bp != &sc->ts_cbuf) { /* no ioctl */ + bus_dmamap_unload(sc->sc_dmat, sc->sc_dmam); + uba_done((void *)sc->sc_dev.dv_parent); + } + bp->b_resid = sc->sc_vts->status.rbpcr; + if ((bp->b_flags & B_ERROR) == 0) + bp->b_error = 0; biodone (bp); } - if ((sr & TS_TC) > TS_TC_FR) - tsreset (ctlr); - - return; + tsstart(sc, 0); } @@ -1095,19 +797,11 @@ tsintr(ctlr) * in the run state, call init to initialize the ts controller first. */ int -tsopen (dev, flag, type, p) - dev_t dev; - int flag, type; - struct proc *p; +tsopen(dev_t dev, int flag, int type, struct proc *p) { - register struct uba_device *ui; - register struct uba_ctlr *um; - register struct ts_softc *sc; - register int unit = TS_UNIT(dev); - int s; + struct ts_softc *sc; + int unit = TS_UNIT(dev); - trace (("tsopen (%x, %x)\n", dev, flag)); - if (unit >= ts_cd.cd_ndevs) return ENXIO; @@ -1115,33 +809,43 @@ tsopen (dev, flag, type, p) if (sc == 0) return ENXIO; + if (sc->sc_state < TS_RUNNING) + return ENXIO; + if (sc->sc_openf) return EBUSY; - sc->sc_openf = 1; - s = splbio (); - if (sc->sc_state < ST_RUNNING) { /* XXX */ - printf ("%s not running.\n", sc->sc_dev.dv_xname); - (void) splx (s); - sc->sc_openf = 0; - return (ENXIO); - } - (void) splx (s); - /* * check if transport is really online. * (without attention-interrupts enabled, we really don't know * the actual state of the transport. Thus we call get-status * (ie. MTNOP) once and check the actual status.) */ - tscommand (dev, MTNOP, 1); - if (ts[unit].reg->tssr & TS_OFL) { - printf ("%s: transport is offline.\n", sc->sc_dev.dv_xname); + if (TS_RCSR(TSSR) & TS_OFL) { + uprintf("%s: transport is offline.\n", XNAME); sc->sc_openf = 0; return EIO; /* transport is offline */ } - + tscommand(sc, dev, MTNOP, 1); + if ((flag & FWRITE) && (sc->sc_vts->status.xst0 & TS_SF_WLK)) { + uprintf("%s: no write ring.\n", XNAME); + sc->sc_openf = 0; + return EROFS; + } + if (sc->sc_vts->status.xst0 & TS_SF_VCK) { + sc->sc_vts->cmd.cmdr = TS_CF_CVC|TS_CF_ACK; + TS_WCSR(TSDB, sc->sc_waddr); + } + tscommand(sc, dev, MTNOP, 1); +#ifdef TSDEBUG + { + char buf[100]; + bitmask_snprintf(sc->sc_vts->status.xst0, + TS_XST0_BITS, buf, sizeof(buf)); + printf("tsopen: xst0 %s\n", buf); + } +#endif sc->sc_liowf = 0; return 0; } @@ -1157,12 +861,9 @@ tsopen (dev, flag, type, p) * Make the tape available to others, by clearing openf flag. */ int -tsclose (dev, flag, type, p) - dev_t dev; - int flag, type; - struct proc *p; +tsclose(dev_t dev, int flag, int type, struct proc *p) { - register struct ts_softc *sc = ts_cd.cd_devs[TS_UNIT(dev)]; + struct ts_softc *sc = ts_cd.cd_devs[TS_UNIT(dev)]; if (flag == FWRITE || ((flag & FWRITE) && sc->sc_liowf)) { /* @@ -1170,13 +871,13 @@ tsclose (dev, flag, type, p) * before the second one, so that another write operation * will overwrite the second one and leave and EOF-mark. */ - tscommand (dev, MTWEOF, 1); /* Write Tape Mark */ - tscommand (dev, MTWEOF, 1); /* Write Tape Mark */ - tscommand (dev, MTBSF, 1); /* Skip Tape Marks Reverse */ + tscommand(sc, dev, MTWEOF, 1); /* Write Tape Mark */ + tscommand(sc, dev, MTWEOF, 1); /* Write Tape Mark */ + tscommand(sc, dev, MTBSF, 1); /* Skip Tape Marks Reverse */ } if ((dev & T_NOREWIND) == 0) - tscommand (dev, MTREW, 0); + tscommand(sc, dev, MTREW, 0); sc->sc_openf = 0; sc->sc_liowf = 0; @@ -1188,23 +889,21 @@ tsclose (dev, flag, type, p) * Manage buffers and perform block mode read and write operations. */ void -tsstrategy (bp) - register struct buf *bp; +tsstrategy(struct buf *bp) { register int unit = TS_UNIT(bp->b_dev); struct ts_softc *sc = (void *)ts_cd.cd_devs[unit]; - int s; + int s, empty; +#ifdef TSDEBUG + printf("buf: %p bcount %ld blkno %d\n", bp, bp->b_bcount, bp->b_blkno); +#endif s = splbio (); - /* - * we have only one command at one time, no credits. - * thus we don't need buffer management and controller queue - * just try to execute the command ... - */ - - tsstart (sc, bp); + empty = TAILQ_EMPTY(&sc->sc_bufq.bq_head); + BUFQ_INSERT_TAIL(&sc->sc_bufq, bp); + if (empty) + tsstart(sc, 0); splx(s); - return; } @@ -1212,23 +911,28 @@ tsstrategy (bp) * Catch ioctl commands, and call the "command" routine to do them. */ int -tsioctl (dev, cmd, data, flag, p) +tsioctl(dev, cmd, data, flag, p) dev_t dev; u_long cmd; caddr_t data; int flag; struct proc *p; { - register struct buf *bp = &ts_cbuf[TS_UNIT(dev)]; - register struct ts_softc *sc; - register struct mtop *mtop; /* mag tape cmd op to perform */ - register struct mtget *mtget; /* mag tape struct to get info in */ - register callcount; /* number of times to call routine */ + struct buf *bp; + struct ts_softc *sc; + struct mtop *mtop; /* mag tape cmd op to perform */ + struct mtget *mtget; /* mag tape struct to get info in */ + int callcount; /* number of times to call routine */ int scount; /* number of files/records to space */ int spaceop = 0; /* flag for skip/space operation */ int error = 0; - trace (("tsioctl (%x, %x, %x, %d)\n", dev, cmd, data, flag)); +#ifdef TSDEBUG + printf("tsioctl (%x, %lx, %p, %d)\n", dev, cmd, data, flag); +#endif + + sc = ts_cd.cd_devs[TS_UNIT(dev)]; + bp = &sc->ts_cbuf; switch (cmd) { case MTIOCTOP: /* do a mag tape op */ @@ -1238,11 +942,11 @@ tsioctl (dev, cmd, data, flag, p) callcount = mtop->mt_count; scount = 1; break; - case MTFSF: /* forward space file */ - case MTBSF: /* backward space file */ case MTFSR: /* forward space record */ case MTBSR: /* backward space record */ spaceop = 1; + case MTFSF: /* forward space file */ + case MTBSF: /* backward space file */ callcount = 1; scount = mtop->mt_count; break; @@ -1260,25 +964,33 @@ tsioctl (dev, cmd, data, flag, p) case MTNOCACHE: /* disable controller cache */ case MTSETBSIZ: /* set block size; 0 for variable */ case MTSETDNSTY: /* set density code for current mode */ - debug (("ioctl %d not implemented.\n", mtop->mt_op)); + printf("ioctl %d not implemented.\n", mtop->mt_op); return (ENXIO); default: - debug (("invalid ioctl %d\n", mtop->mt_op)); +#ifdef TSDEBUG + printf("invalid ioctl %d\n", mtop->mt_op); +#endif return (ENXIO); } /* switch (mtop->mt_op) */ if (callcount <= 0 || scount <= 0) { - debug (("invalid values %d/%d\n", callcount, scount)); +#ifdef TSDEBUG + printf("invalid values %d/%d\n", callcount, scount); +#endif return (EINVAL); } do { - tscommand (dev, mtop->mt_op, scount); + tscommand(sc, dev, mtop->mt_op, scount); if (spaceop && bp->b_resid) { - debug (("spaceop didn't complete\n")); +#ifdef TSDEBUG + printf(("spaceop didn't complete\n")); +#endif return (EIO); } if (bp->b_flags & B_ERROR) { - debug (("error in ioctl %d\n", mtop->mt_op)); +#ifdef TSDEBUG + printf("error in ioctl %d\n", mtop->mt_op); +#endif break; } } while (--callcount > 0); @@ -1288,25 +1000,30 @@ tsioctl (dev, cmd, data, flag, p) return (error); case MTIOCGET: /* get tape status */ - sc = ts_cd.cd_devs[TS_UNIT(dev)]; mtget = (struct mtget *)data; mtget->mt_type = MT_ISTS; - mtget->mt_dsreg = (unsigned)(ts[TS_UNIT(dev)].reg->tssr); - mtget->mt_erreg = (unsigned)(ts[TS_UNIT(dev)].msg.hdr); + mtget->mt_dsreg = TS_RCSR(TSSR); + mtget->mt_erreg = sc->sc_vts->status.xst0; mtget->mt_resid = 0; /* ??? */ mtget->mt_density = 0; /* ??? */ break; case MTIOCIEOT: /* ignore EOT error */ - debug (("MTIOCIEOT not implemented.\n")); +#ifdef TSDEBUG + printf(("MTIOCIEOT not implemented.\n")); +#endif return (ENXIO); case MTIOCEEOT: /* enable EOT error */ - debug (("MTIOCEEOT not implemented.\n")); +#ifdef TSDEBUG + printf(("MTIOCEEOT not implemented.\n")); +#endif return (ENXIO); default: - debug (("invalid ioctl cmd 0x%x\n", cmd)); +#ifdef TSDEBUG + printf("invalid ioctl cmd 0x%lx\n", cmd); +#endif return (ENXIO); } @@ -1318,9 +1035,7 @@ tsioctl (dev, cmd, data, flag, p) * */ int -tsread (dev, uio) - dev_t dev; - struct uio *uio; +tsread(dev_t dev, struct uio *uio, int flag) { return (physio (tsstrategy, NULL, dev, B_READ, minphys, uio)); } @@ -1329,9 +1044,7 @@ tsread (dev, uio) * */ int -tswrite (dev, uio) - dev_t dev; - struct uio *uio; +tswrite(dev_t dev, struct uio *uio, int flag) { return (physio (tsstrategy, NULL, dev, B_WRITE, minphys, uio)); } @@ -1346,109 +1059,5 @@ tsdump(dev, blkno, va, size) caddr_t va; size_t size; { - trace (("tsdump (%x)\n", dev)); - return 0; -} - -/*----------------------------------------------------------------------*/ - -int -tsstatus (sr) - int sr; -{ -#ifdef DEBUG - char bits[64]; - - debug (("status: TSSR=%s\n", bitmask_snprintf(sr, TS_TSSR_BITS, - bits, sizeof(bits)))); - - if (tsdebug < 5) - return (0); - - if (sr & TS_SC) printf ("special condition\n"); - if (sr & TS_UPE) printf ("UPE\n"); - if (sr & TS_SCE) printf ("Sanity Check Error\n"); - if (sr & TS_RMR) printf ("Register Modification Refused\n"); - if (sr & TS_NXM) printf ("Nonexistent Memory\n"); - if (sr & TS_NBA) printf ("Need Buffer Address\n"); - if (sr & TS_A11) printf ("Address Bits 17-16\n"); - if (sr & TS_SSR) printf ("Subsystem Ready\n"); - if (sr & TS_OFL) printf ("Off Line\n"); - if (sr & TS_FTC) printf ("Fatal Termination Class Code\n"); - switch (sr & TS_TC) { - case TS_TC_NORM: printf ("Normal Termination\n"); break; - case TS_TC_ATTN: printf ("Attention Condition\n"); break; - case TS_TC_TSA: printf ("Tape status \n"); break; - case TS_TC_FR: printf ("Function reject\n"); break; - case TS_TC_TPD: printf ("Tape position down\n"); break; - case TS_TC_TNM: printf ("Tape not moved\n"); break; - case TS_TC_TPL: printf ("Tape position lost\n"); break; - case TS_TC_FCE: printf ("Fatal Controller Error\n"); break; - } -#endif - return (0); -} - -void -tsxstatus (mp) - struct tsmsg *mp; -{ -#ifdef DEBUG - char bits[64]; - - debug (("tsxstatus: xst0=%s, ", bitmask_snprintf(mp->xst0, - TS_XST0_BITS, bits, sizeof(bits)))); - debug (("xst1=%s, ", bitmask_snprintf(mp->xst1, TS_XST1_BITS, - bits, sizeof(bits)))); - debug (("xst2=%s, ", bitmask_snprintf(mp->xst2, TS_XST2_BITS, - bits, sizeof(bits)))); - debug (("xst3=%s, ", bitmask_snprintf(mp->xst3, TS_XST3_BITS, - bits, sizeof(bits)))); - debug (("xst4=%s\n", bitmask_snprintf(mp->xst4, "\20", - bits, sizeof(bits)))); - - if (tsdebug < 10) - return (0); - - if (mp->xst0 & TS_SF_TMK) printf ("Tape Mark Detected\n"); - if (mp->xst0 & TS_SF_RLS) printf ("Record Length Short\n"); - if (mp->xst0 & TS_SF_LET) printf ("Logical End of Tape\n"); - if (mp->xst0 & TS_SF_RLL) printf ("Record Length Long\n"); - if (mp->xst0 & TS_SF_WLE) printf ("Write Lock Error\n"); - if (mp->xst0 & TS_SF_NEF) printf ("Nonexecutable Function\n"); - if (mp->xst0 & TS_SF_ILC) printf ("Illegal Command\n"); - if (mp->xst0 & TS_SF_ILA) printf ("Illegal Address\n"); - if (mp->xst0 & TS_SF_MOT) printf ("Motion\n"); - if (mp->xst0 & TS_SF_ONL) printf ("On-Line\n"); - if (mp->xst0 & TS_SF_IE) printf ("Interrupt Enable\n"); - if (mp->xst0 & TS_SF_VCK) printf ("Volume Check\n"); - if (mp->xst0 & TS_SF_PED) printf ("Phase Encoded Drive\n"); - if (mp->xst0 & TS_SF_WLK) printf ("Write Locked\n"); - if (mp->xst0 & TS_SF_BOT) printf ("Beginning of Tape\n"); - if (mp->xst0 & TS_SF_EOT) printf ("End of Tape\n"); - - if (mp->xst1 & TS_SF_DLT) printf ("Data Late\n"); - if (mp->xst1 & TS_SF_COR) printf ("Correctable Data\n"); - if (mp->xst1 & TS_SF_RBP) printf ("Read Bus Parity Error\n"); - if (mp->xst1 & TS_SF_UNC) printf ("Uncorrectable Data or Hard Error\n"); - - if (mp->xst2 & TS_SF_OPM) printf ("Operation in Progress\n"); - if (mp->xst2 & TS_SF_RCE) printf ("RAM Checksum Error\n"); - if (mp->xst2 & TS_SF_WCF) printf ("Write Clock Failure\n"); - if (mp->xst2 & TS_SF_EFES) printf ("extended features enabled\n"); - if (mp->xst2 & TS_SF_BES) printf ("Buffering enabled\n"); - - printf ("micro-code revision level: %d\n", (mp->xst2 & TS_SF_MCRL)>>2); - printf ("unit number: %d\n", (mp->xst2 & TS_SF_UNIT)); - - if (mp->xst3 & TS_SF_MDE) - printf ("Micro-Diagnostics Error Code: 0x%x\n", mp->xst3 >> 8); - if (mp->xst3 & TS_SF_OPI) printf ("Operation Incomplete\n"); - if (mp->xst3 & TS_SF_REV) printf ("Revers\n"); - if (mp->xst3 & TS_SF_DCK) printf ("Density Check\n"); - if (mp->xst3 & TS_SF_RIB) printf ("Reverse into BOT\n"); - - if (mp->xst4 & TS_SF_HSP) printf ("High Speed\n"); - if (mp->xst4 & TS_SF_RCX) printf ("Retry Count Exceeded\n"); -#endif + return EIO; } diff --git a/sys/dev/qbus/tsreg.h b/sys/dev/qbus/tsreg.h index 53ab72004bb0..cd9e98dfa9ec 100644 --- a/sys/dev/qbus/tsreg.h +++ b/sys/dev/qbus/tsreg.h @@ -1,4 +1,4 @@ -/* $NetBSD: tsreg.h,v 1.1 2001/05/13 15:30:10 ragge Exp $ */ +/* $NetBSD: tsreg.h,v 1.2 2001/05/13 15:32:40 ragge Exp $ */ /* * Copyright (c) 1995 Ludd, University of Lule}, Sweden. * All rights reserved. @@ -42,10 +42,16 @@ * Bufffer (TSDBX). The TSDB is an 18-bit register that is ... */ +#ifdef notdef struct tsdevice { unsigned short tsdb;/* Data Buffer (TSDB)/Bus Address Register (TSBA) */ unsigned short tssr;/* Status Reg. (TSSR)/Extended Data Buffer(TSDBX) */ }; +#endif +#define TSDB 0 +#define TSBA 0 +#define TSSR 2 +#define TSDBX 3 /* * TSSR Register bit definitions @@ -83,7 +89,7 @@ struct tsdevice { #define TS_TC_TPL (6<<1) /* Tape position lost (unrecoverable) */ #define TS_TC_FCE (7<<1) /* Fatal Controller Error (see FTC) */ -struct tscmd { /* command packet (not all words required) */ +struct cmd { /* command packet (not all words required) */ unsigned short cmdr; /* command word */ unsigned short cw1; /* low order data pointer address (A15-00) */ unsigned short cw2; /* high order data pointer address (A21-16) */ @@ -144,7 +150,7 @@ struct tscmd { /* command packet (not all words required) */ #define TS_CC_STAT 0x0F /* GET STATUS */ #define TS_CMD_STAT TS_CMD(0,TS_CC_STAT) /* Get Status (END) */ -struct tsmsg { /* message packet */ +struct status { /* message packet */ unsigned short hdr; /* ACK, class-code, format 1, message type */ unsigned short dfl; /* data field length (8 bit) */ unsigned short rbpcr; /* residual b/r/tm count word */ @@ -155,6 +161,13 @@ struct tsmsg { /* message packet */ unsigned short xst4; /* total size: 16 bytes */ }; +struct chr { + unsigned short sadrl; /* low-word of status addr */ + unsigned short sadrh; + unsigned short onesix; /* 016/020 */ + unsigned short chrw; /* Characteristics word */ + unsigned short xchrw; /* TS05 extra word */ +}; /* * Flags used in write-characteristics command */ @@ -162,7 +175,9 @@ struct tsmsg { /* message packet */ #define TS_WC_ENB (1<<6) /* Enable Tape Mark Stop at Bot */ #define TS_WC_EAI (1<<5) /* Enable Attention interrupts */ #define TS_WC_ERI (1<<4) /* Enable Message Buffer Release interrupts */ -#define TS_WC_HSP (1<<5) /* High Speed Select (25 in/s vs. 100 in/s) */ +#define TS_WCX_HSP (1<<5) /* High Speed Select (25 in/s vs. 100 in/s) */ +#define TS_WCX_RBUF (1<<4) /* Enable read buffering */ +#define TS_WCX_WBUF (1<<3) /* Enable write buffering */ /* * Status flags @@ -221,6 +236,7 @@ struct tsmsg { /* message packet */ #define TS_SF_RCE (1<<14) /* RAM Checksum Error */ #define TS_SF_SBP (1<<13) /* TS11: Serial 08 bus parity */ #define TS_SF_CAF (1<<12) /* TS11: Capstan Acceleration fail */ +#define TS_SF_TU80 (1<<11) /* Is a TU80 */ #define TS_SF_WCF (1<<10) /* Write Clock Failure */ #define TS_SF_PDT (1<< 8) /* TS11: Parity Dead Track */ #define TS_SF_RL 0x00FF /* Revision Level */