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