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 $
24 * $DragonFly: src/sys/dev/disk/wt/wt.c,v 1.19 2006/12/22 23:26:17 swildner Exp $
29 * Code for MTERASE added by John Lind (john@starfire.mn.org) 95/09/02.
30 * This was very easy due to the excellent structure and clear coding
31 * of the original driver.
35 * Copyright (c) 1989 Carnegie-Mellon University.
36 * All rights reserved.
38 * Authors: Robert Baron
40 * Permission to use, copy, modify and distribute this software and
41 * its documentation is hereby granted, provided that both the copyright
42 * notice and this permission notice appear in all copies of the
43 * software, derivative works or modified versions, and any portions
44 * thereof, and that both notices appear in supporting documentation.
46 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
48 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
50 * Carnegie Mellon requests users of this software to return to
52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53 * School of Computer Science
54 * Carnegie Mellon University
55 * Pittsburgh PA 15213-3890
57 * any improvements or extensions that they make and grant Carnegie the
58 * rights to redistribute these changes.
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
67 #include <sys/fcntl.h>
68 #include <sys/malloc.h>
71 #include <sys/thread2.h>
74 #include <machine/clock.h>
76 #include <bus/isa/i386/isa_device.h>
77 #include <bus/isa/isavar.h>
82 * Uncomment this to enable internal device tracing.
84 #define TRACE(s) /* kprintf s */
87 * Wangtek controller ports
89 #define WT_CTLPORT(base) ((base)+0) /* control, write only */
90 #define WT_STATPORT(base) ((base)+0) /* status, read only */
91 #define WT_CMDPORT(base) ((base)+1) /* command, write only */
92 #define WT_DATAPORT(base) ((base)+1) /* data, read only */
93 #define WT_NPORT 2 /* 2 i/o ports */
95 /* status port bits */
96 #define WT_BUSY 0x01 /* not ready bit define */
97 #define WT_NOEXCEP 0x02 /* no exception bit define */
98 #define WT_RESETMASK 0x07 /* to check after reset */
99 #define WT_RESETVAL 0x05 /* state after reset */
101 /* control port bits */
102 #define WT_ONLINE 0x01 /* device selected */
103 #define WT_RESET 0x02 /* reset command */
104 #define WT_REQUEST 0x04 /* request command */
105 #define WT_IEN 0x08 /* enable dma */
108 * Archive controller ports
110 #define AV_DATAPORT(base) ((base)+0) /* data, read only */
111 #define AV_CMDPORT(base) ((base)+0) /* command, write only */
112 #define AV_STATPORT(base) ((base)+1) /* status, read only */
113 #define AV_CTLPORT(base) ((base)+1) /* control, write only */
114 #define AV_SDMAPORT(base) ((base)+2) /* start dma */
115 #define AV_RDMAPORT(base) ((base)+3) /* reset dma */
116 #define AV_NPORT 4 /* 4 i/o ports */
118 /* status port bits */
119 #define AV_BUSY 0x40 /* not ready bit define */
120 #define AV_NOEXCEP 0x20 /* no exception bit define */
121 #define AV_RESETMASK 0xf8 /* to check after reset */
122 #define AV_RESETVAL 0x50 /* state after reset */
124 /* control port bits */
125 #define AV_RESET 0x80 /* reset command */
126 #define AV_REQUEST 0x40 /* request command */
127 #define AV_IEN 0x20 /* enable interrupts */
130 UNKNOWN = 0, /* unknown type, driver disabled */
131 ARCHIVE, /* Archive Viper SC499, SC402 etc */
132 WANGTEK /* Wangtek */
136 unsigned short err; /* code for error encountered */
137 unsigned short ercnt; /* number of error blocks */
138 unsigned short urcnt; /* number of underruns */
142 enum wttype type; /* type of controller */
143 unsigned unit; /* unit number */
144 unsigned port; /* base i/o port */
145 unsigned chan; /* dma channel number, 1..3 */
146 unsigned flags; /* state of tape drive */
147 unsigned dens; /* tape density */
148 int bsize; /* tape block size */
149 void *buf; /* internal i/o buffer */
151 void *dmavaddr; /* virtual address of dma i/o buffer */
152 unsigned dmatotal; /* size of i/o buffer */
153 unsigned dmaflags; /* i/o direction, ISADMA_READ or ISADMA_WRITE */
154 unsigned dmacount; /* resulting length of dma i/o */
156 wtstatus_t error; /* status of controller */
158 unsigned short DATAPORT, CMDPORT, STATPORT, CTLPORT, SDMAPORT, RDMAPORT;
159 unsigned char BUSY, NOEXCEP, RESETMASK, RESETVAL;
160 unsigned char ONLINE, RESET, REQUEST, IEN;
161 struct callout timeout_ch;
164 static wtinfo_t wttab[NWT]; /* tape info by unit number */
166 static int wtwait (wtinfo_t *t, int catch, char *msg);
167 static int wtcmd (wtinfo_t *t, int cmd);
168 static int wtstart (wtinfo_t *t, unsigned flags, void *vaddr, unsigned len);
169 static void wtdma (wtinfo_t *t);
170 static timeout_t wtimer;
171 static void wtclock (wtinfo_t *t);
172 static int wtreset (wtinfo_t *t);
173 static int wtsense (wtinfo_t *t, int verb, int ignor);
174 static int wtstatus (wtinfo_t *t);
175 static void wtintr(void *);
176 static void wtrewind (wtinfo_t *t);
177 static int wtreadfm (wtinfo_t *t);
178 static int wtwritefm (wtinfo_t *t);
179 static int wtpoll (wtinfo_t *t, int mask, int bits);
181 static d_open_t wtopen;
182 static d_close_t wtclose;
183 static d_ioctl_t wtioctl;
184 static d_strategy_t wtstrategy;
186 #define CDEV_MAJOR 10
188 static struct dev_ops wt_ops = {
189 { "wt", CDEV_MAJOR, 0 },
193 .d_write = physwrite,
195 .d_strategy = wtstrategy,
200 * Probe for the presence of the device.
203 wtprobe (struct isa_device *id)
205 wtinfo_t *t = wttab + id->id_unit;
207 callout_init(&t->timeout_ch);
208 t->unit = id->id_unit;
209 t->chan = id->id_drq;
210 t->port = id->id_iobase;
211 if (t->chan<1 || t->chan>3) {
212 kprintf ("wt%d: Bad drq=%d, should be 1..3\n", t->unit, t->chan);
218 t->CTLPORT = WT_CTLPORT (t->port); t->STATPORT = WT_STATPORT (t->port);
219 t->CMDPORT = WT_CMDPORT (t->port); t->DATAPORT = WT_DATAPORT (t->port);
220 t->SDMAPORT = 0; t->RDMAPORT = 0;
221 t->BUSY = WT_BUSY; t->NOEXCEP = WT_NOEXCEP;
222 t->RESETMASK = WT_RESETMASK; t->RESETVAL = WT_RESETVAL;
223 t->ONLINE = WT_ONLINE; t->RESET = WT_RESET;
224 t->REQUEST = WT_REQUEST; t->IEN = WT_IEN;
230 t->CTLPORT = AV_CTLPORT (t->port); t->STATPORT = AV_STATPORT (t->port);
231 t->CMDPORT = AV_CMDPORT (t->port); t->DATAPORT = AV_DATAPORT (t->port);
232 t->SDMAPORT = AV_SDMAPORT (t->port); t->RDMAPORT = AV_RDMAPORT (t->port);
233 t->BUSY = AV_BUSY; t->NOEXCEP = AV_NOEXCEP;
234 t->RESETMASK = AV_RESETMASK; t->RESETVAL = AV_RESETVAL;
235 t->ONLINE = 0; t->RESET = AV_RESET;
236 t->REQUEST = AV_REQUEST; t->IEN = AV_IEN;
240 /* Tape controller not found. */
246 * Device is found, configure it.
249 wtattach (struct isa_device *id)
251 wtinfo_t *t = wttab + id->id_unit;
253 id->id_intr = (inthand2_t *)wtintr;
254 if (t->type == ARCHIVE) {
255 kprintf ("wt%d: type <Archive>\n", t->unit);
256 outb (t->RDMAPORT, 0); /* reset dma */
258 kprintf ("wt%d: type <Wangtek>\n", t->unit);
259 t->flags = TPSTART; /* tape is rewound */
260 t->dens = -1; /* unknown density */
261 isa_dmainit(t->chan, 1024);
263 dev_ops_add(&wt_ops, -1, id->id_unit);
264 make_dev(&wt_ops, id->id_unit, 0, 0, 0600, "rwt%d", id->id_unit);
268 struct isa_driver wtdriver = { wtprobe, wtattach, "wt", };
271 * Open routine, called on every device open.
274 wtopen (struct dev_open_args *ap)
276 cdev_t dev = ap->a_head.a_dev;
277 int u = minor (dev) & T_UNIT;
278 wtinfo_t *t = wttab + u;
281 if (u >= NWT || t->type == UNKNOWN)
284 /* Check that device is not in use */
285 if (t->flags & TPINUSE)
288 /* If the tape is in rewound state, check the status and set density. */
289 if (t->flags & TPSTART) {
290 /* If rewind is going on, wait */
291 error = wtwait (t, PCATCH, "wtrew");
295 /* Check the controller status */
296 if (! wtsense (t, 0, (ap->a_oflags & FWRITE) ? 0 : TP_WRP)) {
297 /* Bad status, reset the controller */
300 if (! wtsense (t, 1, (ap->a_oflags & FWRITE) ? 0 : TP_WRP))
304 /* Set up tape density. */
305 if (t->dens != (minor (dev) & WT_DENSEL)) {
308 switch (minor (dev) & WT_DENSEL) {
309 case WT_DENSDFLT: default: break; /* default density */
310 case WT_QIC11: d = QIC_FMT11; break; /* minor 010 */
311 case WT_QIC24: d = QIC_FMT24; break; /* minor 020 */
312 case WT_QIC120: d = QIC_FMT120; break; /* minor 030 */
313 case WT_QIC150: d = QIC_FMT150; break; /* minor 040 */
314 case WT_QIC300: d = QIC_FMT300; break; /* minor 050 */
315 case WT_QIC600: d = QIC_FMT600; break; /* minor 060 */
318 /* Change tape density. */
321 if (! wtsense (t, 1, TP_WRP | TP_ILL))
324 /* Check the status of the controller. */
325 if (t->error.err & TP_ILL) {
326 kprintf ("wt%d: invalid tape density\n", t->unit);
330 t->dens = minor (dev) & WT_DENSEL;
332 t->flags &= ~TPSTART;
333 } else if (t->dens != (minor (dev) & WT_DENSEL))
336 t->bsize = (minor (dev) & WT_BSIZE) ? 1024 : 512;
337 t->buf = kmalloc (t->bsize, M_TEMP, M_WAITOK);
341 if (isa_dma_acquire(t->chan))
346 if (ap->a_oflags & FREAD)
348 if (ap->a_oflags & FWRITE)
354 * Close routine, called on last device close.
357 wtclose (struct dev_close_args *ap)
359 cdev_t dev = ap->a_head.a_dev;
360 int u = minor (dev) & T_UNIT;
361 wtinfo_t *t = wttab + u;
363 if (u >= NWT || t->type == UNKNOWN)
366 /* If rewind is pending, do nothing */
367 if (t->flags & TPREW)
370 /* If seek forward is pending and no rewind on close, do nothing */
371 if (t->flags & TPRMARK) {
372 if (minor (dev) & T_NOREWIND)
375 /* If read file mark is going on, wait */
376 wtwait (t, 0, "wtrfm");
379 if (t->flags & TPWANY)
380 /* Tape was written. Write file mark. */
383 if (! (minor (dev) & T_NOREWIND)) {
384 /* Rewind tape to beginning of tape. */
385 /* Don't wait until rewind, though. */
389 if ((t->flags & TPRANY) && ! (t->flags & (TPVOL | TPWANY)))
390 /* Space forward to after next file mark if no writing done. */
391 /* Don't wait for completion. */
394 t->flags &= TPREW | TPRMARK | TPSTART | TPTIMER;
395 kfree (t->buf, M_TEMP);
396 isa_dma_release(t->chan);
401 * Ioctl routine. Compatible with BSD ioctls.
402 * There are two possible ioctls:
403 * ioctl (int fd, MTIOCGET, struct mtget *buf) -- get status
404 * ioctl (int fd, MTIOCTOP, struct mtop *buf) -- do BSD-like op
407 wtioctl (struct dev_ioctl_args *ap)
409 cdev_t dev = ap->a_head.a_dev;
410 caddr_t arg = ap->a_data;
411 int u = minor (dev) & T_UNIT;
412 wtinfo_t *t = wttab + u;
413 int error, count, op;
415 if (u >= NWT || t->type == UNKNOWN)
421 case MTIOCIEOT: /* ignore EOT errors */
422 case MTIOCEEOT: /* enable EOT errors */
425 ((struct mtget*)arg)->mt_type =
426 t->type == ARCHIVE ? MT_ISVIPER1 : 0x11;
427 ((struct mtget*)arg)->mt_dsreg = t->flags; /* status */
428 ((struct mtget*)arg)->mt_erreg = t->error.err; /* errors */
429 ((struct mtget*)arg)->mt_resid = 0;
430 ((struct mtget*)arg)->mt_fileno = 0; /* file */
431 ((struct mtget*)arg)->mt_blkno = 0; /* block */
436 switch ((short) ((struct mtop*)arg)->mt_op) {
438 case MTFSR: /* forward space record */
439 case MTBSR: /* backward space record */
440 case MTBSF: /* backward space file */
442 case MTNOP: /* no operation, sets status only */
443 case MTCACHE: /* enable controller cache */
444 case MTNOCACHE: /* disable controller cache */
446 case MTREW: /* rewind */
447 case MTOFFL: /* rewind and put the drive offline */
448 if (t->flags & TPREW) /* rewind is running */
450 error = wtwait (t, PCATCH, "wtorew");
455 case MTFSF: /* forward space file */
456 for (count=((struct mtop*)arg)->mt_count; count>0; --count) {
457 error = wtwait (t, PCATCH, "wtorfm");
460 error = wtreadfm (t);
465 case MTWEOF: /* write an end-of-file record */
466 if (! (t->flags & TPWRITE) || (t->flags & TPWP))
468 error = wtwait (t, PCATCH, "wtowfm");
471 error = wtwritefm (t);
475 case MTRETENS: /* re-tension tape */
476 error = wtwait (t, PCATCH, "wtretens");
482 case MTERASE: /* erase to EOM */
483 if (! (t->flags & TPWRITE) || (t->flags & TPWP))
485 error = wtwait (t, PCATCH, "wterase");
490 /* ERASE and RETENS operations work like REWIND. */
491 /* Simulate the rewind operation here. */
492 t->flags &= ~(TPRO | TPWO | TPVOL);
495 t->flags |= TPSTART | TPREW;
507 wtstrategy (struct dev_strategy_args *ap)
509 cdev_t dev = ap->a_head.a_dev;
510 struct bio *bio = ap->a_bio;
511 struct buf *bp = bio->bio_buf;
512 int u = minor(dev) & T_UNIT;
513 wtinfo_t *t = wttab + u;
516 bp->b_resid = bp->b_bcount;
517 if (u >= NWT || t->type == UNKNOWN) {
522 /* at file marks and end of tape, we just return '0 bytes available' */
523 if (t->flags & TPVOL)
526 if (bp->b_bcount % t->bsize != 0) {
527 bp->b_error = EINVAL;
531 if (bp->b_cmd == BUF_CMD_READ) {
532 /* Check read access and no previous write to this tape. */
533 if (! (t->flags & TPREAD) || (t->flags & TPWANY))
536 /* For now, we assume that all data will be copied out */
537 /* If read command outstanding, just skip down */
538 if (! (t->flags & TPRO)) {
539 if (! wtsense (t, 1, TP_WRP)) /* clear status */
541 if (! wtcmd (t, QIC_RDDATA)) { /* sed read mode */
542 wtsense (t, 1, TP_WRP);
545 t->flags |= TPRO | TPRANY;
549 /* Check write access and write protection. */
550 /* No previous read from this tape allowed. */
551 if (! (t->flags & TPWRITE) || (t->flags & (TPWP | TPRANY)))
554 /* If write command outstanding, just skip down */
555 if (! (t->flags & TPWO)) {
556 if (! wtsense (t, 1, 0)) /* clear status */
558 if (! wtcmd (t, QIC_WRTDATA)) { /* set write mode */
562 t->flags |= TPWO | TPWANY;
564 flags = ISADMA_WRITE;
570 t->flags &= ~TPEXCEP;
572 if (wtstart (t, flags, bp->b_data, bp->b_bcount)) {
573 wtwait (t, 0, (flags & ISADMA_READ) ? "wtread" : "wtwrite");
574 bp->b_resid -= t->dmacount;
578 if (t->flags & TPEXCEP) {
579 errxit: bp->b_error = EIO;
580 err2xit: bp->b_flags |= B_ERROR;
593 wtinfo_t *t = wttab + u;
596 if (u >= NWT || t->type == UNKNOWN) {
597 TRACE (("wtintr() -- device not configured\n"));
601 s = inb (t->STATPORT); /* get status */
602 TRACE (("wtintr() status=0x%x -- ", s));
603 if ((s & (t->BUSY | t->NOEXCEP)) == (t->BUSY | t->NOEXCEP)) {
605 return; /* device is busy */
609 * Check if rewind finished.
611 if (t->flags & TPREW) {
612 TRACE (((s & (t->BUSY | t->NOEXCEP)) == (t->BUSY | t->NOEXCEP) ?
613 "rewind busy?\n" : "rewind finished\n"));
614 t->flags &= ~TPREW; /* Rewind finished. */
615 wtsense (t, 1, TP_WRP);
621 * Check if writing/reading of file mark finished.
623 if (t->flags & (TPRMARK | TPWMARK)) {
624 TRACE (((s & (t->BUSY | t->NOEXCEP)) == (t->BUSY | t->NOEXCEP) ?
625 "marker r/w busy?\n" : "marker r/w finished\n"));
626 if (! (s & t->NOEXCEP)) /* operation failed */
627 wtsense (t, 1, (t->flags & TPRMARK) ? TP_WRP : 0);
628 t->flags &= ~(TPRMARK | TPWMARK); /* operation finished */
634 * Do we started any i/o? If no, just return.
636 if (! (t->flags & TPACTIVE)) {
637 TRACE (("unexpected interrupt\n"));
644 if ((t->dmaflags & ISADMA_READ) && (t->dmatotal - t->dmacount) < t->bsize) {
645 /* If reading short block, copy the internal buffer
646 * to the user memory. */
647 isa_dmadone (t->dmaflags, t->buf, t->bsize, t->chan);
648 bcopy (t->buf, t->dmavaddr, t->dmatotal - t->dmacount);
650 isa_dmadone (t->dmaflags, t->dmavaddr, t->bsize, t->chan);
652 t->flags &= ~TPACTIVE;
653 t->dmacount += t->bsize;
654 t->dmavaddr = (char *)t->dmavaddr + t->bsize;
657 * On exception, check for end of file and end of volume.
659 if (! (s & t->NOEXCEP)) {
660 TRACE (("i/o exception\n"));
661 wtsense (t, 1, (t->dmaflags & ISADMA_READ) ? TP_WRP : 0);
662 if (t->error.err & (TP_EOM | TP_FIL))
663 t->flags |= TPVOL; /* end of file */
665 t->flags |= TPEXCEP; /* i/o error */
670 if (t->dmacount < t->dmatotal) { /* continue i/o */
672 TRACE (("continue i/o, %d\n", t->dmacount));
675 if (t->dmacount > t->dmatotal) /* short last block */
676 t->dmacount = t->dmatotal;
677 wakeup ((caddr_t)t); /* wake up user level */
678 TRACE (("i/o finished, %d\n", t->dmacount));
681 /* start the rewind operation */
683 wtrewind (wtinfo_t *t)
685 int rwmode = (t->flags & (TPRO | TPWO));
687 t->flags &= ~(TPRO | TPWO | TPVOL);
689 * Wangtek strictly follows QIC-02 standard:
690 * clearing ONLINE in read/write modes causes rewind.
691 * REWIND command is not allowed in read/write mode
692 * and gives `illegal command' error.
694 if (t->type==WANGTEK && rwmode) {
695 outb (t->CTLPORT, 0);
696 } else if (! wtcmd (t, QIC_REWIND))
698 t->flags |= TPSTART | TPREW;
702 /* start the `read marker' operation */
704 wtreadfm (wtinfo_t *t)
706 t->flags &= ~(TPRO | TPWO | TPVOL);
707 if (! wtcmd (t, QIC_READFM)) {
708 wtsense (t, 1, TP_WRP);
711 t->flags |= TPRMARK | TPRANY;
713 /* Don't wait for completion here. */
717 /* write marker to the tape */
719 wtwritefm (wtinfo_t *t)
721 tsleep ((caddr_t)wtwritefm, 0, "wtwfm", hz); /* timeout: 1 second */
722 t->flags &= ~(TPRO | TPWO);
723 if (! wtcmd (t, QIC_WRITEFM)) {
727 t->flags |= TPWMARK | TPWANY;
729 return (wtwait (t, 0, "wtwfm"));
732 /* while controller status & mask == bits continue waiting */
734 wtpoll (wtinfo_t *t, int mask, int bits)
738 /* Poll status port, waiting for specified bits. */
739 for (i=0; i<1000; ++i) { /* up to 1 msec */
740 s = inb (t->STATPORT);
741 if ((s & mask) != bits)
745 for (i=0; i<100; ++i) { /* up to 10 msec */
746 s = inb (t->STATPORT);
747 if ((s & mask) != bits)
751 for (;;) { /* forever */
752 s = inb (t->STATPORT);
753 if ((s & mask) != bits)
755 tsleep ((caddr_t)wtpoll, 0, "wtpoll", 1); /* timeout: 1 tick */
759 /* execute QIC command */
761 wtcmd (wtinfo_t *t, int cmd)
765 TRACE (("wtcmd() cmd=0x%x\n", cmd));
767 s = wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP); /* ready? */
768 if (! (s & t->NOEXCEP)) { /* error */
773 outb (t->CMDPORT, cmd); /* output the command */
775 outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */
776 wtpoll (t, t->BUSY, t->BUSY); /* wait for ready */
777 outb (t->CTLPORT, t->IEN | t->ONLINE); /* reset request */
778 wtpoll (t, t->BUSY, 0); /* wait for not ready */
783 /* wait for the end of i/o, seeking marker or rewind operation */
785 wtwait (wtinfo_t *t, int catch, char *msg)
789 TRACE (("wtwait() `%s'\n", msg));
790 while (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK)) {
791 error = tsleep ((caddr_t)t, catch, msg, 0);
798 /* initialize dma for the i/o operation */
802 t->flags |= TPACTIVE;
805 if (t->type == ARCHIVE)
806 outb (t->SDMAPORT, 0); /* set dma */
808 if ((t->dmaflags & ISADMA_READ) && (t->dmatotal - t->dmacount) < t->bsize)
809 /* Reading short block. Do it through the internal buffer. */
810 isa_dmastart (t->dmaflags, t->buf, t->bsize, t->chan);
812 isa_dmastart (t->dmaflags, t->dmavaddr, t->bsize, t->chan);
815 /* start i/o operation */
817 wtstart (wtinfo_t *t, unsigned flags, void *vaddr, unsigned len)
821 TRACE (("wtstart()\n"));
823 s = wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP); /* ready? */
824 if (! (s & t->NOEXCEP)) {
825 t->flags |= TPEXCEP; /* error */
829 t->flags &= ~TPEXCEP; /* clear exception flag */
841 wtclock (wtinfo_t *t)
843 if (! (t->flags & TPTIMER)) {
845 /* Some controllers seem to lose dma interrupts too often.
846 * To make the tape stream we need 1 tick timeout. */
847 callout_reset(&t->timeout_ch, ((t->flags & TPACTIVE) ? 1 : hz),
853 * Simulate an interrupt periodically while i/o is going.
854 * This is necessary in case interrupts get eaten due to
855 * multiple devices on a single IRQ line.
860 wtinfo_t *t = (wtinfo_t *)xt;
862 t->flags &= ~TPTIMER;
863 if (! (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK)))
866 /* If i/o going, simulate interrupt. */
868 if ((inb (t->STATPORT) & (t->BUSY | t->NOEXCEP)) != (t->BUSY | t->NOEXCEP)) {
869 TRACE (("wtimer() -- "));
870 wtintr ((void *)t->unit);
874 /* Restart timer if i/o pending. */
875 if (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK))
879 /* reset the controller */
881 wtreset (wtinfo_t *t)
883 /* Perform QIC-02 and QIC-36 compatible reset sequence. */
884 /* Thanks to Mikael Hybsch <micke@dynas.se>. */
887 outb (t->CTLPORT, t->RESET | t->ONLINE); /* send reset */
889 outb (t->CTLPORT, t->ONLINE); /* turn off reset */
892 /* Read the controller status. */
893 s = inb (t->STATPORT);
894 if (s == 0xff) /* no port at this address? */
897 /* Wait 3 sec for reset to complete. Needed for QIC-36 boards? */
898 for (i=0; i<3000; ++i) {
899 if (! (s & t->BUSY) || ! (s & t->NOEXCEP))
902 s = inb (t->STATPORT);
904 return ((s & t->RESETMASK) == t->RESETVAL);
907 /* get controller status information */
908 /* return 0 if user i/o request should receive an i/o error code */
910 wtsense (wtinfo_t *t, int verb, int ignor)
915 TRACE (("wtsense() ignor=0x%x\n", ignor));
916 t->flags &= ~(TPRO | TPWO);
919 if (! (t->error.err & TP_ST0))
920 t->error.err &= ~TP_ST0MASK;
921 if (! (t->error.err & TP_ST1))
922 t->error.err &= ~TP_ST1MASK;
923 t->error.err &= ~ignor; /* ignore certain errors */
924 err = t->error.err & (TP_FIL | TP_BNL | TP_UDA | TP_EOM | TP_WRP |
925 TP_USL | TP_CNI | TP_MBD | TP_NDT | TP_ILL);
931 /* lifted from tdriver.c from Wangtek */
932 if (err & TP_USL) msg = "Drive not online";
933 else if (err & TP_CNI) msg = "No cartridge";
934 else if ((err & TP_WRP) && !(t->flags & TPWP)) {
935 msg = "Tape is write protected";
938 else if (err & TP_FIL) msg = 0 /*"Filemark detected"*/;
939 else if (err & TP_EOM) msg = 0 /*"End of tape"*/;
940 else if (err & TP_BNL) msg = "Block not located";
941 else if (err & TP_UDA) msg = "Unrecoverable data error";
942 else if (err & TP_NDT) msg = "No data detected";
943 else if (err & TP_ILL) msg = "Illegal command";
945 kprintf ("wt%d: %s\n", t->unit, msg);
949 /* get controller status information */
951 wtstatus (wtinfo_t *t)
956 wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP); /* ready? */
957 outb (t->CMDPORT, QIC_RDSTAT); /* send `read status' command */
959 outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */
960 wtpoll (t, t->BUSY, t->BUSY); /* wait for ready */
961 outb (t->CTLPORT, t->ONLINE); /* reset request */
962 wtpoll (t, t->BUSY, 0); /* wait for not ready */
964 p = (char*) &t->error;
965 while (p < (char*)&t->error + 6) {
966 int s = wtpoll (t, t->BUSY | t->NOEXCEP, t->BUSY | t->NOEXCEP);
967 if (! (s & t->NOEXCEP)) { /* error */
972 *p++ = inb (t->DATAPORT); /* read status byte */
974 outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */
975 wtpoll (t, t->BUSY, 0); /* wait for not ready */
977 outb (t->CTLPORT, t->ONLINE); /* unset request */