3 * Streamer tape driver for 386bsd and FreeBSD.
4 * Supports Archive and Wangtek compatible QIC-02/QIC-36 boards.
6 * Copyright (C) 1993 by:
7 * Sergey Ryzhkov <sir@kiae.su>
8 * Serge Vakulenko <vak@zebub.msk.su>
10 * This software is distributed with NO WARRANTIES, not even the implied
11 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * Authors grant any other persons or organisations permission to use
14 * or modify this software as long as this message is kept with the software,
15 * all derivative works or modified versions.
17 * This driver is derived from the old 386bsd Wangtek streamer tape driver,
18 * made by Robert Baron at CMU, based on Intel sources.
19 * Authors thank Robert Baron, CMU and Intel and retain here
20 * the original CMU copyright notice.
22 * Version 1.3, Thu Nov 11 12:09:13 MSK 1993
23 * $FreeBSD: src/sys/i386/isa/wt.c,v 1.57.2.1 2000/08/08 19:49:53 peter Exp $
28 * Code for MTERASE added by John Lind (john@starfire.mn.org) 95/09/02.
29 * This was very easy due to the excellent structure and clear coding
30 * of the original driver.
34 * Copyright (c) 1989 Carnegie-Mellon University.
35 * All rights reserved.
37 * Authors: Robert Baron
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/kernel.h>
66 #include <sys/fcntl.h>
67 #include <sys/malloc.h>
70 #include <sys/thread2.h>
73 #include <machine/clock.h>
75 #include <bus/isa/isa_device.h>
76 #include <bus/isa/isavar.h>
81 * Uncomment this to enable internal device tracing.
83 #define TRACE(s) /* kprintf s */
86 * Wangtek controller ports
88 #define WT_CTLPORT(base) ((base)+0) /* control, write only */
89 #define WT_STATPORT(base) ((base)+0) /* status, read only */
90 #define WT_CMDPORT(base) ((base)+1) /* command, write only */
91 #define WT_DATAPORT(base) ((base)+1) /* data, read only */
92 #define WT_NPORT 2 /* 2 i/o ports */
94 /* status port bits */
95 #define WT_BUSY 0x01 /* not ready bit define */
96 #define WT_NOEXCEP 0x02 /* no exception bit define */
97 #define WT_RESETMASK 0x07 /* to check after reset */
98 #define WT_RESETVAL 0x05 /* state after reset */
100 /* control port bits */
101 #define WT_ONLINE 0x01 /* device selected */
102 #define WT_RESET 0x02 /* reset command */
103 #define WT_REQUEST 0x04 /* request command */
104 #define WT_IEN 0x08 /* enable dma */
107 * Archive controller ports
109 #define AV_DATAPORT(base) ((base)+0) /* data, read only */
110 #define AV_CMDPORT(base) ((base)+0) /* command, write only */
111 #define AV_STATPORT(base) ((base)+1) /* status, read only */
112 #define AV_CTLPORT(base) ((base)+1) /* control, write only */
113 #define AV_SDMAPORT(base) ((base)+2) /* start dma */
114 #define AV_RDMAPORT(base) ((base)+3) /* reset dma */
115 #define AV_NPORT 4 /* 4 i/o ports */
117 /* status port bits */
118 #define AV_BUSY 0x40 /* not ready bit define */
119 #define AV_NOEXCEP 0x20 /* no exception bit define */
120 #define AV_RESETMASK 0xf8 /* to check after reset */
121 #define AV_RESETVAL 0x50 /* state after reset */
123 /* control port bits */
124 #define AV_RESET 0x80 /* reset command */
125 #define AV_REQUEST 0x40 /* request command */
126 #define AV_IEN 0x20 /* enable interrupts */
129 UNKNOWN = 0, /* unknown type, driver disabled */
130 ARCHIVE, /* Archive Viper SC499, SC402 etc */
131 WANGTEK /* Wangtek */
135 unsigned short err; /* code for error encountered */
136 unsigned short ercnt; /* number of error blocks */
137 unsigned short urcnt; /* number of underruns */
141 enum wttype type; /* type of controller */
142 unsigned unit; /* unit number */
143 unsigned port; /* base i/o port */
144 unsigned chan; /* dma channel number, 1..3 */
145 unsigned flags; /* state of tape drive */
146 unsigned dens; /* tape density */
147 int bsize; /* tape block size */
148 void *buf; /* internal i/o buffer */
150 void *dmavaddr; /* virtual address of dma i/o buffer */
151 unsigned dmatotal; /* size of i/o buffer */
152 unsigned dmaflags; /* i/o direction, ISADMA_READ or ISADMA_WRITE */
153 unsigned dmacount; /* resulting length of dma i/o */
155 wtstatus_t error; /* status of controller */
157 unsigned short DATAPORT, CMDPORT, STATPORT, CTLPORT, SDMAPORT, RDMAPORT;
158 unsigned char BUSY, NOEXCEP, RESETMASK, RESETVAL;
159 unsigned char ONLINE, RESET, REQUEST, IEN;
160 struct callout timeout_ch;
163 static wtinfo_t wttab[NWT]; /* tape info by unit number */
165 static int wtwait (wtinfo_t *t, int catch, char *msg);
166 static int wtcmd (wtinfo_t *t, int cmd);
167 static int wtstart (wtinfo_t *t, unsigned flags, void *vaddr, unsigned len);
168 static void wtdma (wtinfo_t *t);
169 static timeout_t wtimer;
170 static void wtclock (wtinfo_t *t);
171 static int wtreset (wtinfo_t *t);
172 static int wtsense (wtinfo_t *t, int verb, int ignor);
173 static int wtstatus (wtinfo_t *t);
174 static void wtintr(void *);
175 static void wtrewind (wtinfo_t *t);
176 static int wtreadfm (wtinfo_t *t);
177 static int wtwritefm (wtinfo_t *t);
178 static int wtpoll (wtinfo_t *t, int mask, int bits);
180 static d_open_t wtopen;
181 static d_close_t wtclose;
182 static d_ioctl_t wtioctl;
183 static d_strategy_t wtstrategy;
185 static struct dev_ops wt_ops = {
190 .d_write = physwrite,
192 .d_strategy = wtstrategy,
197 * Probe for the presence of the device.
200 wtprobe (struct isa_device *id)
202 wtinfo_t *t = wttab + id->id_unit;
204 callout_init(&t->timeout_ch);
205 t->unit = id->id_unit;
206 t->chan = id->id_drq;
207 t->port = id->id_iobase;
208 if (t->chan<1 || t->chan>3) {
209 kprintf ("wt%d: Bad drq=%d, should be 1..3\n", t->unit, t->chan);
215 t->CTLPORT = WT_CTLPORT (t->port); t->STATPORT = WT_STATPORT (t->port);
216 t->CMDPORT = WT_CMDPORT (t->port); t->DATAPORT = WT_DATAPORT (t->port);
217 t->SDMAPORT = 0; t->RDMAPORT = 0;
218 t->BUSY = WT_BUSY; t->NOEXCEP = WT_NOEXCEP;
219 t->RESETMASK = WT_RESETMASK; t->RESETVAL = WT_RESETVAL;
220 t->ONLINE = WT_ONLINE; t->RESET = WT_RESET;
221 t->REQUEST = WT_REQUEST; t->IEN = WT_IEN;
227 t->CTLPORT = AV_CTLPORT (t->port); t->STATPORT = AV_STATPORT (t->port);
228 t->CMDPORT = AV_CMDPORT (t->port); t->DATAPORT = AV_DATAPORT (t->port);
229 t->SDMAPORT = AV_SDMAPORT (t->port); t->RDMAPORT = AV_RDMAPORT (t->port);
230 t->BUSY = AV_BUSY; t->NOEXCEP = AV_NOEXCEP;
231 t->RESETMASK = AV_RESETMASK; t->RESETVAL = AV_RESETVAL;
232 t->ONLINE = 0; t->RESET = AV_RESET;
233 t->REQUEST = AV_REQUEST; t->IEN = AV_IEN;
237 /* Tape controller not found. */
243 * Device is found, configure it.
246 wtattach (struct isa_device *id)
248 wtinfo_t *t = wttab + id->id_unit;
250 id->id_intr = (inthand2_t *)wtintr;
251 if (t->type == ARCHIVE) {
252 kprintf ("wt%d: type <Archive>\n", t->unit);
253 outb (t->RDMAPORT, 0); /* reset dma */
255 kprintf ("wt%d: type <Wangtek>\n", t->unit);
256 t->flags = TPSTART; /* tape is rewound */
257 t->dens = -1; /* unknown density */
258 isa_dmainit(t->chan, 1024);
260 make_dev(&wt_ops, id->id_unit, 0, 0, 0600, "rwt%d", id->id_unit);
264 struct isa_driver wtdriver = { wtprobe, wtattach, "wt", };
267 * Open routine, called on every device open.
270 wtopen (struct dev_open_args *ap)
272 cdev_t dev = ap->a_head.a_dev;
273 int u = minor (dev) & T_UNIT;
274 wtinfo_t *t = wttab + u;
277 if (u >= NWT || t->type == UNKNOWN)
280 /* Check that device is not in use */
281 if (t->flags & TPINUSE)
284 /* If the tape is in rewound state, check the status and set density. */
285 if (t->flags & TPSTART) {
286 /* If rewind is going on, wait */
287 error = wtwait (t, PCATCH, "wtrew");
291 /* Check the controller status */
292 if (! wtsense (t, 0, (ap->a_oflags & FWRITE) ? 0 : TP_WRP)) {
293 /* Bad status, reset the controller */
296 if (! wtsense (t, 1, (ap->a_oflags & FWRITE) ? 0 : TP_WRP))
300 /* Set up tape density. */
301 if (t->dens != (minor (dev) & WT_DENSEL)) {
304 switch (minor (dev) & WT_DENSEL) {
305 case WT_DENSDFLT: default: break; /* default density */
306 case WT_QIC11: d = QIC_FMT11; break; /* minor 010 */
307 case WT_QIC24: d = QIC_FMT24; break; /* minor 020 */
308 case WT_QIC120: d = QIC_FMT120; break; /* minor 030 */
309 case WT_QIC150: d = QIC_FMT150; break; /* minor 040 */
310 case WT_QIC300: d = QIC_FMT300; break; /* minor 050 */
311 case WT_QIC600: d = QIC_FMT600; break; /* minor 060 */
314 /* Change tape density. */
317 if (! wtsense (t, 1, TP_WRP | TP_ILL))
320 /* Check the status of the controller. */
321 if (t->error.err & TP_ILL) {
322 kprintf ("wt%d: invalid tape density\n", t->unit);
326 t->dens = minor (dev) & WT_DENSEL;
328 t->flags &= ~TPSTART;
329 } else if (t->dens != (minor (dev) & WT_DENSEL))
332 t->bsize = (minor (dev) & WT_BSIZE) ? 1024 : 512;
333 t->buf = kmalloc (t->bsize, M_TEMP, M_WAITOK);
335 if (isa_dma_acquire(t->chan))
340 if (ap->a_oflags & FREAD)
342 if (ap->a_oflags & FWRITE)
348 * Close routine, called on last device close.
351 wtclose (struct dev_close_args *ap)
353 cdev_t dev = ap->a_head.a_dev;
354 int u = minor (dev) & T_UNIT;
355 wtinfo_t *t = wttab + u;
357 if (u >= NWT || t->type == UNKNOWN)
360 /* If rewind is pending, do nothing */
361 if (t->flags & TPREW)
364 /* If seek forward is pending and no rewind on close, do nothing */
365 if (t->flags & TPRMARK) {
366 if (minor (dev) & T_NOREWIND)
369 /* If read file mark is going on, wait */
370 wtwait (t, 0, "wtrfm");
373 if (t->flags & TPWANY)
374 /* Tape was written. Write file mark. */
377 if (! (minor (dev) & T_NOREWIND)) {
378 /* Rewind tape to beginning of tape. */
379 /* Don't wait until rewind, though. */
383 if ((t->flags & TPRANY) && ! (t->flags & (TPVOL | TPWANY)))
384 /* Space forward to after next file mark if no writing done. */
385 /* Don't wait for completion. */
388 t->flags &= TPREW | TPRMARK | TPSTART | TPTIMER;
389 kfree (t->buf, M_TEMP);
390 isa_dma_release(t->chan);
395 * Ioctl routine. Compatible with BSD ioctls.
396 * There are two possible ioctls:
397 * ioctl (int fd, MTIOCGET, struct mtget *buf) -- get status
398 * ioctl (int fd, MTIOCTOP, struct mtop *buf) -- do BSD-like op
401 wtioctl (struct dev_ioctl_args *ap)
403 cdev_t dev = ap->a_head.a_dev;
404 caddr_t arg = ap->a_data;
405 int u = minor (dev) & T_UNIT;
406 wtinfo_t *t = wttab + u;
407 int error, count, op;
409 if (u >= NWT || t->type == UNKNOWN)
415 case MTIOCIEOT: /* ignore EOT errors */
416 case MTIOCEEOT: /* enable EOT errors */
419 ((struct mtget*)arg)->mt_type =
420 t->type == ARCHIVE ? MT_ISVIPER1 : 0x11;
421 ((struct mtget*)arg)->mt_dsreg = t->flags; /* status */
422 ((struct mtget*)arg)->mt_erreg = t->error.err; /* errors */
423 ((struct mtget*)arg)->mt_resid = 0;
424 ((struct mtget*)arg)->mt_fileno = 0; /* file */
425 ((struct mtget*)arg)->mt_blkno = 0; /* block */
430 switch ((short) ((struct mtop*)arg)->mt_op) {
432 case MTFSR: /* forward space record */
433 case MTBSR: /* backward space record */
434 case MTBSF: /* backward space file */
436 case MTNOP: /* no operation, sets status only */
437 case MTCACHE: /* enable controller cache */
438 case MTNOCACHE: /* disable controller cache */
440 case MTREW: /* rewind */
441 case MTOFFL: /* rewind and put the drive offline */
442 if (t->flags & TPREW) /* rewind is running */
444 error = wtwait (t, PCATCH, "wtorew");
449 case MTFSF: /* forward space file */
450 for (count=((struct mtop*)arg)->mt_count; count>0; --count) {
451 error = wtwait (t, PCATCH, "wtorfm");
454 error = wtreadfm (t);
459 case MTWEOF: /* write an end-of-file record */
460 if (! (t->flags & TPWRITE) || (t->flags & TPWP))
462 error = wtwait (t, PCATCH, "wtowfm");
465 error = wtwritefm (t);
469 case MTRETENS: /* re-tension tape */
470 error = wtwait (t, PCATCH, "wtretens");
476 case MTERASE: /* erase to EOM */
477 if (! (t->flags & TPWRITE) || (t->flags & TPWP))
479 error = wtwait (t, PCATCH, "wterase");
484 /* ERASE and RETENS operations work like REWIND. */
485 /* Simulate the rewind operation here. */
486 t->flags &= ~(TPRO | TPWO | TPVOL);
489 t->flags |= TPSTART | TPREW;
501 wtstrategy (struct dev_strategy_args *ap)
503 cdev_t dev = ap->a_head.a_dev;
504 struct bio *bio = ap->a_bio;
505 struct buf *bp = bio->bio_buf;
506 int u = minor(dev) & T_UNIT;
507 wtinfo_t *t = wttab + u;
510 bp->b_resid = bp->b_bcount;
511 if (u >= NWT || t->type == UNKNOWN) {
516 /* at file marks and end of tape, we just return '0 bytes available' */
517 if (t->flags & TPVOL)
520 if (bp->b_bcount % t->bsize != 0) {
521 bp->b_error = EINVAL;
525 if (bp->b_cmd == BUF_CMD_READ) {
526 /* Check read access and no previous write to this tape. */
527 if (! (t->flags & TPREAD) || (t->flags & TPWANY))
530 /* For now, we assume that all data will be copied out */
531 /* If read command outstanding, just skip down */
532 if (! (t->flags & TPRO)) {
533 if (! wtsense (t, 1, TP_WRP)) /* clear status */
535 if (! wtcmd (t, QIC_RDDATA)) { /* sed read mode */
536 wtsense (t, 1, TP_WRP);
539 t->flags |= TPRO | TPRANY;
543 /* Check write access and write protection. */
544 /* No previous read from this tape allowed. */
545 if (! (t->flags & TPWRITE) || (t->flags & (TPWP | TPRANY)))
548 /* If write command outstanding, just skip down */
549 if (! (t->flags & TPWO)) {
550 if (! wtsense (t, 1, 0)) /* clear status */
552 if (! wtcmd (t, QIC_WRTDATA)) { /* set write mode */
556 t->flags |= TPWO | TPWANY;
558 flags = ISADMA_WRITE;
564 t->flags &= ~TPEXCEP;
566 if (wtstart (t, flags, bp->b_data, bp->b_bcount)) {
567 wtwait (t, 0, (flags & ISADMA_READ) ? "wtread" : "wtwrite");
568 bp->b_resid -= t->dmacount;
572 if (t->flags & TPEXCEP) {
573 errxit: bp->b_error = EIO;
574 err2xit: bp->b_flags |= B_ERROR;
587 wtinfo_t *t = wttab + u;
590 if (u >= NWT || t->type == UNKNOWN) {
591 TRACE (("wtintr() -- device not configured\n"));
595 s = inb (t->STATPORT); /* get status */
596 TRACE (("wtintr() status=0x%x -- ", s));
597 if ((s & (t->BUSY | t->NOEXCEP)) == (t->BUSY | t->NOEXCEP)) {
599 return; /* device is busy */
603 * Check if rewind finished.
605 if (t->flags & TPREW) {
606 TRACE (((s & (t->BUSY | t->NOEXCEP)) == (t->BUSY | t->NOEXCEP) ?
607 "rewind busy?\n" : "rewind finished\n"));
608 t->flags &= ~TPREW; /* Rewind finished. */
609 wtsense (t, 1, TP_WRP);
615 * Check if writing/reading of file mark finished.
617 if (t->flags & (TPRMARK | TPWMARK)) {
618 TRACE (((s & (t->BUSY | t->NOEXCEP)) == (t->BUSY | t->NOEXCEP) ?
619 "marker r/w busy?\n" : "marker r/w finished\n"));
620 if (! (s & t->NOEXCEP)) /* operation failed */
621 wtsense (t, 1, (t->flags & TPRMARK) ? TP_WRP : 0);
622 t->flags &= ~(TPRMARK | TPWMARK); /* operation finished */
628 * Do we started any i/o? If no, just return.
630 if (! (t->flags & TPACTIVE)) {
631 TRACE (("unexpected interrupt\n"));
638 if ((t->dmaflags & ISADMA_READ) && (t->dmatotal - t->dmacount) < t->bsize) {
639 /* If reading short block, copy the internal buffer
640 * to the user memory. */
641 isa_dmadone (t->dmaflags, t->buf, t->bsize, t->chan);
642 bcopy (t->buf, t->dmavaddr, t->dmatotal - t->dmacount);
644 isa_dmadone (t->dmaflags, t->dmavaddr, t->bsize, t->chan);
646 t->flags &= ~TPACTIVE;
647 t->dmacount += t->bsize;
648 t->dmavaddr = (char *)t->dmavaddr + t->bsize;
651 * On exception, check for end of file and end of volume.
653 if (! (s & t->NOEXCEP)) {
654 TRACE (("i/o exception\n"));
655 wtsense (t, 1, (t->dmaflags & ISADMA_READ) ? TP_WRP : 0);
656 if (t->error.err & (TP_EOM | TP_FIL))
657 t->flags |= TPVOL; /* end of file */
659 t->flags |= TPEXCEP; /* i/o error */
664 if (t->dmacount < t->dmatotal) { /* continue i/o */
666 TRACE (("continue i/o, %d\n", t->dmacount));
669 if (t->dmacount > t->dmatotal) /* short last block */
670 t->dmacount = t->dmatotal;
671 wakeup ((caddr_t)t); /* wake up user level */
672 TRACE (("i/o finished, %d\n", t->dmacount));
675 /* start the rewind operation */
677 wtrewind (wtinfo_t *t)
679 int rwmode = (t->flags & (TPRO | TPWO));
681 t->flags &= ~(TPRO | TPWO | TPVOL);
683 * Wangtek strictly follows QIC-02 standard:
684 * clearing ONLINE in read/write modes causes rewind.
685 * REWIND command is not allowed in read/write mode
686 * and gives `illegal command' error.
688 if (t->type==WANGTEK && rwmode) {
689 outb (t->CTLPORT, 0);
690 } else if (! wtcmd (t, QIC_REWIND))
692 t->flags |= TPSTART | TPREW;
696 /* start the `read marker' operation */
698 wtreadfm (wtinfo_t *t)
700 t->flags &= ~(TPRO | TPWO | TPVOL);
701 if (! wtcmd (t, QIC_READFM)) {
702 wtsense (t, 1, TP_WRP);
705 t->flags |= TPRMARK | TPRANY;
707 /* Don't wait for completion here. */
711 /* write marker to the tape */
713 wtwritefm (wtinfo_t *t)
715 tsleep ((caddr_t)wtwritefm, 0, "wtwfm", hz); /* timeout: 1 second */
716 t->flags &= ~(TPRO | TPWO);
717 if (! wtcmd (t, QIC_WRITEFM)) {
721 t->flags |= TPWMARK | TPWANY;
723 return (wtwait (t, 0, "wtwfm"));
726 /* while controller status & mask == bits continue waiting */
728 wtpoll (wtinfo_t *t, int mask, int bits)
732 /* Poll status port, waiting for specified bits. */
733 for (i=0; i<1000; ++i) { /* up to 1 msec */
734 s = inb (t->STATPORT);
735 if ((s & mask) != bits)
739 for (i=0; i<100; ++i) { /* up to 10 msec */
740 s = inb (t->STATPORT);
741 if ((s & mask) != bits)
745 for (;;) { /* forever */
746 s = inb (t->STATPORT);
747 if ((s & mask) != bits)
749 tsleep ((caddr_t)wtpoll, 0, "wtpoll", 1); /* timeout: 1 tick */
753 /* execute QIC command */
755 wtcmd (wtinfo_t *t, int cmd)
759 TRACE (("wtcmd() cmd=0x%x\n", cmd));
761 s = wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP); /* ready? */
762 if (! (s & t->NOEXCEP)) { /* error */
767 outb (t->CMDPORT, cmd); /* output the command */
769 outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */
770 wtpoll (t, t->BUSY, t->BUSY); /* wait for ready */
771 outb (t->CTLPORT, t->IEN | t->ONLINE); /* reset request */
772 wtpoll (t, t->BUSY, 0); /* wait for not ready */
777 /* wait for the end of i/o, seeking marker or rewind operation */
779 wtwait (wtinfo_t *t, int catch, char *msg)
783 TRACE (("wtwait() `%s'\n", msg));
784 while (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK)) {
785 error = tsleep ((caddr_t)t, catch, msg, 0);
792 /* initialize dma for the i/o operation */
796 t->flags |= TPACTIVE;
799 if (t->type == ARCHIVE)
800 outb (t->SDMAPORT, 0); /* set dma */
802 if ((t->dmaflags & ISADMA_READ) && (t->dmatotal - t->dmacount) < t->bsize)
803 /* Reading short block. Do it through the internal buffer. */
804 isa_dmastart (t->dmaflags, t->buf, t->bsize, t->chan);
806 isa_dmastart (t->dmaflags, t->dmavaddr, t->bsize, t->chan);
809 /* start i/o operation */
811 wtstart (wtinfo_t *t, unsigned flags, void *vaddr, unsigned len)
815 TRACE (("wtstart()\n"));
817 s = wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP); /* ready? */
818 if (! (s & t->NOEXCEP)) {
819 t->flags |= TPEXCEP; /* error */
823 t->flags &= ~TPEXCEP; /* clear exception flag */
835 wtclock (wtinfo_t *t)
837 if (! (t->flags & TPTIMER)) {
839 /* Some controllers seem to lose dma interrupts too often.
840 * To make the tape stream we need 1 tick timeout. */
841 callout_reset(&t->timeout_ch, ((t->flags & TPACTIVE) ? 1 : hz),
847 * Simulate an interrupt periodically while i/o is going.
848 * This is necessary in case interrupts get eaten due to
849 * multiple devices on a single IRQ line.
854 wtinfo_t *t = (wtinfo_t *)xt;
856 t->flags &= ~TPTIMER;
857 if (! (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK)))
860 /* If i/o going, simulate interrupt. */
862 if ((inb (t->STATPORT) & (t->BUSY | t->NOEXCEP)) != (t->BUSY | t->NOEXCEP)) {
863 TRACE (("wtimer() -- "));
864 wtintr ((void *)t->unit);
868 /* Restart timer if i/o pending. */
869 if (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK))
873 /* reset the controller */
875 wtreset (wtinfo_t *t)
877 /* Perform QIC-02 and QIC-36 compatible reset sequence. */
878 /* Thanks to Mikael Hybsch <micke@dynas.se>. */
881 outb (t->CTLPORT, t->RESET | t->ONLINE); /* send reset */
883 outb (t->CTLPORT, t->ONLINE); /* turn off reset */
886 /* Read the controller status. */
887 s = inb (t->STATPORT);
888 if (s == 0xff) /* no port at this address? */
891 /* Wait 3 sec for reset to complete. Needed for QIC-36 boards? */
892 for (i=0; i<3000; ++i) {
893 if (! (s & t->BUSY) || ! (s & t->NOEXCEP))
896 s = inb (t->STATPORT);
898 return ((s & t->RESETMASK) == t->RESETVAL);
901 /* get controller status information */
902 /* return 0 if user i/o request should receive an i/o error code */
904 wtsense (wtinfo_t *t, int verb, int ignor)
909 TRACE (("wtsense() ignor=0x%x\n", ignor));
910 t->flags &= ~(TPRO | TPWO);
913 if (! (t->error.err & TP_ST0))
914 t->error.err &= ~TP_ST0MASK;
915 if (! (t->error.err & TP_ST1))
916 t->error.err &= ~TP_ST1MASK;
917 t->error.err &= ~ignor; /* ignore certain errors */
918 err = t->error.err & (TP_FIL | TP_BNL | TP_UDA | TP_EOM | TP_WRP |
919 TP_USL | TP_CNI | TP_MBD | TP_NDT | TP_ILL);
925 /* lifted from tdriver.c from Wangtek */
926 if (err & TP_USL) msg = "Drive not online";
927 else if (err & TP_CNI) msg = "No cartridge";
928 else if ((err & TP_WRP) && !(t->flags & TPWP)) {
929 msg = "Tape is write protected";
932 else if (err & TP_FIL) msg = 0 /*"Filemark detected"*/;
933 else if (err & TP_EOM) msg = 0 /*"End of tape"*/;
934 else if (err & TP_BNL) msg = "Block not located";
935 else if (err & TP_UDA) msg = "Unrecoverable data error";
936 else if (err & TP_NDT) msg = "No data detected";
937 else if (err & TP_ILL) msg = "Illegal command";
939 kprintf ("wt%d: %s\n", t->unit, msg);
943 /* get controller status information */
945 wtstatus (wtinfo_t *t)
950 wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP); /* ready? */
951 outb (t->CMDPORT, QIC_RDSTAT); /* send `read status' command */
953 outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */
954 wtpoll (t, t->BUSY, t->BUSY); /* wait for ready */
955 outb (t->CTLPORT, t->ONLINE); /* reset request */
956 wtpoll (t, t->BUSY, 0); /* wait for not ready */
958 p = (char*) &t->error;
959 while (p < (char*)&t->error + 6) {
960 int s = wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP);
961 if (! (s & t->NOEXCEP)) { /* error */
966 *p++ = inb (t->DATAPORT); /* read status byte */
968 outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */
969 wtpoll (t, t->BUSY, 0); /* wait for not ready */
971 outb (t->CTLPORT, t->ONLINE); /* unset request */