mt.c revision 1.8 1 1.8 scottr /* $NetBSD: mt.c,v 1.8 1997/03/31 07:37:29 scottr Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.7 thorpej * Copyright (c) 1996, 1997 Jason R. Thorpe. All rights reserved.
5 1.1 thorpej * Copyright (c) 1992, The University of Utah and
6 1.1 thorpej * the Computer Systems Laboratory at the University of Utah (CSL).
7 1.1 thorpej * All rights reserved.
8 1.1 thorpej *
9 1.1 thorpej * Permission to use, copy, modify and distribute this software is hereby
10 1.1 thorpej * granted provided that (1) source code retains these copyright, permission,
11 1.1 thorpej * and disclaimer notices, and (2) redistributions including binaries
12 1.1 thorpej * reproduce the notices in supporting documentation, and (3) all advertising
13 1.1 thorpej * materials mentioning features or use of this software display the following
14 1.1 thorpej * acknowledgement: ``This product includes software developed by the
15 1.1 thorpej * Computer Systems Laboratory at the University of Utah.''
16 1.1 thorpej *
17 1.1 thorpej * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
18 1.1 thorpej * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
19 1.1 thorpej * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
20 1.1 thorpej *
21 1.1 thorpej * CSL requests users of this software to return to csl-dist (at) cs.utah.edu any
22 1.1 thorpej * improvements that they make and grant CSL redistribution rights.
23 1.1 thorpej *
24 1.1 thorpej * Utah $Hdr: mt.c 1.8 95/09/12$
25 1.1 thorpej */
26 1.1 thorpej /* @(#)mt.c 3.9 90/07/10 mt Xinu
27 1.1 thorpej *
28 1.1 thorpej * Magnetic tape driver (7974a, 7978a/b, 7979a, 7980a, 7980xc)
29 1.1 thorpej * Original version contributed by Mt. Xinu.
30 1.1 thorpej * Modified for 4.4BSD by Mark Davies and Andrew Vignaux, Department of
31 1.1 thorpej * Computer Science, Victoria University of Wellington
32 1.1 thorpej */
33 1.1 thorpej
34 1.1 thorpej #include <sys/param.h>
35 1.1 thorpej #include <sys/systm.h>
36 1.1 thorpej #include <sys/buf.h>
37 1.1 thorpej #include <sys/ioctl.h>
38 1.1 thorpej #include <sys/mtio.h>
39 1.1 thorpej #include <sys/file.h>
40 1.1 thorpej #include <sys/proc.h>
41 1.1 thorpej #include <sys/errno.h>
42 1.1 thorpej #include <sys/syslog.h>
43 1.1 thorpej #include <sys/tty.h>
44 1.1 thorpej #include <sys/kernel.h>
45 1.1 thorpej #include <sys/tprintf.h>
46 1.7 thorpej #include <sys/device.h>
47 1.7 thorpej #include <sys/conf.h>
48 1.1 thorpej
49 1.1 thorpej #include <hp300/dev/hpibvar.h>
50 1.7 thorpej
51 1.1 thorpej #include <hp300/dev/mtreg.h>
52 1.1 thorpej
53 1.1 thorpej struct mtinfo {
54 1.1 thorpej u_short hwid;
55 1.1 thorpej char *desc;
56 1.1 thorpej } mtinfo[] = {
57 1.8 scottr { MT7978ID, "7978" },
58 1.8 scottr { MT7979AID, "7979A" },
59 1.8 scottr { MT7980ID, "7980" },
60 1.8 scottr { MT7974AID, "7974A" },
61 1.1 thorpej };
62 1.1 thorpej int nmtinfo = sizeof(mtinfo) / sizeof(mtinfo[0]);
63 1.1 thorpej
64 1.1 thorpej struct mt_softc {
65 1.7 thorpej struct device sc_dev;
66 1.7 thorpej int sc_hpibno; /* logical HPIB this slave it attached to */
67 1.7 thorpej int sc_slave; /* HPIB slave address (0-6) */
68 1.1 thorpej short sc_flags; /* see below */
69 1.1 thorpej u_char sc_lastdsj; /* place for DSJ in mtreaddsj() */
70 1.1 thorpej u_char sc_lastecmd; /* place for End Command in mtreaddsj() */
71 1.1 thorpej short sc_recvtimeo; /* count of hpibsend timeouts to prevent hang */
72 1.1 thorpej short sc_statindex; /* index for next sc_stat when MTF_STATTIMEO */
73 1.1 thorpej struct mt_stat sc_stat;/* status bytes last read from device */
74 1.1 thorpej short sc_density; /* current density of tape (mtio.h format) */
75 1.1 thorpej short sc_type; /* tape drive model (hardware IDs) */
76 1.7 thorpej struct hpibqueue sc_hq; /* HPIB device queue member */
77 1.1 thorpej tpr_t sc_ttyp;
78 1.7 thorpej struct buf sc_tab; /* buf queue */
79 1.7 thorpej struct buf sc_bufstore; /* XXX buffer storage */
80 1.7 thorpej };
81 1.1 thorpej
82 1.1 thorpej #ifdef DEBUG
83 1.1 thorpej int mtdebug = 0;
84 1.1 thorpej #define dlog if (mtdebug) log
85 1.1 thorpej #else
86 1.1 thorpej #define dlog if (0) log
87 1.1 thorpej #endif
88 1.1 thorpej
89 1.1 thorpej #define UNIT(x) (minor(x) & 3)
90 1.1 thorpej
91 1.1 thorpej #define B_CMD B_XXX /* command buf instead of data */
92 1.1 thorpej #define b_cmd b_blkno /* blkno holds cmd when B_CMD */
93 1.1 thorpej
94 1.7 thorpej int mtmatch __P((struct device *, struct cfdata *, void *));
95 1.7 thorpej void mtattach __P((struct device *, struct device *, void *));
96 1.7 thorpej
97 1.7 thorpej struct cfattach mt_ca = {
98 1.7 thorpej sizeof(struct mt_softc), mtmatch, mtattach
99 1.1 thorpej };
100 1.1 thorpej
101 1.7 thorpej struct cfdriver mt_cd = {
102 1.7 thorpej NULL, "mt", DV_TAPE
103 1.7 thorpej };
104 1.7 thorpej
105 1.7 thorpej int mtident __P((struct mt_softc *, struct hpibbus_attach_args *));
106 1.7 thorpej void mtustart __P((struct mt_softc *));
107 1.7 thorpej int mtreaddsj __P((struct mt_softc *, int));
108 1.7 thorpej int mtcommand __P((dev_t, int, int));
109 1.7 thorpej void spl_mtintr __P((void *));
110 1.7 thorpej void spl_mtstart __P((void *));
111 1.7 thorpej
112 1.7 thorpej void mtstart __P((void *));
113 1.7 thorpej void mtgo __P((void *));
114 1.7 thorpej void mtintr __P((void *));
115 1.7 thorpej
116 1.7 thorpej bdev_decl(mt);
117 1.7 thorpej cdev_decl(mt);
118 1.7 thorpej
119 1.2 thorpej int
120 1.7 thorpej mtmatch(parent, match, aux)
121 1.7 thorpej struct device *parent;
122 1.7 thorpej struct cfdata *match;
123 1.7 thorpej void *aux;
124 1.1 thorpej {
125 1.7 thorpej struct hpibbus_attach_args *ha = aux;
126 1.2 thorpej
127 1.7 thorpej return (mtident(NULL, ha));
128 1.2 thorpej }
129 1.2 thorpej
130 1.2 thorpej void
131 1.7 thorpej mtattach(parent, self, aux)
132 1.7 thorpej struct device *parent, *self;
133 1.7 thorpej void *aux;
134 1.7 thorpej {
135 1.7 thorpej struct mt_softc *sc = (struct mt_softc *)self;
136 1.7 thorpej struct hpibbus_attach_args *ha = aux;
137 1.7 thorpej int unit, hpibno, slave;
138 1.7 thorpej
139 1.7 thorpej if (mtident(sc, ha) == 0) {
140 1.7 thorpej printf("\n%s: impossible!\n", sc->sc_dev.dv_xname);
141 1.7 thorpej return;
142 1.7 thorpej }
143 1.2 thorpej
144 1.7 thorpej unit = self->dv_unit;
145 1.7 thorpej hpibno = parent->dv_unit;
146 1.7 thorpej slave = ha->ha_slave;
147 1.1 thorpej
148 1.7 thorpej sc->sc_tab.b_actb = &sc->sc_tab.b_actf;
149 1.1 thorpej
150 1.1 thorpej sc->sc_hpibno = hpibno;
151 1.1 thorpej sc->sc_slave = slave;
152 1.1 thorpej sc->sc_flags = MTF_EXISTS;
153 1.6 thorpej
154 1.7 thorpej /* Initialize hpib job queue entry. */
155 1.7 thorpej sc->sc_hq.hq_softc = sc;
156 1.7 thorpej sc->sc_hq.hq_slave = sc->sc_slave;
157 1.7 thorpej sc->sc_hq.hq_start = mtstart;
158 1.7 thorpej sc->sc_hq.hq_go = mtgo;
159 1.7 thorpej sc->sc_hq.hq_intr = mtintr;
160 1.7 thorpej }
161 1.7 thorpej
162 1.7 thorpej int
163 1.7 thorpej mtident(sc, ha)
164 1.7 thorpej struct mt_softc *sc;
165 1.7 thorpej struct hpibbus_attach_args *ha;
166 1.7 thorpej {
167 1.7 thorpej int i;
168 1.7 thorpej
169 1.7 thorpej for (i = 0; i < nmtinfo; i++) {
170 1.7 thorpej if (ha->ha_id == mtinfo[i].hwid) {
171 1.7 thorpej if (sc != NULL) {
172 1.7 thorpej sc->sc_type = mtinfo[i].hwid;
173 1.7 thorpej printf(": %s tape\n", mtinfo[i].desc);
174 1.7 thorpej }
175 1.7 thorpej return (1);
176 1.7 thorpej }
177 1.7 thorpej }
178 1.7 thorpej return (0);
179 1.1 thorpej }
180 1.1 thorpej
181 1.1 thorpej /*
182 1.1 thorpej * Perform a read of "Device Status Jump" register and update the
183 1.1 thorpej * status if necessary. If status is read, the given "ecmd" is also
184 1.1 thorpej * performed, unless "ecmd" is zero. Returns DSJ value, -1 on failure
185 1.1 thorpej * and -2 on "temporary" failure.
186 1.1 thorpej */
187 1.7 thorpej int
188 1.7 thorpej mtreaddsj(sc, ecmd)
189 1.7 thorpej struct mt_softc *sc;
190 1.1 thorpej int ecmd;
191 1.1 thorpej {
192 1.1 thorpej int retval;
193 1.1 thorpej
194 1.1 thorpej if (sc->sc_flags & MTF_STATTIMEO)
195 1.1 thorpej goto getstats;
196 1.1 thorpej retval = hpibrecv(sc->sc_hpibno,
197 1.7 thorpej (sc->sc_flags & MTF_DSJTIMEO) ? -1 : sc->sc_slave,
198 1.7 thorpej MTT_DSJ, &(sc->sc_lastdsj), 1);
199 1.1 thorpej sc->sc_flags &= ~MTF_DSJTIMEO;
200 1.1 thorpej if (retval != 1) {
201 1.7 thorpej dlog(LOG_DEBUG, "%s can't hpibrecv DSJ",
202 1.7 thorpej sc->sc_dev.dv_xname);
203 1.1 thorpej if (sc->sc_recvtimeo == 0)
204 1.1 thorpej sc->sc_recvtimeo = hz;
205 1.1 thorpej if (--sc->sc_recvtimeo == 0)
206 1.1 thorpej return (-1);
207 1.1 thorpej if (retval == 0)
208 1.1 thorpej sc->sc_flags |= MTF_DSJTIMEO;
209 1.1 thorpej return (-2);
210 1.1 thorpej }
211 1.1 thorpej sc->sc_recvtimeo = 0;
212 1.1 thorpej sc->sc_statindex = 0;
213 1.7 thorpej dlog(LOG_DEBUG, "%s readdsj: 0x%x", sc->sc_dev.dv_xname,
214 1.7 thorpej sc->sc_lastdsj);
215 1.1 thorpej sc->sc_lastecmd = ecmd;
216 1.1 thorpej switch (sc->sc_lastdsj) {
217 1.1 thorpej case 0:
218 1.1 thorpej if (ecmd & MTE_DSJ_FORCE)
219 1.1 thorpej break;
220 1.1 thorpej return (0);
221 1.1 thorpej
222 1.1 thorpej case 2:
223 1.1 thorpej sc->sc_lastecmd = MTE_COMPLETE;
224 1.1 thorpej case 1:
225 1.1 thorpej break;
226 1.1 thorpej
227 1.1 thorpej default:
228 1.7 thorpej log(LOG_ERR, "%s readdsj: DSJ 0x%x\n", sc->sc_dev.dv_xname,
229 1.7 thorpej sc->sc_lastdsj);
230 1.1 thorpej return (-1);
231 1.1 thorpej }
232 1.1 thorpej getstats:
233 1.1 thorpej retval = hpibrecv(sc->sc_hpibno,
234 1.7 thorpej (sc->sc_flags & MTF_STATCONT) ? -1 : sc->sc_slave,
235 1.7 thorpej MTT_STAT, ((char *)&(sc->sc_stat)) + sc->sc_statindex,
236 1.7 thorpej sizeof(sc->sc_stat) - sc->sc_statindex);
237 1.1 thorpej sc->sc_flags &= ~(MTF_STATTIMEO | MTF_STATCONT);
238 1.1 thorpej if (retval != sizeof(sc->sc_stat) - sc->sc_statindex) {
239 1.1 thorpej if (sc->sc_recvtimeo == 0)
240 1.1 thorpej sc->sc_recvtimeo = hz;
241 1.1 thorpej if (--sc->sc_recvtimeo != 0) {
242 1.1 thorpej if (retval >= 0) {
243 1.1 thorpej sc->sc_statindex += retval;
244 1.1 thorpej sc->sc_flags |= MTF_STATCONT;
245 1.1 thorpej }
246 1.1 thorpej sc->sc_flags |= MTF_STATTIMEO;
247 1.1 thorpej return (-2);
248 1.1 thorpej }
249 1.7 thorpej log(LOG_ERR, "%s readdsj: can't read status",
250 1.7 thorpej sc->sc_dev.dv_xname);
251 1.1 thorpej return (-1);
252 1.1 thorpej }
253 1.1 thorpej sc->sc_recvtimeo = 0;
254 1.1 thorpej sc->sc_statindex = 0;
255 1.7 thorpej dlog(LOG_DEBUG, "%s readdsj: status is %x %x %x %x %x %x",
256 1.7 thorpej sc->sc_dev.dv_xname,
257 1.7 thorpej sc->sc_stat1, sc->sc_stat2, sc->sc_stat3,
258 1.7 thorpej sc->sc_stat4, sc->sc_stat5, sc->sc_stat6);
259 1.1 thorpej if (sc->sc_lastecmd)
260 1.1 thorpej (void) hpibsend(sc->sc_hpibno, sc->sc_slave,
261 1.7 thorpej MTL_ECMD, &(sc->sc_lastecmd), 1);
262 1.1 thorpej return ((int) sc->sc_lastdsj);
263 1.1 thorpej }
264 1.1 thorpej
265 1.7 thorpej int
266 1.1 thorpej mtopen(dev, flag, mode, p)
267 1.1 thorpej dev_t dev;
268 1.1 thorpej int flag, mode;
269 1.1 thorpej struct proc *p;
270 1.1 thorpej {
271 1.8 scottr int unit = UNIT(dev);
272 1.7 thorpej struct mt_softc *sc;
273 1.8 scottr int req_den;
274 1.1 thorpej int error;
275 1.1 thorpej
276 1.7 thorpej if (unit >= mt_cd.cd_ndevs ||
277 1.7 thorpej (sc = mt_cd.cd_devs[unit]) == NULL ||
278 1.7 thorpej (sc->sc_flags & MTF_EXISTS) == 0)
279 1.1 thorpej return (ENXIO);
280 1.7 thorpej
281 1.7 thorpej dlog(LOG_DEBUG, "%s open: flags 0x%x", sc->sc_dev.dv_xname,
282 1.7 thorpej sc->sc_flags);
283 1.1 thorpej if (sc->sc_flags & MTF_OPEN)
284 1.1 thorpej return (EBUSY);
285 1.1 thorpej sc->sc_flags |= MTF_OPEN;
286 1.1 thorpej sc->sc_ttyp = tprintf_open(p);
287 1.1 thorpej if ((sc->sc_flags & MTF_ALIVE) == 0) {
288 1.1 thorpej error = mtcommand(dev, MTRESET, 0);
289 1.1 thorpej if (error != 0 || (sc->sc_flags & MTF_ALIVE) == 0)
290 1.1 thorpej goto errout;
291 1.1 thorpej if ((sc->sc_stat1 & (SR1_BOT | SR1_ONLINE)) == SR1_ONLINE)
292 1.1 thorpej (void) mtcommand(dev, MTREW, 0);
293 1.1 thorpej }
294 1.1 thorpej for (;;) {
295 1.1 thorpej if ((error = mtcommand(dev, MTNOP, 0)) != 0)
296 1.1 thorpej goto errout;
297 1.1 thorpej if (!(sc->sc_flags & MTF_REW))
298 1.1 thorpej break;
299 1.7 thorpej if (tsleep((caddr_t) &lbolt, PCATCH | (PZERO + 1),
300 1.7 thorpej "mt", 0) != 0) {
301 1.1 thorpej error = EINTR;
302 1.1 thorpej goto errout;
303 1.1 thorpej }
304 1.1 thorpej }
305 1.1 thorpej if ((flag & FWRITE) && (sc->sc_stat1 & SR1_RO)) {
306 1.1 thorpej error = EROFS;
307 1.1 thorpej goto errout;
308 1.1 thorpej }
309 1.1 thorpej if (!(sc->sc_stat1 & SR1_ONLINE)) {
310 1.7 thorpej uprintf("%s: not online\n", sc->sc_dev.dv_xname);
311 1.1 thorpej error = EIO;
312 1.1 thorpej goto errout;
313 1.1 thorpej }
314 1.1 thorpej /*
315 1.1 thorpej * Select density:
316 1.1 thorpej * - find out what density the drive is set to
317 1.1 thorpej * (i.e. the density of the current tape)
318 1.1 thorpej * - if we are going to write
319 1.1 thorpej * - if we're not at the beginning of the tape
320 1.1 thorpej * - complain if we want to change densities
321 1.1 thorpej * - otherwise, select the mtcommand to set the density
322 1.1 thorpej *
323 1.1 thorpej * If the drive doesn't support it then don't change the recorded
324 1.1 thorpej * density.
325 1.1 thorpej *
326 1.1 thorpej * The original MOREbsd code had these additional conditions
327 1.1 thorpej * for the mid-tape change
328 1.1 thorpej *
329 1.1 thorpej * req_den != T_BADBPI &&
330 1.1 thorpej * sc->sc_density != T_6250BPI
331 1.1 thorpej *
332 1.1 thorpej * which suggests that it would be possible to write multiple
333 1.1 thorpej * densities if req_den == T_BAD_BPI or the current tape
334 1.1 thorpej * density was 6250. Testing of our 7980 suggests that the
335 1.1 thorpej * device cannot change densities mid-tape.
336 1.1 thorpej *
337 1.1 thorpej * ajv (at) comp.vuw.ac.nz
338 1.1 thorpej */
339 1.1 thorpej sc->sc_density = (sc->sc_stat2 & SR2_6250) ? T_6250BPI : (
340 1.1 thorpej (sc->sc_stat3 & SR3_1600) ? T_1600BPI : (
341 1.1 thorpej (sc->sc_stat3 & SR3_800) ? T_800BPI : -1));
342 1.1 thorpej req_den = (dev & T_DENSEL);
343 1.1 thorpej
344 1.1 thorpej if (flag & FWRITE) {
345 1.1 thorpej if (!(sc->sc_stat1 & SR1_BOT)) {
346 1.1 thorpej if (sc->sc_density != req_den) {
347 1.2 thorpej uprintf("%s: can't change density mid-tape\n",
348 1.7 thorpej sc->sc_dev.dv_xname);
349 1.1 thorpej error = EIO;
350 1.1 thorpej goto errout;
351 1.1 thorpej }
352 1.1 thorpej }
353 1.1 thorpej else {
354 1.1 thorpej int mtset_density =
355 1.1 thorpej (req_den == T_800BPI ? MTSET800BPI : (
356 1.1 thorpej req_den == T_1600BPI ? MTSET1600BPI : (
357 1.1 thorpej req_den == T_6250BPI ? MTSET6250BPI : (
358 1.1 thorpej sc->sc_type == MT7980ID
359 1.1 thorpej ? MTSET6250DC
360 1.1 thorpej : MTSET6250BPI))));
361 1.1 thorpej if (mtcommand(dev, mtset_density, 0) == 0)
362 1.1 thorpej sc->sc_density = req_den;
363 1.1 thorpej }
364 1.1 thorpej }
365 1.1 thorpej return (0);
366 1.1 thorpej errout:
367 1.1 thorpej sc->sc_flags &= ~MTF_OPEN;
368 1.1 thorpej return (error);
369 1.1 thorpej }
370 1.1 thorpej
371 1.7 thorpej int
372 1.7 thorpej mtclose(dev, flag, fmt, p)
373 1.1 thorpej dev_t dev;
374 1.7 thorpej int flag, fmt;
375 1.7 thorpej struct proc *p;
376 1.1 thorpej {
377 1.7 thorpej struct mt_softc *sc = mt_cd.cd_devs[UNIT(dev)];
378 1.1 thorpej
379 1.1 thorpej if (sc->sc_flags & MTF_WRT) {
380 1.1 thorpej (void) mtcommand(dev, MTWEOF, 2);
381 1.1 thorpej (void) mtcommand(dev, MTBSF, 0);
382 1.1 thorpej }
383 1.1 thorpej if ((minor(dev) & T_NOREWIND) == 0)
384 1.1 thorpej (void) mtcommand(dev, MTREW, 0);
385 1.1 thorpej sc->sc_flags &= ~MTF_OPEN;
386 1.1 thorpej tprintf_close(sc->sc_ttyp);
387 1.1 thorpej return (0);
388 1.1 thorpej }
389 1.1 thorpej
390 1.7 thorpej int
391 1.1 thorpej mtcommand(dev, cmd, cnt)
392 1.1 thorpej dev_t dev;
393 1.1 thorpej int cmd;
394 1.1 thorpej int cnt;
395 1.1 thorpej {
396 1.7 thorpej struct mt_softc *sc = mt_cd.cd_devs[UNIT(dev)];
397 1.7 thorpej struct buf *bp = &sc->sc_bufstore;
398 1.1 thorpej int error = 0;
399 1.1 thorpej
400 1.1 thorpej #if 1
401 1.1 thorpej if (bp->b_flags & B_BUSY)
402 1.1 thorpej return (EBUSY);
403 1.1 thorpej #endif
404 1.1 thorpej bp->b_cmd = cmd;
405 1.1 thorpej bp->b_dev = dev;
406 1.1 thorpej do {
407 1.1 thorpej bp->b_flags = B_BUSY | B_CMD;
408 1.1 thorpej mtstrategy(bp);
409 1.1 thorpej iowait(bp);
410 1.1 thorpej if (bp->b_flags & B_ERROR) {
411 1.1 thorpej error = (int) (unsigned) bp->b_error;
412 1.1 thorpej break;
413 1.1 thorpej }
414 1.1 thorpej } while (--cnt > 0);
415 1.1 thorpej #if 0
416 1.1 thorpej bp->b_flags = 0 /*&= ~B_BUSY*/;
417 1.1 thorpej #else
418 1.1 thorpej bp->b_flags &= ~B_BUSY;
419 1.1 thorpej #endif
420 1.1 thorpej return (error);
421 1.1 thorpej }
422 1.1 thorpej
423 1.1 thorpej /*
424 1.1 thorpej * Only thing to check here is for legal record lengths (writes only).
425 1.1 thorpej */
426 1.1 thorpej void
427 1.1 thorpej mtstrategy(bp)
428 1.8 scottr struct buf *bp;
429 1.1 thorpej {
430 1.8 scottr struct mt_softc *sc;
431 1.8 scottr struct buf *dp;
432 1.8 scottr int unit;
433 1.8 scottr int s;
434 1.1 thorpej
435 1.1 thorpej unit = UNIT(bp->b_dev);
436 1.7 thorpej sc = mt_cd.cd_devs[unit];
437 1.7 thorpej dlog(LOG_DEBUG, "%s strategy", sc->sc_dev.dv_xname);
438 1.1 thorpej if ((bp->b_flags & (B_CMD | B_READ)) == 0) {
439 1.1 thorpej #define WRITE_BITS_IGNORED 8
440 1.1 thorpej #if 0
441 1.1 thorpej if (bp->b_bcount & ((1 << WRITE_BITS_IGNORED) - 1)) {
442 1.1 thorpej tprintf(sc->sc_ttyp,
443 1.2 thorpej "%s: write record must be multiple of %d\n",
444 1.7 thorpej sc->sc_dev.dv_xname, 1 << WRITE_BITS_IGNORED);
445 1.1 thorpej goto error;
446 1.1 thorpej }
447 1.1 thorpej #endif
448 1.1 thorpej s = 16 * 1024;
449 1.1 thorpej if (sc->sc_stat2 & SR2_LONGREC) {
450 1.1 thorpej switch (sc->sc_density) {
451 1.1 thorpej case T_1600BPI:
452 1.1 thorpej s = 32 * 1024;
453 1.1 thorpej break;
454 1.1 thorpej
455 1.1 thorpej case T_6250BPI:
456 1.1 thorpej case T_BADBPI:
457 1.1 thorpej s = 60 * 1024;
458 1.1 thorpej break;
459 1.1 thorpej }
460 1.1 thorpej }
461 1.1 thorpej if (bp->b_bcount > s) {
462 1.1 thorpej tprintf(sc->sc_ttyp,
463 1.8 scottr "%s: write record (%ld) too big: limit (%d)\n",
464 1.7 thorpej sc->sc_dev.dv_xname, bp->b_bcount, s);
465 1.8 scottr #if 0 /* XXX see above */
466 1.1 thorpej error:
467 1.8 scottr #endif
468 1.1 thorpej bp->b_flags |= B_ERROR;
469 1.1 thorpej bp->b_error = EIO;
470 1.1 thorpej iodone(bp);
471 1.1 thorpej return;
472 1.1 thorpej }
473 1.1 thorpej }
474 1.7 thorpej dp = &sc->sc_tab;
475 1.1 thorpej bp->b_actf = NULL;
476 1.1 thorpej s = splbio();
477 1.1 thorpej bp->b_actb = dp->b_actb;
478 1.1 thorpej *dp->b_actb = bp;
479 1.1 thorpej dp->b_actb = &bp->b_actf;
480 1.1 thorpej if (dp->b_active == 0) {
481 1.1 thorpej dp->b_active = 1;
482 1.7 thorpej mtustart(sc);
483 1.1 thorpej }
484 1.1 thorpej splx(s);
485 1.1 thorpej }
486 1.1 thorpej
487 1.1 thorpej void
488 1.7 thorpej mtustart(sc)
489 1.7 thorpej struct mt_softc *sc;
490 1.1 thorpej {
491 1.1 thorpej
492 1.7 thorpej dlog(LOG_DEBUG, "%s ustart", sc->sc_dev.dv_xname);
493 1.7 thorpej if (hpibreq(sc->sc_dev.dv_parent, &sc->sc_hq))
494 1.7 thorpej mtstart(sc);
495 1.1 thorpej }
496 1.1 thorpej
497 1.1 thorpej void
498 1.3 thorpej spl_mtintr(arg)
499 1.3 thorpej void *arg;
500 1.1 thorpej {
501 1.3 thorpej struct mt_softc *sc = arg;
502 1.1 thorpej int s = splbio();
503 1.1 thorpej
504 1.3 thorpej hpibppclear(sc->sc_hpibno);
505 1.3 thorpej mtintr(sc);
506 1.1 thorpej (void) splx(s);
507 1.1 thorpej }
508 1.1 thorpej
509 1.1 thorpej void
510 1.7 thorpej spl_mtstart(arg)
511 1.7 thorpej void *arg;
512 1.1 thorpej {
513 1.1 thorpej int s = splbio();
514 1.1 thorpej
515 1.7 thorpej mtstart(arg);
516 1.1 thorpej (void) splx(s);
517 1.1 thorpej }
518 1.1 thorpej
519 1.1 thorpej void
520 1.7 thorpej mtstart(arg)
521 1.7 thorpej void *arg;
522 1.1 thorpej {
523 1.7 thorpej struct mt_softc *sc = arg;
524 1.8 scottr struct buf *bp, *dp;
525 1.1 thorpej short cmdcount = 1;
526 1.1 thorpej u_char cmdbuf[2];
527 1.1 thorpej
528 1.7 thorpej dlog(LOG_DEBUG, "%s start", sc->sc_dev.dv_xname);
529 1.1 thorpej sc->sc_flags &= ~MTF_WRT;
530 1.7 thorpej bp = sc->sc_tab.b_actf;
531 1.1 thorpej if ((sc->sc_flags & MTF_ALIVE) == 0 &&
532 1.1 thorpej ((bp->b_flags & B_CMD) == 0 || bp->b_cmd != MTRESET))
533 1.1 thorpej goto fatalerror;
534 1.1 thorpej
535 1.1 thorpej if (sc->sc_flags & MTF_REW) {
536 1.1 thorpej if (!hpibpptest(sc->sc_hpibno, sc->sc_slave))
537 1.1 thorpej goto stillrew;
538 1.7 thorpej switch (mtreaddsj(sc, MTE_DSJ_FORCE|MTE_COMPLETE|MTE_IDLE)) {
539 1.1 thorpej case 0:
540 1.1 thorpej case 1:
541 1.1 thorpej stillrew:
542 1.1 thorpej if ((sc->sc_stat1 & SR1_BOT) ||
543 1.1 thorpej !(sc->sc_stat1 & SR1_ONLINE)) {
544 1.1 thorpej sc->sc_flags &= ~MTF_REW;
545 1.1 thorpej break;
546 1.1 thorpej }
547 1.1 thorpej case -2:
548 1.1 thorpej /*
549 1.1 thorpej * -2 means "timeout" reading DSJ, which is probably
550 1.1 thorpej * temporary. This is considered OK when doing a NOP,
551 1.1 thorpej * but not otherwise.
552 1.1 thorpej */
553 1.1 thorpej if (sc->sc_flags & (MTF_DSJTIMEO | MTF_STATTIMEO)) {
554 1.7 thorpej timeout(spl_mtstart, sc, hz >> 5);
555 1.1 thorpej return;
556 1.1 thorpej }
557 1.1 thorpej case 2:
558 1.1 thorpej if (bp->b_cmd != MTNOP || !(bp->b_flags & B_CMD)) {
559 1.1 thorpej bp->b_error = EBUSY;
560 1.1 thorpej goto errdone;
561 1.1 thorpej }
562 1.1 thorpej goto done;
563 1.1 thorpej
564 1.1 thorpej default:
565 1.1 thorpej goto fatalerror;
566 1.1 thorpej }
567 1.1 thorpej }
568 1.1 thorpej if (bp->b_flags & B_CMD) {
569 1.1 thorpej if (sc->sc_flags & MTF_PASTEOT) {
570 1.1 thorpej switch(bp->b_cmd) {
571 1.1 thorpej case MTFSF:
572 1.1 thorpej case MTWEOF:
573 1.1 thorpej case MTFSR:
574 1.1 thorpej bp->b_error = ENOSPC;
575 1.1 thorpej goto errdone;
576 1.1 thorpej
577 1.1 thorpej case MTBSF:
578 1.1 thorpej case MTOFFL:
579 1.1 thorpej case MTBSR:
580 1.1 thorpej case MTREW:
581 1.1 thorpej sc->sc_flags &= ~(MTF_PASTEOT | MTF_ATEOT);
582 1.1 thorpej break;
583 1.1 thorpej }
584 1.1 thorpej }
585 1.1 thorpej switch(bp->b_cmd) {
586 1.1 thorpej case MTFSF:
587 1.1 thorpej if (sc->sc_flags & MTF_HITEOF)
588 1.1 thorpej goto done;
589 1.1 thorpej cmdbuf[0] = MTTC_FSF;
590 1.1 thorpej break;
591 1.1 thorpej
592 1.1 thorpej case MTBSF:
593 1.1 thorpej if (sc->sc_flags & MTF_HITBOF)
594 1.1 thorpej goto done;
595 1.1 thorpej cmdbuf[0] = MTTC_BSF;
596 1.1 thorpej break;
597 1.1 thorpej
598 1.1 thorpej case MTOFFL:
599 1.1 thorpej sc->sc_flags |= MTF_REW;
600 1.1 thorpej cmdbuf[0] = MTTC_REWOFF;
601 1.1 thorpej break;
602 1.1 thorpej
603 1.1 thorpej case MTWEOF:
604 1.1 thorpej cmdbuf[0] = MTTC_WFM;
605 1.1 thorpej break;
606 1.1 thorpej
607 1.1 thorpej case MTBSR:
608 1.1 thorpej cmdbuf[0] = MTTC_BSR;
609 1.1 thorpej break;
610 1.1 thorpej
611 1.1 thorpej case MTFSR:
612 1.1 thorpej cmdbuf[0] = MTTC_FSR;
613 1.1 thorpej break;
614 1.1 thorpej
615 1.1 thorpej case MTREW:
616 1.1 thorpej sc->sc_flags |= MTF_REW;
617 1.1 thorpej cmdbuf[0] = MTTC_REW;
618 1.1 thorpej break;
619 1.1 thorpej
620 1.1 thorpej case MTNOP:
621 1.1 thorpej /*
622 1.1 thorpej * NOP is supposed to set status bits.
623 1.1 thorpej * Force readdsj to do it.
624 1.1 thorpej */
625 1.7 thorpej switch (mtreaddsj(sc,
626 1.7 thorpej MTE_DSJ_FORCE | MTE_COMPLETE | MTE_IDLE)) {
627 1.1 thorpej default:
628 1.1 thorpej goto done;
629 1.1 thorpej
630 1.1 thorpej case -1:
631 1.1 thorpej /*
632 1.1 thorpej * If this fails, perform a device clear
633 1.1 thorpej * to fix any protocol problems and (most
634 1.1 thorpej * likely) get the status.
635 1.1 thorpej */
636 1.1 thorpej bp->b_cmd = MTRESET;
637 1.1 thorpej break;
638 1.1 thorpej
639 1.1 thorpej case -2:
640 1.7 thorpej timeout(spl_mtstart, sc, hz >> 5);
641 1.1 thorpej return;
642 1.1 thorpej }
643 1.1 thorpej
644 1.1 thorpej case MTRESET:
645 1.1 thorpej /*
646 1.1 thorpej * 1) selected device clear (send with "-2" secondary)
647 1.1 thorpej * 2) set timeout, then wait for "service request"
648 1.1 thorpej * 3) interrupt will read DSJ (and END COMPLETE-IDLE)
649 1.1 thorpej */
650 1.1 thorpej if (hpibsend(sc->sc_hpibno, sc->sc_slave, -2, NULL, 0)){
651 1.7 thorpej log(LOG_ERR, "%s can't reset",
652 1.7 thorpej sc->sc_dev.dv_xname);
653 1.1 thorpej goto fatalerror;
654 1.1 thorpej }
655 1.7 thorpej timeout(spl_mtintr, sc, 4 * hz);
656 1.8 scottr hpibawait(sc->sc_hpibno);
657 1.1 thorpej return;
658 1.1 thorpej
659 1.1 thorpej case MTSET800BPI:
660 1.1 thorpej cmdbuf[0] = MTTC_800;
661 1.1 thorpej break;
662 1.1 thorpej
663 1.1 thorpej case MTSET1600BPI:
664 1.1 thorpej cmdbuf[0] = MTTC_1600;
665 1.1 thorpej break;
666 1.1 thorpej
667 1.1 thorpej case MTSET6250BPI:
668 1.1 thorpej cmdbuf[0] = MTTC_6250;
669 1.1 thorpej break;
670 1.1 thorpej
671 1.1 thorpej case MTSET6250DC:
672 1.1 thorpej cmdbuf[0] = MTTC_DC6250;
673 1.1 thorpej break;
674 1.1 thorpej }
675 1.1 thorpej } else {
676 1.1 thorpej if (sc->sc_flags & MTF_PASTEOT) {
677 1.1 thorpej bp->b_error = ENOSPC;
678 1.1 thorpej goto errdone;
679 1.1 thorpej }
680 1.1 thorpej if (bp->b_flags & B_READ) {
681 1.1 thorpej sc->sc_flags |= MTF_IO;
682 1.1 thorpej cmdbuf[0] = MTTC_READ;
683 1.1 thorpej } else {
684 1.1 thorpej sc->sc_flags |= MTF_WRT | MTF_IO;
685 1.1 thorpej cmdbuf[0] = MTTC_WRITE;
686 1.1 thorpej cmdbuf[1] = (bp->b_bcount + ((1 << WRITE_BITS_IGNORED) - 1)) >> WRITE_BITS_IGNORED;
687 1.1 thorpej cmdcount = 2;
688 1.1 thorpej }
689 1.1 thorpej }
690 1.1 thorpej if (hpibsend(sc->sc_hpibno, sc->sc_slave, MTL_TCMD, cmdbuf, cmdcount)
691 1.1 thorpej == cmdcount) {
692 1.1 thorpej if (sc->sc_flags & MTF_REW)
693 1.1 thorpej goto done;
694 1.1 thorpej hpibawait(sc->sc_hpibno);
695 1.1 thorpej return;
696 1.1 thorpej }
697 1.1 thorpej fatalerror:
698 1.1 thorpej /*
699 1.1 thorpej * If anything fails, the drive is probably hosed, so mark it not
700 1.1 thorpej * "ALIVE" (but it EXISTS and is OPEN or we wouldn't be here, and
701 1.1 thorpej * if, last we heard, it was REWinding, remember that).
702 1.1 thorpej */
703 1.1 thorpej sc->sc_flags &= MTF_EXISTS | MTF_OPEN | MTF_REW;
704 1.1 thorpej bp->b_error = EIO;
705 1.1 thorpej errdone:
706 1.1 thorpej bp->b_flags |= B_ERROR;
707 1.1 thorpej done:
708 1.1 thorpej sc->sc_flags &= ~(MTF_HITEOF | MTF_HITBOF);
709 1.1 thorpej iodone(bp);
710 1.8 scottr if ((dp = bp->b_actf))
711 1.1 thorpej dp->b_actb = bp->b_actb;
712 1.1 thorpej else
713 1.7 thorpej sc->sc_tab.b_actb = bp->b_actb;
714 1.1 thorpej *bp->b_actb = dp;
715 1.7 thorpej hpibfree(sc->sc_dev.dv_parent, &sc->sc_hq);
716 1.1 thorpej if ((bp = dp) == NULL)
717 1.7 thorpej sc->sc_tab.b_active = 0;
718 1.1 thorpej else
719 1.7 thorpej mtustart(sc);
720 1.1 thorpej }
721 1.1 thorpej
722 1.1 thorpej /*
723 1.1 thorpej * The Utah code had a bug which meant that the driver was unable to read.
724 1.1 thorpej * "rw" was initialized to bp->b_flags & B_READ before "bp" was initialized.
725 1.1 thorpej * -- ajv (at) comp.vuw.ac.nz
726 1.1 thorpej */
727 1.1 thorpej void
728 1.7 thorpej mtgo(arg)
729 1.7 thorpej void *arg;
730 1.1 thorpej {
731 1.7 thorpej struct mt_softc *sc = arg;
732 1.7 thorpej struct buf *bp;
733 1.1 thorpej int rw;
734 1.1 thorpej
735 1.7 thorpej dlog(LOG_DEBUG, "%s go", sc->sc_dev.dv_xname);
736 1.7 thorpej bp = sc->sc_tab.b_actf;
737 1.1 thorpej rw = bp->b_flags & B_READ;
738 1.1 thorpej hpibgo(sc->sc_hpibno, sc->sc_slave, rw ? MTT_READ : MTL_WRITE,
739 1.7 thorpej bp->b_un.b_addr, bp->b_bcount, rw, rw != 0);
740 1.1 thorpej }
741 1.1 thorpej
742 1.7 thorpej void
743 1.3 thorpej mtintr(arg)
744 1.3 thorpej void *arg;
745 1.1 thorpej {
746 1.7 thorpej struct mt_softc *sc = arg;
747 1.7 thorpej struct buf *bp, *dp;
748 1.7 thorpej int i;
749 1.7 thorpej u_char cmdbuf[4];
750 1.1 thorpej
751 1.7 thorpej bp = sc->sc_tab.b_actf;
752 1.1 thorpej if (bp == NULL) {
753 1.7 thorpej log(LOG_ERR, "%s intr: bp == NULL", sc->sc_dev.dv_xname);
754 1.1 thorpej return;
755 1.1 thorpej }
756 1.7 thorpej
757 1.7 thorpej dlog(LOG_DEBUG, "%s intr", sc->sc_dev.dv_xname);
758 1.7 thorpej
759 1.1 thorpej /*
760 1.1 thorpej * Some operation completed. Read status bytes and report errors.
761 1.1 thorpej * Clear EOF flags here `cause they're set once on specific conditions
762 1.1 thorpej * below when a command succeeds.
763 1.1 thorpej * A DSJ of 2 always means keep waiting. If the command was READ
764 1.1 thorpej * (and we're in data DMA phase) stop data transfer first.
765 1.1 thorpej */
766 1.1 thorpej sc->sc_flags &= ~(MTF_HITEOF | MTF_HITBOF);
767 1.1 thorpej if ((bp->b_flags & (B_CMD|B_READ)) == B_READ &&
768 1.1 thorpej !(sc->sc_flags & (MTF_IO | MTF_STATTIMEO | MTF_DSJTIMEO))){
769 1.1 thorpej cmdbuf[0] = MTE_STOP;
770 1.1 thorpej (void) hpibsend(sc->sc_hpibno, sc->sc_slave, MTL_ECMD,cmdbuf,1);
771 1.1 thorpej }
772 1.7 thorpej switch (mtreaddsj(sc, 0)) {
773 1.1 thorpej case 0:
774 1.1 thorpej break;
775 1.1 thorpej
776 1.1 thorpej case 1:
777 1.1 thorpej /*
778 1.1 thorpej * If we're in the middle of a READ/WRITE and have yet to
779 1.1 thorpej * start the data transfer, a DSJ of one should terminate it.
780 1.1 thorpej */
781 1.1 thorpej sc->sc_flags &= ~MTF_IO;
782 1.1 thorpej break;
783 1.1 thorpej
784 1.1 thorpej case 2:
785 1.1 thorpej (void) hpibawait(sc->sc_hpibno);
786 1.1 thorpej return;
787 1.1 thorpej
788 1.1 thorpej case -2:
789 1.1 thorpej /*
790 1.1 thorpej * -2 means that the drive failed to respond quickly enough
791 1.1 thorpej * to the request for DSJ. It's probably just "busy" figuring
792 1.1 thorpej * it out and will know in a little bit...
793 1.1 thorpej */
794 1.7 thorpej timeout(spl_mtintr, sc, hz >> 5);
795 1.1 thorpej return;
796 1.1 thorpej
797 1.1 thorpej default:
798 1.7 thorpej log(LOG_ERR, "%s intr: can't get drive stat",
799 1.7 thorpej sc->sc_dev.dv_xname);
800 1.1 thorpej goto error;
801 1.1 thorpej }
802 1.1 thorpej if (sc->sc_stat1 & (SR1_ERR | SR1_REJECT)) {
803 1.1 thorpej i = sc->sc_stat4 & SR4_ERCLMASK;
804 1.7 thorpej log(LOG_ERR, "%s: %s error, retry %d, SR2/3 %x/%x, code %d",
805 1.7 thorpej sc->sc_dev.dv_xname, i == SR4_DEVICE ? "device" :
806 1.1 thorpej (i == SR4_PROTOCOL ? "protocol" :
807 1.1 thorpej (i == SR4_SELFTEST ? "selftest" : "unknown")),
808 1.1 thorpej sc->sc_stat4 & SR4_RETRYMASK, sc->sc_stat2,
809 1.1 thorpej sc->sc_stat3, sc->sc_stat5);
810 1.1 thorpej
811 1.1 thorpej if ((bp->b_flags & B_CMD) && bp->b_cmd == MTRESET)
812 1.7 thorpej untimeout(spl_mtintr, sc);
813 1.1 thorpej if (sc->sc_stat3 & SR3_POWERUP)
814 1.1 thorpej sc->sc_flags &= MTF_OPEN | MTF_EXISTS;
815 1.1 thorpej goto error;
816 1.1 thorpej }
817 1.1 thorpej /*
818 1.1 thorpej * Report and clear any soft errors.
819 1.1 thorpej */
820 1.1 thorpej if (sc->sc_stat1 & SR1_SOFTERR) {
821 1.2 thorpej log(LOG_WARNING, "%s: soft error, retry %d\n",
822 1.7 thorpej sc->sc_dev.dv_xname, sc->sc_stat4 & SR4_RETRYMASK);
823 1.1 thorpej sc->sc_stat1 &= ~SR1_SOFTERR;
824 1.1 thorpej }
825 1.1 thorpej /*
826 1.1 thorpej * We've initiated a read or write, but haven't actually started to
827 1.1 thorpej * DMA the data yet. At this point, the drive's ready.
828 1.1 thorpej */
829 1.1 thorpej if (sc->sc_flags & MTF_IO) {
830 1.1 thorpej sc->sc_flags &= ~MTF_IO;
831 1.1 thorpej if (hpibustart(sc->sc_hpibno))
832 1.7 thorpej mtgo(sc);
833 1.1 thorpej return;
834 1.1 thorpej }
835 1.1 thorpej /*
836 1.1 thorpej * Check for End Of Tape - we're allowed to hit EOT and then write (or
837 1.1 thorpej * read) one more record. If we get here and have not already hit EOT,
838 1.1 thorpej * return ENOSPC to inform the process that it's hit it. If we get
839 1.1 thorpej * here and HAVE already hit EOT, don't allow any more operations that
840 1.1 thorpej * move the tape forward.
841 1.1 thorpej */
842 1.1 thorpej if (sc->sc_stat1 & SR1_EOT) {
843 1.1 thorpej if (sc->sc_flags & MTF_ATEOT)
844 1.1 thorpej sc->sc_flags |= MTF_PASTEOT;
845 1.1 thorpej else {
846 1.1 thorpej bp->b_flags |= B_ERROR;
847 1.1 thorpej bp->b_error = ENOSPC;
848 1.1 thorpej sc->sc_flags |= MTF_ATEOT;
849 1.1 thorpej }
850 1.1 thorpej }
851 1.1 thorpej /*
852 1.1 thorpej * If a motion command was being executed, check for Tape Marks.
853 1.1 thorpej * If we were doing data, make sure we got the right amount, and
854 1.1 thorpej * check for hitting tape marks on reads.
855 1.1 thorpej */
856 1.1 thorpej if (bp->b_flags & B_CMD) {
857 1.1 thorpej if (sc->sc_stat1 & SR1_EOF) {
858 1.1 thorpej if (bp->b_cmd == MTFSR)
859 1.1 thorpej sc->sc_flags |= MTF_HITEOF;
860 1.1 thorpej if (bp->b_cmd == MTBSR)
861 1.1 thorpej sc->sc_flags |= MTF_HITBOF;
862 1.1 thorpej }
863 1.1 thorpej if (bp->b_cmd == MTRESET) {
864 1.7 thorpej untimeout(spl_mtintr, sc);
865 1.1 thorpej sc->sc_flags |= MTF_ALIVE;
866 1.1 thorpej }
867 1.1 thorpej } else {
868 1.1 thorpej i = hpibrecv(sc->sc_hpibno, sc->sc_slave, MTT_BCNT, cmdbuf, 2);
869 1.1 thorpej if (i != 2) {
870 1.8 scottr log(LOG_ERR, "%s intr: can't get xfer length\n",
871 1.8 scottr sc->sc_dev.dv_xname);
872 1.1 thorpej goto error;
873 1.1 thorpej }
874 1.1 thorpej i = (int) *((u_short *) cmdbuf);
875 1.1 thorpej if (i <= bp->b_bcount) {
876 1.1 thorpej if (i == 0)
877 1.1 thorpej sc->sc_flags |= MTF_HITEOF;
878 1.1 thorpej bp->b_resid = bp->b_bcount - i;
879 1.8 scottr dlog(LOG_DEBUG, "%s intr: bcount %ld, resid %ld",
880 1.7 thorpej sc->sc_dev.dv_xname, bp->b_bcount, bp->b_resid);
881 1.1 thorpej } else {
882 1.1 thorpej tprintf(sc->sc_ttyp,
883 1.8 scottr "%s: record (%d) larger than wanted (%ld)\n",
884 1.7 thorpej sc->sc_dev.dv_xname, i, bp->b_bcount);
885 1.1 thorpej error:
886 1.1 thorpej sc->sc_flags &= ~MTF_IO;
887 1.1 thorpej bp->b_error = EIO;
888 1.1 thorpej bp->b_flags |= B_ERROR;
889 1.1 thorpej }
890 1.1 thorpej }
891 1.1 thorpej /*
892 1.1 thorpej * The operation is completely done.
893 1.1 thorpej * Let the drive know with an END command.
894 1.1 thorpej */
895 1.1 thorpej cmdbuf[0] = MTE_COMPLETE | MTE_IDLE;
896 1.1 thorpej (void) hpibsend(sc->sc_hpibno, sc->sc_slave, MTL_ECMD, cmdbuf, 1);
897 1.1 thorpej bp->b_flags &= ~B_CMD;
898 1.1 thorpej iodone(bp);
899 1.8 scottr if ((dp = bp->b_actf))
900 1.1 thorpej dp->b_actb = bp->b_actb;
901 1.1 thorpej else
902 1.7 thorpej sc->sc_tab.b_actb = bp->b_actb;
903 1.1 thorpej *bp->b_actb = dp;
904 1.7 thorpej hpibfree(sc->sc_dev.dv_parent, &sc->sc_hq);
905 1.1 thorpej #if 0
906 1.7 thorpej if (bp /*sc->sc_tab.b_actf*/ == NULL)
907 1.1 thorpej #else
908 1.7 thorpej if (sc->sc_tab.b_actf == NULL)
909 1.1 thorpej #endif
910 1.7 thorpej sc->sc_tab.b_active = 0;
911 1.1 thorpej else
912 1.7 thorpej mtustart(sc);
913 1.1 thorpej }
914 1.1 thorpej
915 1.7 thorpej int
916 1.7 thorpej mtread(dev, uio, flags)
917 1.1 thorpej dev_t dev;
918 1.1 thorpej struct uio *uio;
919 1.7 thorpej int flags;
920 1.1 thorpej {
921 1.7 thorpej struct mt_softc *sc = mt_cd.cd_devs[UNIT(dev)];
922 1.7 thorpej
923 1.7 thorpej return(physio(mtstrategy, &sc->sc_bufstore,
924 1.7 thorpej dev, B_READ, minphys, uio));
925 1.1 thorpej }
926 1.1 thorpej
927 1.7 thorpej int
928 1.7 thorpej mtwrite(dev, uio, flags)
929 1.1 thorpej dev_t dev;
930 1.1 thorpej struct uio *uio;
931 1.7 thorpej int flags;
932 1.1 thorpej {
933 1.7 thorpej struct mt_softc *sc = mt_cd.cd_devs[UNIT(dev)];
934 1.7 thorpej
935 1.7 thorpej return(physio(mtstrategy, &sc->sc_bufstore,
936 1.7 thorpej dev, B_WRITE, minphys, uio));
937 1.1 thorpej }
938 1.1 thorpej
939 1.7 thorpej int
940 1.7 thorpej mtioctl(dev, cmd, data, flag, p)
941 1.1 thorpej dev_t dev;
942 1.1 thorpej u_long cmd;
943 1.1 thorpej caddr_t data;
944 1.1 thorpej int flag;
945 1.7 thorpej struct proc *p;
946 1.1 thorpej {
947 1.8 scottr struct mtop *op;
948 1.1 thorpej int cnt;
949 1.1 thorpej
950 1.1 thorpej switch (cmd) {
951 1.1 thorpej case MTIOCTOP:
952 1.1 thorpej op = (struct mtop *)data;
953 1.1 thorpej switch(op->mt_op) {
954 1.1 thorpej case MTWEOF:
955 1.1 thorpej case MTFSF:
956 1.1 thorpej case MTBSR:
957 1.1 thorpej case MTBSF:
958 1.1 thorpej case MTFSR:
959 1.1 thorpej cnt = op->mt_count;
960 1.1 thorpej break;
961 1.1 thorpej
962 1.1 thorpej case MTOFFL:
963 1.1 thorpej case MTREW:
964 1.1 thorpej case MTNOP:
965 1.1 thorpej cnt = 0;
966 1.1 thorpej break;
967 1.1 thorpej
968 1.1 thorpej default:
969 1.1 thorpej return (EINVAL);
970 1.1 thorpej }
971 1.1 thorpej return (mtcommand(dev, op->mt_op, cnt));
972 1.1 thorpej
973 1.1 thorpej case MTIOCGET:
974 1.1 thorpej break;
975 1.1 thorpej
976 1.1 thorpej default:
977 1.1 thorpej return (EINVAL);
978 1.1 thorpej }
979 1.1 thorpej return (0);
980 1.1 thorpej }
981 1.1 thorpej
982 1.1 thorpej /*ARGSUSED*/
983 1.7 thorpej int
984 1.7 thorpej mtdump(dev, blkno, va, size)
985 1.1 thorpej dev_t dev;
986 1.7 thorpej daddr_t blkno;
987 1.7 thorpej caddr_t va;
988 1.7 thorpej size_t size;
989 1.1 thorpej {
990 1.7 thorpej return (ENODEV);
991 1.1 thorpej }
992