Home | History | Annotate | Line # | Download | only in gpib
mt.c revision 1.5.8.1
      1  1.5.8.1      yamt /*	$NetBSD: mt.c,v 1.5.8.1 2006/04/01 12:06:55 yamt Exp $ */
      2      1.1  gmcgarry 
      3      1.1  gmcgarry /*-
      4      1.1  gmcgarry  * Copyright (c) 1996-2003 The NetBSD Foundation, Inc.
      5      1.1  gmcgarry  * All rights reserved.
      6      1.1  gmcgarry  *
      7      1.1  gmcgarry  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  gmcgarry  * by Jason R. Thorpe.
      9      1.1  gmcgarry  *
     10      1.1  gmcgarry  * Redistribution and use in source and binary forms, with or without
     11      1.1  gmcgarry  * modification, are permitted provided that the following conditions
     12      1.1  gmcgarry  * are met:
     13      1.1  gmcgarry  * 1. Redistributions of source code must retain the above copyright
     14      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer.
     15      1.1  gmcgarry  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  gmcgarry  *    documentation and/or other materials provided with the distribution.
     18      1.1  gmcgarry  * 3. All advertising materials mentioning features or use of this software
     19      1.1  gmcgarry  *    must display the following acknowledgement:
     20      1.1  gmcgarry  *	This product includes software developed by the NetBSD
     21      1.1  gmcgarry  *	Foundation, Inc. and its contributors.
     22      1.1  gmcgarry  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  gmcgarry  *    contributors may be used to endorse or promote products derived
     24      1.1  gmcgarry  *    from this software without specific prior written permission.
     25      1.1  gmcgarry  *
     26      1.1  gmcgarry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  gmcgarry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  gmcgarry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  gmcgarry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  gmcgarry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  gmcgarry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  gmcgarry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  gmcgarry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  gmcgarry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  gmcgarry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  gmcgarry  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  gmcgarry  */
     38      1.1  gmcgarry 
     39      1.1  gmcgarry /*
     40      1.1  gmcgarry  * Copyright (c) 1982, 1990, 1993
     41      1.1  gmcgarry  *	The Regents of the University of California.  All rights reserved.
     42      1.1  gmcgarry  *
     43      1.1  gmcgarry  * This code is derived from software contributed to Berkeley by
     44      1.1  gmcgarry  * the Systems Programming Group of the University of Utah Computer
     45      1.1  gmcgarry  * Science Department.
     46      1.1  gmcgarry  *
     47      1.1  gmcgarry  * Redistribution and use in source and binary forms, with or without
     48      1.1  gmcgarry  * modification, are permitted provided that the following conditions
     49      1.1  gmcgarry  * are met:
     50      1.1  gmcgarry  * 1. Redistributions of source code must retain the above copyright
     51      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer.
     52      1.1  gmcgarry  * 2. Redistributions in binary form must reproduce the above copyright
     53      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer in the
     54      1.1  gmcgarry  *    documentation and/or other materials provided with the distribution.
     55      1.2       agc  * 3. Neither the name of the University nor the names of its contributors
     56      1.2       agc  *    may be used to endorse or promote products derived from this software
     57      1.2       agc  *    without specific prior written permission.
     58      1.2       agc  *
     59      1.2       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60      1.2       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61      1.2       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62      1.2       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63      1.2       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64      1.2       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65      1.2       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66      1.2       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67      1.2       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68      1.2       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69      1.2       agc  * SUCH DAMAGE.
     70      1.2       agc  *
     71      1.2       agc  * from: Utah $Hdr: rd.c 1.44 92/12/26$
     72      1.2       agc  *
     73      1.2       agc  *	@(#)rd.c	8.2 (Berkeley) 5/19/94
     74      1.2       agc  */
     75      1.2       agc 
     76      1.2       agc /*
     77      1.2       agc  * Copyright (c) 1988 University of Utah.
     78      1.2       agc  *
     79      1.2       agc  * This code is derived from software contributed to Berkeley by
     80      1.2       agc  * the Systems Programming Group of the University of Utah Computer
     81      1.2       agc  * Science Department.
     82      1.2       agc  *
     83      1.2       agc  * Redistribution and use in source and binary forms, with or without
     84      1.2       agc  * modification, are permitted provided that the following conditions
     85      1.2       agc  * are met:
     86      1.2       agc  * 1. Redistributions of source code must retain the above copyright
     87      1.2       agc  *    notice, this list of conditions and the following disclaimer.
     88      1.2       agc  * 2. Redistributions in binary form must reproduce the above copyright
     89      1.2       agc  *    notice, this list of conditions and the following disclaimer in the
     90      1.2       agc  *    documentation and/or other materials provided with the distribution.
     91      1.1  gmcgarry  * 3. All advertising materials mentioning features or use of this software
     92      1.1  gmcgarry  *    must display the following acknowledgement:
     93      1.1  gmcgarry  *	This product includes software developed by the University of
     94      1.1  gmcgarry  *	California, Berkeley and its contributors.
     95      1.1  gmcgarry  * 4. Neither the name of the University nor the names of its contributors
     96      1.1  gmcgarry  *    may be used to endorse or promote products derived from this software
     97      1.1  gmcgarry  *    without specific prior written permission.
     98      1.1  gmcgarry  *
     99      1.1  gmcgarry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    100      1.1  gmcgarry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    101      1.1  gmcgarry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    102      1.1  gmcgarry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    103      1.1  gmcgarry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    104      1.1  gmcgarry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    105      1.1  gmcgarry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    106      1.1  gmcgarry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    107      1.1  gmcgarry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    108      1.1  gmcgarry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    109      1.1  gmcgarry  * SUCH DAMAGE.
    110      1.1  gmcgarry  *
    111      1.1  gmcgarry  * from: Utah $Hdr: rd.c 1.44 92/12/26$
    112      1.1  gmcgarry  *
    113      1.1  gmcgarry  *	@(#)rd.c	8.2 (Berkeley) 5/19/94
    114      1.1  gmcgarry  */
    115      1.1  gmcgarry 
    116      1.1  gmcgarry /*
    117      1.1  gmcgarry  * Magnetic tape driver (HP7974a, HP7978a/b, HP7979a, HP7980a, HP7980xc)
    118      1.1  gmcgarry  * Original version contributed by Mt. Xinu.
    119      1.1  gmcgarry  * Modified for 4.4BSD by Mark Davies and Andrew Vignaux, Department of
    120      1.1  gmcgarry  * Computer Science, Victoria University of Wellington
    121      1.1  gmcgarry  */
    122      1.1  gmcgarry 
    123      1.1  gmcgarry #include <sys/cdefs.h>
    124  1.5.8.1      yamt __KERNEL_RCSID(0, "$NetBSD: mt.c,v 1.5.8.1 2006/04/01 12:06:55 yamt Exp $");
    125      1.1  gmcgarry 
    126      1.1  gmcgarry #include <sys/param.h>
    127      1.1  gmcgarry #include <sys/systm.h>
    128      1.1  gmcgarry #include <sys/callout.h>
    129      1.1  gmcgarry #include <sys/buf.h>
    130      1.3      yamt #include <sys/bufq.h>
    131      1.1  gmcgarry #include <sys/ioctl.h>
    132      1.1  gmcgarry #include <sys/mtio.h>
    133      1.1  gmcgarry #include <sys/file.h>
    134      1.1  gmcgarry #include <sys/proc.h>
    135      1.1  gmcgarry #include <sys/tty.h>
    136      1.1  gmcgarry #include <sys/kernel.h>
    137      1.1  gmcgarry #include <sys/tprintf.h>
    138      1.1  gmcgarry #include <sys/device.h>
    139      1.1  gmcgarry #include <sys/conf.h>
    140      1.1  gmcgarry 
    141      1.1  gmcgarry #include <dev/gpib/gpibvar.h>
    142      1.1  gmcgarry #include <dev/gpib/cs80busvar.h>
    143      1.1  gmcgarry 
    144      1.1  gmcgarry #include <dev/gpib/mtreg.h>
    145      1.1  gmcgarry 
    146      1.1  gmcgarry #ifdef DEBUG
    147      1.1  gmcgarry int	mtdebug = 0;
    148      1.1  gmcgarry #define MDB_ANY		0xff
    149      1.1  gmcgarry #define MDB_FOLLOW	0x01
    150      1.1  gmcgarry #define	DPRINTF(mask, str)	if (mtdebug & (mask)) printf str
    151      1.1  gmcgarry #else
    152      1.1  gmcgarry #define	DPRINTF(mask, str)	/* nothing */
    153      1.1  gmcgarry #endif
    154      1.1  gmcgarry 
    155      1.1  gmcgarry struct	mt_softc {
    156      1.1  gmcgarry 	struct	device sc_dev;
    157      1.1  gmcgarry 
    158      1.1  gmcgarry 	gpib_chipset_tag_t sc_ic;
    159      1.1  gmcgarry 	gpib_handle_t sc_hdl;
    160      1.1  gmcgarry 
    161      1.1  gmcgarry 	int	sc_slave;	/* GPIB slave address (0-6) */
    162      1.1  gmcgarry 	short	sc_flags;	/* see below */
    163      1.1  gmcgarry 	u_char	sc_lastdsj;	/* place for DSJ in mtreaddsj() */
    164      1.1  gmcgarry 	u_char	sc_lastecmd;	/* place for End Command in mtreaddsj() */
    165      1.1  gmcgarry 	short	sc_recvtimeo;	/* count of gpibsend timeouts to prevent hang */
    166      1.1  gmcgarry 	short	sc_statindex;	/* index for next sc_stat when MTF_STATTIMEO */
    167      1.1  gmcgarry 	struct	mt_stat sc_stat;/* status bytes last read from device */
    168      1.1  gmcgarry 	short	sc_density;	/* current density of tape (mtio.h format) */
    169      1.1  gmcgarry 	short	sc_type;	/* tape drive model (hardware IDs) */
    170      1.1  gmcgarry 	tpr_t	sc_ttyp;
    171      1.4      yamt 	struct bufq_state *sc_tab;/* buf queue */
    172      1.1  gmcgarry 	int	sc_active;
    173      1.1  gmcgarry 	struct buf sc_bufstore;	/* XXX buffer storage */
    174      1.1  gmcgarry 
    175      1.1  gmcgarry 	struct	callout sc_start_ch;
    176      1.1  gmcgarry 	struct	callout sc_intr_ch;
    177      1.1  gmcgarry };
    178      1.1  gmcgarry 
    179      1.1  gmcgarry #define	MTUNIT(x)	(minor(x) & 0x03)
    180      1.1  gmcgarry 
    181      1.1  gmcgarry #define B_CMD		B_XXX		/* command buf instead of data */
    182      1.1  gmcgarry #define	b_cmd		b_blkno		/* blkno holds cmd when B_CMD */
    183      1.1  gmcgarry 
    184      1.1  gmcgarry int	mtmatch(struct device *, struct cfdata *, void *);
    185      1.1  gmcgarry void	mtattach(struct device *, struct device *, void *);
    186      1.1  gmcgarry 
    187      1.1  gmcgarry CFATTACH_DECL(mt, sizeof(struct mt_softc),
    188      1.1  gmcgarry 	mtmatch, mtattach, NULL, NULL);
    189      1.1  gmcgarry 
    190      1.1  gmcgarry int	mtlookup(int, int, int);
    191      1.1  gmcgarry void	mtustart(struct mt_softc *);
    192      1.1  gmcgarry int	mtreaddsj(struct mt_softc *, int);
    193      1.1  gmcgarry int	mtcommand(dev_t, int, int);
    194      1.1  gmcgarry 
    195      1.1  gmcgarry void	mtintr_callout(void *);
    196      1.1  gmcgarry void	mtstart_callout(void *);
    197      1.1  gmcgarry 
    198      1.1  gmcgarry void	mtcallback(void *, int);
    199      1.1  gmcgarry void	mtstart(struct mt_softc *);
    200      1.1  gmcgarry void	mtintr(struct mt_softc  *);
    201      1.1  gmcgarry 
    202      1.1  gmcgarry dev_type_open(mtopen);
    203      1.1  gmcgarry dev_type_close(mtclose);
    204      1.1  gmcgarry dev_type_read(mtread);
    205      1.1  gmcgarry dev_type_write(mtwrite);
    206      1.1  gmcgarry dev_type_ioctl(mtioctl);
    207      1.1  gmcgarry dev_type_strategy(mtstrategy);
    208      1.1  gmcgarry 
    209      1.1  gmcgarry const struct bdevsw mt_bdevsw = {
    210      1.1  gmcgarry 	mtopen, mtclose, mtstrategy, mtioctl, nodump, nosize, D_TAPE
    211      1.1  gmcgarry };
    212      1.1  gmcgarry 
    213      1.1  gmcgarry const struct cdevsw mt_cdevsw = {
    214      1.1  gmcgarry 	mtopen, mtclose, mtread, mtwrite, mtioctl,
    215      1.1  gmcgarry 	nostop, notty, nopoll, nommap, nokqfilter, D_TAPE
    216      1.1  gmcgarry };
    217      1.1  gmcgarry 
    218      1.1  gmcgarry 
    219      1.1  gmcgarry extern struct cfdriver mt_cd;
    220      1.1  gmcgarry 
    221      1.1  gmcgarry struct	mtinfo {
    222      1.1  gmcgarry 	u_short	hwid;
    223      1.1  gmcgarry 	char	*desc;
    224      1.1  gmcgarry } mtinfo[] = {
    225      1.1  gmcgarry 	{ MT7978ID,	"7978"	},
    226      1.1  gmcgarry 	{ MT7979AID,	"7979A"	},
    227      1.1  gmcgarry 	{ MT7980ID,	"7980"	},
    228      1.1  gmcgarry 	{ MT7974AID,	"7974A"	},
    229      1.1  gmcgarry };
    230      1.1  gmcgarry int	nmtinfo = sizeof(mtinfo) / sizeof(mtinfo[0]);
    231      1.1  gmcgarry 
    232      1.1  gmcgarry 
    233      1.1  gmcgarry int
    234      1.1  gmcgarry mtlookup(id, slave, punit)
    235      1.1  gmcgarry 	int id;
    236      1.1  gmcgarry 	int slave;
    237      1.1  gmcgarry 	int punit;
    238      1.1  gmcgarry {
    239      1.1  gmcgarry 	int i;
    240      1.1  gmcgarry 
    241      1.1  gmcgarry 	for (i = 0; i < nmtinfo; i++)
    242      1.1  gmcgarry 		if (mtinfo[i].hwid == id)
    243      1.1  gmcgarry 			break;
    244      1.1  gmcgarry 	if (i == nmtinfo)
    245      1.1  gmcgarry 		return (-1);
    246      1.1  gmcgarry 	return (0);
    247      1.1  gmcgarry }
    248      1.1  gmcgarry 
    249      1.1  gmcgarry int
    250      1.1  gmcgarry mtmatch(parent, match, aux)
    251      1.1  gmcgarry 	struct device *parent;
    252      1.1  gmcgarry 	struct cfdata *match;
    253      1.1  gmcgarry 	void *aux;
    254      1.1  gmcgarry {
    255      1.1  gmcgarry 	struct cs80bus_attach_args *ca = aux;
    256      1.1  gmcgarry 
    257      1.1  gmcgarry 	ca->ca_punit = 0;
    258      1.1  gmcgarry 	return (mtlookup(ca->ca_id, ca->ca_slave, ca->ca_punit) == 0);
    259      1.1  gmcgarry }
    260      1.1  gmcgarry 
    261      1.1  gmcgarry void
    262      1.1  gmcgarry mtattach(parent, self, aux)
    263      1.1  gmcgarry 	struct device *parent, *self;
    264      1.1  gmcgarry 	void *aux;
    265      1.1  gmcgarry {
    266  1.5.8.1      yamt 	struct mt_softc *sc = device_private(self);
    267      1.1  gmcgarry 	struct cs80bus_attach_args *ca = aux;
    268      1.1  gmcgarry 	int type;
    269      1.1  gmcgarry 
    270      1.1  gmcgarry 	sc->sc_ic = ca->ca_ic;
    271      1.1  gmcgarry 	sc->sc_slave = ca->ca_slave;
    272      1.1  gmcgarry 
    273      1.1  gmcgarry 	if ((type = mtlookup(ca->ca_id, ca->ca_slave, ca->ca_punit)) < 0)
    274      1.1  gmcgarry 		return;
    275      1.1  gmcgarry 
    276      1.1  gmcgarry 	printf(": %s tape\n", mtinfo[type].desc);
    277      1.1  gmcgarry 
    278      1.1  gmcgarry 	sc->sc_type = type;
    279      1.1  gmcgarry 	sc->sc_flags = MTF_EXISTS;
    280      1.1  gmcgarry 
    281      1.4      yamt 	bufq_alloc(&sc->sc_tab, "fcfs", 0);
    282      1.1  gmcgarry 	callout_init(&sc->sc_start_ch);
    283      1.1  gmcgarry 	callout_init(&sc->sc_intr_ch);
    284      1.1  gmcgarry 
    285      1.1  gmcgarry 	if (gpibregister(sc->sc_ic, sc->sc_slave, mtcallback, sc,
    286      1.1  gmcgarry 	    &sc->sc_hdl)) {
    287      1.1  gmcgarry 		printf("%s: can't register callback\n", sc->sc_dev.dv_xname);
    288      1.1  gmcgarry 		return;
    289      1.1  gmcgarry 	}
    290      1.1  gmcgarry }
    291      1.1  gmcgarry 
    292      1.1  gmcgarry /*
    293      1.1  gmcgarry  * Perform a read of "Device Status Jump" register and update the
    294      1.1  gmcgarry  * status if necessary.  If status is read, the given "ecmd" is also
    295      1.1  gmcgarry  * performed, unless "ecmd" is zero.  Returns DSJ value, -1 on failure
    296      1.1  gmcgarry  * and -2 on "temporary" failure.
    297      1.1  gmcgarry  */
    298      1.1  gmcgarry int
    299      1.1  gmcgarry mtreaddsj(sc, ecmd)
    300      1.1  gmcgarry 	struct mt_softc *sc;
    301      1.1  gmcgarry 	int ecmd;
    302      1.1  gmcgarry {
    303      1.1  gmcgarry 	int retval;
    304      1.1  gmcgarry 
    305      1.1  gmcgarry 	if (sc->sc_flags & MTF_STATTIMEO)
    306      1.1  gmcgarry 		goto getstats;
    307      1.1  gmcgarry 	retval = gpibrecv(sc->sc_ic,
    308      1.1  gmcgarry 	    (sc->sc_flags & MTF_DSJTIMEO) ? -1 : sc->sc_slave,
    309      1.1  gmcgarry 	    MTT_DSJ, &(sc->sc_lastdsj), 1);
    310      1.1  gmcgarry 	sc->sc_flags &= ~MTF_DSJTIMEO;
    311      1.1  gmcgarry 	if (retval != 1) {
    312      1.1  gmcgarry 		DPRINTF(MDB_ANY, ("%s can't gpibrecv DSJ",
    313      1.1  gmcgarry 		    sc->sc_dev.dv_xname));
    314      1.1  gmcgarry 		if (sc->sc_recvtimeo == 0)
    315      1.1  gmcgarry 			sc->sc_recvtimeo = hz;
    316      1.1  gmcgarry 		if (--sc->sc_recvtimeo == 0)
    317      1.1  gmcgarry 			return (-1);
    318      1.1  gmcgarry 		if (retval == 0)
    319      1.1  gmcgarry 			sc->sc_flags |= MTF_DSJTIMEO;
    320      1.1  gmcgarry 		return (-2);
    321      1.1  gmcgarry 	}
    322      1.1  gmcgarry 	sc->sc_recvtimeo = 0;
    323      1.1  gmcgarry 	sc->sc_statindex = 0;
    324      1.1  gmcgarry 	DPRINTF(MDB_ANY, ("%s readdsj: 0x%x", sc->sc_dev.dv_xname,
    325      1.1  gmcgarry 	    sc->sc_lastdsj));
    326      1.1  gmcgarry 	sc->sc_lastecmd = ecmd;
    327      1.1  gmcgarry 	switch (sc->sc_lastdsj) {
    328      1.1  gmcgarry 	    case 0:
    329      1.1  gmcgarry 		if (ecmd & MTE_DSJ_FORCE)
    330      1.1  gmcgarry 			break;
    331      1.1  gmcgarry 		return (0);
    332      1.1  gmcgarry 
    333      1.1  gmcgarry 	    case 2:
    334      1.1  gmcgarry 		sc->sc_lastecmd = MTE_COMPLETE;
    335      1.1  gmcgarry 	    case 1:
    336      1.1  gmcgarry 		break;
    337      1.1  gmcgarry 
    338      1.1  gmcgarry 	    default:
    339      1.1  gmcgarry 		printf("%s readdsj: DSJ 0x%x\n", sc->sc_dev.dv_xname,
    340      1.1  gmcgarry 		    sc->sc_lastdsj);
    341      1.1  gmcgarry 		return (-1);
    342      1.1  gmcgarry 	}
    343      1.1  gmcgarry 
    344      1.1  gmcgarry getstats:
    345      1.1  gmcgarry 	retval = gpibrecv(sc->sc_ic,
    346      1.1  gmcgarry 	    (sc->sc_flags & MTF_STATCONT) ? -1 : sc->sc_slave, MTT_STAT,
    347      1.1  gmcgarry 	     ((char *)&(sc->sc_stat)) + sc->sc_statindex,
    348      1.1  gmcgarry 	    sizeof(sc->sc_stat) - sc->sc_statindex);
    349      1.1  gmcgarry 	sc->sc_flags &= ~(MTF_STATTIMEO | MTF_STATCONT);
    350      1.1  gmcgarry 	if (retval != sizeof(sc->sc_stat) - sc->sc_statindex) {
    351      1.1  gmcgarry 		if (sc->sc_recvtimeo == 0)
    352      1.1  gmcgarry 			sc->sc_recvtimeo = hz;
    353      1.1  gmcgarry 		if (--sc->sc_recvtimeo != 0) {
    354      1.1  gmcgarry 			if (retval >= 0) {
    355      1.1  gmcgarry 				sc->sc_statindex += retval;
    356      1.1  gmcgarry 				sc->sc_flags |= MTF_STATCONT;
    357      1.1  gmcgarry 			}
    358      1.1  gmcgarry 			sc->sc_flags |= MTF_STATTIMEO;
    359      1.1  gmcgarry 			return (-2);
    360      1.1  gmcgarry 		}
    361      1.1  gmcgarry 		printf("%s readdsj: can't read status", sc->sc_dev.dv_xname);
    362      1.1  gmcgarry 		return (-1);
    363      1.1  gmcgarry 	}
    364      1.1  gmcgarry 	sc->sc_recvtimeo = 0;
    365      1.1  gmcgarry 	sc->sc_statindex = 0;
    366      1.1  gmcgarry 	DPRINTF(MDB_ANY, ("%s readdsj: status is %x %x %x %x %x %x",
    367      1.1  gmcgarry 	    sc->sc_dev.dv_xname,
    368      1.1  gmcgarry 	    sc->sc_stat1, sc->sc_stat2, sc->sc_stat3,
    369      1.1  gmcgarry 	    sc->sc_stat4, sc->sc_stat5, sc->sc_stat6));
    370      1.1  gmcgarry 	if (sc->sc_lastecmd)
    371      1.1  gmcgarry 		(void) gpibsend(sc->sc_ic, sc->sc_slave,
    372      1.1  gmcgarry 		    MTL_ECMD, &(sc->sc_lastecmd), 1);
    373      1.1  gmcgarry 	return ((int) sc->sc_lastdsj);
    374      1.1  gmcgarry }
    375      1.1  gmcgarry 
    376      1.1  gmcgarry int
    377      1.1  gmcgarry mtopen(dev, flag, mode, p)
    378      1.1  gmcgarry 	dev_t dev;
    379      1.1  gmcgarry 	int flag, mode;
    380      1.1  gmcgarry 	struct proc *p;
    381      1.1  gmcgarry {
    382      1.1  gmcgarry 	struct mt_softc *sc;
    383      1.1  gmcgarry 	int req_den;
    384      1.1  gmcgarry 	int error;
    385      1.1  gmcgarry 
    386      1.1  gmcgarry 	sc = device_lookup(&mt_cd, MTUNIT(dev));
    387      1.1  gmcgarry 	if (sc == NULL || (sc->sc_flags & MTF_EXISTS) == 0)
    388      1.1  gmcgarry 		return (ENXIO);
    389      1.1  gmcgarry 
    390      1.1  gmcgarry 	if (sc->sc_flags & MTF_OPEN)
    391      1.1  gmcgarry 		return (EBUSY);
    392      1.1  gmcgarry 
    393      1.1  gmcgarry 	DPRINTF(MDB_ANY, ("%s open: flags 0x%x", sc->sc_dev.dv_xname,
    394      1.1  gmcgarry 	    sc->sc_flags));
    395      1.1  gmcgarry 
    396      1.1  gmcgarry 	sc->sc_flags |= MTF_OPEN;
    397      1.1  gmcgarry 	sc->sc_ttyp = tprintf_open(p);
    398      1.1  gmcgarry 	if ((sc->sc_flags & MTF_ALIVE) == 0) {
    399      1.1  gmcgarry 		error = mtcommand(dev, MTRESET, 0);
    400      1.1  gmcgarry 		if (error != 0 || (sc->sc_flags & MTF_ALIVE) == 0)
    401      1.1  gmcgarry 			goto errout;
    402      1.1  gmcgarry 		if ((sc->sc_stat1 & (SR1_BOT | SR1_ONLINE)) == SR1_ONLINE)
    403      1.1  gmcgarry 			(void) mtcommand(dev, MTREW, 0);
    404      1.1  gmcgarry 	}
    405      1.1  gmcgarry 	for (;;) {
    406      1.1  gmcgarry 		if ((error = mtcommand(dev, MTNOP, 0)) != 0)
    407      1.1  gmcgarry 			goto errout;
    408      1.1  gmcgarry 		if (!(sc->sc_flags & MTF_REW))
    409      1.1  gmcgarry 			break;
    410      1.1  gmcgarry 		if (tsleep((caddr_t) &lbolt, PCATCH | (PZERO + 1),
    411      1.1  gmcgarry 		    "mt", 0) != 0) {
    412      1.1  gmcgarry 			error = EINTR;
    413      1.1  gmcgarry 			goto errout;
    414      1.1  gmcgarry 		}
    415      1.1  gmcgarry 	}
    416      1.1  gmcgarry 	if ((flag & FWRITE) && (sc->sc_stat1 & SR1_RO)) {
    417      1.1  gmcgarry 		error = EROFS;
    418      1.1  gmcgarry 		goto errout;
    419      1.1  gmcgarry 	}
    420      1.1  gmcgarry 	if (!(sc->sc_stat1 & SR1_ONLINE)) {
    421      1.1  gmcgarry 		uprintf("%s: not online\n", sc->sc_dev.dv_xname);
    422      1.1  gmcgarry 		error = EIO;
    423      1.1  gmcgarry 		goto errout;
    424      1.1  gmcgarry 	}
    425      1.1  gmcgarry 	/*
    426      1.1  gmcgarry 	 * Select density:
    427      1.1  gmcgarry 	 *  - find out what density the drive is set to
    428      1.1  gmcgarry 	 *	(i.e. the density of the current tape)
    429      1.1  gmcgarry 	 *  - if we are going to write
    430      1.1  gmcgarry 	 *    - if we're not at the beginning of the tape
    431      1.1  gmcgarry 	 *      - complain if we want to change densities
    432      1.1  gmcgarry 	 *    - otherwise, select the mtcommand to set the density
    433      1.1  gmcgarry 	 *
    434      1.1  gmcgarry 	 * If the drive doesn't support it then don't change the recorded
    435      1.1  gmcgarry 	 * density.
    436      1.1  gmcgarry 	 *
    437      1.1  gmcgarry 	 * The original MOREbsd code had these additional conditions
    438      1.1  gmcgarry 	 * for the mid-tape change
    439      1.1  gmcgarry 	 *
    440      1.1  gmcgarry 	 *	req_den != T_BADBPI &&
    441      1.1  gmcgarry 	 *	sc->sc_density != T_6250BPI
    442      1.1  gmcgarry 	 *
    443      1.1  gmcgarry 	 * which suggests that it would be possible to write multiple
    444      1.1  gmcgarry 	 * densities if req_den == T_BAD_BPI or the current tape
    445      1.1  gmcgarry 	 * density was 6250.  Testing of our 7980 suggests that the
    446      1.1  gmcgarry 	 * device cannot change densities mid-tape.
    447      1.1  gmcgarry 	 *
    448      1.1  gmcgarry 	 * ajv (at) comp.vuw.ac.nz
    449      1.1  gmcgarry 	 */
    450      1.1  gmcgarry 	sc->sc_density = (sc->sc_stat2 & SR2_6250) ? T_6250BPI : (
    451      1.1  gmcgarry 			 (sc->sc_stat3 & SR3_1600) ? T_1600BPI : (
    452      1.1  gmcgarry 			 (sc->sc_stat3 & SR3_800) ? T_800BPI : -1));
    453      1.1  gmcgarry 	req_den = (dev & T_DENSEL);
    454      1.1  gmcgarry 
    455      1.1  gmcgarry 	if (flag & FWRITE) {
    456      1.1  gmcgarry 		if (!(sc->sc_stat1 & SR1_BOT)) {
    457      1.1  gmcgarry 			if (sc->sc_density != req_den) {
    458      1.1  gmcgarry 				uprintf("%s: can't change density mid-tape\n",
    459      1.1  gmcgarry 				    sc->sc_dev.dv_xname);
    460      1.1  gmcgarry 				error = EIO;
    461      1.1  gmcgarry 				goto errout;
    462      1.1  gmcgarry 			}
    463      1.1  gmcgarry 		}
    464      1.1  gmcgarry 		else {
    465      1.1  gmcgarry 			int mtset_density =
    466      1.1  gmcgarry 			    (req_den == T_800BPI  ? MTSET800BPI : (
    467      1.1  gmcgarry 			     req_den == T_1600BPI ? MTSET1600BPI : (
    468      1.1  gmcgarry 			     req_den == T_6250BPI ? MTSET6250BPI : (
    469      1.1  gmcgarry 			     sc->sc_type == MT7980ID
    470      1.1  gmcgarry 						  ? MTSET6250DC
    471      1.1  gmcgarry 						  : MTSET6250BPI))));
    472      1.1  gmcgarry 			if (mtcommand(dev, mtset_density, 0) == 0)
    473      1.1  gmcgarry 				sc->sc_density = req_den;
    474      1.1  gmcgarry 		}
    475      1.1  gmcgarry 	}
    476      1.1  gmcgarry 	return (0);
    477      1.1  gmcgarry errout:
    478      1.1  gmcgarry 	sc->sc_flags &= ~MTF_OPEN;
    479      1.1  gmcgarry 	return (error);
    480      1.1  gmcgarry }
    481      1.1  gmcgarry 
    482      1.1  gmcgarry int
    483      1.1  gmcgarry mtclose(dev, flag, fmt, p)
    484      1.1  gmcgarry 	dev_t dev;
    485      1.1  gmcgarry 	int flag, fmt;
    486      1.1  gmcgarry 	struct proc *p;
    487      1.1  gmcgarry {
    488      1.1  gmcgarry 	struct mt_softc *sc;
    489      1.1  gmcgarry 
    490      1.1  gmcgarry 	sc = device_lookup(&mt_cd, MTUNIT(dev));
    491      1.1  gmcgarry 	if (sc == NULL)
    492      1.1  gmcgarry 		return (ENXIO);
    493      1.1  gmcgarry 
    494      1.1  gmcgarry 	if (sc->sc_flags & MTF_WRT) {
    495      1.1  gmcgarry 		(void) mtcommand(dev, MTWEOF, 2);
    496      1.1  gmcgarry 		(void) mtcommand(dev, MTBSF, 0);
    497      1.1  gmcgarry 	}
    498      1.1  gmcgarry 	if ((minor(dev) & T_NOREWIND) == 0)
    499      1.1  gmcgarry 		(void) mtcommand(dev, MTREW, 0);
    500      1.1  gmcgarry 	sc->sc_flags &= ~MTF_OPEN;
    501      1.1  gmcgarry 	tprintf_close(sc->sc_ttyp);
    502      1.1  gmcgarry 	return (0);
    503      1.1  gmcgarry }
    504      1.1  gmcgarry 
    505      1.1  gmcgarry int
    506      1.1  gmcgarry mtcommand(dev, cmd, cnt)
    507      1.1  gmcgarry 	dev_t dev;
    508      1.1  gmcgarry 	int cmd;
    509      1.1  gmcgarry 	int cnt;
    510      1.1  gmcgarry {
    511      1.1  gmcgarry 	struct mt_softc *sc;
    512      1.1  gmcgarry 	struct buf *bp;
    513      1.1  gmcgarry 	int error = 0;
    514      1.1  gmcgarry 
    515      1.1  gmcgarry 	sc = device_lookup(&mt_cd, MTUNIT(dev));
    516      1.1  gmcgarry 	bp = &sc->sc_bufstore;
    517      1.1  gmcgarry 
    518      1.1  gmcgarry 	if (bp->b_flags & B_BUSY)
    519      1.1  gmcgarry 		return (EBUSY);
    520      1.1  gmcgarry 
    521      1.1  gmcgarry 	bp->b_cmd = cmd;
    522      1.1  gmcgarry 	bp->b_dev = dev;
    523      1.1  gmcgarry 	do {
    524      1.1  gmcgarry 		bp->b_flags = B_BUSY | B_CMD;
    525      1.1  gmcgarry 		mtstrategy(bp);
    526      1.1  gmcgarry 		biowait(bp);
    527      1.1  gmcgarry 		if (bp->b_flags & B_ERROR) {
    528      1.1  gmcgarry 			error = (int) (unsigned) bp->b_error;
    529      1.1  gmcgarry 			break;
    530      1.1  gmcgarry 		}
    531      1.1  gmcgarry 	} while (--cnt > 0);
    532      1.1  gmcgarry #if 0
    533      1.1  gmcgarry 	bp->b_flags = 0 /*&= ~B_BUSY*/;
    534      1.1  gmcgarry #else
    535      1.1  gmcgarry 	bp->b_flags &= ~B_BUSY;
    536      1.1  gmcgarry #endif
    537      1.1  gmcgarry 	return (error);
    538      1.1  gmcgarry }
    539      1.1  gmcgarry 
    540      1.1  gmcgarry /*
    541      1.1  gmcgarry  * Only thing to check here is for legal record lengths (writes only).
    542      1.1  gmcgarry  */
    543      1.1  gmcgarry void
    544      1.1  gmcgarry mtstrategy(bp)
    545      1.1  gmcgarry 	struct buf *bp;
    546      1.1  gmcgarry {
    547      1.1  gmcgarry 	struct mt_softc *sc;
    548      1.1  gmcgarry 	int s;
    549      1.1  gmcgarry 
    550      1.1  gmcgarry 	sc = device_lookup(&mt_cd, MTUNIT(bp->b_dev));
    551      1.1  gmcgarry 
    552      1.1  gmcgarry 	DPRINTF(MDB_ANY, ("%s strategy", sc->sc_dev.dv_xname));
    553      1.1  gmcgarry 
    554      1.1  gmcgarry 	if ((bp->b_flags & (B_CMD | B_READ)) == 0) {
    555      1.1  gmcgarry #define WRITE_BITS_IGNORED	8
    556      1.1  gmcgarry #if 0
    557      1.1  gmcgarry 		if (bp->b_bcount & ((1 << WRITE_BITS_IGNORED) - 1)) {
    558      1.1  gmcgarry 			tprintf(sc->sc_ttyp,
    559      1.1  gmcgarry 				"%s: write record must be multiple of %d\n",
    560      1.1  gmcgarry 				sc->sc_dev.dv_xname, 1 << WRITE_BITS_IGNORED);
    561      1.1  gmcgarry 			goto error;
    562      1.1  gmcgarry 		}
    563      1.1  gmcgarry #endif
    564      1.1  gmcgarry 		s = 16 * 1024;
    565      1.1  gmcgarry 		if (sc->sc_stat2 & SR2_LONGREC) {
    566      1.1  gmcgarry 			switch (sc->sc_density) {
    567      1.1  gmcgarry 			    case T_1600BPI:
    568      1.1  gmcgarry 				s = 32 * 1024;
    569      1.1  gmcgarry 				break;
    570      1.1  gmcgarry 
    571      1.1  gmcgarry 			    case T_6250BPI:
    572      1.1  gmcgarry 			    case T_BADBPI:
    573      1.1  gmcgarry 				s = 60 * 1024;
    574      1.1  gmcgarry 				break;
    575      1.1  gmcgarry 			}
    576      1.1  gmcgarry 		}
    577      1.1  gmcgarry 		if (bp->b_bcount > s) {
    578      1.1  gmcgarry 			tprintf(sc->sc_ttyp,
    579      1.1  gmcgarry 				"%s: write record (%ld) too big: limit (%d)\n",
    580      1.1  gmcgarry 				sc->sc_dev.dv_xname, bp->b_bcount, s);
    581      1.1  gmcgarry #if 0 /* XXX see above */
    582      1.1  gmcgarry 	    error:
    583      1.1  gmcgarry #endif
    584      1.1  gmcgarry 			bp->b_flags |= B_ERROR;
    585      1.1  gmcgarry 			bp->b_error = EIO;
    586      1.1  gmcgarry 			biodone(bp);
    587      1.1  gmcgarry 			return;
    588      1.1  gmcgarry 		}
    589      1.1  gmcgarry 	}
    590      1.1  gmcgarry 	s = splbio();
    591      1.4      yamt 	BUFQ_PUT(sc->sc_tab, bp);
    592      1.1  gmcgarry 	if (sc->sc_active == 0) {
    593      1.1  gmcgarry 		sc->sc_active = 1;
    594      1.1  gmcgarry 		mtustart(sc);
    595      1.1  gmcgarry 	}
    596      1.1  gmcgarry 	splx(s);
    597      1.1  gmcgarry }
    598      1.1  gmcgarry 
    599      1.1  gmcgarry void
    600      1.1  gmcgarry mtustart(sc)
    601      1.1  gmcgarry 	struct mt_softc *sc;
    602      1.1  gmcgarry {
    603      1.1  gmcgarry 
    604      1.1  gmcgarry 	DPRINTF(MDB_ANY, ("%s ustart", sc->sc_dev.dv_xname));
    605      1.1  gmcgarry 	if (gpibrequest(sc->sc_ic, sc->sc_hdl))
    606      1.1  gmcgarry 		mtstart(sc);
    607      1.1  gmcgarry }
    608      1.1  gmcgarry 
    609      1.1  gmcgarry void
    610      1.1  gmcgarry mtcallback(v, action)
    611      1.1  gmcgarry 	void *v;
    612      1.1  gmcgarry 	int action;
    613      1.1  gmcgarry {
    614      1.1  gmcgarry 	struct mt_softc *sc = v;
    615      1.1  gmcgarry 
    616      1.1  gmcgarry 	DPRINTF(MDB_FOLLOW, ("mtcallback: v=%p, action=%d\n", v, action));
    617      1.1  gmcgarry 
    618      1.1  gmcgarry 	switch (action) {
    619      1.1  gmcgarry 	case GPIBCBF_START:
    620      1.1  gmcgarry 		mtstart(sc);
    621      1.1  gmcgarry 		break;
    622      1.1  gmcgarry 	case GPIBCBF_INTR:
    623      1.1  gmcgarry 		mtintr(sc);
    624      1.1  gmcgarry 		break;
    625      1.1  gmcgarry #ifdef DEBUG
    626      1.1  gmcgarry 	default:
    627      1.1  gmcgarry 		printf("mtcallback: unknown action %d\n", action);
    628      1.1  gmcgarry 		break;
    629      1.1  gmcgarry #endif
    630      1.1  gmcgarry 	}
    631      1.1  gmcgarry }
    632      1.1  gmcgarry 
    633      1.1  gmcgarry void
    634      1.1  gmcgarry mtintr_callout(arg)
    635      1.1  gmcgarry 	void *arg;
    636      1.1  gmcgarry {
    637      1.1  gmcgarry 	struct mt_softc *sc = arg;
    638      1.1  gmcgarry 	int s = splbio();
    639      1.1  gmcgarry 
    640      1.1  gmcgarry 	gpibppclear(sc->sc_ic);
    641      1.1  gmcgarry 	mtintr(sc);
    642      1.1  gmcgarry 	splx(s);
    643      1.1  gmcgarry }
    644      1.1  gmcgarry 
    645      1.1  gmcgarry void
    646      1.1  gmcgarry mtstart_callout(arg)
    647      1.1  gmcgarry 	void *arg;
    648      1.1  gmcgarry {
    649      1.1  gmcgarry 	int s = splbio();
    650      1.1  gmcgarry 
    651      1.1  gmcgarry 	mtstart((struct mt_softc *)arg);
    652      1.1  gmcgarry 	splx(s);
    653      1.1  gmcgarry }
    654      1.1  gmcgarry 
    655      1.1  gmcgarry void
    656      1.1  gmcgarry mtstart(sc)
    657      1.1  gmcgarry 	struct mt_softc *sc;
    658      1.1  gmcgarry {
    659      1.1  gmcgarry 	struct buf *bp;
    660      1.1  gmcgarry 	short	cmdcount = 1;
    661      1.1  gmcgarry 	u_char	cmdbuf[2];
    662      1.1  gmcgarry 
    663      1.1  gmcgarry 	DPRINTF(MDB_ANY, ("%s start", sc->sc_dev.dv_xname));
    664      1.1  gmcgarry 	sc->sc_flags &= ~MTF_WRT;
    665      1.4      yamt 	bp = BUFQ_PEEK(sc->sc_tab);
    666      1.1  gmcgarry 	if ((sc->sc_flags & MTF_ALIVE) == 0 &&
    667      1.1  gmcgarry 	    ((bp->b_flags & B_CMD) == 0 || bp->b_cmd != MTRESET))
    668      1.1  gmcgarry 		goto fatalerror;
    669      1.1  gmcgarry 
    670      1.1  gmcgarry 	if (sc->sc_flags & MTF_REW) {
    671      1.1  gmcgarry 		if (!gpibpptest(sc->sc_ic, sc->sc_slave))
    672      1.1  gmcgarry 			goto stillrew;
    673      1.1  gmcgarry 		switch (mtreaddsj(sc, MTE_DSJ_FORCE|MTE_COMPLETE|MTE_IDLE)) {
    674      1.1  gmcgarry 		    case 0:
    675      1.1  gmcgarry 		    case 1:
    676      1.1  gmcgarry 		stillrew:
    677      1.1  gmcgarry 			if ((sc->sc_stat1 & SR1_BOT) ||
    678      1.1  gmcgarry 			    !(sc->sc_stat1 & SR1_ONLINE)) {
    679      1.1  gmcgarry 				sc->sc_flags &= ~MTF_REW;
    680      1.1  gmcgarry 				break;
    681      1.1  gmcgarry 			}
    682      1.1  gmcgarry 		    case -2:
    683      1.1  gmcgarry 			/*
    684      1.1  gmcgarry 			 * -2 means "timeout" reading DSJ, which is probably
    685      1.1  gmcgarry 			 * temporary.  This is considered OK when doing a NOP,
    686      1.1  gmcgarry 			 * but not otherwise.
    687      1.1  gmcgarry 			 */
    688      1.1  gmcgarry 			if (sc->sc_flags & (MTF_DSJTIMEO | MTF_STATTIMEO)) {
    689      1.1  gmcgarry 				callout_reset(&sc->sc_start_ch, hz >> 5,
    690      1.1  gmcgarry 				    mtstart_callout, sc);
    691      1.1  gmcgarry 				return;
    692      1.1  gmcgarry 			}
    693      1.1  gmcgarry 		    case 2:
    694      1.1  gmcgarry 			if (bp->b_cmd != MTNOP || !(bp->b_flags & B_CMD)) {
    695      1.1  gmcgarry 				bp->b_error = EBUSY;
    696      1.1  gmcgarry 				goto errdone;
    697      1.1  gmcgarry 			}
    698      1.1  gmcgarry 			goto done;
    699      1.1  gmcgarry 
    700      1.1  gmcgarry 		    default:
    701      1.1  gmcgarry 			goto fatalerror;
    702      1.1  gmcgarry 		}
    703      1.1  gmcgarry 	}
    704      1.1  gmcgarry 	if (bp->b_flags & B_CMD) {
    705      1.1  gmcgarry 		if (sc->sc_flags & MTF_PASTEOT) {
    706      1.1  gmcgarry 			switch(bp->b_cmd) {
    707      1.1  gmcgarry 			    case MTFSF:
    708      1.1  gmcgarry 			    case MTWEOF:
    709      1.1  gmcgarry 			    case MTFSR:
    710      1.1  gmcgarry 				bp->b_error = ENOSPC;
    711      1.1  gmcgarry 				goto errdone;
    712      1.1  gmcgarry 
    713      1.1  gmcgarry 			    case MTBSF:
    714      1.1  gmcgarry 			    case MTOFFL:
    715      1.1  gmcgarry 			    case MTBSR:
    716      1.1  gmcgarry 			    case MTREW:
    717      1.1  gmcgarry 				sc->sc_flags &= ~(MTF_PASTEOT | MTF_ATEOT);
    718      1.1  gmcgarry 				break;
    719      1.1  gmcgarry 			}
    720      1.1  gmcgarry 		}
    721      1.1  gmcgarry 		switch(bp->b_cmd) {
    722      1.1  gmcgarry 		    case MTFSF:
    723      1.1  gmcgarry 			if (sc->sc_flags & MTF_HITEOF)
    724      1.1  gmcgarry 				goto done;
    725      1.1  gmcgarry 			cmdbuf[0] = MTTC_FSF;
    726      1.1  gmcgarry 			break;
    727      1.1  gmcgarry 
    728      1.1  gmcgarry 		    case MTBSF:
    729      1.1  gmcgarry 			if (sc->sc_flags & MTF_HITBOF)
    730      1.1  gmcgarry 				goto done;
    731      1.1  gmcgarry 			cmdbuf[0] = MTTC_BSF;
    732      1.1  gmcgarry 			break;
    733      1.1  gmcgarry 
    734      1.1  gmcgarry 		    case MTOFFL:
    735      1.1  gmcgarry 			sc->sc_flags |= MTF_REW;
    736      1.1  gmcgarry 			cmdbuf[0] = MTTC_REWOFF;
    737      1.1  gmcgarry 			break;
    738      1.1  gmcgarry 
    739      1.1  gmcgarry 		    case MTWEOF:
    740      1.1  gmcgarry 			cmdbuf[0] = MTTC_WFM;
    741      1.1  gmcgarry 			break;
    742      1.1  gmcgarry 
    743      1.1  gmcgarry 		    case MTBSR:
    744      1.1  gmcgarry 			cmdbuf[0] = MTTC_BSR;
    745      1.1  gmcgarry 			break;
    746      1.1  gmcgarry 
    747      1.1  gmcgarry 		    case MTFSR:
    748      1.1  gmcgarry 			cmdbuf[0] = MTTC_FSR;
    749      1.1  gmcgarry 			break;
    750      1.1  gmcgarry 
    751      1.1  gmcgarry 		    case MTREW:
    752      1.1  gmcgarry 			sc->sc_flags |= MTF_REW;
    753      1.1  gmcgarry 			cmdbuf[0] = MTTC_REW;
    754      1.1  gmcgarry 			break;
    755      1.1  gmcgarry 
    756      1.1  gmcgarry 		    case MTNOP:
    757      1.1  gmcgarry 			/*
    758      1.1  gmcgarry 			 * NOP is supposed to set status bits.
    759      1.1  gmcgarry 			 * Force readdsj to do it.
    760      1.1  gmcgarry 			 */
    761      1.1  gmcgarry 			switch (mtreaddsj(sc,
    762      1.1  gmcgarry 			  MTE_DSJ_FORCE | MTE_COMPLETE | MTE_IDLE)) {
    763      1.1  gmcgarry 			    default:
    764      1.1  gmcgarry 				goto done;
    765      1.1  gmcgarry 
    766      1.1  gmcgarry 			    case -1:
    767      1.1  gmcgarry 				/*
    768      1.1  gmcgarry 				 * If this fails, perform a device clear
    769      1.1  gmcgarry 				 * to fix any protocol problems and (most
    770      1.1  gmcgarry 				 * likely) get the status.
    771      1.1  gmcgarry 				 */
    772      1.1  gmcgarry 				bp->b_cmd = MTRESET;
    773      1.1  gmcgarry 				break;
    774      1.1  gmcgarry 
    775      1.1  gmcgarry 			    case -2:
    776      1.1  gmcgarry 				callout_reset(&sc->sc_start_ch, hz >> 5,
    777      1.1  gmcgarry 				    mtstart_callout, sc);
    778      1.1  gmcgarry 				return;
    779      1.1  gmcgarry 			}
    780      1.1  gmcgarry 
    781      1.1  gmcgarry 		    case MTRESET:
    782      1.1  gmcgarry 			/*
    783      1.1  gmcgarry 			 * 1) selected device clear (send with "-2" secondary)
    784      1.1  gmcgarry 			 * 2) set timeout, then wait for "service request"
    785      1.1  gmcgarry 			 * 3) interrupt will read DSJ (and END COMPLETE-IDLE)
    786      1.1  gmcgarry 			 */
    787      1.1  gmcgarry 			if (gpibsend(sc->sc_ic, sc->sc_slave, -2, NULL, 0)){
    788      1.1  gmcgarry 				printf("%s can't reset", sc->sc_dev.dv_xname);
    789      1.1  gmcgarry 				goto fatalerror;
    790      1.1  gmcgarry 			}
    791      1.1  gmcgarry 			callout_reset(&sc->sc_intr_ch, 4*hz, mtintr_callout,
    792      1.1  gmcgarry 			    sc);
    793      1.1  gmcgarry 			gpibawait(sc->sc_ic);
    794      1.1  gmcgarry 			return;
    795      1.1  gmcgarry 
    796      1.1  gmcgarry 		    case MTSET800BPI:
    797      1.1  gmcgarry 			cmdbuf[0] = MTTC_800;
    798      1.1  gmcgarry 			break;
    799      1.1  gmcgarry 
    800      1.1  gmcgarry 		    case MTSET1600BPI:
    801      1.1  gmcgarry 			cmdbuf[0] = MTTC_1600;
    802      1.1  gmcgarry 			break;
    803      1.1  gmcgarry 
    804      1.1  gmcgarry 		    case MTSET6250BPI:
    805      1.1  gmcgarry 			cmdbuf[0] = MTTC_6250;
    806      1.1  gmcgarry 			break;
    807      1.1  gmcgarry 
    808      1.1  gmcgarry 		    case MTSET6250DC:
    809      1.1  gmcgarry 			cmdbuf[0] = MTTC_DC6250;
    810      1.1  gmcgarry 			break;
    811      1.1  gmcgarry 		}
    812      1.1  gmcgarry 	} else {
    813      1.1  gmcgarry 		if (sc->sc_flags & MTF_PASTEOT) {
    814      1.1  gmcgarry 			bp->b_error = ENOSPC;
    815      1.1  gmcgarry 			goto errdone;
    816      1.1  gmcgarry 		}
    817      1.1  gmcgarry 		if (bp->b_flags & B_READ) {
    818      1.1  gmcgarry 			sc->sc_flags |= MTF_IO;
    819      1.1  gmcgarry 			cmdbuf[0] = MTTC_READ;
    820      1.1  gmcgarry 		} else {
    821      1.1  gmcgarry 			sc->sc_flags |= MTF_WRT | MTF_IO;
    822      1.1  gmcgarry 			cmdbuf[0] = MTTC_WRITE;
    823      1.1  gmcgarry 			cmdbuf[1] = (bp->b_bcount +((1 << WRITE_BITS_IGNORED) - 1)) >> WRITE_BITS_IGNORED;
    824      1.1  gmcgarry 			cmdcount = 2;
    825      1.1  gmcgarry 		}
    826      1.1  gmcgarry 	}
    827      1.1  gmcgarry 	if (gpibsend(sc->sc_ic, sc->sc_slave, MTL_TCMD, cmdbuf, cmdcount)
    828      1.1  gmcgarry 	    == cmdcount) {
    829      1.1  gmcgarry 		if (sc->sc_flags & MTF_REW)
    830      1.1  gmcgarry 			goto done;
    831      1.1  gmcgarry 		gpibawait(sc->sc_ic);
    832      1.1  gmcgarry 		return;
    833      1.1  gmcgarry 	}
    834      1.1  gmcgarry fatalerror:
    835      1.1  gmcgarry 	/*
    836      1.1  gmcgarry 	 * If anything fails, the drive is probably hosed, so mark it not
    837      1.1  gmcgarry 	 * "ALIVE" (but it EXISTS and is OPEN or we wouldn't be here, and
    838      1.1  gmcgarry 	 * if, last we heard, it was REWinding, remember that).
    839      1.1  gmcgarry 	 */
    840      1.1  gmcgarry 	sc->sc_flags &= MTF_EXISTS | MTF_OPEN | MTF_REW;
    841      1.1  gmcgarry 	bp->b_error = EIO;
    842      1.1  gmcgarry errdone:
    843      1.1  gmcgarry 	bp->b_flags |= B_ERROR;
    844      1.1  gmcgarry done:
    845      1.1  gmcgarry 	sc->sc_flags &= ~(MTF_HITEOF | MTF_HITBOF);
    846      1.4      yamt 	(void)BUFQ_GET(sc->sc_tab);
    847      1.1  gmcgarry 	biodone(bp);
    848      1.1  gmcgarry 	gpibrelease(sc->sc_ic, sc->sc_hdl);
    849      1.4      yamt 	if ((bp = BUFQ_PEEK(sc->sc_tab)) == NULL)
    850      1.1  gmcgarry 		sc->sc_active = 0;
    851      1.1  gmcgarry 	else
    852      1.1  gmcgarry 		mtustart(sc);
    853      1.1  gmcgarry }
    854      1.1  gmcgarry 
    855      1.1  gmcgarry void
    856      1.1  gmcgarry mtintr(sc)
    857      1.1  gmcgarry 	struct mt_softc *sc;
    858      1.1  gmcgarry {
    859      1.1  gmcgarry 	struct buf *bp;
    860      1.1  gmcgarry 	int slave, dir, i;
    861      1.1  gmcgarry 	u_char cmdbuf[4];
    862      1.1  gmcgarry 
    863      1.1  gmcgarry 	slave = sc->sc_slave;
    864      1.1  gmcgarry 
    865      1.4      yamt 	bp = BUFQ_PEEK(sc->sc_tab);
    866      1.1  gmcgarry 	if (bp == NULL) {
    867      1.1  gmcgarry 		printf("%s intr: bp == NULL", sc->sc_dev.dv_xname);
    868      1.1  gmcgarry 		return;
    869      1.1  gmcgarry 	}
    870      1.1  gmcgarry 
    871      1.1  gmcgarry 	DPRINTF(MDB_ANY, ("%s intr", sc->sc_dev.dv_xname));
    872      1.1  gmcgarry 
    873      1.1  gmcgarry 	/*
    874      1.1  gmcgarry 	 * Some operation completed.  Read status bytes and report errors.
    875      1.1  gmcgarry 	 * Clear EOF flags here `cause they're set once on specific conditions
    876      1.1  gmcgarry 	 * below when a command succeeds.
    877      1.1  gmcgarry 	 * A DSJ of 2 always means keep waiting.  If the command was READ
    878      1.1  gmcgarry 	 * (and we're in data DMA phase) stop data transfer first.
    879      1.1  gmcgarry 	 */
    880      1.1  gmcgarry 	sc->sc_flags &= ~(MTF_HITEOF | MTF_HITBOF);
    881      1.1  gmcgarry 	if ((bp->b_flags & (B_CMD|B_READ)) == B_READ &&
    882      1.1  gmcgarry 	    !(sc->sc_flags & (MTF_IO | MTF_STATTIMEO | MTF_DSJTIMEO))){
    883      1.1  gmcgarry 		cmdbuf[0] = MTE_STOP;
    884      1.1  gmcgarry 		(void) gpibsend(sc->sc_ic, slave, MTL_ECMD,cmdbuf,1);
    885      1.1  gmcgarry 	}
    886      1.1  gmcgarry 	switch (mtreaddsj(sc, 0)) {
    887      1.1  gmcgarry 	    case 0:
    888      1.1  gmcgarry 		break;
    889      1.1  gmcgarry 
    890      1.1  gmcgarry 	    case 1:
    891      1.1  gmcgarry 		/*
    892      1.1  gmcgarry 		 * If we're in the middle of a READ/WRITE and have yet to
    893      1.1  gmcgarry 		 * start the data transfer, a DSJ of one should terminate it.
    894      1.1  gmcgarry 		 */
    895      1.1  gmcgarry 		sc->sc_flags &= ~MTF_IO;
    896      1.1  gmcgarry 		break;
    897      1.1  gmcgarry 
    898      1.1  gmcgarry 	    case 2:
    899      1.1  gmcgarry 		(void) gpibawait(sc->sc_ic);
    900      1.1  gmcgarry 		return;
    901      1.1  gmcgarry 
    902      1.1  gmcgarry 	    case -2:
    903      1.1  gmcgarry 		/*
    904      1.1  gmcgarry 		 * -2 means that the drive failed to respond quickly enough
    905      1.1  gmcgarry 		 * to the request for DSJ.  It's probably just "busy" figuring
    906      1.1  gmcgarry 		 * it out and will know in a little bit...
    907      1.1  gmcgarry 		 */
    908      1.1  gmcgarry 		callout_reset(&sc->sc_intr_ch, hz >> 5, mtintr_callout, sc);
    909      1.1  gmcgarry 		return;
    910      1.1  gmcgarry 
    911      1.1  gmcgarry 	    default:
    912      1.1  gmcgarry 		printf("%s intr: can't get drive stat", sc->sc_dev.dv_xname);
    913      1.1  gmcgarry 		goto error;
    914      1.1  gmcgarry 	}
    915      1.1  gmcgarry 	if (sc->sc_stat1 & (SR1_ERR | SR1_REJECT)) {
    916      1.1  gmcgarry 		i = sc->sc_stat4 & SR4_ERCLMASK;
    917      1.1  gmcgarry 		printf("%s: %s error, retry %d, SR2/3 %x/%x, code %d",
    918      1.1  gmcgarry 			sc->sc_dev.dv_xname, i == SR4_DEVICE ? "device" :
    919      1.1  gmcgarry 			(i == SR4_PROTOCOL ? "protocol" :
    920      1.1  gmcgarry 			(i == SR4_SELFTEST ? "selftest" : "unknown")),
    921      1.1  gmcgarry 			sc->sc_stat4 & SR4_RETRYMASK, sc->sc_stat2,
    922      1.1  gmcgarry 			sc->sc_stat3, sc->sc_stat5);
    923      1.1  gmcgarry 
    924      1.1  gmcgarry 		if ((bp->b_flags & B_CMD) && bp->b_cmd == MTRESET)
    925      1.1  gmcgarry 			callout_stop(&sc->sc_intr_ch);
    926      1.1  gmcgarry 		if (sc->sc_stat3 & SR3_POWERUP)
    927      1.1  gmcgarry 			sc->sc_flags &= MTF_OPEN | MTF_EXISTS;
    928      1.1  gmcgarry 		goto error;
    929      1.1  gmcgarry 	}
    930      1.1  gmcgarry 	/*
    931      1.1  gmcgarry 	 * Report and clear any soft errors.
    932      1.1  gmcgarry 	 */
    933      1.1  gmcgarry 	if (sc->sc_stat1 & SR1_SOFTERR) {
    934      1.1  gmcgarry 		printf("%s: soft error, retry %d\n", sc->sc_dev.dv_xname,
    935      1.1  gmcgarry 		    sc->sc_stat4 & SR4_RETRYMASK);
    936      1.1  gmcgarry 		sc->sc_stat1 &= ~SR1_SOFTERR;
    937      1.1  gmcgarry 	}
    938      1.1  gmcgarry 	/*
    939      1.1  gmcgarry 	 * We've initiated a read or write, but haven't actually started to
    940      1.1  gmcgarry 	 * DMA the data yet.  At this point, the drive's ready.
    941      1.1  gmcgarry 	 */
    942      1.1  gmcgarry 	if (sc->sc_flags & MTF_IO) {
    943      1.1  gmcgarry 		sc->sc_flags &= ~MTF_IO;
    944      1.1  gmcgarry 		dir = (bp->b_flags & B_READ ? GPIB_READ : GPIB_WRITE);
    945      1.1  gmcgarry 		gpibxfer(sc->sc_ic, slave,
    946      1.1  gmcgarry 		    dir == GPIB_READ ? MTT_READ : MTL_WRITE,
    947      1.1  gmcgarry 		    bp->b_data, bp->b_bcount, dir, dir == GPIB_READ);
    948      1.1  gmcgarry 		return;
    949      1.1  gmcgarry 	}
    950      1.1  gmcgarry 	/*
    951      1.1  gmcgarry 	 * Check for End Of Tape - we're allowed to hit EOT and then write (or
    952      1.1  gmcgarry 	 * read) one more record.  If we get here and have not already hit EOT,
    953      1.1  gmcgarry 	 * return ENOSPC to inform the process that it's hit it.  If we get
    954      1.1  gmcgarry 	 * here and HAVE already hit EOT, don't allow any more operations that
    955      1.1  gmcgarry 	 * move the tape forward.
    956      1.1  gmcgarry 	 */
    957      1.1  gmcgarry 	if (sc->sc_stat1 & SR1_EOT) {
    958      1.1  gmcgarry 		if (sc->sc_flags & MTF_ATEOT)
    959      1.1  gmcgarry 			sc->sc_flags |= MTF_PASTEOT;
    960      1.1  gmcgarry 		else {
    961      1.1  gmcgarry 			bp->b_flags |= B_ERROR;
    962      1.1  gmcgarry 			bp->b_error = ENOSPC;
    963      1.1  gmcgarry 			sc->sc_flags |= MTF_ATEOT;
    964      1.1  gmcgarry 		}
    965      1.1  gmcgarry 	}
    966      1.1  gmcgarry 	/*
    967      1.1  gmcgarry 	 * If a motion command was being executed, check for Tape Marks.
    968      1.1  gmcgarry 	 * If we were doing data, make sure we got the right amount, and
    969      1.1  gmcgarry 	 * check for hitting tape marks on reads.
    970      1.1  gmcgarry 	 */
    971      1.1  gmcgarry 	if (bp->b_flags & B_CMD) {
    972      1.1  gmcgarry 		if (sc->sc_stat1 & SR1_EOF) {
    973      1.1  gmcgarry 			if (bp->b_cmd == MTFSR)
    974      1.1  gmcgarry 				sc->sc_flags |= MTF_HITEOF;
    975      1.1  gmcgarry 			if (bp->b_cmd == MTBSR)
    976      1.1  gmcgarry 				sc->sc_flags |= MTF_HITBOF;
    977      1.1  gmcgarry 		}
    978      1.1  gmcgarry 		if (bp->b_cmd == MTRESET) {
    979      1.1  gmcgarry 			callout_stop(&sc->sc_intr_ch);
    980      1.1  gmcgarry 			sc->sc_flags |= MTF_ALIVE;
    981      1.1  gmcgarry 		}
    982      1.1  gmcgarry 	} else {
    983      1.1  gmcgarry 		i = gpibrecv(sc->sc_ic, slave, MTT_BCNT, cmdbuf, 2);
    984      1.1  gmcgarry 		if (i != 2) {
    985      1.1  gmcgarry 			printf("%s intr: can't get xfer length\n",
    986      1.1  gmcgarry 			    sc->sc_dev.dv_xname);
    987      1.1  gmcgarry 			goto error;
    988      1.1  gmcgarry 		}
    989      1.1  gmcgarry 		i = (int) *((u_short *) cmdbuf);
    990      1.1  gmcgarry 		if (i <= bp->b_bcount) {
    991      1.1  gmcgarry 			if (i == 0)
    992      1.1  gmcgarry 				sc->sc_flags |= MTF_HITEOF;
    993      1.1  gmcgarry 			bp->b_resid = bp->b_bcount - i;
    994      1.1  gmcgarry 			DPRINTF(MDB_ANY, ("%s intr: bcount %ld, resid %ld",
    995      1.1  gmcgarry 			    sc->sc_dev.dv_xname, bp->b_bcount, bp->b_resid));
    996      1.1  gmcgarry 		} else {
    997      1.1  gmcgarry 			tprintf(sc->sc_ttyp,
    998      1.1  gmcgarry 				"%s: record (%d) larger than wanted (%ld)\n",
    999      1.1  gmcgarry 				sc->sc_dev.dv_xname, i, bp->b_bcount);
   1000      1.1  gmcgarry error:
   1001      1.1  gmcgarry 			sc->sc_flags &= ~MTF_IO;
   1002      1.1  gmcgarry 			bp->b_error = EIO;
   1003      1.1  gmcgarry 			bp->b_flags |= B_ERROR;
   1004      1.1  gmcgarry 		}
   1005      1.1  gmcgarry 	}
   1006      1.1  gmcgarry 	/*
   1007      1.1  gmcgarry 	 * The operation is completely done.
   1008      1.1  gmcgarry 	 * Let the drive know with an END command.
   1009      1.1  gmcgarry 	 */
   1010      1.1  gmcgarry 	cmdbuf[0] = MTE_COMPLETE | MTE_IDLE;
   1011      1.1  gmcgarry 	(void) gpibsend(sc->sc_ic, slave, MTL_ECMD, cmdbuf, 1);
   1012      1.1  gmcgarry 	bp->b_flags &= ~B_CMD;
   1013      1.4      yamt 	(void)BUFQ_GET(sc->sc_tab);
   1014      1.1  gmcgarry 	biodone(bp);
   1015      1.1  gmcgarry 	gpibrelease(sc->sc_ic, sc->sc_hdl);
   1016      1.4      yamt 	if (BUFQ_PEEK(sc->sc_tab) == NULL)
   1017      1.1  gmcgarry 		sc->sc_active = 0;
   1018      1.1  gmcgarry 	else
   1019      1.1  gmcgarry 		mtustart(sc);
   1020      1.1  gmcgarry }
   1021      1.1  gmcgarry 
   1022      1.1  gmcgarry int
   1023      1.1  gmcgarry mtread(dev, uio, flags)
   1024      1.1  gmcgarry 	dev_t dev;
   1025      1.1  gmcgarry 	struct uio *uio;
   1026      1.1  gmcgarry 	int flags;
   1027      1.1  gmcgarry {
   1028      1.1  gmcgarry 	struct mt_softc *sc;
   1029      1.1  gmcgarry 
   1030      1.1  gmcgarry 	sc = device_lookup(&mt_cd, MTUNIT(dev));
   1031      1.1  gmcgarry 
   1032      1.1  gmcgarry 	return (physio(mtstrategy, &sc->sc_bufstore,
   1033      1.1  gmcgarry 	    dev, B_READ, minphys, uio));
   1034      1.1  gmcgarry }
   1035      1.1  gmcgarry 
   1036      1.1  gmcgarry int
   1037      1.1  gmcgarry mtwrite(dev, uio, flags)
   1038      1.1  gmcgarry 	dev_t dev;
   1039      1.1  gmcgarry 	struct uio *uio;
   1040      1.1  gmcgarry 	int flags;
   1041      1.1  gmcgarry {
   1042      1.1  gmcgarry 	struct mt_softc *sc;
   1043      1.1  gmcgarry 
   1044      1.1  gmcgarry 	sc = device_lookup(&mt_cd, MTUNIT(dev));
   1045      1.1  gmcgarry 
   1046      1.1  gmcgarry 	return (physio(mtstrategy, &sc->sc_bufstore,
   1047      1.1  gmcgarry 	    dev, B_WRITE, minphys, uio));
   1048      1.1  gmcgarry }
   1049      1.1  gmcgarry 
   1050      1.1  gmcgarry int
   1051      1.1  gmcgarry mtioctl(dev, cmd, data, flag, p)
   1052      1.1  gmcgarry 	dev_t dev;
   1053      1.1  gmcgarry 	u_long cmd;
   1054      1.1  gmcgarry 	caddr_t data;
   1055      1.1  gmcgarry 	int flag;
   1056      1.1  gmcgarry 	struct proc *p;
   1057      1.1  gmcgarry {
   1058      1.1  gmcgarry 	struct mtop *op;
   1059      1.1  gmcgarry 	int cnt;
   1060      1.1  gmcgarry 
   1061      1.1  gmcgarry 	switch (cmd) {
   1062      1.1  gmcgarry 	    case MTIOCTOP:
   1063      1.1  gmcgarry 		op = (struct mtop *)data;
   1064      1.1  gmcgarry 		switch(op->mt_op) {
   1065      1.1  gmcgarry 		    case MTWEOF:
   1066      1.1  gmcgarry 		    case MTFSF:
   1067      1.1  gmcgarry 		    case MTBSR:
   1068      1.1  gmcgarry 		    case MTBSF:
   1069      1.1  gmcgarry 		    case MTFSR:
   1070      1.1  gmcgarry 			cnt = op->mt_count;
   1071      1.1  gmcgarry 			break;
   1072      1.1  gmcgarry 
   1073      1.1  gmcgarry 		    case MTOFFL:
   1074      1.1  gmcgarry 		    case MTREW:
   1075      1.1  gmcgarry 		    case MTNOP:
   1076      1.1  gmcgarry 			cnt = 0;
   1077      1.1  gmcgarry 			break;
   1078      1.1  gmcgarry 
   1079      1.1  gmcgarry 		    default:
   1080      1.1  gmcgarry 			return (EINVAL);
   1081      1.1  gmcgarry 		}
   1082      1.1  gmcgarry 		return (mtcommand(dev, op->mt_op, cnt));
   1083      1.1  gmcgarry 
   1084      1.1  gmcgarry 	    case MTIOCGET:
   1085      1.1  gmcgarry 		break;
   1086      1.1  gmcgarry 
   1087      1.1  gmcgarry 	    default:
   1088      1.1  gmcgarry 		return (EINVAL);
   1089      1.1  gmcgarry 	}
   1090      1.1  gmcgarry 	return (0);
   1091      1.1  gmcgarry }
   1092