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