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