mscp_tape.c revision 1.31.12.2 1 1.31.12.2 ad /* $NetBSD: mscp_tape.c,v 1.31.12.2 2007/07/29 12:15:44 ad Exp $ */
2 1.31.12.2 ad /*
3 1.31.12.2 ad * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
4 1.31.12.2 ad * All rights reserved.
5 1.31.12.2 ad *
6 1.31.12.2 ad * Redistribution and use in source and binary forms, with or without
7 1.31.12.2 ad * modification, are permitted provided that the following conditions
8 1.31.12.2 ad * are met:
9 1.31.12.2 ad * 1. Redistributions of source code must retain the above copyright
10 1.31.12.2 ad * notice, this list of conditions and the following disclaimer.
11 1.31.12.2 ad * 2. Redistributions in binary form must reproduce the above copyright
12 1.31.12.2 ad * notice, this list of conditions and the following disclaimer in the
13 1.31.12.2 ad * documentation and/or other materials provided with the distribution.
14 1.31.12.2 ad * 3. All advertising materials mentioning features or use of this software
15 1.31.12.2 ad * must display the following acknowledgement:
16 1.31.12.2 ad * This product includes software developed at Ludd, University of
17 1.31.12.2 ad * Lule}, Sweden and its contributors.
18 1.31.12.2 ad * 4. The name of the author may not be used to endorse or promote products
19 1.31.12.2 ad * derived from this software without specific prior written permission
20 1.31.12.2 ad *
21 1.31.12.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.31.12.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.31.12.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.31.12.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.31.12.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.31.12.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.31.12.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.31.12.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.31.12.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.31.12.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.31.12.2 ad */
32 1.31.12.2 ad
33 1.31.12.2 ad
34 1.31.12.2 ad /*
35 1.31.12.2 ad * MSCP tape device driver
36 1.31.12.2 ad */
37 1.31.12.2 ad
38 1.31.12.2 ad /*
39 1.31.12.2 ad * TODO
40 1.31.12.2 ad * Write status handling code.
41 1.31.12.2 ad */
42 1.31.12.2 ad
43 1.31.12.2 ad #include <sys/cdefs.h>
44 1.31.12.2 ad __KERNEL_RCSID(0, "$NetBSD: mscp_tape.c,v 1.31.12.2 2007/07/29 12:15:44 ad Exp $");
45 1.31.12.2 ad
46 1.31.12.2 ad #include <sys/param.h>
47 1.31.12.2 ad #include <sys/device.h>
48 1.31.12.2 ad #include <sys/kernel.h>
49 1.31.12.2 ad #include <sys/buf.h>
50 1.31.12.2 ad #include <sys/bufq.h>
51 1.31.12.2 ad #include <sys/ioccom.h>
52 1.31.12.2 ad #include <sys/mtio.h>
53 1.31.12.2 ad #include <sys/fcntl.h>
54 1.31.12.2 ad #include <sys/malloc.h>
55 1.31.12.2 ad #include <sys/systm.h>
56 1.31.12.2 ad #include <sys/proc.h>
57 1.31.12.2 ad #include <sys/conf.h>
58 1.31.12.2 ad
59 1.31.12.2 ad #include <machine/bus.h>
60 1.31.12.2 ad #include <machine/cpu.h>
61 1.31.12.2 ad
62 1.31.12.2 ad #include <dev/mscp/mscp.h>
63 1.31.12.2 ad #include <dev/mscp/mscpreg.h>
64 1.31.12.2 ad #include <dev/mscp/mscpvar.h>
65 1.31.12.2 ad
66 1.31.12.2 ad #include "locators.h"
67 1.31.12.2 ad
68 1.31.12.2 ad /*
69 1.31.12.2 ad * Drive status, per drive
70 1.31.12.2 ad */
71 1.31.12.2 ad struct mt_softc {
72 1.31.12.2 ad struct device mt_dev; /* Autoconf struct */
73 1.31.12.2 ad int mt_state; /* open/closed state */
74 1.31.12.2 ad int mt_hwunit; /* Hardware unit number */
75 1.31.12.2 ad int mt_inuse; /* Locks the tape drive for others */
76 1.31.12.2 ad int mt_waswrite; /* Last operation was a write op */
77 1.31.12.2 ad int mt_serex; /* Got serious exception */
78 1.31.12.2 ad int mt_ioctlerr; /* Error after last ioctl */
79 1.31.12.2 ad };
80 1.31.12.2 ad
81 1.31.12.2 ad #define MT_OFFLINE 0
82 1.31.12.2 ad #define MT_ONLINE 1
83 1.31.12.2 ad
84 1.31.12.2 ad int mtmatch(struct device *, struct cfdata *, void *);
85 1.31.12.2 ad void mtattach(struct device *, struct device *, void *);
86 1.31.12.2 ad void mtdgram(struct device *, struct mscp *, struct mscp_softc *);
87 1.31.12.2 ad void mtiodone(struct device *, struct buf *);
88 1.31.12.2 ad int mtonline(struct device *, struct mscp *);
89 1.31.12.2 ad int mtgotstatus(struct device *, struct mscp *);
90 1.31.12.2 ad int mtioerror(struct device *, struct mscp *, struct buf *);
91 1.31.12.2 ad void mtfillin(struct buf *, struct mscp *);
92 1.31.12.2 ad int mtcmd(struct mt_softc *, int, int, int);
93 1.31.12.2 ad void mtcmddone(struct device *, struct mscp *);
94 1.31.12.2 ad int mt_putonline(struct mt_softc *);
95 1.31.12.2 ad
96 1.31.12.2 ad struct mscp_device mt_device = {
97 1.31.12.2 ad mtdgram,
98 1.31.12.2 ad mtiodone,
99 1.31.12.2 ad mtonline,
100 1.31.12.2 ad mtgotstatus,
101 1.31.12.2 ad 0,
102 1.31.12.2 ad mtioerror,
103 1.31.12.2 ad 0,
104 1.31.12.2 ad mtfillin,
105 1.31.12.2 ad mtcmddone,
106 1.31.12.2 ad };
107 1.31.12.2 ad
108 1.31.12.2 ad /* This is not good, should allow more than 4 tapes/device type */
109 1.31.12.2 ad #define mtunit(dev) (minor(dev) & T_UNIT)
110 1.31.12.2 ad #define mtnorewind(dev) (dev & T_NOREWIND)
111 1.31.12.2 ad #define mthdensity(dev) (dev & T_1600BPI)
112 1.31.12.2 ad
113 1.31.12.2 ad CFATTACH_DECL(mt, sizeof(struct mt_softc),
114 1.31.12.2 ad mtmatch, mtattach, NULL, NULL);
115 1.31.12.2 ad
116 1.31.12.2 ad extern struct cfdriver mt_cd;
117 1.31.12.2 ad
118 1.31.12.2 ad dev_type_open(mtopen);
119 1.31.12.2 ad dev_type_close(mtclose);
120 1.31.12.2 ad dev_type_read(mtread);
121 1.31.12.2 ad dev_type_write(mtwrite);
122 1.31.12.2 ad dev_type_ioctl(mtioctl);
123 1.31.12.2 ad dev_type_strategy(mtstrategy);
124 1.31.12.2 ad dev_type_dump(mtdump);
125 1.31.12.2 ad
126 1.31.12.2 ad const struct bdevsw mt_bdevsw = {
127 1.31.12.2 ad mtopen, mtclose, mtstrategy, mtioctl, mtdump, nosize, D_TAPE
128 1.31.12.2 ad };
129 1.31.12.2 ad
130 1.31.12.2 ad const struct cdevsw mt_cdevsw = {
131 1.31.12.2 ad mtopen, mtclose, mtread, mtwrite, mtioctl,
132 1.31.12.2 ad nostop, notty, nopoll, nommap, nokqfilter, D_TAPE
133 1.31.12.2 ad };
134 1.31.12.2 ad
135 1.31.12.2 ad /*
136 1.31.12.2 ad * More driver definitions, for generic MSCP code.
137 1.31.12.2 ad */
138 1.31.12.2 ad
139 1.31.12.2 ad int
140 1.31.12.2 ad mtmatch(parent, cf, aux)
141 1.31.12.2 ad struct device *parent;
142 1.31.12.2 ad struct cfdata *cf;
143 1.31.12.2 ad void *aux;
144 1.31.12.2 ad {
145 1.31.12.2 ad struct drive_attach_args *da = aux;
146 1.31.12.2 ad struct mscp *mp = da->da_mp;
147 1.31.12.2 ad
148 1.31.12.2 ad if ((da->da_typ & MSCPBUS_TAPE) == 0)
149 1.31.12.2 ad return 0;
150 1.31.12.2 ad if (cf->cf_loc[MSCPBUSCF_DRIVE] != MSCPBUSCF_DRIVE_DEFAULT &&
151 1.31.12.2 ad cf->cf_loc[MSCPBUSCF_DRIVE] != mp->mscp_unit)
152 1.31.12.2 ad return 0;
153 1.31.12.2 ad return 1;
154 1.31.12.2 ad }
155 1.31.12.2 ad
156 1.31.12.2 ad /*
157 1.31.12.2 ad * The attach routine only checks and prints drive type.
158 1.31.12.2 ad */
159 1.31.12.2 ad void
160 1.31.12.2 ad mtattach(parent, self, aux)
161 1.31.12.2 ad struct device *parent, *self;
162 1.31.12.2 ad void *aux;
163 1.31.12.2 ad {
164 1.31.12.2 ad struct mt_softc *mt = device_private(self);
165 1.31.12.2 ad struct drive_attach_args *da = aux;
166 1.31.12.2 ad struct mscp *mp = da->da_mp;
167 1.31.12.2 ad struct mscp_softc *mi = (void *)parent;
168 1.31.12.2 ad
169 1.31.12.2 ad mt->mt_hwunit = mp->mscp_unit;
170 1.31.12.2 ad mi->mi_dp[mp->mscp_unit] = self;
171 1.31.12.2 ad
172 1.31.12.2 ad disk_printtype(mp->mscp_unit, mp->mscp_guse.guse_mediaid);
173 1.31.12.2 ad }
174 1.31.12.2 ad
175 1.31.12.2 ad /*
176 1.31.12.2 ad * (Try to) put the drive online. This is done the first time the
177 1.31.12.2 ad * drive is opened, or if it has fallen offline.
178 1.31.12.2 ad */
179 1.31.12.2 ad int
180 1.31.12.2 ad mt_putonline(mt)
181 1.31.12.2 ad struct mt_softc *mt;
182 1.31.12.2 ad {
183 1.31.12.2 ad struct mscp *mp;
184 1.31.12.2 ad struct mscp_softc *mi =
185 1.31.12.2 ad (struct mscp_softc *)device_parent(&mt->mt_dev);
186 1.31.12.2 ad volatile int i;
187 1.31.12.2 ad
188 1.31.12.2 ad ((volatile struct mt_softc *) mt)->mt_state = MT_OFFLINE;
189 1.31.12.2 ad mp = mscp_getcp(mi, MSCP_WAIT);
190 1.31.12.2 ad mp->mscp_opcode = M_OP_ONLINE;
191 1.31.12.2 ad mp->mscp_unit = mt->mt_hwunit;
192 1.31.12.2 ad mp->mscp_cmdref = (long)&mt->mt_state;
193 1.31.12.2 ad *mp->mscp_addr |= MSCP_OWN | MSCP_INT;
194 1.31.12.2 ad
195 1.31.12.2 ad /* Poll away */
196 1.31.12.2 ad i = bus_space_read_2(mi->mi_iot, mi->mi_iph, 0);
197 1.31.12.2 ad if (tsleep(&mt->mt_state, PRIBIO, "mtonline", 240 * hz))
198 1.31.12.2 ad return MSCP_FAILED;
199 1.31.12.2 ad
200 1.31.12.2 ad if ((volatile int)mt->mt_state != MT_ONLINE)
201 1.31.12.2 ad return MSCP_FAILED;
202 1.31.12.2 ad
203 1.31.12.2 ad return MSCP_DONE;
204 1.31.12.2 ad }
205 1.31.12.2 ad /*
206 1.31.12.2 ad * Open a drive.
207 1.31.12.2 ad */
208 1.31.12.2 ad /*ARGSUSED*/
209 1.31.12.2 ad int
210 1.31.12.2 ad mtopen(dev, flag, fmt, l)
211 1.31.12.2 ad dev_t dev;
212 1.31.12.2 ad int flag, fmt;
213 1.31.12.2 ad struct lwp *l;
214 1.31.12.2 ad {
215 1.31.12.2 ad struct mt_softc *mt;
216 1.31.12.2 ad int unit;
217 1.31.12.2 ad
218 1.31.12.2 ad /*
219 1.31.12.2 ad * Make sure this is a reasonable open request.
220 1.31.12.2 ad */
221 1.31.12.2 ad unit = mtunit(dev);
222 1.31.12.2 ad if (unit >= mt_cd.cd_ndevs)
223 1.31.12.2 ad return ENXIO;
224 1.31.12.2 ad mt = mt_cd.cd_devs[unit];
225 1.31.12.2 ad if (mt == 0)
226 1.31.12.2 ad return ENXIO;
227 1.31.12.2 ad
228 1.31.12.2 ad if (mt->mt_inuse)
229 1.31.12.2 ad return EBUSY;
230 1.31.12.2 ad mt->mt_inuse = 1;
231 1.31.12.2 ad
232 1.31.12.2 ad if (mt_putonline(mt) == MSCP_FAILED) {
233 1.31.12.2 ad mt->mt_inuse = 0;
234 1.31.12.2 ad return EIO;
235 1.31.12.2 ad }
236 1.31.12.2 ad
237 1.31.12.2 ad return 0;
238 1.31.12.2 ad }
239 1.31.12.2 ad
240 1.31.12.2 ad /* ARGSUSED */
241 1.31.12.2 ad int
242 1.31.12.2 ad mtclose(dev, flags, fmt, l)
243 1.31.12.2 ad dev_t dev;
244 1.31.12.2 ad int flags, fmt;
245 1.31.12.2 ad struct lwp *l;
246 1.31.12.2 ad {
247 1.31.12.2 ad int unit = mtunit(dev);
248 1.31.12.2 ad struct mt_softc *mt = mt_cd.cd_devs[unit];
249 1.31.12.2 ad
250 1.31.12.2 ad /*
251 1.31.12.2 ad * If we just have finished a writing, write EOT marks.
252 1.31.12.2 ad */
253 1.31.12.2 ad if ((flags & FWRITE) && mt->mt_waswrite) {
254 1.31.12.2 ad mtcmd(mt, MTWEOF, 0, 0);
255 1.31.12.2 ad mtcmd(mt, MTWEOF, 0, 0);
256 1.31.12.2 ad mtcmd(mt, MTBSR, 1, 0);
257 1.31.12.2 ad }
258 1.31.12.2 ad if (mtnorewind(dev) == 0)
259 1.31.12.2 ad mtcmd(mt, MTREW, 0, 1);
260 1.31.12.2 ad if (mt->mt_serex)
261 1.31.12.2 ad mtcmd(mt, -1, 0, 0);
262 1.31.12.2 ad
263 1.31.12.2 ad mt->mt_inuse = 0; /* Release the tape */
264 1.31.12.2 ad return 0;
265 1.31.12.2 ad }
266 1.31.12.2 ad
267 1.31.12.2 ad void
268 1.31.12.2 ad mtstrategy(bp)
269 1.31.12.2 ad struct buf *bp;
270 1.31.12.2 ad {
271 1.31.12.2 ad int unit;
272 1.31.12.2 ad struct mt_softc *mt;
273 1.31.12.2 ad
274 1.31.12.2 ad /*
275 1.31.12.2 ad * Make sure this is a reasonable drive to use.
276 1.31.12.2 ad */
277 1.31.12.2 ad unit = mtunit(bp->b_dev);
278 1.31.12.2 ad if (unit > mt_cd.cd_ndevs || (mt = mt_cd.cd_devs[unit]) == NULL) {
279 1.31.12.2 ad bp->b_error = ENXIO;
280 1.31.12.2 ad biodone(bp);
281 1.31.12.2 ad return;
282 1.31.12.2 ad }
283 1.31.12.2 ad
284 1.31.12.2 ad mt->mt_waswrite = bp->b_flags & B_READ ? 0 : 1;
285 1.31.12.2 ad mscp_strategy(bp, device_parent(&mt->mt_dev));
286 1.31.12.2 ad return;
287 1.31.12.2 ad }
288 1.31.12.2 ad
289 1.31.12.2 ad int
290 1.31.12.2 ad mtread(dev, uio, flag)
291 1.31.12.2 ad dev_t dev;
292 1.31.12.2 ad struct uio *uio;
293 1.31.12.2 ad int flag;
294 1.31.12.2 ad {
295 1.31.12.2 ad
296 1.31.12.2 ad return (physio(mtstrategy, NULL, dev, B_READ, minphys, uio));
297 1.31.12.2 ad }
298 1.31.12.2 ad
299 1.31.12.2 ad int
300 1.31.12.2 ad mtwrite(dev, uio, flag)
301 1.31.12.2 ad dev_t dev;
302 1.31.12.2 ad struct uio *uio;
303 1.31.12.2 ad int flag;
304 1.31.12.2 ad {
305 1.31.12.2 ad
306 1.31.12.2 ad return (physio(mtstrategy, NULL, dev, B_WRITE, minphys, uio));
307 1.31.12.2 ad }
308 1.31.12.2 ad
309 1.31.12.2 ad void
310 1.31.12.2 ad mtiodone(usc, bp)
311 1.31.12.2 ad struct device *usc;
312 1.31.12.2 ad struct buf *bp;
313 1.31.12.2 ad {
314 1.31.12.2 ad
315 1.31.12.2 ad biodone(bp);
316 1.31.12.2 ad }
317 1.31.12.2 ad
318 1.31.12.2 ad /*
319 1.31.12.2 ad * Fill in drive addresses in a mscp packet waiting for transfer.
320 1.31.12.2 ad */
321 1.31.12.2 ad void
322 1.31.12.2 ad mtfillin(bp, mp)
323 1.31.12.2 ad struct buf *bp;
324 1.31.12.2 ad struct mscp *mp;
325 1.31.12.2 ad {
326 1.31.12.2 ad int unit = mtunit(bp->b_dev);
327 1.31.12.2 ad struct mt_softc *mt = mt_cd.cd_devs[unit];
328 1.31.12.2 ad
329 1.31.12.2 ad mp->mscp_unit = mt->mt_hwunit;
330 1.31.12.2 ad if (mt->mt_serex == 2) {
331 1.31.12.2 ad mp->mscp_modifier = M_MD_CLSEX;
332 1.31.12.2 ad mt->mt_serex = 0;
333 1.31.12.2 ad } else
334 1.31.12.2 ad mp->mscp_modifier = 0;
335 1.31.12.2 ad
336 1.31.12.2 ad mp->mscp_seq.seq_bytecount = bp->b_bcount;
337 1.31.12.2 ad }
338 1.31.12.2 ad
339 1.31.12.2 ad /*
340 1.31.12.2 ad * Handle an error datagram.
341 1.31.12.2 ad */
342 1.31.12.2 ad void
343 1.31.12.2 ad mtdgram(usc, mp, mi)
344 1.31.12.2 ad struct device *usc;
345 1.31.12.2 ad struct mscp *mp;
346 1.31.12.2 ad struct mscp_softc *mi;
347 1.31.12.2 ad {
348 1.31.12.2 ad if (mscp_decodeerror(usc == NULL?"unconf mt" : usc->dv_xname, mp, mi))
349 1.31.12.2 ad return;
350 1.31.12.2 ad }
351 1.31.12.2 ad
352 1.31.12.2 ad /*
353 1.31.12.2 ad * A drive came on line, make sure it really _is_ on line before
354 1.31.12.2 ad * trying to use it.
355 1.31.12.2 ad */
356 1.31.12.2 ad int
357 1.31.12.2 ad mtonline(usc, mp)
358 1.31.12.2 ad struct device *usc;
359 1.31.12.2 ad struct mscp *mp;
360 1.31.12.2 ad {
361 1.31.12.2 ad struct mt_softc *mt = (void *)usc;
362 1.31.12.2 ad
363 1.31.12.2 ad wakeup((void *)&mt->mt_state);
364 1.31.12.2 ad if ((mp->mscp_status & M_ST_MASK) == M_ST_SUCCESS)
365 1.31.12.2 ad mt->mt_state = MT_ONLINE;
366 1.31.12.2 ad
367 1.31.12.2 ad return (MSCP_DONE);
368 1.31.12.2 ad }
369 1.31.12.2 ad
370 1.31.12.2 ad /*
371 1.31.12.2 ad * We got some (configured) unit's status. Return DONE.
372 1.31.12.2 ad */
373 1.31.12.2 ad int
374 1.31.12.2 ad mtgotstatus(usc, mp)
375 1.31.12.2 ad struct device *usc;
376 1.31.12.2 ad struct mscp *mp;
377 1.31.12.2 ad {
378 1.31.12.2 ad return (MSCP_DONE);
379 1.31.12.2 ad }
380 1.31.12.2 ad
381 1.31.12.2 ad static const char *mt_ioerrs[] = {
382 1.31.12.2 ad "invalid command", /* 1 M_ST_INVALCMD */
383 1.31.12.2 ad "command aborted", /* 2 M_ST_ABORTED */
384 1.31.12.2 ad "unit offline", /* 3 M_ST_OFFLINE */
385 1.31.12.2 ad "unknown", /* 4 M_ST_AVAILABLE */
386 1.31.12.2 ad "unknown", /* 5 M_ST_MFMTERR */
387 1.31.12.2 ad "unit write protected", /* 6 M_ST_WRPROT */
388 1.31.12.2 ad "compare error", /* 7 M_ST_COMPERR */
389 1.31.12.2 ad "data error", /* 8 M_ST_DATAERR */
390 1.31.12.2 ad "host buffer access error", /* 9 M_ST_HOSTBUFERR */
391 1.31.12.2 ad "controller error", /* 10 M_ST_CTLRERR */
392 1.31.12.2 ad "drive error", /* 11 M_ST_DRIVEERR */
393 1.31.12.2 ad "formatter error", /* 12 M_ST_FORMATTERR */
394 1.31.12.2 ad "BOT encountered", /* 13 M_ST_BOT */
395 1.31.12.2 ad "tape mark encountered",/* 14 M_ST_TAPEMARK */
396 1.31.12.2 ad "unknown", /* 15 */
397 1.31.12.2 ad "record data truncated",/* 16 M_ST_RDTRUNC */
398 1.31.12.2 ad };
399 1.31.12.2 ad
400 1.31.12.2 ad /*
401 1.31.12.2 ad * An I/O error, may be because of a tapemark encountered.
402 1.31.12.2 ad * Check that before failing.
403 1.31.12.2 ad */
404 1.31.12.2 ad /*ARGSUSED*/
405 1.31.12.2 ad int
406 1.31.12.2 ad mtioerror(usc, mp, bp)
407 1.31.12.2 ad struct device *usc;
408 1.31.12.2 ad struct mscp *mp;
409 1.31.12.2 ad struct buf *bp;
410 1.31.12.2 ad {
411 1.31.12.2 ad struct mt_softc *mt = (void *)usc;
412 1.31.12.2 ad int st = mp->mscp_status & M_ST_MASK;
413 1.31.12.2 ad
414 1.31.12.2 ad if (mp->mscp_flags & M_EF_SEREX)
415 1.31.12.2 ad mt->mt_serex = 1;
416 1.31.12.2 ad if (st == M_ST_TAPEMARK)
417 1.31.12.2 ad mt->mt_serex = 2;
418 1.31.12.2 ad else {
419 1.31.12.2 ad if (st && st < 17)
420 1.31.12.2 ad printf("%s: error %d (%s)\n", mt->mt_dev.dv_xname, st,
421 1.31.12.2 ad mt_ioerrs[st-1]);
422 1.31.12.2 ad else
423 1.31.12.2 ad printf("%s: error %d\n", mt->mt_dev.dv_xname, st);
424 1.31.12.2 ad bp->b_error = EROFS;
425 1.31.12.2 ad }
426 1.31.12.2 ad
427 1.31.12.2 ad return (MSCP_DONE);
428 1.31.12.2 ad }
429 1.31.12.2 ad
430 1.31.12.2 ad /*
431 1.31.12.2 ad * I/O controls.
432 1.31.12.2 ad */
433 1.31.12.2 ad int
434 1.31.12.2 ad mtioctl(dev, cmd, data, flag, l)
435 1.31.12.2 ad dev_t dev;
436 1.31.12.2 ad u_long cmd;
437 1.31.12.2 ad void *data;
438 1.31.12.2 ad int flag;
439 1.31.12.2 ad struct lwp *l;
440 1.31.12.2 ad {
441 1.31.12.2 ad int unit = mtunit(dev);
442 1.31.12.2 ad struct mt_softc *mt = mt_cd.cd_devs[unit];
443 1.31.12.2 ad struct mtop *mtop;
444 1.31.12.2 ad int error = 0;
445 1.31.12.2 ad
446 1.31.12.2 ad switch (cmd) {
447 1.31.12.2 ad
448 1.31.12.2 ad case MTIOCTOP:
449 1.31.12.2 ad mtop = (void *)data;
450 1.31.12.2 ad if (mtop->mt_op == MTWEOF) {
451 1.31.12.2 ad while (mtop->mt_count-- > 0)
452 1.31.12.2 ad if ((error = mtcmd(mt, mtop->mt_op, 0, 0)))
453 1.31.12.2 ad break;
454 1.31.12.2 ad } else
455 1.31.12.2 ad error = mtcmd(mt, mtop->mt_op, mtop->mt_count, 0);
456 1.31.12.2 ad
457 1.31.12.2 ad case MTIOCGET:
458 1.31.12.2 ad ((struct mtget *)data)->mt_type = MT_ISTMSCP;
459 1.31.12.2 ad /* XXX we need to fill in more fields here */
460 1.31.12.2 ad break;
461 1.31.12.2 ad
462 1.31.12.2 ad default:
463 1.31.12.2 ad error = ENXIO;
464 1.31.12.2 ad break;
465 1.31.12.2 ad }
466 1.31.12.2 ad return (error);
467 1.31.12.2 ad }
468 1.31.12.2 ad
469 1.31.12.2 ad /*
470 1.31.12.2 ad * No crash dump support...
471 1.31.12.2 ad */
472 1.31.12.2 ad int
473 1.31.12.2 ad mtdump(dev, blkno, va, size)
474 1.31.12.2 ad dev_t dev;
475 1.31.12.2 ad daddr_t blkno;
476 1.31.12.2 ad void *va;
477 1.31.12.2 ad size_t size;
478 1.31.12.2 ad {
479 1.31.12.2 ad return -1;
480 1.31.12.2 ad }
481 1.31.12.2 ad
482 1.31.12.2 ad /*
483 1.31.12.2 ad * Send a command to the tape drive. Wait until the command is
484 1.31.12.2 ad * finished before returning.
485 1.31.12.2 ad * This routine must only be called when there are no data transfer
486 1.31.12.2 ad * active on this device. Can we be sure of this? Or does the ctlr
487 1.31.12.2 ad * queue up all command packets and take them in sequential order?
488 1.31.12.2 ad * It sure would be nice if my manual stated this... /ragge
489 1.31.12.2 ad */
490 1.31.12.2 ad int
491 1.31.12.2 ad mtcmd(mt, cmd, count, complete)
492 1.31.12.2 ad struct mt_softc *mt;
493 1.31.12.2 ad int cmd, count, complete;
494 1.31.12.2 ad {
495 1.31.12.2 ad struct mscp *mp;
496 1.31.12.2 ad struct mscp_softc *mi = (void *)device_parent(&mt->mt_dev);
497 1.31.12.2 ad volatile int i;
498 1.31.12.2 ad
499 1.31.12.2 ad mp = mscp_getcp(mi, MSCP_WAIT);
500 1.31.12.2 ad
501 1.31.12.2 ad mt->mt_ioctlerr = 0;
502 1.31.12.2 ad mp->mscp_unit = mt->mt_hwunit;
503 1.31.12.2 ad mp->mscp_cmdref = -1;
504 1.31.12.2 ad *mp->mscp_addr |= MSCP_OWN | MSCP_INT;
505 1.31.12.2 ad
506 1.31.12.2 ad switch (cmd) {
507 1.31.12.2 ad case MTWEOF:
508 1.31.12.2 ad mp->mscp_opcode = M_OP_WRITM;
509 1.31.12.2 ad break;
510 1.31.12.2 ad
511 1.31.12.2 ad case MTBSF:
512 1.31.12.2 ad mp->mscp_modifier = M_MD_REVERSE;
513 1.31.12.2 ad case MTFSF:
514 1.31.12.2 ad mp->mscp_opcode = M_OP_POS;
515 1.31.12.2 ad mp->mscp_seq.seq_buffer = count;
516 1.31.12.2 ad break;
517 1.31.12.2 ad
518 1.31.12.2 ad case MTBSR:
519 1.31.12.2 ad mp->mscp_modifier = M_MD_REVERSE;
520 1.31.12.2 ad case MTFSR:
521 1.31.12.2 ad mp->mscp_opcode = M_OP_POS;
522 1.31.12.2 ad mp->mscp_modifier |= M_MD_OBJCOUNT;
523 1.31.12.2 ad mp->mscp_seq.seq_bytecount = count;
524 1.31.12.2 ad break;
525 1.31.12.2 ad
526 1.31.12.2 ad case MTREW:
527 1.31.12.2 ad mp->mscp_opcode = M_OP_POS;
528 1.31.12.2 ad mp->mscp_modifier = M_MD_REWIND | M_MD_CLSEX;
529 1.31.12.2 ad if (complete)
530 1.31.12.2 ad mp->mscp_modifier |= M_MD_IMMEDIATE;
531 1.31.12.2 ad mt->mt_serex = 0;
532 1.31.12.2 ad break;
533 1.31.12.2 ad
534 1.31.12.2 ad case MTOFFL:
535 1.31.12.2 ad mp->mscp_opcode = M_OP_AVAILABLE;
536 1.31.12.2 ad mp->mscp_modifier = M_MD_UNLOAD | M_MD_CLSEX;
537 1.31.12.2 ad mt->mt_serex = 0;
538 1.31.12.2 ad break;
539 1.31.12.2 ad
540 1.31.12.2 ad case MTNOP:
541 1.31.12.2 ad mp->mscp_opcode = M_OP_GETUNITST;
542 1.31.12.2 ad break;
543 1.31.12.2 ad
544 1.31.12.2 ad case -1: /* Clear serious exception only */
545 1.31.12.2 ad mp->mscp_opcode = M_OP_POS;
546 1.31.12.2 ad mp->mscp_modifier = M_MD_CLSEX;
547 1.31.12.2 ad mt->mt_serex = 0;
548 1.31.12.2 ad break;
549 1.31.12.2 ad
550 1.31.12.2 ad default:
551 1.31.12.2 ad printf("Bad ioctl %x\n", cmd);
552 1.31.12.2 ad mp->mscp_opcode = M_OP_POS;
553 1.31.12.2 ad break;
554 1.31.12.2 ad }
555 1.31.12.2 ad
556 1.31.12.2 ad i = bus_space_read_2(mi->mi_iot, mi->mi_iph, 0);
557 1.31.12.2 ad tsleep(&mt->mt_inuse, PRIBIO, "mtioctl", 0);
558 1.31.12.2 ad return mt->mt_ioctlerr;
559 1.31.12.2 ad }
560 1.31.12.2 ad
561 1.31.12.2 ad /*
562 1.31.12.2 ad * Called from bus routines whenever a non-data transfer is finished.
563 1.31.12.2 ad */
564 1.31.12.2 ad void
565 1.31.12.2 ad mtcmddone(usc, mp)
566 1.31.12.2 ad struct device *usc;
567 1.31.12.2 ad struct mscp *mp;
568 1.31.12.2 ad {
569 1.31.12.2 ad struct mt_softc *mt = (void *)usc;
570 1.31.12.2 ad
571 1.31.12.2 ad if (mp->mscp_status) {
572 1.31.12.2 ad mt->mt_ioctlerr = EIO;
573 1.31.12.2 ad printf("%s: bad status %x\n", mt->mt_dev.dv_xname,
574 1.31.12.2 ad mp->mscp_status);
575 1.31.12.2 ad }
576 1.31.12.2 ad wakeup(&mt->mt_inuse);
577 1.31.12.2 ad }
578