1 /* $NetBSD: ts.c,v 1.26 2008/12/16 22:35:35 christos Exp $ */
4 * Copyright (c) 1991 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)tmscp.c 7.16 (Berkeley) 5/9/91
35 * sccsid = "@(#)tmscp.c 1.24 (ULTRIX) 1/21/86";
38 /************************************************************************
40 * Licensed from Digital Equipment Corporation *
42 * Digital Equipment Corporation *
43 * Maynard, Massachusetts *
45 * All rights reserved. *
47 * The Information in this software is subject to change *
48 * without notice and should not be construed as a commitment *
49 * by Digital Equipment Corporation. Digital makes no *
50 * representations about the suitability of this software for *
51 * any purpose. It is supplied "As Is" without expressed or *
54 * If the Regents of the University of California or its *
55 * licensees modify the software in a manner creating *
56 * derivative copyright rights, appropriate copyright *
57 * legends may be placed on the derivative work in addition *
58 * to that set forth above. *
60 ************************************************************************/
63 * TSV05/TS05 device driver, written by Bertram Barth.
65 * should be TS11 compatible (untested)
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: ts.c,v 1.26 2008/12/16 22:35:35 christos Exp $");
76 * Keep track of tape position so that lseek et al works.
77 * Use tprintf to inform the user, not the system console.
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/kernel.h>
87 #include <sys/errno.h>
89 #include <sys/syslog.h>
90 #include <sys/ioctl.h>
97 #include <dev/qbus/ubareg.h>
98 #include <dev/qbus/ubavar.h>
100 #include <dev/qbus/tsreg.h>
105 struct cmd cmd
; /* command packet */
106 struct chr chr
; /* characteristics packet */
107 struct status status
; /* status packet */
111 * Software status, per controller.
112 * also status per tape-unit, since only one unit per controller
113 * (thus we have no struct ts_info)
116 device_t sc_dev
; /* Autoconf ... */
117 struct uba_softc
*sc_uh
; /* the parent UBA */
118 struct uba_unit sc_unit
; /* Struct common for UBA to talk */
119 struct evcnt sc_intrcnt
; /* Interrupt counting */
120 struct ubinfo sc_ui
; /* mapping info for struct ts */
121 struct uba_unit sc_uu
; /* Struct for UBA to communicate */
122 bus_space_tag_t sc_iot
;
124 bus_dma_tag_t sc_dmat
;
125 bus_dmamap_t sc_dmam
;
126 volatile struct ts
*sc_vts
; /* Memory address of ts struct */
127 struct ts
*sc_bts
; /* Unibus address of ts struct */
128 int sc_type
; /* TS11 or TS05? */
129 short sc_waddr
; /* Value to write to TSDB */
130 struct bufq_state
*sc_bufq
; /* pending I/O requests */
132 short sc_mapped
; /* Unibus map allocated ? */
133 short sc_state
; /* see below: ST_xxx */
134 short sc_rtc
; /* retry count for lcmd */
135 short sc_openf
; /* lock against multiple opens */
136 short sc_liowf
; /* last operation was write */
137 struct buf ts_cbuf
; /* internal cmd buffer (for ioctls) */
140 #define TS_WCSR(csr, val) \
141 bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
142 #define TS_RCSR(csr) \
143 bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
145 #define LOWORD(x) ((int)(x) & 0xffff)
146 #define HIWORD(x) (((int)(x) >> 16) & 0x3f)
155 #define TS_FASTREPOS 3
157 static void tsintr(void *);
158 static void tsinit(struct ts_softc
*);
159 static void tscommand(struct ts_softc
*, dev_t
, int, int);
160 static int tsstart(struct ts_softc
*, int);
161 static void tswchar(struct ts_softc
*);
162 static bool tsreset(struct ts_softc
*);
163 static int tsmatch(device_t
, cfdata_t
, void *);
164 static void tsattach(device_t
, device_t
, void *);
165 static int tsready(struct uba_unit
*);
167 CFATTACH_DECL_NEW(ts
, sizeof(struct ts_softc
),
168 tsmatch
, tsattach
, NULL
, NULL
);
170 dev_type_open(tsopen
);
171 dev_type_close(tsclose
);
172 dev_type_read(tsread
);
173 dev_type_write(tswrite
);
174 dev_type_ioctl(tsioctl
);
175 dev_type_strategy(tsstrategy
);
176 dev_type_dump(tsdump
);
178 const struct bdevsw ts_bdevsw
= {
179 tsopen
, tsclose
, tsstrategy
, tsioctl
, tsdump
, nosize
, D_TAPE
182 const struct cdevsw ts_cdevsw
= {
183 tsopen
, tsclose
, tsread
, tswrite
, tsioctl
,
184 nostop
, notty
, nopoll
, nommap
, nokqfilter
, D_TAPE
187 /* Bits in minor device */
188 #define TS_UNIT(dev) (minor(dev)&03)
189 #define TS_HIDENSITY 010
191 #define TS_PRI LOG_INFO
195 * Probe for device. If found, try to raise an interrupt.
198 tsmatch(device_t parent
, cfdata_t match
, void *aux
)
202 struct ts_softc
*sc
= &ssc
;
203 struct uba_attach_args
*ua
= aux
;
206 sc
->sc_iot
= ua
->ua_iot
;
207 sc
->sc_ioh
= ua
->ua_ioh
;
210 sc
->sc_uh
= device_private(parent
);
211 strcpy(sc
->sc_dev
->dv_xname
, "ts");
213 /* Try to reset the device */
214 for (i
= 0; i
< 3; i
++) {
223 tswchar(sc
); /* write charact. to enable interrupts */
224 /* completion of this will raise the intr. */
226 DELAY(1000000); /* Wait for interrupt */
227 ubmemfree(sc
->sc_uh
, &sc
->sc_ui
);
234 tsattach(device_t parent
, device_t self
, void *aux
)
236 struct ts_softc
*sc
= device_private(self
);
237 struct uba_attach_args
*ua
= aux
;
242 sc
->sc_uh
= device_private(parent
);
243 sc
->sc_iot
= ua
->ua_iot
;
244 sc
->sc_ioh
= ua
->ua_ioh
;
245 sc
->sc_dmat
= ua
->ua_dmat
;
247 sc
->sc_uu
.uu_dev
= self
;
248 sc
->sc_uu
.uu_ready
= tsready
;
250 tsinit(sc
); /* reset and map */
252 error
= bus_dmamap_create(sc
->sc_dmat
, (64*1024), 16, (64*1024),
253 0, BUS_DMA_NOWAIT
, &sc
->sc_dmam
);
255 aprint_error(": failed create DMA map %d\n", error
);
259 bufq_alloc(&sc
->sc_bufq
, "fcfs", 0);
262 * write the characteristics (again)
264 sc
->sc_state
= TS_INIT
; /* tsintr() checks this ... */
266 if (tsleep(sc
, PRIBIO
, "tsattach", 100)) {
267 aprint_error(": failed SET CHARACTERISTICS\n");
271 sc
->sc_state
= TS_RUNNING
;
272 if (sc
->sc_uh
->uh_type
== UBA_UBA
) {
273 if (sc
->sc_vts
->status
.xst2
& TS_SF_TU80
) {
274 sc
->sc_type
= TYPE_TU80
;
277 sc
->sc_type
= TYPE_TS11
;
281 sc
->sc_type
= TYPE_TS05
;
285 aprint_normal(": %s\n", t
);
286 aprint_normal_dev(sc
->sc_dev
,
287 "rev %d, extended features %s, transport %s\n",
288 (sc
->sc_vts
->status
.xst2
& TS_SF_MCRL
) >> 2,
289 (sc
->sc_vts
->status
.xst2
& TS_SF_EFES
? "enabled" : "disabled"),
290 (TS_RCSR(TSSR
) & TS_OFL
? "offline" : "online"));
292 uba_intr_establish(ua
->ua_icookie
, ua
->ua_cvec
, tsintr
,
293 sc
, &sc
->sc_intrcnt
);
294 evcnt_attach_dynamic(&sc
->sc_intrcnt
, EVCNT_TYPE_INTR
, ua
->ua_evcnt
,
295 device_xname(sc
->sc_dev
), "intr");
299 * Initialize a TS device. Set up UBA mapping registers,
300 * initialize data structures, what else ???
303 tsinit(struct ts_softc
*sc
)
305 if (sc
->sc_mapped
== 0) {
308 * Map the communications area and command and message
309 * buffer into Unibus address space.
311 sc
->sc_ui
.ui_size
= sizeof(struct ts
);
312 if (ubmemalloc(sc
->sc_uh
, &sc
->sc_ui
, UBA_CANTWAIT
))
314 sc
->sc_vts
= (void *)sc
->sc_ui
.ui_vaddr
;
315 sc
->sc_bts
= (void *)sc
->sc_ui
.ui_baddr
;
316 sc
->sc_waddr
= sc
->sc_ui
.ui_baddr
|
317 ((sc
->sc_ui
.ui_baddr
>> 16) & 3);
324 * Execute a (ioctl) command on the tape drive a specified number of times.
325 * This routine sets up a buffer and calls the strategy routine which
326 * issues the command to the controller.
329 tscommand(struct ts_softc
*sc
, dev_t dev
, int cmd
, int count
)
334 printf("tscommand (%x, %d)\n", cmd
, count
);
339 mutex_enter(&bufcache_lock
);
340 while (bp
->b_cflags
& BC_BUSY
) {
342 * This special check is because BC_BUSY never
343 * gets cleared in the non-waiting rewind case. ???
345 if (bp
->b_bcount
== 0 && (bp
->b_oflags
& BO_DONE
))
347 if (bbusy(bp
, false, 0, NULL
) == 0)
349 /* check MOT-flag !!! */
351 bp
->b_flags
= B_READ
;
352 mutex_exit(&bufcache_lock
);
355 * Load the buffer. The b_count field gets used to hold the command
356 * count. the b_resid field gets used to hold the command mneumonic.
357 * These 2 fields are "known" to be "safe" to use for this purpose.
358 * (Most other drivers also use these fields in this way.)
361 bp
->b_bcount
= count
;
365 bp
->b_objlock
= &buffer_lock
;
368 * In case of rewind from close, don't wait.
369 * This is the only case where count can be 0.
374 mutex_enter(&bufcache_lock
);
375 cv_broadcast(&bp
->b_busy
);
377 mutex_exit(&bufcache_lock
);
381 * Start an I/O operation on TS05 controller
384 tsstart(struct ts_softc
*sc
, int isloaded
)
389 bp
= bufq_peek(sc
->sc_bufq
);
394 printf("buf: %p bcount %ld blkno %d\n", bp
, bp
->b_bcount
, bp
->b_blkno
);
397 * Check if command is an ioctl or not (ie. read or write).
398 * If it's an ioctl then just set the flags for later use;
399 * For other commands attempt to setup a buffer pointer.
401 if (bp
== &sc
->ts_cbuf
) {
402 switch ((int)bp
->b_resid
) {
408 sc
->sc_vts
->cmd
.cw1
= bp
->b_bcount
;
412 sc
->sc_vts
->cmd
.cw1
= bp
->b_bcount
;
416 sc
->sc_vts
->cmd
.cw1
= bp
->b_bcount
;
420 sc
->sc_vts
->cmd
.cw1
= bp
->b_bcount
;
432 aprint_error_dev(sc
->sc_dev
, "bad ioctl %d\n",
434 /* Need a no-op. get status */
436 } /* end switch (bp->b_resid) */
440 * now we try to map the buffer into uba map space (???)
442 if (bus_dmamap_load(sc
->sc_dmat
, sc
->sc_dmam
,
444 bp
->b_bcount
, bp
->b_proc
, BUS_DMA_NOWAIT
)) {
445 uba_enqueue(&sc
->sc_uu
);
450 sc
->sc_vts
->cmd
.cw1
= LOWORD(sc
->sc_dmam
->dm_segs
[0].ds_addr
);
451 sc
->sc_vts
->cmd
.cw2
= HIWORD(sc
->sc_dmam
->dm_segs
[0].ds_addr
);
452 sc
->sc_vts
->cmd
.cw3
= bp
->b_bcount
;
453 bp
->b_error
= 0; /* Used for error count */
455 printf("tsstart-1: err %d\n", bp
->b_error
);
457 if (bp
->b_flags
& B_READ
)
464 * Now that the command-buffer is setup, give it to the controller
466 sc
->sc_vts
->cmd
.cmdr
= TS_CF_ACK
| TS_CF_IE
| cmd
;
468 printf("tsstart: sending cmdr %x\n", sc
->sc_vts
->cmd
.cmdr
);
470 TS_WCSR(TSDB
, sc
->sc_waddr
);
475 * Called when there are free uba resources.
478 tsready(struct uba_unit
*uu
)
480 struct ts_softc
*sc
= device_private(uu
->uu_dev
);
481 struct buf
*bp
= bufq_peek(sc
->sc_bufq
);
483 if (bus_dmamap_load(sc
->sc_dmat
, sc
->sc_dmam
, bp
->b_data
,
484 bp
->b_bcount
, bp
->b_proc
, BUS_DMA_NOWAIT
))
492 * initialize the controller by sending WRITE CHARACTERISTICS command.
493 * contents of command- and message-buffer are assembled during this
497 tswchar(struct ts_softc
*sc
)
500 * assemble and send "WRITE CHARACTERISTICS" command
503 sc
->sc_vts
->cmd
.cmdr
= TS_CF_ACK
| TS_CF_IE
| TS_CMD_WCHAR
;
504 sc
->sc_vts
->cmd
.cw1
= LOWORD(&sc
->sc_bts
->chr
);
505 sc
->sc_vts
->cmd
.cw2
= HIWORD(&sc
->sc_bts
->chr
);
506 sc
->sc_vts
->cmd
.cw3
= 010; /* size of charact.-data */
508 sc
->sc_vts
->chr
.sadrl
= LOWORD(&sc
->sc_bts
->status
);
509 sc
->sc_vts
->chr
.sadrh
= HIWORD(&sc
->sc_bts
->status
);
510 sc
->sc_vts
->chr
.onesix
= (sc
->sc_type
== TYPE_TS05
? 020 : 016);
511 sc
->sc_vts
->chr
.chrw
= TS_WC_ESS
;
512 sc
->sc_vts
->chr
.xchrw
= TS_WCX_HSP
|TS_WCX_RBUF
|TS_WCX_WBUF
;
514 TS_WCSR(TSDB
, sc
->sc_waddr
);
518 * Reset the TS11. Return 1 if failed, 0 if succeeded.
521 tsreset(struct ts_softc
*sc
)
526 * reset ctlr by writing into TSSR, then write characteristics
528 timeout
= 0; /* timeout in 10 seconds */
529 TS_WCSR(TSSR
, 0); /* start initialization */
530 while ((TS_RCSR(TSSR
) & TS_SSR
) == 0) {
532 if (timeout
++ > 1000)
539 prtstat(struct ts_softc
*sc
, int sr
)
543 snprintb(buf
, sizeof(buf
), TS_TSSR_BITS
, sr
);
544 aprint_normal_dev(sc
->sc_dev
, "TSSR=%s\n", buf
);
545 snprintb(buf
, sizeof(buf
), TS_XST0_BITS
, sc
->sc_vts
->status
.xst0
);
546 aprint_normal_dev(sc
->sc_dev
, "XST0=%s\n", buf
);
550 * TSV05/TS05 interrupt routine
555 struct ts_softc
*sc
= arg
;
558 unsigned short sr
= TS_RCSR(TSSR
); /* save TSSR */
559 unsigned short mh
= sc
->sc_vts
->status
.hdr
; /* and msg-header */
560 /* clear the message header ??? */
562 short ccode
= sc
->sc_vts
->cmd
.cmdr
& TS_CF_CCODE
;
564 bp
= bufq_peek(sc
->sc_bufq
);
568 snprintb(buf
, sizeof(buf
), TS_TSSR_BITS
, sr
);
569 printf("tsintr: sr %x mh %x\n", sr
, mh
);
570 printf("srbits: %s\n", buf
);
574 * There are two different things which can (and should) be checked:
575 * the actual (internal) state and the device's result (tssr/msg.hdr)
577 * For each state there's only one "normal" interrupt. Anything else
578 * has to be checked more intensively. Thus in a first run according
579 * to the internal state the expected interrupt is checked/handled.
581 * In a second run the remaining (not yet handled) interrupts are
582 * checked according to the drive's result.
584 switch (sc
->sc_state
) {
588 * Ignore unsolicited interrupts.
590 log(LOG_WARNING
, "%s: stray intr [%x,%x]\n",
591 device_xname(sc
->sc_dev
), sr
, mh
);
604 * Here we expect interrupts indicating the end of
605 * commands or indicating problems.
608 * Anything else is handled outside this switch ...
613 aprint_error_dev(sc
->sc_dev
,
614 "unexpected interrupt during state %d [%x,%x]\n",
615 sc
->sc_state
, sr
, mh
);
620 * now we check the termination class.
622 switch (sr
& TS_TC
) {
626 * Normal termination -- The operation is completed
629 if (sc
->sc_state
== TS_FASTREPOS
) {
631 printf("Fast repos interrupt\n");
633 /* Fast repos succeeded, start normal data xfer */
634 sc
->sc_state
= TS_RUNNING
;
638 sc
->sc_liowf
= (ccode
== TS_CC_WRITE
);
643 * Attention condition -- this code indicates that the
644 * drive has undergone a status change, such as going
645 * off-line or coming on-line.
646 * (Without EAI enabled, no Attention interrupts occur.
647 * drive status changes are signaled by the VCK flag.)
653 * Tape Status Alert -- A status condition is encountered
654 * that may have significance to the program. Bits of
655 * interest in the extended status registers include
661 snprintb(buf
, sizeof(buf
),
662 TS_XST0_BITS
, sc
->sc_vts
->status
.xst0
);
663 printf("TSA: sr %x bits %s\n",
664 sc
->sc_vts
->status
.xst0
, buf
);
667 if (sc
->sc_vts
->status
.xst0
& TS_SF_TMK
) {
669 printf(("Tape Mark detected"));
671 /* Read to end-of-file. No error. */
674 if (sc
->sc_vts
->status
.xst0
& TS_SF_EOT
) {
675 /* End of tape. Bad. */
677 printf("TS_TC_TSA: EOT\n");
683 if (sc
->sc_vts
->status
.xst0
& TS_SF_RLS
)
688 snprintb(buf
, sizeof(buf
),
689 TS_XST0_BITS
, sc
->sc_vts
->status
.xst0
);
690 printf("TSA: sr %x bits %s\n",
691 sc
->sc_vts
->status
.xst0
, buf
);
698 * Function Reject -- The specified function was not
699 * initiated. Bits of interest include OFL, VCK, BOT,
703 printf("tape is off-line.\n");
707 snprintb(buf
, sizeof(buf
),
708 TS_XST0_BITS
, sc
->sc_vts
->status
.xst0
);
709 printf("FR: sr %x bits %s\n",
710 sc
->sc_vts
->status
.xst0
, buf
);
713 if (sc
->sc_vts
->status
.xst0
& TS_SF_VCK
)
714 printf("Volume check\n");
715 if (sc
->sc_vts
->status
.xst0
& TS_SF_BOT
)
716 printf("Start of tape.\n");
717 if (sc
->sc_vts
->status
.xst0
& TS_SF_WLE
)
718 printf("Write Lock Error\n");
719 if (sc
->sc_vts
->status
.xst0
& TS_SF_EOT
)
720 printf("End of tape.\n");
725 * Recoverable Error -- Tape position is a record beyond
726 * what its position was when the function was initiated.
727 * Suggested recovery procedure is to log the error and
728 * issue the appropriate retry command.
730 * Do a fast repositioning one record back.
732 sc
->sc_state
= TS_FASTREPOS
;
734 printf("TS_TC_TPD: errcnt %d\n", sc
->sc_rtc
);
736 if (sc
->sc_rtc
++ == 8) {
737 aprint_error_dev(sc
->sc_dev
, "failed 8 retries\n");
743 sc
->sc_vts
->cmd
.cmdr
= TS_CF_ACK
| TS_CF_IE
| TS_CMD_SRR
;
744 sc
->sc_vts
->cmd
.cw1
= 1;
745 TS_WCSR(TSDB
, sc
->sc_waddr
);
750 * Recoverable Error -- Tape position has not changed.
751 * Suggested recovery procedure is to log the error and
752 * reissue the original command.
754 if (sc
->sc_rtc
++ == 8) {
755 aprint_error_dev(sc
->sc_dev
, "failed 8 retries\n");
766 * Unrecoverable Error -- Tape position has been lost.
767 * No valid recovery procedures exist unless the tape
768 * has labels or sequence numbers.
770 aprint_error_dev(sc
->sc_dev
, "tape position lost\n");
777 * Fatal subsytem Error -- The subsytem is incapable
778 * of properly performing commands, or at least its
779 * integrity is seriously questionable. Refer to the
780 * fatal class code field in the TSSR register for
781 * additional information on the type of fatal error.
783 aprint_error_dev(sc
->sc_dev
, "fatal controller error\n");
788 aprint_error_dev(sc
->sc_dev
,
789 "error 0x%x, resetting controller\n", sr
& TS_TC
);
792 if ((bp
= bufq_get(sc
->sc_bufq
)) != NULL
) {
794 printf("tsintr2: que %p\n", bufq_peek(sc
->sc_bufq
));
796 if (bp
!= &sc
->ts_cbuf
) { /* no ioctl */
797 bus_dmamap_unload(sc
->sc_dmat
, sc
->sc_dmam
);
800 bp
->b_resid
= sc
->sc_vts
->status
.rbpcr
;
808 * Open a ts device and set the unit online. If the controller is not
809 * in the run state, call init to initialize the ts controller first.
812 tsopen(dev_t dev
, int flag
, int type
, struct lwp
*l
)
814 struct ts_softc
*sc
= device_lookup_private(&ts_cd
, TS_UNIT(dev
));
819 if (sc
->sc_state
< TS_RUNNING
)
827 * check if transport is really online.
828 * (without attention-interrupts enabled, we really don't know
829 * the actual state of the transport. Thus we call get-status
830 * (ie. MTNOP) once and check the actual status.)
832 if (TS_RCSR(TSSR
) & TS_OFL
) {
833 uprintf("%s: transport is offline.\n", device_xname(sc
->sc_dev
));
835 return EIO
; /* transport is offline */
837 tscommand(sc
, dev
, MTNOP
, 1);
838 if ((flag
& FWRITE
) && (sc
->sc_vts
->status
.xst0
& TS_SF_WLK
)) {
839 uprintf("%s: no write ring.\n", device_xname(sc
->sc_dev
));
843 if (sc
->sc_vts
->status
.xst0
& TS_SF_VCK
) {
844 sc
->sc_vts
->cmd
.cmdr
= TS_CF_CVC
|TS_CF_ACK
;
845 TS_WCSR(TSDB
, sc
->sc_waddr
);
847 tscommand(sc
, dev
, MTNOP
, 1);
851 snprintb(buf
, sizeof(buf
),
852 TS_XST0_BITS
, sc
->sc_vts
->status
.xst0
);
853 printf("tsopen: xst0 %s\n", buf
);
864 * If tape was open for writing or last operation was
865 * a write, then write two EOF's and backspace over the last one.
866 * Unless this is a non-rewinding special file, rewind the tape.
868 * Make the tape available to others, by clearing openf flag.
871 tsclose(dev_t dev
, int flag
, int type
, struct lwp
*l
)
873 struct ts_softc
*sc
= device_lookup_private(&ts_cd
, TS_UNIT(dev
));
875 if (flag
== FWRITE
|| ((flag
& FWRITE
) && sc
->sc_liowf
)) {
877 * We are writing two tape marks (EOT), but place the tape
878 * before the second one, so that another write operation
879 * will overwrite the second one and leave and EOF-mark.
881 tscommand(sc
, dev
, MTWEOF
, 1); /* Write Tape Mark */
882 tscommand(sc
, dev
, MTWEOF
, 1); /* Write Tape Mark */
883 tscommand(sc
, dev
, MTBSF
, 1); /* Skip Tape Marks Reverse */
886 if ((dev
& T_NOREWIND
) == 0)
887 tscommand(sc
, dev
, MTREW
, 0);
896 * Manage buffers and perform block mode read and write operations.
899 tsstrategy(struct buf
*bp
)
901 struct ts_softc
*sc
= device_lookup_private(&ts_cd
, TS_UNIT(bp
->b_dev
));
906 printf("buf: %p bcount %ld blkno %d\n", bp
, bp
->b_bcount
, bp
->b_blkno
);
909 empty
= (bufq_peek(sc
->sc_bufq
) == NULL
);
910 bufq_put(sc
->sc_bufq
, bp
);
918 * Catch ioctl commands, and call the "command" routine to do them.
928 struct ts_softc
* const sc
= device_lookup_private(&ts_cd
, TS_UNIT(dev
));
929 struct mtop
*mtop
; /* mag tape cmd op to perform */
930 struct mtget
*mtget
; /* mag tape struct to get info in */
931 int callcount
; /* number of times to call routine */
932 int scount
; /* number of files/records to space */
933 int spaceop
= 0; /* flag for skip/space operation */
937 printf("tsioctl (%x, %lx, %p, %d)\n", dev
, cmd
, data
, flag
);
943 case MTIOCTOP
: /* do a mag tape op */
944 mtop
= (struct mtop
*)data
;
945 switch (mtop
->mt_op
) {
946 case MTWEOF
: /* write an end-of-file record */
947 callcount
= mtop
->mt_count
;
950 case MTFSR
: /* forward space record */
951 case MTBSR
: /* backward space record */
953 case MTFSF
: /* forward space file */
954 case MTBSF
: /* backward space file */
956 scount
= mtop
->mt_count
;
958 case MTREW
: /* rewind */
959 case MTOFFL
: /* rewind and put the drive offline */
960 case MTNOP
: /* no operation, sets status only */
962 scount
= 1; /* wait for this rewind */
964 case MTRETEN
: /* retension */
965 case MTERASE
: /* erase entire tape */
966 case MTEOM
: /* forward to end of media */
967 case MTNBSF
: /* backward space to begin of file */
968 case MTCACHE
: /* enable controller cache */
969 case MTNOCACHE
: /* disable controller cache */
970 case MTSETBSIZ
: /* set block size; 0 for variable */
971 case MTSETDNSTY
: /* set density code for current mode */
972 printf("ioctl %d not implemented.\n", mtop
->mt_op
);
976 printf("invalid ioctl %d\n", mtop
->mt_op
);
979 } /* switch (mtop->mt_op) */
981 if (callcount
<= 0 || scount
<= 0) {
983 printf("invalid values %d/%d\n", callcount
, scount
);
988 tscommand(sc
, dev
, mtop
->mt_op
, scount
);
989 if (spaceop
&& bp
->b_resid
) {
991 printf(("spaceop didn't complete\n"));
995 if (bp
->b_error
!= 0) {
997 printf("error in ioctl %d\n", mtop
->mt_op
);
1001 } while (--callcount
> 0);
1002 if (bp
->b_error
!= 0)
1003 error
= bp
->b_error
;
1006 case MTIOCGET
: /* get tape status */
1007 mtget
= (struct mtget
*)data
;
1008 mtget
->mt_type
= MT_ISTS
;
1009 mtget
->mt_dsreg
= TS_RCSR(TSSR
);
1010 mtget
->mt_erreg
= sc
->sc_vts
->status
.xst0
;
1011 mtget
->mt_resid
= 0; /* ??? */
1012 mtget
->mt_density
= 0; /* ??? */
1015 case MTIOCIEOT
: /* ignore EOT error */
1017 printf(("MTIOCIEOT not implemented.\n"));
1021 case MTIOCEEOT
: /* enable EOT error */
1023 printf(("MTIOCEEOT not implemented.\n"));
1029 printf("invalid ioctl cmd 0x%lx\n", cmd
);
1042 tsread(dev_t dev
, struct uio
*uio
, int flag
)
1044 return (physio (tsstrategy
, NULL
, dev
, B_READ
, minphys
, uio
));
1051 tswrite(dev_t dev
, struct uio
*uio
, int flag
)
1053 return (physio (tsstrategy
, NULL
, dev
, B_WRITE
, minphys
, uio
));
1060 tsdump(dev_t dev
, daddr_t blkno
, void *va
, size_t size
)