Home | History | Annotate | Line # | Download | only in gpib
ct.c revision 1.11.10.2
      1  1.11.10.2  ad /*	$NetBSD: ct.c,v 1.11.10.2 2007/07/29 12:15:44 ad Exp $ */
      2  1.11.10.2  ad 
      3  1.11.10.2  ad /*-
      4  1.11.10.2  ad  * Copyright (c) 1996-2003 The NetBSD Foundation, Inc.
      5  1.11.10.2  ad  * All rights reserved.
      6  1.11.10.2  ad  *
      7  1.11.10.2  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.11.10.2  ad  * by Jason R. Thorpe.
      9  1.11.10.2  ad  *
     10  1.11.10.2  ad  * Redistribution and use in source and binary forms, with or without
     11  1.11.10.2  ad  * modification, are permitted provided that the following conditions
     12  1.11.10.2  ad  * are met:
     13  1.11.10.2  ad  * 1. Redistributions of source code must retain the above copyright
     14  1.11.10.2  ad  *    notice, this list of conditions and the following disclaimer.
     15  1.11.10.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.11.10.2  ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.11.10.2  ad  *    documentation and/or other materials provided with the distribution.
     18  1.11.10.2  ad  * 3. All advertising materials mentioning features or use of this software
     19  1.11.10.2  ad  *    must display the following acknowledgement:
     20  1.11.10.2  ad  *	This product includes software developed by the NetBSD
     21  1.11.10.2  ad  *	Foundation, Inc. and its contributors.
     22  1.11.10.2  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.11.10.2  ad  *    contributors may be used to endorse or promote products derived
     24  1.11.10.2  ad  *    from this software without specific prior written permission.
     25  1.11.10.2  ad  *
     26  1.11.10.2  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.11.10.2  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.11.10.2  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.11.10.2  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.11.10.2  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.11.10.2  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.11.10.2  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.11.10.2  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.11.10.2  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.11.10.2  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.11.10.2  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.11.10.2  ad  */
     38  1.11.10.2  ad 
     39  1.11.10.2  ad /*
     40  1.11.10.2  ad  * Copyright (c) 1982, 1990, 1993
     41  1.11.10.2  ad  *	The Regents of the University of California.  All rights reserved.
     42  1.11.10.2  ad  *
     43  1.11.10.2  ad  * This code is derived from software contributed to Berkeley by
     44  1.11.10.2  ad  * the Systems Programming Group of the University of Utah Computer
     45  1.11.10.2  ad  * Science Department.
     46  1.11.10.2  ad  *
     47  1.11.10.2  ad  * Redistribution and use in source and binary forms, with or without
     48  1.11.10.2  ad  * modification, are permitted provided that the following conditions
     49  1.11.10.2  ad  * are met:
     50  1.11.10.2  ad  * 1. Redistributions of source code must retain the above copyright
     51  1.11.10.2  ad  *    notice, this list of conditions and the following disclaimer.
     52  1.11.10.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.11.10.2  ad  *    notice, this list of conditions and the following disclaimer in the
     54  1.11.10.2  ad  *    documentation and/or other materials provided with the distribution.
     55  1.11.10.2  ad  * 3. Neither the name of the University nor the names of its contributors
     56  1.11.10.2  ad  *    may be used to endorse or promote products derived from this software
     57  1.11.10.2  ad  *    without specific prior written permission.
     58  1.11.10.2  ad  *
     59  1.11.10.2  ad  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.11.10.2  ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.11.10.2  ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.11.10.2  ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.11.10.2  ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.11.10.2  ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.11.10.2  ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.11.10.2  ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.11.10.2  ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.11.10.2  ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.11.10.2  ad  * SUCH DAMAGE.
     70  1.11.10.2  ad  *
     71  1.11.10.2  ad  * from: Utah $Hdr: rd.c 1.44 92/12/26$
     72  1.11.10.2  ad  *
     73  1.11.10.2  ad  *	@(#)rd.c	8.2 (Berkeley) 5/19/94
     74  1.11.10.2  ad  */
     75  1.11.10.2  ad 
     76  1.11.10.2  ad /*
     77  1.11.10.2  ad  * Copyright (c) 1988 University of Utah.
     78  1.11.10.2  ad  *
     79  1.11.10.2  ad  * This code is derived from software contributed to Berkeley by
     80  1.11.10.2  ad  * the Systems Programming Group of the University of Utah Computer
     81  1.11.10.2  ad  * Science Department.
     82  1.11.10.2  ad  *
     83  1.11.10.2  ad  * Redistribution and use in source and binary forms, with or without
     84  1.11.10.2  ad  * modification, are permitted provided that the following conditions
     85  1.11.10.2  ad  * are met:
     86  1.11.10.2  ad  * 1. Redistributions of source code must retain the above copyright
     87  1.11.10.2  ad  *    notice, this list of conditions and the following disclaimer.
     88  1.11.10.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     89  1.11.10.2  ad  *    notice, this list of conditions and the following disclaimer in the
     90  1.11.10.2  ad  *    documentation and/or other materials provided with the distribution.
     91  1.11.10.2  ad  * 3. All advertising materials mentioning features or use of this software
     92  1.11.10.2  ad  *    must display the following acknowledgement:
     93  1.11.10.2  ad  *	This product includes software developed by the University of
     94  1.11.10.2  ad  *	California, Berkeley and its contributors.
     95  1.11.10.2  ad  * 4. Neither the name of the University nor the names of its contributors
     96  1.11.10.2  ad  *    may be used to endorse or promote products derived from this software
     97  1.11.10.2  ad  *    without specific prior written permission.
     98  1.11.10.2  ad  *
     99  1.11.10.2  ad  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    100  1.11.10.2  ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    101  1.11.10.2  ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    102  1.11.10.2  ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    103  1.11.10.2  ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    104  1.11.10.2  ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    105  1.11.10.2  ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    106  1.11.10.2  ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    107  1.11.10.2  ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    108  1.11.10.2  ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    109  1.11.10.2  ad  * SUCH DAMAGE.
    110  1.11.10.2  ad  *
    111  1.11.10.2  ad  * from: Utah $Hdr: rd.c 1.44 92/12/26$
    112  1.11.10.2  ad  *
    113  1.11.10.2  ad  *	@(#)rd.c	8.2 (Berkeley) 5/19/94
    114  1.11.10.2  ad  */
    115  1.11.10.2  ad 
    116  1.11.10.2  ad /*
    117  1.11.10.2  ad  * CS/80 cartridge tape driver (HP9144, HP88140, HP9145)
    118  1.11.10.2  ad  *
    119  1.11.10.2  ad  * Reminder:
    120  1.11.10.2  ad  *	C_CC bit (character count option) when used in the CS/80 command
    121  1.11.10.2  ad  *	'set options' will cause the tape not to stream.
    122  1.11.10.2  ad  *
    123  1.11.10.2  ad  * TODO:
    124  1.11.10.2  ad  *	make filesystem compatible
    125  1.11.10.2  ad  *	make block mode work according to mtio(4) spec. (if possible)
    126  1.11.10.2  ad  *	merge with CS/80 disk driver
    127  1.11.10.2  ad  *	finish support of HP9145
    128  1.11.10.2  ad  */
    129  1.11.10.2  ad 
    130  1.11.10.2  ad #include <sys/cdefs.h>
    131  1.11.10.2  ad __KERNEL_RCSID(0, "$NetBSD: ct.c,v 1.11.10.2 2007/07/29 12:15:44 ad Exp $");
    132  1.11.10.2  ad 
    133  1.11.10.2  ad #include <sys/param.h>
    134  1.11.10.2  ad #include <sys/systm.h>
    135  1.11.10.2  ad #include <sys/buf.h>
    136  1.11.10.2  ad #include <sys/bufq.h>
    137  1.11.10.2  ad #include <sys/conf.h>
    138  1.11.10.2  ad #include <sys/device.h>
    139  1.11.10.2  ad #include <sys/ioctl.h>
    140  1.11.10.2  ad #include <sys/mtio.h>
    141  1.11.10.2  ad #include <sys/proc.h>
    142  1.11.10.2  ad #include <sys/tprintf.h>
    143  1.11.10.2  ad 
    144  1.11.10.2  ad #include <dev/gpib/ctreg.h>	/* XXX must be before cs80busvar.h ATM */
    145  1.11.10.2  ad 
    146  1.11.10.2  ad #include <dev/gpib/gpibvar.h>
    147  1.11.10.2  ad #include <dev/gpib/cs80busvar.h>
    148  1.11.10.2  ad 
    149  1.11.10.2  ad /* number of eof marks to remember */
    150  1.11.10.2  ad #define EOFS	128
    151  1.11.10.2  ad 
    152  1.11.10.2  ad #ifdef DEBUG
    153  1.11.10.2  ad int ctdebug = 0xff;
    154  1.11.10.2  ad #define CDB_FILES	0x01
    155  1.11.10.2  ad #define CDB_BSF		0x02
    156  1.11.10.2  ad #define CDB_IDENT	0x04
    157  1.11.10.2  ad #define CDB_FAIL	0x08
    158  1.11.10.2  ad #define CDB_FOLLOW	0x10
    159  1.11.10.2  ad #define DPRINTF(mask, str)	if (ctdebug & (mask)) printf str
    160  1.11.10.2  ad #else
    161  1.11.10.2  ad #define DPRINTF(mask, str)	/* nothing */
    162  1.11.10.2  ad #endif
    163  1.11.10.2  ad 
    164  1.11.10.2  ad struct	ct_softc {
    165  1.11.10.2  ad 	struct	device sc_dev;
    166  1.11.10.2  ad 
    167  1.11.10.2  ad 	gpib_chipset_tag_t sc_ic;
    168  1.11.10.2  ad 	gpib_handle_t sc_hdl;
    169  1.11.10.2  ad 
    170  1.11.10.2  ad 	int	sc_slave;		/* GPIB slave ID */
    171  1.11.10.2  ad 	int	sc_punit;		/* physical unit */
    172  1.11.10.2  ad 	struct	ct_iocmd sc_ioc;
    173  1.11.10.2  ad 	struct	ct_rscmd sc_rsc;
    174  1.11.10.2  ad 	struct	cs80_stat sc_stat;
    175  1.11.10.2  ad 	struct	bufq_state *sc_tab;
    176  1.11.10.2  ad 	int	sc_active;
    177  1.11.10.2  ad 	struct	buf *sc_bp;
    178  1.11.10.2  ad 	struct	buf sc_bufstore;	/* XXX */
    179  1.11.10.2  ad 	int	sc_blkno;
    180  1.11.10.2  ad 	int	sc_cmd;
    181  1.11.10.2  ad 	int	sc_resid;
    182  1.11.10.2  ad 	char	*sc_addr;
    183  1.11.10.2  ad 	int	sc_flags;
    184  1.11.10.2  ad #define	CTF_OPEN	0x01
    185  1.11.10.2  ad #define	CTF_ALIVE	0x02
    186  1.11.10.2  ad #define	CTF_WRT		0x04
    187  1.11.10.2  ad #define	CTF_CMD		0x08
    188  1.11.10.2  ad #define	CTF_IO		0x10
    189  1.11.10.2  ad #define	CTF_BEOF	0x20
    190  1.11.10.2  ad #define	CTF_AEOF	0x40
    191  1.11.10.2  ad #define	CTF_EOT		0x80
    192  1.11.10.2  ad #define	CTF_STATWAIT	0x100
    193  1.11.10.2  ad #define CTF_CANSTREAM	0x200
    194  1.11.10.2  ad #define	CTF_WRTTN	0x400
    195  1.11.10.2  ad 	short	sc_type;
    196  1.11.10.2  ad 	tpr_t	sc_tpr;
    197  1.11.10.2  ad 	int	sc_eofp;
    198  1.11.10.2  ad 	int	sc_eofs[EOFS];
    199  1.11.10.2  ad };
    200  1.11.10.2  ad 
    201  1.11.10.2  ad int	ctmatch(struct device *, struct cfdata *, void *);
    202  1.11.10.2  ad void	ctattach(struct device *, struct device *, void *);
    203  1.11.10.2  ad 
    204  1.11.10.2  ad CFATTACH_DECL(ct, sizeof(struct ct_softc),
    205  1.11.10.2  ad 	ctmatch, ctattach, NULL, NULL);
    206  1.11.10.2  ad 
    207  1.11.10.2  ad int	ctident(struct device *, struct ct_softc *,
    208  1.11.10.2  ad 	    struct cs80bus_attach_args *);
    209  1.11.10.2  ad 
    210  1.11.10.2  ad int	ctlookup(int, int, int);
    211  1.11.10.2  ad void	ctaddeof(struct ct_softc *);
    212  1.11.10.2  ad void	ctustart(struct ct_softc *);
    213  1.11.10.2  ad void	cteof(struct ct_softc *, struct buf *);
    214  1.11.10.2  ad void	ctdone(struct ct_softc *, struct buf *);
    215  1.11.10.2  ad 
    216  1.11.10.2  ad void	ctcallback(void *, int);
    217  1.11.10.2  ad void	ctstart(struct ct_softc *);
    218  1.11.10.2  ad void	ctintr(struct ct_softc *);
    219  1.11.10.2  ad 
    220  1.11.10.2  ad void	ctcommand(dev_t, int, int);
    221  1.11.10.2  ad 
    222  1.11.10.2  ad dev_type_open(ctopen);
    223  1.11.10.2  ad dev_type_close(ctclose);
    224  1.11.10.2  ad dev_type_read(ctread);
    225  1.11.10.2  ad dev_type_write(ctwrite);
    226  1.11.10.2  ad dev_type_ioctl(ctioctl);
    227  1.11.10.2  ad dev_type_strategy(ctstrategy);
    228  1.11.10.2  ad 
    229  1.11.10.2  ad const struct bdevsw ct_bdevsw = {
    230  1.11.10.2  ad 	ctopen, ctclose, ctstrategy, ctioctl, nodump, nosize, D_TAPE
    231  1.11.10.2  ad };
    232  1.11.10.2  ad 
    233  1.11.10.2  ad const struct cdevsw ct_cdevsw = {
    234  1.11.10.2  ad 	ctopen, ctclose, ctread, ctwrite, ctioctl,
    235  1.11.10.2  ad 	nostop, notty, nopoll, nommap, nokqfilter, D_TAPE
    236  1.11.10.2  ad };
    237  1.11.10.2  ad 
    238  1.11.10.2  ad extern struct cfdriver ct_cd;
    239  1.11.10.2  ad 
    240  1.11.10.2  ad struct	ctinfo {
    241  1.11.10.2  ad 	short	hwid;
    242  1.11.10.2  ad 	short	punit;
    243  1.11.10.2  ad 	const char	*desc;
    244  1.11.10.2  ad } ctinfo[] = {
    245  1.11.10.2  ad 	{ CT7946ID,	1,	"7946A"	},
    246  1.11.10.2  ad 	{ CT7912PID,	1,	"7912P"	},
    247  1.11.10.2  ad 	{ CT7914PID,	1,	"7914P"	},
    248  1.11.10.2  ad 	{ CT9144ID,	0,	"9144"	},
    249  1.11.10.2  ad 	{ CT9145ID,	0,	"9145"	},
    250  1.11.10.2  ad 	{ CT35401ID,	0,	"35401A"},
    251  1.11.10.2  ad };
    252  1.11.10.2  ad int	nctinfo = sizeof(ctinfo) / sizeof(ctinfo[0]);
    253  1.11.10.2  ad 
    254  1.11.10.2  ad #define	CT_NOREW	4
    255  1.11.10.2  ad #define	CT_STREAM	8
    256  1.11.10.2  ad #define	CTUNIT(x)	(minor(x) & 0x03)
    257  1.11.10.2  ad 
    258  1.11.10.2  ad int
    259  1.11.10.2  ad ctlookup(id, slave, punit)
    260  1.11.10.2  ad 	int id;
    261  1.11.10.2  ad 	int slave;
    262  1.11.10.2  ad 	int punit;
    263  1.11.10.2  ad {
    264  1.11.10.2  ad 	int i;
    265  1.11.10.2  ad 
    266  1.11.10.2  ad 	for (i = 0; i < nctinfo; i++)
    267  1.11.10.2  ad 		if (ctinfo[i].hwid == id)
    268  1.11.10.2  ad 			break;
    269  1.11.10.2  ad 	if (i == nctinfo)
    270  1.11.10.2  ad 		return (-1);
    271  1.11.10.2  ad 	return (i);
    272  1.11.10.2  ad }
    273  1.11.10.2  ad 
    274  1.11.10.2  ad int
    275  1.11.10.2  ad ctmatch(parent, match, aux)
    276  1.11.10.2  ad 	struct device *parent;
    277  1.11.10.2  ad 	struct cfdata *match;
    278  1.11.10.2  ad 	void *aux;
    279  1.11.10.2  ad {
    280  1.11.10.2  ad 	struct cs80bus_attach_args *ca = aux;
    281  1.11.10.2  ad 	int i;
    282  1.11.10.2  ad 
    283  1.11.10.2  ad 	if ((i = ctlookup(ca->ca_id, ca->ca_slave, ca->ca_punit)) < 0)
    284  1.11.10.2  ad 		return (0);
    285  1.11.10.2  ad 	ca->ca_punit = ctinfo[i].punit;
    286  1.11.10.2  ad 	return (1);
    287  1.11.10.2  ad }
    288  1.11.10.2  ad 
    289  1.11.10.2  ad void
    290  1.11.10.2  ad ctattach(parent, self, aux)
    291  1.11.10.2  ad 	struct device *parent, *self;
    292  1.11.10.2  ad 	void *aux;
    293  1.11.10.2  ad {
    294  1.11.10.2  ad 	struct ct_softc *sc = device_private(self);
    295  1.11.10.2  ad 	struct cs80bus_attach_args *ca = aux;
    296  1.11.10.2  ad 	struct cs80_description csd;
    297  1.11.10.2  ad 	char name[7];
    298  1.11.10.2  ad 	int type, i, n, canstream = 0;
    299  1.11.10.2  ad 
    300  1.11.10.2  ad 	sc->sc_ic = ca->ca_ic;
    301  1.11.10.2  ad 	sc->sc_slave = ca->ca_slave;
    302  1.11.10.2  ad 	sc->sc_punit = ca->ca_punit;
    303  1.11.10.2  ad 
    304  1.11.10.2  ad 	if ((type = ctlookup(ca->ca_id, ca->ca_slave, ca->ca_punit)) < 0)
    305  1.11.10.2  ad 		return;
    306  1.11.10.2  ad 
    307  1.11.10.2  ad 	if (cs80reset(parent, sc->sc_slave, sc->sc_punit)) {
    308  1.11.10.2  ad 		printf("\n%s: can't reset device\n", sc->sc_dev.dv_xname);
    309  1.11.10.2  ad 		return;
    310  1.11.10.2  ad 	}
    311  1.11.10.2  ad 
    312  1.11.10.2  ad 	if (cs80describe(parent, sc->sc_slave, sc->sc_punit, &csd)) {
    313  1.11.10.2  ad 		printf("\n%s: didn't respond to describe command\n",
    314  1.11.10.2  ad 		    sc->sc_dev.dv_xname);
    315  1.11.10.2  ad 		return;
    316  1.11.10.2  ad 	}
    317  1.11.10.2  ad 	memset(name, 0, sizeof(name));
    318  1.11.10.2  ad 	for (i=0, n=0; i<3; i++) {
    319  1.11.10.2  ad 		name[n++] = (csd.d_name[i] >> 4) + '0';
    320  1.11.10.2  ad 		name[n++] = (csd.d_name[i] & 0x0f) + '0';
    321  1.11.10.2  ad 	}
    322  1.11.10.2  ad 
    323  1.11.10.2  ad #ifdef DEBUG
    324  1.11.10.2  ad 	if (ctdebug & CDB_IDENT) {
    325  1.11.10.2  ad 		printf("\n%s: name: ('%s')\n",
    326  1.11.10.2  ad 		    sc->sc_dev.dv_xname,name);
    327  1.11.10.2  ad 		printf("  iuw %x, maxxfr %d, ctype %d\n",
    328  1.11.10.2  ad 		    csd.d_iuw, csd.d_cmaxxfr, csd.d_ctype);
    329  1.11.10.2  ad 		printf("  utype %d, bps %d, blkbuf %d, burst %d, blktime %d\n",
    330  1.11.10.2  ad 		    csd.d_utype, csd.d_sectsize,
    331  1.11.10.2  ad 		    csd.d_blkbuf, csd.d_burstsize, csd.d_blocktime);
    332  1.11.10.2  ad 		printf("  avxfr %d, ort %d, atp %d, maxint %d, fv %x, rv %x\n",
    333  1.11.10.2  ad 		    csd.d_uavexfr, csd.d_retry, csd.d_access,
    334  1.11.10.2  ad 		    csd.d_maxint, csd.d_fvbyte, csd.d_rvbyte);
    335  1.11.10.2  ad 		printf("  maxcyl/head/sect %d/%d/%d, maxvsect %d, inter %d\n",
    336  1.11.10.2  ad 		    csd.d_maxcylhead >> 8 , csd.d_maxcylhead & 0xff,
    337  1.11.10.2  ad 		    csd.d_maxsect, csd.d_maxvsectl, csd.d_interleave);
    338  1.11.10.2  ad 		printf("%s", sc->sc_dev.dv_xname);
    339  1.11.10.2  ad 	}
    340  1.11.10.2  ad #endif
    341  1.11.10.2  ad 
    342  1.11.10.2  ad 	switch (ca->ca_id) {
    343  1.11.10.2  ad 	case CT7946ID:
    344  1.11.10.2  ad 		if (memcmp(name, "079450", 6) == 0)
    345  1.11.10.2  ad 			return;			/* not really a 7946 */
    346  1.11.10.2  ad 		/* fall into... */
    347  1.11.10.2  ad 	case CT9144ID:
    348  1.11.10.2  ad 	case CT9145ID:
    349  1.11.10.2  ad 	case CT35401ID:
    350  1.11.10.2  ad 		sc->sc_type = CT9144;
    351  1.11.10.2  ad 		canstream = 1;
    352  1.11.10.2  ad 		break;
    353  1.11.10.2  ad 
    354  1.11.10.2  ad 	case CT7912PID:
    355  1.11.10.2  ad 	case CT7914PID:
    356  1.11.10.2  ad 		sc->sc_type = CT88140;
    357  1.11.10.2  ad 		break;
    358  1.11.10.2  ad 	default:
    359  1.11.10.2  ad 		sc->sc_type = type;
    360  1.11.10.2  ad 		break;
    361  1.11.10.2  ad 	}
    362  1.11.10.2  ad 
    363  1.11.10.2  ad 	sc->sc_type = type;
    364  1.11.10.2  ad 	sc->sc_flags = canstream ? CTF_CANSTREAM : 0;
    365  1.11.10.2  ad 	printf(": %s %stape\n", ctinfo[type].desc,
    366  1.11.10.2  ad 	    canstream ? "streaming " : "");
    367  1.11.10.2  ad 
    368  1.11.10.2  ad 	bufq_alloc(&sc->sc_tab, "fcfs", 0);
    369  1.11.10.2  ad 
    370  1.11.10.2  ad 	if (gpibregister(sc->sc_ic, sc->sc_slave, ctcallback, sc,
    371  1.11.10.2  ad 	    &sc->sc_hdl)) {
    372  1.11.10.2  ad 		printf("%s: can't register callback\n", sc->sc_dev.dv_xname);
    373  1.11.10.2  ad 		return;
    374  1.11.10.2  ad 	}
    375  1.11.10.2  ad 
    376  1.11.10.2  ad 	sc->sc_flags |= CTF_ALIVE;
    377  1.11.10.2  ad }
    378  1.11.10.2  ad 
    379  1.11.10.2  ad /*ARGSUSED*/
    380  1.11.10.2  ad int
    381  1.11.10.2  ad ctopen(dev, flag, type, l)
    382  1.11.10.2  ad 	dev_t dev;
    383  1.11.10.2  ad 	int flag, type;
    384  1.11.10.2  ad 	struct lwp *l;
    385  1.11.10.2  ad {
    386  1.11.10.2  ad 	struct ct_softc *sc;
    387  1.11.10.2  ad 	u_int8_t opt;
    388  1.11.10.2  ad 
    389  1.11.10.2  ad 	sc = device_lookup(&ct_cd, CTUNIT(dev));
    390  1.11.10.2  ad 	if (sc == NULL || (sc->sc_flags & CTF_ALIVE) == 0)
    391  1.11.10.2  ad 		return (ENXIO);
    392  1.11.10.2  ad 
    393  1.11.10.2  ad 	if (sc->sc_flags & CTF_OPEN)
    394  1.11.10.2  ad 		return (EBUSY);
    395  1.11.10.2  ad 
    396  1.11.10.2  ad 	if ((dev & CT_STREAM) && (sc->sc_flags & CTF_CANSTREAM))
    397  1.11.10.2  ad 		opt = C_SPAR | C_IMRPT;
    398  1.11.10.2  ad 	else
    399  1.11.10.2  ad 		opt = C_SPAR;
    400  1.11.10.2  ad 
    401  1.11.10.2  ad 	if (cs80setoptions(device_parent(&sc->sc_dev), sc->sc_slave,
    402  1.11.10.2  ad 	    sc->sc_punit, opt))
    403  1.11.10.2  ad 		return (EBUSY);
    404  1.11.10.2  ad 
    405  1.11.10.2  ad 	sc->sc_tpr = tprintf_open(l->l_proc);
    406  1.11.10.2  ad 	sc->sc_flags |= CTF_OPEN;
    407  1.11.10.2  ad 
    408  1.11.10.2  ad 	return (0);
    409  1.11.10.2  ad }
    410  1.11.10.2  ad 
    411  1.11.10.2  ad /*ARGSUSED*/
    412  1.11.10.2  ad int
    413  1.11.10.2  ad ctclose(dev, flag, fmt, l)
    414  1.11.10.2  ad 	dev_t dev;
    415  1.11.10.2  ad 	int flag, fmt;
    416  1.11.10.2  ad 	struct lwp *l;
    417  1.11.10.2  ad {
    418  1.11.10.2  ad 	struct ct_softc *sc;
    419  1.11.10.2  ad 
    420  1.11.10.2  ad 	sc = device_lookup(&ct_cd, CTUNIT(dev));
    421  1.11.10.2  ad 	if (sc == NULL)
    422  1.11.10.2  ad 		return (ENXIO);
    423  1.11.10.2  ad 
    424  1.11.10.2  ad 	if ((sc->sc_flags & (CTF_WRT|CTF_WRTTN)) == (CTF_WRT|CTF_WRTTN) &&
    425  1.11.10.2  ad 	    (sc->sc_flags & CTF_EOT) == 0 ) { /* XXX return error if EOT ?? */
    426  1.11.10.2  ad 		ctcommand(dev, MTWEOF, 2);
    427  1.11.10.2  ad 		ctcommand(dev, MTBSR, 1);
    428  1.11.10.2  ad 		if (sc->sc_eofp == EOFS - 1)
    429  1.11.10.2  ad 			sc->sc_eofs[EOFS - 1]--;
    430  1.11.10.2  ad 		else
    431  1.11.10.2  ad 			sc->sc_eofp--;
    432  1.11.10.2  ad 		DPRINTF(CDB_BSF, ("%s: ctclose backup eofs prt %d blk %d\n",
    433  1.11.10.2  ad 		    sc->sc_dev.dv_xname, sc->sc_eofp,
    434  1.11.10.2  ad 		    sc->sc_eofs[sc->sc_eofp]));
    435  1.11.10.2  ad 	}
    436  1.11.10.2  ad 
    437  1.11.10.2  ad 	if ((minor(dev) & CT_NOREW) == 0)
    438  1.11.10.2  ad 		ctcommand(dev, MTREW, 1);
    439  1.11.10.2  ad 	sc->sc_flags &= ~(CTF_OPEN | CTF_WRT | CTF_WRTTN);
    440  1.11.10.2  ad 	tprintf_close(sc->sc_tpr);
    441  1.11.10.2  ad 	DPRINTF(CDB_FILES, ("ctclose: flags %x\n", sc->sc_flags));
    442  1.11.10.2  ad 
    443  1.11.10.2  ad 	return (0);	/* XXX */
    444  1.11.10.2  ad }
    445  1.11.10.2  ad 
    446  1.11.10.2  ad void
    447  1.11.10.2  ad ctcommand(dev, cmd, cnt)
    448  1.11.10.2  ad 	dev_t dev;
    449  1.11.10.2  ad 	int cmd;
    450  1.11.10.2  ad 	int cnt;
    451  1.11.10.2  ad {
    452  1.11.10.2  ad 	struct ct_softc *sc;
    453  1.11.10.2  ad 	struct buf *bp;
    454  1.11.10.2  ad 	struct buf *nbp = 0;
    455  1.11.10.2  ad 
    456  1.11.10.2  ad 	sc = device_lookup(&ct_cd, CTUNIT(dev));
    457  1.11.10.2  ad 	bp = &sc->sc_bufstore;
    458  1.11.10.2  ad 
    459  1.11.10.2  ad 	DPRINTF(CDB_FOLLOW, ("ctcommand: called\n"));
    460  1.11.10.2  ad 
    461  1.11.10.2  ad 	if (cmd == MTBSF && sc->sc_eofp == EOFS - 1) {
    462  1.11.10.2  ad 		cnt = sc->sc_eofs[EOFS - 1] - cnt;
    463  1.11.10.2  ad 		ctcommand(dev, MTREW, 1);
    464  1.11.10.2  ad 		ctcommand(dev, MTFSF, cnt);
    465  1.11.10.2  ad 		cnt = 2;
    466  1.11.10.2  ad 		cmd = MTBSR;
    467  1.11.10.2  ad 	}
    468  1.11.10.2  ad 
    469  1.11.10.2  ad 	if (cmd == MTBSF && sc->sc_eofp - cnt < 0) {
    470  1.11.10.2  ad 		cnt = 1;
    471  1.11.10.2  ad 		cmd = MTREW;
    472  1.11.10.2  ad 	}
    473  1.11.10.2  ad 
    474  1.11.10.2  ad 	sc->sc_flags |= CTF_CMD;
    475  1.11.10.2  ad 	sc->sc_bp = bp;
    476  1.11.10.2  ad 	sc->sc_cmd = cmd;
    477  1.11.10.2  ad 	bp->b_dev = dev;
    478  1.11.10.2  ad 	if (cmd == MTFSF) {
    479  1.11.10.2  ad 		nbp = (struct buf *)geteblk(MAXBSIZE);
    480  1.11.10.2  ad 		bp->b_data = nbp->b_data;
    481  1.11.10.2  ad 		bp->b_bcount = MAXBSIZE;
    482  1.11.10.2  ad 	}
    483  1.11.10.2  ad 
    484  1.11.10.2  ad 	while (cnt-- > 0) {
    485  1.11.10.2  ad 		bp->b_flags = B_BUSY;
    486  1.11.10.2  ad 		if (cmd == MTBSF) {
    487  1.11.10.2  ad 			sc->sc_blkno = sc->sc_eofs[sc->sc_eofp];
    488  1.11.10.2  ad 			sc->sc_eofp--;
    489  1.11.10.2  ad 			DPRINTF(CDB_BSF, ("%s: backup eof pos %d blk %d\n",
    490  1.11.10.2  ad 			    sc->sc_dev.dv_xname, sc->sc_eofp,
    491  1.11.10.2  ad 			    sc->sc_eofs[sc->sc_eofp]));
    492  1.11.10.2  ad 		}
    493  1.11.10.2  ad 		ctstrategy(bp);
    494  1.11.10.2  ad 		biowait(bp);
    495  1.11.10.2  ad 	}
    496  1.11.10.2  ad 	bp->b_flags = 0;
    497  1.11.10.2  ad 	sc->sc_flags &= ~CTF_CMD;
    498  1.11.10.2  ad 	if (nbp)
    499  1.11.10.2  ad 		brelse(nbp);
    500  1.11.10.2  ad }
    501  1.11.10.2  ad 
    502  1.11.10.2  ad void
    503  1.11.10.2  ad ctstrategy(bp)
    504  1.11.10.2  ad 	struct buf *bp;
    505  1.11.10.2  ad {
    506  1.11.10.2  ad 	struct ct_softc *sc;
    507  1.11.10.2  ad 	int s;
    508  1.11.10.2  ad 
    509  1.11.10.2  ad 	DPRINTF(CDB_FOLLOW, ("cdstrategy(%p): dev %x, bn %x, bcount %lx, %c\n",
    510  1.11.10.2  ad 	    bp, bp->b_dev, bp->b_blkno, bp->b_bcount,
    511  1.11.10.2  ad 	    (bp->b_flags & B_READ) ? 'R' : 'W'));
    512  1.11.10.2  ad 
    513  1.11.10.2  ad 	sc = device_lookup(&ct_cd, CTUNIT(bp->b_dev));
    514  1.11.10.2  ad 
    515  1.11.10.2  ad 	s = splbio();
    516  1.11.10.2  ad 	BUFQ_PUT(sc->sc_tab, bp);
    517  1.11.10.2  ad 	if (sc->sc_active == 0) {
    518  1.11.10.2  ad 		sc->sc_active = 1;
    519  1.11.10.2  ad 		ctustart(sc);
    520  1.11.10.2  ad 	}
    521  1.11.10.2  ad 	splx(s);
    522  1.11.10.2  ad }
    523  1.11.10.2  ad 
    524  1.11.10.2  ad void
    525  1.11.10.2  ad ctustart(sc)
    526  1.11.10.2  ad 	struct ct_softc *sc;
    527  1.11.10.2  ad {
    528  1.11.10.2  ad 	struct buf *bp;
    529  1.11.10.2  ad 
    530  1.11.10.2  ad 	bp = BUFQ_PEEK(sc->sc_tab);
    531  1.11.10.2  ad 	sc->sc_addr = bp->b_data;
    532  1.11.10.2  ad 	sc->sc_resid = bp->b_bcount;
    533  1.11.10.2  ad 	if (gpibrequest(sc->sc_ic, sc->sc_hdl))
    534  1.11.10.2  ad 		ctstart(sc);
    535  1.11.10.2  ad }
    536  1.11.10.2  ad 
    537  1.11.10.2  ad void
    538  1.11.10.2  ad ctstart(sc)
    539  1.11.10.2  ad 	struct ct_softc *sc;
    540  1.11.10.2  ad {
    541  1.11.10.2  ad 	struct buf *bp;
    542  1.11.10.2  ad 	struct ct_ulcmd ul;
    543  1.11.10.2  ad 	struct ct_wfmcmd wfm;
    544  1.11.10.2  ad 	int i, slave, punit;
    545  1.11.10.2  ad 
    546  1.11.10.2  ad 	slave = sc->sc_slave;
    547  1.11.10.2  ad 	punit = sc->sc_punit;
    548  1.11.10.2  ad 
    549  1.11.10.2  ad 	bp = BUFQ_PEEK(sc->sc_tab);
    550  1.11.10.2  ad 	if ((sc->sc_flags & CTF_CMD) && sc->sc_bp == bp) {
    551  1.11.10.2  ad 		switch(sc->sc_cmd) {
    552  1.11.10.2  ad 		case MTFSF:
    553  1.11.10.2  ad 			bp->b_flags |= B_READ;
    554  1.11.10.2  ad 			goto mustio;
    555  1.11.10.2  ad 
    556  1.11.10.2  ad 		case MTBSF:
    557  1.11.10.2  ad 			goto gotaddr;
    558  1.11.10.2  ad 
    559  1.11.10.2  ad 		case MTOFFL:
    560  1.11.10.2  ad 			sc->sc_blkno = 0;
    561  1.11.10.2  ad 			ul.unit = CS80CMD_SUNIT(punit);
    562  1.11.10.2  ad 			ul.cmd = CS80CMD_UNLOAD;
    563  1.11.10.2  ad 			(void) cs80send(device_parent(&sc->sc_dev), slave,
    564  1.11.10.2  ad 			    punit, CS80CMD_SCMD, &ul, sizeof(ul));
    565  1.11.10.2  ad 			break;
    566  1.11.10.2  ad 
    567  1.11.10.2  ad 		case MTWEOF:
    568  1.11.10.2  ad 			sc->sc_blkno++;
    569  1.11.10.2  ad 			sc->sc_flags |= CTF_WRT;
    570  1.11.10.2  ad 			wfm.unit = CS80CMD_SUNIT(sc->sc_punit);
    571  1.11.10.2  ad 			wfm.cmd = CS80CMD_WFM;
    572  1.11.10.2  ad 			(void) cs80send(device_parent(&sc->sc_dev), slave,
    573  1.11.10.2  ad 			    punit, CS80CMD_SCMD, &wfm, sizeof(wfm));
    574  1.11.10.2  ad 			ctaddeof(sc);
    575  1.11.10.2  ad 			break;
    576  1.11.10.2  ad 
    577  1.11.10.2  ad 		case MTBSR:
    578  1.11.10.2  ad 			sc->sc_blkno--;
    579  1.11.10.2  ad 			goto gotaddr;
    580  1.11.10.2  ad 
    581  1.11.10.2  ad 		case MTFSR:
    582  1.11.10.2  ad 			sc->sc_blkno++;
    583  1.11.10.2  ad 			goto gotaddr;
    584  1.11.10.2  ad 
    585  1.11.10.2  ad 		case MTREW:
    586  1.11.10.2  ad 			sc->sc_blkno = 0;
    587  1.11.10.2  ad 			DPRINTF(CDB_BSF, ("%s: clearing eofs\n",
    588  1.11.10.2  ad 			    sc->sc_dev.dv_xname));
    589  1.11.10.2  ad 			for (i=0; i<EOFS; i++)
    590  1.11.10.2  ad 				sc->sc_eofs[i] = 0;
    591  1.11.10.2  ad 			sc->sc_eofp = 0;
    592  1.11.10.2  ad 
    593  1.11.10.2  ad gotaddr:
    594  1.11.10.2  ad 			sc->sc_ioc.unit = CS80CMD_SUNIT(sc->sc_punit);
    595  1.11.10.2  ad 			sc->sc_ioc.saddr = CS80CMD_SADDR;
    596  1.11.10.2  ad 			sc->sc_ioc.addr0 = 0;
    597  1.11.10.2  ad 			sc->sc_ioc.addr = htobe32(sc->sc_blkno);
    598  1.11.10.2  ad 			sc->sc_ioc.nop2 = CS80CMD_NOP;
    599  1.11.10.2  ad 			sc->sc_ioc.slen = CS80CMD_SLEN;
    600  1.11.10.2  ad 			sc->sc_ioc.len = htobe32(0);
    601  1.11.10.2  ad 			sc->sc_ioc.nop3 = CS80CMD_NOP;
    602  1.11.10.2  ad 			sc->sc_ioc.cmd = CS80CMD_READ;
    603  1.11.10.2  ad 			(void) cs80send(device_parent(&sc->sc_dev), slave,
    604  1.11.10.2  ad 			    punit, CS80CMD_SCMD, &sc->sc_ioc,
    605  1.11.10.2  ad 			    sizeof(sc->sc_ioc));
    606  1.11.10.2  ad 			break;
    607  1.11.10.2  ad 		}
    608  1.11.10.2  ad 	} else {
    609  1.11.10.2  ad mustio:
    610  1.11.10.2  ad 		if ((bp->b_flags & B_READ) &&
    611  1.11.10.2  ad 		    sc->sc_flags & (CTF_BEOF|CTF_EOT)) {
    612  1.11.10.2  ad 			DPRINTF(CDB_FILES, ("ctstart: before %x\n",
    613  1.11.10.2  ad 				    sc->sc_flags));
    614  1.11.10.2  ad 			if (sc->sc_flags & CTF_BEOF) {
    615  1.11.10.2  ad 				sc->sc_flags &= ~CTF_BEOF;
    616  1.11.10.2  ad 				sc->sc_flags |= CTF_AEOF;
    617  1.11.10.2  ad 				DPRINTF(CDB_FILES, ("ctstart: after %x\n",
    618  1.11.10.2  ad 				    sc->sc_flags));
    619  1.11.10.2  ad 			}
    620  1.11.10.2  ad 			bp->b_resid = bp->b_bcount;
    621  1.11.10.2  ad 			ctdone(sc, bp);
    622  1.11.10.2  ad 			return;
    623  1.11.10.2  ad 		}
    624  1.11.10.2  ad 		sc->sc_flags |= CTF_IO;
    625  1.11.10.2  ad 		sc->sc_ioc.unit = CS80CMD_SUNIT(sc->sc_punit);
    626  1.11.10.2  ad 		sc->sc_ioc.saddr = CS80CMD_SADDR;
    627  1.11.10.2  ad 		sc->sc_ioc.addr0 = 0;
    628  1.11.10.2  ad 		sc->sc_ioc.addr = htobe32(sc->sc_blkno);
    629  1.11.10.2  ad 		sc->sc_ioc.nop2 = CS80CMD_NOP;
    630  1.11.10.2  ad 		sc->sc_ioc.slen = CS80CMD_SLEN;
    631  1.11.10.2  ad 		sc->sc_ioc.len = htobe32(sc->sc_resid);
    632  1.11.10.2  ad 		sc->sc_ioc.nop3 = CS80CMD_NOP;
    633  1.11.10.2  ad 		if (bp->b_flags & B_READ)
    634  1.11.10.2  ad 			sc->sc_ioc.cmd = CS80CMD_READ;
    635  1.11.10.2  ad 		else {
    636  1.11.10.2  ad 			sc->sc_ioc.cmd = CS80CMD_WRITE;
    637  1.11.10.2  ad 			sc->sc_flags |= (CTF_WRT | CTF_WRTTN);
    638  1.11.10.2  ad 		}
    639  1.11.10.2  ad 		(void) cs80send(device_parent(&sc->sc_dev), slave, punit,
    640  1.11.10.2  ad 		    CS80CMD_SCMD, &sc->sc_ioc, sizeof(sc->sc_ioc));
    641  1.11.10.2  ad 	}
    642  1.11.10.2  ad 	gpibawait(sc->sc_ic);
    643  1.11.10.2  ad }
    644  1.11.10.2  ad 
    645  1.11.10.2  ad /*
    646  1.11.10.2  ad  * Hideous grue to handle EOF/EOT (mostly for reads)
    647  1.11.10.2  ad  */
    648  1.11.10.2  ad void
    649  1.11.10.2  ad cteof(sc, bp)
    650  1.11.10.2  ad 	struct ct_softc *sc;
    651  1.11.10.2  ad 	struct buf *bp;
    652  1.11.10.2  ad {
    653  1.11.10.2  ad 	long blks;
    654  1.11.10.2  ad 
    655  1.11.10.2  ad 	/*
    656  1.11.10.2  ad 	 * EOT on a write is an error.
    657  1.11.10.2  ad 	 */
    658  1.11.10.2  ad 	if ((bp->b_flags & B_READ) == 0) {
    659  1.11.10.2  ad 		bp->b_resid = bp->b_bcount;
    660  1.11.10.2  ad 		bp->b_error = ENOSPC;
    661  1.11.10.2  ad 		sc->sc_flags |= CTF_EOT;
    662  1.11.10.2  ad 		return;
    663  1.11.10.2  ad 	}
    664  1.11.10.2  ad 	/*
    665  1.11.10.2  ad 	 * Use returned block position to determine how many blocks
    666  1.11.10.2  ad 	 * we really read and update b_resid.
    667  1.11.10.2  ad 	 */
    668  1.11.10.2  ad 	blks = sc->sc_stat.c_blk - sc->sc_blkno - 1;
    669  1.11.10.2  ad 	DPRINTF(CDB_FILES, ("cteof: bc %ld oblk %d nblk %d read %ld, resid %ld\n",
    670  1.11.10.2  ad 	    bp->b_bcount, sc->sc_blkno, sc->sc_stat.c_blk,
    671  1.11.10.2  ad 	    blks, bp->b_bcount - CTKTOB(blks)));
    672  1.11.10.2  ad 	if (blks == -1) { /* 9145 on EOF does not change sc_stat.c_blk */
    673  1.11.10.2  ad 		blks = 0;
    674  1.11.10.2  ad 		sc->sc_blkno++;
    675  1.11.10.2  ad 	}
    676  1.11.10.2  ad 	else {
    677  1.11.10.2  ad 		sc->sc_blkno = sc->sc_stat.c_blk;
    678  1.11.10.2  ad 	}
    679  1.11.10.2  ad 	bp->b_resid = bp->b_bcount - CTKTOB(blks);
    680  1.11.10.2  ad 	/*
    681  1.11.10.2  ad 	 * If we are at physical EOV or were after an EOF,
    682  1.11.10.2  ad 	 * we are now at logical EOT.
    683  1.11.10.2  ad 	 */
    684  1.11.10.2  ad 	if ((sc->sc_stat.c_aef & AEF_EOV) ||
    685  1.11.10.2  ad 	    (sc->sc_flags & CTF_AEOF)) {
    686  1.11.10.2  ad 		sc->sc_flags |= CTF_EOT;
    687  1.11.10.2  ad 		sc->sc_flags &= ~(CTF_AEOF|CTF_BEOF);
    688  1.11.10.2  ad 	}
    689  1.11.10.2  ad 	/*
    690  1.11.10.2  ad 	 * If we were before an EOF or we have just completed a FSF,
    691  1.11.10.2  ad 	 * we are now after EOF.
    692  1.11.10.2  ad 	 */
    693  1.11.10.2  ad 	else if ((sc->sc_flags & CTF_BEOF) ||
    694  1.11.10.2  ad 		 ((sc->sc_flags & CTF_CMD) && sc->sc_cmd == MTFSF)) {
    695  1.11.10.2  ad 		sc->sc_flags |= CTF_AEOF;
    696  1.11.10.2  ad 		sc->sc_flags &= ~CTF_BEOF;
    697  1.11.10.2  ad 	}
    698  1.11.10.2  ad 	/*
    699  1.11.10.2  ad 	 * Otherwise if we read something we are now before EOF
    700  1.11.10.2  ad 	 * (and no longer after EOF).
    701  1.11.10.2  ad 	 */
    702  1.11.10.2  ad 	else if (blks) {
    703  1.11.10.2  ad 		sc->sc_flags |= CTF_BEOF;
    704  1.11.10.2  ad 		sc->sc_flags &= ~CTF_AEOF;
    705  1.11.10.2  ad 	}
    706  1.11.10.2  ad 	/*
    707  1.11.10.2  ad 	 * Finally, if we didn't read anything we just passed an EOF
    708  1.11.10.2  ad 	 */
    709  1.11.10.2  ad 	else
    710  1.11.10.2  ad 		sc->sc_flags |= CTF_AEOF;
    711  1.11.10.2  ad 	DPRINTF(CDB_FILES, ("cteof: leaving flags %x\n", sc->sc_flags));
    712  1.11.10.2  ad }
    713  1.11.10.2  ad 
    714  1.11.10.2  ad 
    715  1.11.10.2  ad void
    716  1.11.10.2  ad ctcallback(v, action)
    717  1.11.10.2  ad 	void *v;
    718  1.11.10.2  ad 	int action;
    719  1.11.10.2  ad {
    720  1.11.10.2  ad 	struct ct_softc *sc = v;
    721  1.11.10.2  ad 
    722  1.11.10.2  ad 	DPRINTF(CDB_FOLLOW, ("ctcallback: v=%p, action=%d\n", v, action));
    723  1.11.10.2  ad 
    724  1.11.10.2  ad 	switch (action) {
    725  1.11.10.2  ad 	case GPIBCBF_START:
    726  1.11.10.2  ad 		ctstart(sc);
    727  1.11.10.2  ad 		break;
    728  1.11.10.2  ad 	case GPIBCBF_INTR:
    729  1.11.10.2  ad 		ctintr(sc);
    730  1.11.10.2  ad 		break;
    731  1.11.10.2  ad #ifdef DEBUG
    732  1.11.10.2  ad 	default:
    733  1.11.10.2  ad 		DPRINTF(CDB_FAIL, ("ctcallback: unknown action %d\n", action));
    734  1.11.10.2  ad 		break;
    735  1.11.10.2  ad #endif
    736  1.11.10.2  ad 	}
    737  1.11.10.2  ad }
    738  1.11.10.2  ad 
    739  1.11.10.2  ad void
    740  1.11.10.2  ad ctintr(sc)
    741  1.11.10.2  ad 	struct ct_softc *sc;
    742  1.11.10.2  ad {
    743  1.11.10.2  ad 	struct buf *bp;
    744  1.11.10.2  ad 	u_int8_t stat;
    745  1.11.10.2  ad 	int slave, punit;
    746  1.11.10.2  ad 	int dir;
    747  1.11.10.2  ad 
    748  1.11.10.2  ad 	slave = sc->sc_slave;
    749  1.11.10.2  ad 	punit = sc->sc_punit;
    750  1.11.10.2  ad 
    751  1.11.10.2  ad 	bp = BUFQ_PEEK(sc->sc_tab);
    752  1.11.10.2  ad 	if (bp == NULL) {
    753  1.11.10.2  ad 		printf("%s: bp == NULL\n", sc->sc_dev.dv_xname);
    754  1.11.10.2  ad 		return;
    755  1.11.10.2  ad 	}
    756  1.11.10.2  ad 	if (sc->sc_flags & CTF_IO) {
    757  1.11.10.2  ad 		sc->sc_flags &= ~CTF_IO;
    758  1.11.10.2  ad 		dir = (bp->b_flags & B_READ ? GPIB_READ : GPIB_WRITE);
    759  1.11.10.2  ad 		gpibxfer(sc->sc_ic, slave, CS80CMD_EXEC, sc->sc_addr,
    760  1.11.10.2  ad 		    sc->sc_resid, dir, dir == GPIB_READ);
    761  1.11.10.2  ad 		return;
    762  1.11.10.2  ad 	}
    763  1.11.10.2  ad 	if ((sc->sc_flags & CTF_STATWAIT) == 0) {
    764  1.11.10.2  ad 		if (gpibpptest(sc->sc_ic, slave) == 0) {
    765  1.11.10.2  ad 			sc->sc_flags |= CTF_STATWAIT;
    766  1.11.10.2  ad 			gpibawait(sc->sc_ic);
    767  1.11.10.2  ad 			return;
    768  1.11.10.2  ad 		}
    769  1.11.10.2  ad 	} else
    770  1.11.10.2  ad 		sc->sc_flags &= ~CTF_STATWAIT;
    771  1.11.10.2  ad 	(void) gpibrecv(sc->sc_ic, slave, CS80CMD_QSTAT, &stat, 1);
    772  1.11.10.2  ad 	DPRINTF(CDB_FILES, ("ctintr: before flags %x\n", sc->sc_flags));
    773  1.11.10.2  ad 	if (stat) {
    774  1.11.10.2  ad 		sc->sc_rsc.unit = CS80CMD_SUNIT(punit);
    775  1.11.10.2  ad 		sc->sc_rsc.cmd = CS80CMD_STATUS;
    776  1.11.10.2  ad 		(void) gpibsend(sc->sc_ic, slave, CS80CMD_SCMD, &sc->sc_rsc,
    777  1.11.10.2  ad 		    sizeof(sc->sc_rsc));
    778  1.11.10.2  ad 		(void) gpibrecv(sc->sc_ic, slave, CS80CMD_EXEC, &sc->sc_stat,
    779  1.11.10.2  ad 		    sizeof(sc->sc_stat));
    780  1.11.10.2  ad 		(void) gpibrecv(sc->sc_ic, slave, CS80CMD_QSTAT, &stat, 1);
    781  1.11.10.2  ad 		DPRINTF(CDB_FILES, ("ctintr: return stat 0x%x, A%x F%x blk %d\n",
    782  1.11.10.2  ad 			       stat, sc->sc_stat.c_aef,
    783  1.11.10.2  ad 			       sc->sc_stat.c_fef, sc->sc_stat.c_blk));
    784  1.11.10.2  ad 		if (stat == 0) {
    785  1.11.10.2  ad 			if (sc->sc_stat.c_aef & (AEF_EOF | AEF_EOV)) {
    786  1.11.10.2  ad 				cteof(sc, bp);
    787  1.11.10.2  ad 				ctaddeof(sc);
    788  1.11.10.2  ad 				goto done;
    789  1.11.10.2  ad 			}
    790  1.11.10.2  ad 			if (sc->sc_stat.c_fef & FEF_PF) {
    791  1.11.10.2  ad 				cs80reset(sc, slave, punit);
    792  1.11.10.2  ad 				ctstart(sc);
    793  1.11.10.2  ad 				return;
    794  1.11.10.2  ad 			}
    795  1.11.10.2  ad 			if (sc->sc_stat.c_fef & FEF_REXMT) {
    796  1.11.10.2  ad 				ctstart(sc);
    797  1.11.10.2  ad 				return;
    798  1.11.10.2  ad 			}
    799  1.11.10.2  ad 			if (sc->sc_stat.c_aef & 0x5800) {
    800  1.11.10.2  ad 				if (sc->sc_stat.c_aef & 0x4000)
    801  1.11.10.2  ad 					tprintf(sc->sc_tpr,
    802  1.11.10.2  ad 					    "%s: uninitialized media\n",
    803  1.11.10.2  ad 					    sc->sc_dev.dv_xname);
    804  1.11.10.2  ad 				if (sc->sc_stat.c_aef & 0x1000)
    805  1.11.10.2  ad 					tprintf(sc->sc_tpr,
    806  1.11.10.2  ad 					    "%s: not ready\n",
    807  1.11.10.2  ad 					    sc->sc_dev.dv_xname);
    808  1.11.10.2  ad 				if (sc->sc_stat.c_aef & 0x0800)
    809  1.11.10.2  ad 					tprintf(sc->sc_tpr,
    810  1.11.10.2  ad 					    "%s: write protect\n",
    811  1.11.10.2  ad 					    sc->sc_dev.dv_xname);
    812  1.11.10.2  ad 			} else {
    813  1.11.10.2  ad 				printf("%s err: v%d u%d ru%d bn%d, ",
    814  1.11.10.2  ad 				    sc->sc_dev.dv_xname,
    815  1.11.10.2  ad 				    (sc->sc_stat.c_vu>>4)&0xF,
    816  1.11.10.2  ad 				    sc->sc_stat.c_vu&0xF,
    817  1.11.10.2  ad 				    sc->sc_stat.c_pend,
    818  1.11.10.2  ad 				    sc->sc_stat.c_blk);
    819  1.11.10.2  ad 				printf("R0x%x F0x%x A0x%x I0x%x\n",
    820  1.11.10.2  ad 				    sc->sc_stat.c_ref,
    821  1.11.10.2  ad 				    sc->sc_stat.c_fef,
    822  1.11.10.2  ad 				    sc->sc_stat.c_aef,
    823  1.11.10.2  ad 				    sc->sc_stat.c_ief);
    824  1.11.10.2  ad 			}
    825  1.11.10.2  ad 		} else
    826  1.11.10.2  ad 			printf("%s: request status failed\n",
    827  1.11.10.2  ad 			    sc->sc_dev.dv_xname);
    828  1.11.10.2  ad 		bp->b_error = EIO;
    829  1.11.10.2  ad 		goto done;
    830  1.11.10.2  ad 	} else
    831  1.11.10.2  ad 		bp->b_resid = 0;
    832  1.11.10.2  ad 	if (sc->sc_flags & CTF_CMD) {
    833  1.11.10.2  ad 		switch (sc->sc_cmd) {
    834  1.11.10.2  ad 		case MTFSF:
    835  1.11.10.2  ad 			sc->sc_flags &= ~(CTF_BEOF|CTF_AEOF);
    836  1.11.10.2  ad 			sc->sc_blkno += CTBTOK(sc->sc_resid);
    837  1.11.10.2  ad 			ctstart(sc);
    838  1.11.10.2  ad 			return;
    839  1.11.10.2  ad 		case MTBSF:
    840  1.11.10.2  ad 			sc->sc_flags &= ~(CTF_AEOF|CTF_BEOF|CTF_EOT);
    841  1.11.10.2  ad 			break;
    842  1.11.10.2  ad 		case MTBSR:
    843  1.11.10.2  ad 			sc->sc_flags &= ~CTF_BEOF;
    844  1.11.10.2  ad 			if (sc->sc_flags & CTF_EOT) {
    845  1.11.10.2  ad 				sc->sc_flags |= CTF_AEOF;
    846  1.11.10.2  ad 				sc->sc_flags &= ~CTF_EOT;
    847  1.11.10.2  ad 			} else if (sc->sc_flags & CTF_AEOF) {
    848  1.11.10.2  ad 				sc->sc_flags |= CTF_BEOF;
    849  1.11.10.2  ad 				sc->sc_flags &= ~CTF_AEOF;
    850  1.11.10.2  ad 			}
    851  1.11.10.2  ad 			break;
    852  1.11.10.2  ad 		case MTWEOF:
    853  1.11.10.2  ad 			sc->sc_flags &= ~CTF_BEOF;
    854  1.11.10.2  ad 			if (sc->sc_flags & (CTF_AEOF|CTF_EOT)) {
    855  1.11.10.2  ad 				sc->sc_flags |= CTF_EOT;
    856  1.11.10.2  ad 				sc->sc_flags &= ~CTF_AEOF;
    857  1.11.10.2  ad 			} else
    858  1.11.10.2  ad 				sc->sc_flags |= CTF_AEOF;
    859  1.11.10.2  ad 			break;
    860  1.11.10.2  ad 		case MTREW:
    861  1.11.10.2  ad 		case MTOFFL:
    862  1.11.10.2  ad 			sc->sc_flags &= ~(CTF_BEOF|CTF_AEOF|CTF_EOT);
    863  1.11.10.2  ad 			break;
    864  1.11.10.2  ad 		}
    865  1.11.10.2  ad 	} else {
    866  1.11.10.2  ad 		sc->sc_flags &= ~CTF_AEOF;
    867  1.11.10.2  ad 		sc->sc_blkno += CTBTOK(sc->sc_resid);
    868  1.11.10.2  ad 	}
    869  1.11.10.2  ad done:
    870  1.11.10.2  ad 	DPRINTF(CDB_FILES, ("ctintr: after flags %x\n", sc->sc_flags));
    871  1.11.10.2  ad 	ctdone(sc, bp);
    872  1.11.10.2  ad }
    873  1.11.10.2  ad 
    874  1.11.10.2  ad void
    875  1.11.10.2  ad ctdone(sc, bp)
    876  1.11.10.2  ad 	struct ct_softc *sc;
    877  1.11.10.2  ad 	struct buf *bp;
    878  1.11.10.2  ad {
    879  1.11.10.2  ad 
    880  1.11.10.2  ad 	(void)BUFQ_GET(sc->sc_tab);
    881  1.11.10.2  ad 	biodone(bp);
    882  1.11.10.2  ad 	gpibrelease(sc->sc_ic, sc->sc_hdl);
    883  1.11.10.2  ad 	if (BUFQ_PEEK(sc->sc_tab) == NULL) {
    884  1.11.10.2  ad 		sc->sc_active = 0;
    885  1.11.10.2  ad 		return;
    886  1.11.10.2  ad 	}
    887  1.11.10.2  ad 	ctustart(sc);
    888  1.11.10.2  ad }
    889  1.11.10.2  ad 
    890  1.11.10.2  ad int
    891  1.11.10.2  ad ctread(dev, uio, flags)
    892  1.11.10.2  ad 	dev_t dev;
    893  1.11.10.2  ad 	struct uio *uio;
    894  1.11.10.2  ad 	int flags;
    895  1.11.10.2  ad {
    896  1.11.10.2  ad 	return (physio(ctstrategy, NULL, dev, B_READ, minphys, uio));
    897  1.11.10.2  ad }
    898  1.11.10.2  ad 
    899  1.11.10.2  ad int
    900  1.11.10.2  ad ctwrite(dev, uio, flags)
    901  1.11.10.2  ad 	dev_t dev;
    902  1.11.10.2  ad 	struct uio *uio;
    903  1.11.10.2  ad 	int flags;
    904  1.11.10.2  ad {
    905  1.11.10.2  ad 	/* XXX: check for hardware write-protect? */
    906  1.11.10.2  ad 	return (physio(ctstrategy, NULL, dev, B_WRITE, minphys, uio));
    907  1.11.10.2  ad }
    908  1.11.10.2  ad 
    909  1.11.10.2  ad /*ARGSUSED*/
    910  1.11.10.2  ad int
    911  1.11.10.2  ad ctioctl(dev, cmd, data, flag, l)
    912  1.11.10.2  ad 	dev_t dev;
    913  1.11.10.2  ad 	u_long cmd;
    914  1.11.10.2  ad 	int flag;
    915  1.11.10.2  ad 	void *data;
    916  1.11.10.2  ad 	struct lwp *l;
    917  1.11.10.2  ad {
    918  1.11.10.2  ad 	struct mtop *op;
    919  1.11.10.2  ad 	int cnt;
    920  1.11.10.2  ad 
    921  1.11.10.2  ad 	switch (cmd) {
    922  1.11.10.2  ad 
    923  1.11.10.2  ad 	case MTIOCTOP:
    924  1.11.10.2  ad 		op = (struct mtop *)data;
    925  1.11.10.2  ad 		switch(op->mt_op) {
    926  1.11.10.2  ad 
    927  1.11.10.2  ad 		case MTWEOF:
    928  1.11.10.2  ad 		case MTFSF:
    929  1.11.10.2  ad 		case MTBSR:
    930  1.11.10.2  ad 		case MTBSF:
    931  1.11.10.2  ad 		case MTFSR:
    932  1.11.10.2  ad 			cnt = op->mt_count;
    933  1.11.10.2  ad 			break;
    934  1.11.10.2  ad 
    935  1.11.10.2  ad 		case MTREW:
    936  1.11.10.2  ad 		case MTOFFL:
    937  1.11.10.2  ad 			cnt = 1;
    938  1.11.10.2  ad 			break;
    939  1.11.10.2  ad 
    940  1.11.10.2  ad 		default:
    941  1.11.10.2  ad 			return (EINVAL);
    942  1.11.10.2  ad 		}
    943  1.11.10.2  ad 		ctcommand(dev, op->mt_op, cnt);
    944  1.11.10.2  ad 		break;
    945  1.11.10.2  ad 
    946  1.11.10.2  ad 	case MTIOCGET:
    947  1.11.10.2  ad 		break;
    948  1.11.10.2  ad 
    949  1.11.10.2  ad 	default:
    950  1.11.10.2  ad 		return (EINVAL);
    951  1.11.10.2  ad 	}
    952  1.11.10.2  ad 	return (0);
    953  1.11.10.2  ad }
    954  1.11.10.2  ad 
    955  1.11.10.2  ad void
    956  1.11.10.2  ad ctaddeof(sc)
    957  1.11.10.2  ad 	struct ct_softc *sc;
    958  1.11.10.2  ad {
    959  1.11.10.2  ad 
    960  1.11.10.2  ad 	if (sc->sc_eofp == EOFS - 1)
    961  1.11.10.2  ad 		sc->sc_eofs[EOFS - 1]++;
    962  1.11.10.2  ad 	else {
    963  1.11.10.2  ad 		sc->sc_eofp++;
    964  1.11.10.2  ad 		if (sc->sc_eofp == EOFS - 1)
    965  1.11.10.2  ad 			sc->sc_eofs[EOFS - 1] = EOFS;
    966  1.11.10.2  ad 		else
    967  1.11.10.2  ad 			/* save blkno */
    968  1.11.10.2  ad 			sc->sc_eofs[sc->sc_eofp] = sc->sc_blkno - 1;
    969  1.11.10.2  ad 	}
    970  1.11.10.2  ad 	DPRINTF(CDB_BSF, ("%s: add eof pos %d blk %d\n",
    971  1.11.10.2  ad 		       sc->sc_dev.dv_xname, sc->sc_eofp,
    972  1.11.10.2  ad 		       sc->sc_eofs[sc->sc_eofp]));
    973  1.11.10.2  ad }
    974