Commit | Line | Data |
---|---|---|
3ad14429 KM |
1 | /* |
2 | * Copyright (c) 1990 University of Utah. | |
3 | * Copyright (c) 1990 The Regents of the University of California. | |
4 | * All rights reserved. | |
5 | * | |
6 | * This code is derived from software contributed to Berkeley by | |
7 | * the Systems Programming Group of the University of Utah Computer | |
8 | * Science Department. | |
9 | * | |
10 | * %sccs.include.redist.c% | |
11 | * | |
12 | * from: Utah $Hdr: st.c 1.8 90/10/14$ | |
13 | * | |
14 | * @(#)st.c 7.1 (Berkeley) %G% | |
15 | */ | |
16 | ||
17 | /* | |
18 | * SCSI CCS (Command Command Set) tape driver. | |
19 | * | |
20 | * Specific to Exabyte: | |
21 | * mt status: residual="Mbytes to LEOM" | |
22 | * minor bit 4 [b1bbbb] (aka /dev/rst16) selects short filemarks | |
23 | * minor bit 5 [1bbbbb] (aka /dev/rst32) selects fix block mode, 1k blocks. | |
24 | * | |
25 | * Archive drive: | |
26 | * can read both QIC-24 and QIC-II. But only writes | |
27 | * QIC-24. | |
28 | * | |
29 | * Supports Archive Viper QIC-150 tape drive, but scsi.c reports selection | |
30 | * errors. | |
31 | * | |
32 | * Supports Archive Python DAT drive, but will sometimes hang machine. | |
33 | * | |
34 | * Supports HP 35450A DAT drive, but will sometimes hang machine. | |
35 | * Partitioning of tape not supported. | |
36 | * Vendor unique support has not been added. | |
37 | * | |
38 | * | |
39 | * Supports Archive VIPER (QIC-150). | |
40 | * Mostly Supports Archive PYTHON (DAT). | |
41 | * Hangs if write after spin down. | |
42 | * Need scsi.c that does connect/disconnect. | |
43 | */ | |
44 | ||
45 | /* | |
46 | * support for the block device not implemented | |
47 | */ | |
48 | ||
49 | #include "st.h" | |
50 | #if NST > 0 | |
51 | ||
52 | #include "param.h" | |
53 | #include "systm.h" | |
54 | #include "buf.h" | |
55 | #include "errno.h" | |
56 | #include "device.h" | |
57 | #include "scsireg.h" | |
58 | #include "file.h" | |
59 | #include "tty.h" | |
60 | #include "user.h" | |
61 | #include "proc.h" | |
62 | #include "mtio.h" | |
63 | #include "ioctl.h" | |
64 | #include "uio.h" | |
65 | #include "kernel.h" | |
66 | ||
67 | #include "stvar.h" | |
68 | ||
69 | extern int scsi_test_unit_rdy(); | |
70 | extern int scsi_request_sense(); | |
71 | extern int scsiustart(); | |
72 | extern int scsigo(); | |
73 | extern void scsifree(); | |
74 | extern void scsireset(); | |
75 | extern void scsi_delay(); | |
76 | extern int scsi_tt_oddio(); | |
77 | ||
78 | extern int scsi_immed_command(); | |
79 | ||
80 | int stinit(), ststart(), stgo(), stintr(); | |
81 | struct driver stdriver = { | |
82 | stinit, "st", ststart, stgo, stintr, | |
83 | }; | |
84 | ||
85 | struct st_softc { | |
86 | struct hp_device *sc_hd; | |
87 | struct devqueue sc_dq; | |
88 | long sc_blkno; /* (possible block device support?) */ | |
89 | long sc_resid; /* (possible block device support?) */ | |
90 | int sc_flags; | |
91 | int sc_blklen; /* 0 = variable len records */ | |
92 | int sc_filepos; /* file position on tape */ | |
93 | long sc_numblks; /* number of blocks on tape */ | |
94 | short sc_type; /* ansi scsi type */ | |
95 | short sc_punit; /* physical unit (scsi lun) */ | |
96 | short sc_tapeid; /* tape drive id */ | |
97 | char sc_datalen[32]; /* additional data length on some commands */ | |
98 | short sc_tticntdwn; /* interrupts between TTi display updates */ | |
99 | caddr_t sc_ctty; | |
100 | struct buf *sc_bp; | |
101 | u_char sc_cmd; | |
102 | } st_softc[NST]; | |
103 | ||
104 | /* softc flags */ | |
105 | #define STF_ALIVE 0x0001 | |
106 | #define STF_OPEN 0x0002 | |
107 | #define STF_WMODE 0x0004 | |
108 | #define STF_WRTTN 0x0008 | |
109 | #define STF_CMD 0x0010 | |
110 | #define STF_LEOT 0x0020 | |
111 | #define STF_MOVED 0x0040 | |
112 | ||
113 | struct st_mode st_mode[NST]; | |
114 | ||
115 | /* | |
116 | * Maybe this should not be global, but gives chance to get | |
117 | * tape remaining, Rewrites/ECC, etc outside the driver | |
118 | */ | |
119 | static struct st_xsense { | |
120 | struct scsi_xsense sc_xsense; /* data from sense */ | |
121 | struct exb_xsense exb_xsense; /* additional info from exabyte */ | |
122 | } st_xsense[NST]; | |
123 | ||
124 | static struct scsi_fmt_cdb stcmd[NST]; | |
125 | ||
126 | static struct scsi_fmt_cdb st_read_cmd = { 6, CMD_READ }; | |
127 | static struct scsi_fmt_cdb st_write_cmd = { 6, CMD_WRITE }; | |
128 | ||
129 | struct buf sttab[NST]; | |
130 | struct buf stbuf[NST]; | |
131 | ||
132 | #define UNIT(x) (minor(x) & 3) | |
133 | #define stpunit(x) ((x) & 7) | |
134 | ||
135 | #define STDEV_NOREWIND 0x04 | |
136 | #define STDEV_HIDENSITY 0x08 | |
137 | #define STDEV_EXSFMK 0x10 | |
138 | #define STDEV_FIXEDBLK 0x20 | |
139 | ||
140 | #ifdef DEBUG | |
141 | int st_debug = 0x0000; | |
142 | #define ST_OPEN 0x0001 | |
143 | #define ST_GO 0x0002 | |
144 | #define ST_FMKS 0x0004 | |
145 | #define ST_OPENSTAT 0x0008 | |
146 | #define ST_BRESID 0x0010 | |
147 | #define ST_ODDIO 0x0020 | |
148 | #endif | |
149 | ||
150 | /* | |
151 | * Patchable variable. If an even length read is requested a dma transfer is | |
152 | * used. Only after the read will we find out if the read had an odd number | |
153 | * of bytes. The HP98658 hardware cannot do odd length transfers, the last | |
154 | * byte of the data will always be 0x00. Normally, the driver will complain | |
155 | * about such transfers and return EIO. However, if st_dmaoddretry is non- | |
156 | * zero, the driver will try and issue a BSR and then re-read the data using | |
157 | * 'programmed transfer mode'. In most cases this works, however for unknown | |
158 | * reasons it will hang the machine in certain cases. | |
159 | * | |
160 | * Note: | |
161 | * Odd length read requests are always done using programmed transfer mode. | |
162 | */ | |
163 | int st_dmaoddretry = 0; | |
164 | ||
165 | /* | |
166 | * Exabyte only: | |
167 | * From adb can have access to fixed vs. variable length modes. | |
168 | * Use 0x400 for 1k (best capacity) fixed length records. | |
169 | * In st_open, if minor bit 4 set then 1k records are used. | |
170 | * If st_exblken is set to anything other then 0 we are in fixed length mode. | |
171 | * Minor bit 4 overrides any setting of st_exblklen. | |
172 | * | |
173 | */ | |
174 | int st_exblklen = 0; | |
175 | ||
176 | /* exabyte here for adb access, set at open time */ | |
177 | #define EX_CT 0x80 /* international cart - more space W/P6 */ | |
178 | #define EX_ND 0x20 /* no disconnect */ | |
179 | #define EX_NBE 0x08 /* no busy enable */ | |
180 | #define EX_EBD 0x04 /* even byte disconnect */ | |
181 | #define EX_PE 0x02 /* parity enable */ | |
182 | #define EX_NAL 0x01 /* no auto load */ | |
183 | int st_exvup = (EX_CT|EX_ND|EX_NBE); /* vendor unique parameters */ | |
184 | ||
185 | /* | |
186 | * motion and reconnect thresholds guidelines: | |
187 | * write operation; lower motion threshold for faster transfer | |
188 | * raise reconnect threshold for slower transfer | |
189 | * read operation; lower motion threshold for slower transfer | |
190 | * raise reconnect threshold for faster transfer | |
191 | */ | |
192 | int st_exmotthr = 0x80; /* motion threshold, 0x80 default */ | |
193 | int st_exreconthr = 0xa0; /* reconnect threshold, 0xa0 default */ | |
194 | int st_exgapthr = 7; /* gap threshold, 7 default */ | |
195 | #ifdef TTI | |
196 | int st_extti = 0x01; /* bitmask of unit numbers, do extra */ | |
197 | /* sensing so TTi display gets updated */ | |
198 | #endif | |
199 | ||
200 | stinit(hd) | |
201 | register struct hp_device *hd; | |
202 | { | |
203 | register struct st_softc *sc = &st_softc[hd->hp_unit]; | |
204 | ||
205 | sc->sc_hd = hd; | |
206 | sc->sc_punit = stpunit(hd->hp_flags); | |
207 | sc->sc_type = stident(sc, hd); | |
208 | if (sc->sc_type < 0) | |
209 | return(0); | |
210 | sc->sc_dq.dq_ctlr = hd->hp_ctlr; | |
211 | sc->sc_dq.dq_unit = hd->hp_unit; | |
212 | sc->sc_dq.dq_slave = hd->hp_slave; | |
213 | sc->sc_dq.dq_driver = &stdriver; | |
214 | sc->sc_blkno = 0; | |
215 | sc->sc_flags = STF_ALIVE; | |
216 | return(1); | |
217 | } | |
218 | ||
219 | stident(sc, hd) | |
220 | register struct st_softc *sc; | |
221 | register struct hp_device *hd; | |
222 | { | |
223 | int unit; | |
224 | int ctlr, slave; | |
225 | int i, stat, inqlen; | |
226 | char idstr[32]; | |
227 | #if 0 | |
228 | static int havest = 0; | |
229 | #endif | |
230 | struct st_inquiry { | |
231 | struct scsi_inquiry inqbuf; | |
232 | struct exb_inquiry exb_inquiry; | |
233 | } st_inqbuf; | |
234 | static struct scsi_fmt_cdb st_inq = { | |
235 | 6, | |
236 | CMD_INQUIRY, 0, 0, 0, sizeof(st_inqbuf), 0 | |
237 | }; | |
238 | ||
239 | ctlr = hd->hp_ctlr; | |
240 | slave = hd->hp_slave; | |
241 | unit = sc->sc_punit; | |
242 | scsi_delay(-1); | |
243 | ||
244 | inqlen = 0x05; /* min */ | |
245 | st_inq.cdb[4] = 0x05; | |
246 | stat = scsi_immed_command(ctlr, slave, unit, &st_inq, | |
247 | (u_char *)&st_inqbuf, inqlen, B_READ); | |
248 | /* do twice as first command on some scsi tapes always fails */ | |
249 | stat = scsi_immed_command(ctlr, slave, unit, &st_inq, | |
250 | (u_char *)&st_inqbuf, inqlen, B_READ); | |
251 | if (stat == -1) | |
252 | goto failed; | |
253 | ||
254 | if (st_inqbuf.inqbuf.type != 0x01 || /* sequential access device */ | |
255 | st_inqbuf.inqbuf.qual != 0x80 || /* removable media */ | |
256 | (st_inqbuf.inqbuf.version != 0x01 && /* current ANSI SCSI spec */ | |
257 | st_inqbuf.inqbuf.version != 0x02)) /* 0x02 is for HP DAT */ | |
258 | goto failed; | |
259 | ||
260 | /* now get additonal info */ | |
261 | inqlen = 0x05 + st_inqbuf.inqbuf.len; | |
262 | st_inq.cdb[4] = inqlen; | |
263 | bzero(&st_inqbuf, sizeof(st_inqbuf)); | |
264 | stat = scsi_immed_command(ctlr, slave, unit, &st_inq, | |
265 | (u_char *)&st_inqbuf, inqlen, B_READ); | |
266 | ||
267 | if (st_inqbuf.inqbuf.len >= 28) { | |
268 | bcopy((caddr_t)&st_inqbuf.inqbuf.vendor_id, (caddr_t)idstr, 28); | |
269 | for (i = 27; i > 23; --i) | |
270 | if (idstr[i] != ' ') | |
271 | break; | |
272 | idstr[i+1] = 0; | |
273 | for (i = 23; i > 7; --i) | |
274 | if (idstr[i] != ' ') | |
275 | break; | |
276 | idstr[i+1] = 0; | |
277 | for (i = 7; i >= 0; --i) | |
278 | if (idstr[i] != ' ') | |
279 | break; | |
280 | idstr[i+1] = 0; | |
281 | printf("st%d: %s %s rev %s\n", hd->hp_unit, idstr, &idstr[8], | |
282 | &idstr[24]); | |
283 | } else if (inqlen == 5) | |
284 | /* great it's a stupid device, doesn't know it's know name */ | |
285 | idstr[0] = idstr[8] = '\0'; | |
286 | else | |
287 | idstr[8] = '\0'; | |
288 | ||
289 | if (stat == 0xff) { | |
290 | printf("st%d: Cant handle this tape drive\n", hd->hp_unit); | |
291 | goto failed; | |
292 | } | |
293 | ||
294 | if (bcmp("EXB-8200", &idstr[8], 8) == 0) { | |
295 | sc->sc_tapeid = MT_ISEXABYTE; | |
296 | sc->sc_datalen[CMD_REQUEST_SENSE] = 26; | |
297 | sc->sc_datalen[CMD_INQUIRY] = 52; | |
298 | sc->sc_datalen[CMD_MODE_SELECT] = 17; | |
299 | sc->sc_datalen[CMD_MODE_SENSE] = 17; | |
300 | } else if (bcmp("VIPER 150", &idstr[8], 9) == 0) { | |
301 | sc->sc_tapeid = MT_ISVIPER1; | |
302 | sc->sc_datalen[CMD_REQUEST_SENSE] = 14; | |
303 | sc->sc_datalen[CMD_INQUIRY] = 36; | |
304 | sc->sc_datalen[CMD_MODE_SELECT] = 12; | |
305 | sc->sc_datalen[CMD_MODE_SENSE] = 12; | |
306 | } else if (bcmp("Python 25501", &idstr[8], 12) == 0) { | |
307 | sc->sc_tapeid = MT_ISPYTHON; | |
308 | sc->sc_datalen[CMD_REQUEST_SENSE] = 14; | |
309 | sc->sc_datalen[CMD_INQUIRY] = 36; | |
310 | sc->sc_datalen[CMD_MODE_SELECT] = 12; | |
311 | sc->sc_datalen[CMD_MODE_SENSE] = 12; | |
312 | } else if (bcmp("HP35450A", &idstr[8], 8) == 0) { | |
313 | /* XXX "extra" stat makes the HP drive happy at boot time */ | |
314 | stat = scsi_test_unit_rdy(ctlr, slave, unit); | |
315 | sc->sc_tapeid = MT_ISHPDAT; | |
316 | sc->sc_datalen[CMD_REQUEST_SENSE] = 14; | |
317 | sc->sc_datalen[CMD_INQUIRY] = 36; | |
318 | sc->sc_datalen[CMD_MODE_SELECT] = 12; | |
319 | sc->sc_datalen[CMD_MODE_SENSE] = 12; | |
320 | } else { | |
321 | if (idstr[8] == '\0') | |
322 | printf("st%d: No ID, assuming Archive\n", hd->hp_unit); | |
323 | else | |
324 | printf("st%d: Unsupported tape device\n", hd->hp_unit); | |
325 | sc->sc_tapeid = MT_ISAR; | |
326 | sc->sc_datalen[CMD_REQUEST_SENSE] = 8; | |
327 | sc->sc_datalen[CMD_INQUIRY] = 5; | |
328 | sc->sc_datalen[CMD_MODE_SELECT] = 12; | |
329 | sc->sc_datalen[CMD_MODE_SENSE] = 12; | |
330 | } | |
331 | ||
332 | sc->sc_filepos = 0; | |
333 | ||
334 | /* load xsense */ | |
335 | stxsense(ctlr, slave, unit, sc); | |
336 | ||
337 | scsi_delay(0); | |
338 | #if 0 | |
339 | /* XXX if we have a tape, we must up the delays in the HA driver */ | |
340 | if (!havest) { | |
341 | havest = 1; | |
342 | scsi_delay(20000); | |
343 | } | |
344 | #endif | |
345 | return(st_inqbuf.inqbuf.type); | |
346 | failed: | |
347 | scsi_delay(0); | |
348 | return(-1); | |
349 | } | |
350 | ||
351 | stopen(dev, flag) | |
352 | dev_t dev; | |
353 | int flag; | |
354 | { | |
355 | register struct st_softc *sc = &st_softc[UNIT(dev)]; | |
356 | register struct st_xsense *xsense; | |
357 | register int count; | |
358 | register int stat; | |
359 | int ctlr, slave, unit; | |
360 | struct mode_select_data msd; | |
361 | struct mode_sense mode; | |
362 | int modlen; | |
363 | static struct scsi_fmt_cdb modsel = { | |
364 | 6, | |
365 | CMD_MODE_SELECT, 0, 0, 0, sizeof(msd), 0 | |
366 | }; | |
367 | static struct scsi_fmt_cdb unitready = { | |
368 | 6, | |
369 | CMD_TEST_UNIT_READY, 0, 0, 0, 0, 0 | |
370 | }; | |
371 | static struct scsi_fmt_cdb modsense = { | |
372 | 6, | |
373 | CMD_MODE_SENSE, 0, 0, 0, sizeof(mode), 0 | |
374 | }; | |
375 | ||
376 | ctlr = sc->sc_dq.dq_ctlr; | |
377 | slave = sc->sc_dq.dq_slave; | |
378 | unit = sc->sc_punit; | |
379 | xsense = &st_xsense[UNIT(dev)]; | |
380 | ||
381 | if (UNIT(dev) > NST || (sc->sc_flags & STF_ALIVE) == 0) | |
382 | return(ENXIO); | |
383 | if (sc->sc_flags & STF_OPEN) | |
384 | return(EBUSY); | |
385 | ||
386 | /* do a mode sense to get current */ | |
387 | modlen = sc->sc_datalen[CMD_MODE_SENSE]; | |
388 | modsense.cdb[4] = modlen; | |
389 | stat = scsi_immed_command(ctlr, slave, unit, &modsense, | |
390 | (u_char *)&mode, modlen, B_READ); | |
391 | ||
392 | /* do a mode sense to get current */ | |
393 | modlen = sc->sc_datalen[CMD_MODE_SENSE]; | |
394 | modsense.cdb[4] = modlen; | |
395 | stat = scsi_immed_command(ctlr, slave, unit, &modsense, | |
396 | (u_char *)&mode, modlen, B_READ); | |
397 | ||
398 | /* set record length */ | |
399 | switch (sc->sc_tapeid) { | |
400 | case MT_ISAR: | |
401 | sc->sc_blklen = 512; | |
402 | break; | |
403 | case MT_ISEXABYTE: | |
404 | if (minor(dev) & STDEV_FIXEDBLK) | |
405 | sc->sc_blklen = 0x400; | |
406 | else | |
407 | sc->sc_blklen = st_exblklen; | |
408 | break; | |
409 | case MT_ISHPDAT: | |
410 | sc->sc_blklen = 512; | |
411 | break; | |
412 | case MT_ISVIPER1: | |
413 | sc->sc_blklen = 512; | |
414 | break; | |
415 | case MT_ISPYTHON: | |
416 | sc->sc_blklen = 512; | |
417 | break; | |
418 | default: | |
419 | if ((mode.md.blklen2 << 16 | | |
420 | mode.md.blklen1 << 8 | | |
421 | mode.md.blklen0) != 0) | |
422 | sc->sc_blklen = mode.md.blklen2 << 16 | | |
423 | mode.md.blklen1 << 8 | | |
424 | mode.md.blklen0; | |
425 | else | |
426 | sc->sc_blklen = 512; | |
427 | } | |
428 | ||
429 | /* setup for mode select */ | |
430 | msd.rsvd1 = 0; | |
431 | msd.rsvd2 = 0; | |
432 | msd.rsvd3 = 0; | |
433 | msd.buff = 1; | |
434 | msd.speed = 0; | |
435 | msd.blkdeslen = 0x08; | |
436 | msd.density = 0; | |
437 | msd.blks2 = 0; | |
438 | msd.blks1 = 0; | |
439 | msd.blks0 = 0; | |
440 | msd.rsvd4 = 0; | |
441 | msd.blklen2 = (sc->sc_blklen >> 16) & 0xff; | |
442 | msd.blklen1 = (sc->sc_blklen >> 8) & 0xff; | |
443 | msd.blklen0 = sc->sc_blklen & 0xff; | |
444 | ||
445 | switch (sc->sc_tapeid) { | |
446 | case MT_ISAR: | |
447 | if (minor(dev) & STDEV_HIDENSITY) | |
448 | msd.density = 0x5; | |
449 | else { | |
450 | if (flag & FWRITE) { | |
451 | uprintf("Can only write QIC-24\n"); | |
452 | return(EIO); | |
453 | } | |
454 | msd.density = 0x4; | |
455 | } | |
456 | break; | |
457 | case MT_ISEXABYTE: | |
458 | if (minor(dev) & STDEV_HIDENSITY) | |
459 | uprintf("EXB-8200 density support only\n"); | |
460 | msd.vupb = (u_char)st_exvup; | |
461 | msd.rsvd5 = 0; | |
462 | msd.p5 = 0; | |
463 | msd.motionthres = (u_char)st_exmotthr; | |
464 | msd.reconthres = (u_char)st_exreconthr; | |
465 | msd.gapthres = (u_char)st_exgapthr; | |
466 | break; | |
467 | case MT_ISHPDAT: | |
468 | case MT_ISVIPER1: | |
469 | case MT_ISPYTHON: | |
470 | if (minor(dev) & STDEV_HIDENSITY) | |
471 | uprintf("Only one density supported\n"); | |
472 | break; | |
473 | default: | |
474 | uprintf("Unsupported drive\n"); | |
475 | return(EIO); | |
476 | } | |
477 | ||
478 | modlen = sc->sc_datalen[CMD_MODE_SELECT]; | |
479 | modsel.cdb[4] = modlen; | |
480 | ||
481 | /* mode select */ | |
482 | count = 0; | |
483 | retryselect: | |
484 | stat = scsi_immed_command(ctlr, slave, unit, &modsel, | |
485 | (u_char *)&msd, modlen, B_WRITE); | |
486 | /* | |
487 | * First command after power cycle, bus reset or tape change | |
488 | * will error. Try command again | |
489 | */ | |
490 | if (stat == STS_CHECKCOND) { | |
491 | sc->sc_filepos = 0; | |
492 | stxsense(ctlr, slave, unit, sc); | |
493 | stat = scsi_immed_command(ctlr, slave, unit, &modsel, | |
494 | (u_char *)&msd, modlen, B_WRITE); | |
495 | #ifdef DEBUG | |
496 | if (stat && (st_debug & ST_OPEN)) | |
497 | printf("stopen: stat on mode select 0x%x second try\n", stat); | |
498 | #endif | |
499 | if (stat == STS_CHECKCOND) { | |
500 | stxsense(ctlr, slave, unit, sc); | |
501 | prtkey(UNIT(dev), sc); | |
502 | } | |
503 | if (stat) | |
504 | return(EIO); | |
505 | } | |
506 | if (stat == -1 || stat == STS_BUSY) { | |
507 | /* | |
508 | * XXX it might just be that the bus is busy because | |
509 | * another tape is doing a command. This would change | |
510 | * with connect/disconnect, ie. the other drive would | |
511 | * not hold onto the bus. | |
512 | * | |
513 | * Sleep on lbolt for up to 20 minutes (max time to FSF | |
514 | * an exabyte to EOT: 16:xx minutes) | |
515 | */ | |
516 | if (++count > 60*20) { | |
517 | uprintf("SCSI bus timeout\n"); | |
518 | return(EBUSY); | |
519 | } | |
520 | sleep((caddr_t)&lbolt, PZERO+1); | |
521 | goto retryselect; | |
522 | } | |
523 | ||
524 | /* drive ready ? */ | |
525 | stat = scsi_test_unit_rdy(ctlr, slave, unit); | |
526 | ||
527 | if (stat == STS_CHECKCOND) { | |
528 | stxsense(ctlr, slave, unit, sc); | |
529 | switch (sc->sc_tapeid) { | |
530 | case MT_ISEXABYTE: | |
531 | if ((xsense->sc_xsense.key & XSK_NOTRDY) && | |
532 | xsense->exb_xsense.tnp) | |
533 | uprintf("no cartridge\n"); | |
534 | else if (xsense->sc_xsense.key & XSK_NOTRDY) | |
535 | uprintf("cartridge not loaded\n"); | |
536 | else if (xsense->sc_xsense.key & XSK_UNTATTEN) { | |
537 | uprintf("new cart/power interrupt\n"); | |
538 | stat = 0; | |
539 | } else if ((xsense->sc_xsense.key & XSK_UNTATTEN) && | |
540 | xsense->exb_xsense.tnp) | |
541 | uprintf("cartridge unloading\n"); | |
542 | else | |
543 | prtkey(UNIT(dev), sc); | |
544 | break; | |
545 | case MT_ISAR: | |
546 | if (xsense->sc_xsense.key & XSK_UNTATTEN) | |
547 | stat = scsi_test_unit_rdy(ctlr, slave, unit); | |
548 | if (stat == STS_CHECKCOND) { | |
549 | stxsense(ctlr, slave, unit, sc); | |
550 | if (xsense->sc_xsense.key) | |
551 | prtkey(UNIT(dev), sc); | |
552 | } else { | |
553 | sc->sc_filepos = 0; /* new tape */ | |
554 | stat = 0; | |
555 | } | |
556 | break; | |
557 | case MT_ISHPDAT: | |
558 | case MT_ISVIPER1: | |
559 | case MT_ISPYTHON: | |
560 | if (xsense->sc_xsense.key & XSK_UNTATTEN) | |
561 | stat = scsi_test_unit_rdy(ctlr, slave, unit); | |
562 | if (stat == STS_CHECKCOND) { | |
563 | stxsense(ctlr, slave, unit, sc); | |
564 | if (xsense->sc_xsense.key) | |
565 | prtkey(UNIT(dev), sc); | |
566 | } | |
567 | break; | |
568 | default: | |
569 | uprintf("st%d: not ready\n", UNIT(dev)); | |
570 | prtkey(UNIT(dev), sc); | |
571 | break; | |
572 | } | |
573 | } | |
574 | if (stat) | |
575 | return(EIO); | |
576 | ||
577 | /* mode sense */ | |
578 | modlen = sc->sc_datalen[CMD_MODE_SENSE]; | |
579 | modsense.cdb[4] = modlen; | |
580 | stat = scsi_immed_command(ctlr, slave, unit, &modsense, | |
581 | (u_char *)&mode, modlen, B_READ); | |
582 | #ifdef DEBUG | |
583 | if (st_debug & ST_OPENSTAT) | |
584 | prtmodstat(&mode); | |
585 | #endif | |
586 | ||
587 | if (stat == STS_CHECKCOND) { | |
588 | stxsense(ctlr, slave, unit, sc); | |
589 | #ifdef DEBUG | |
590 | if (st_debug & ST_OPEN) | |
591 | dumpxsense(xsense); | |
592 | #endif | |
593 | } | |
594 | if (stat) | |
595 | return(EIO); | |
596 | ||
597 | if ((flag & FWRITE) && mode.md.wp) { | |
598 | uprintf("st:%d write protected\n", UNIT(dev)); | |
599 | return(EACCES); | |
600 | } | |
601 | ||
602 | sc->sc_ctty = (caddr_t)(u.u_procp->p_flag&SCTTY ? | |
603 | u.u_procp->p_session->s_ttyvp : 0); | |
604 | /* save total number of blocks on tape */ | |
605 | sc->sc_numblks = mode.md.numblk2 << 16 | | |
606 | mode.md.numblk1 << 8 | | |
607 | mode.md.numblk0; | |
608 | ||
609 | if (xsense->sc_xsense.eom && !(sc->sc_flags & STF_LEOT)) | |
610 | sc->sc_filepos = 0; | |
611 | #ifdef DEBUG | |
612 | if (st_debug & ST_FMKS) | |
613 | printf("st%d: open filepos = %d\n", UNIT(dev), sc->sc_filepos); | |
614 | #endif | |
615 | ||
616 | sc->sc_flags |= (STF_OPEN); | |
617 | if (flag & FWRITE) | |
618 | sc->sc_flags |= STF_WMODE; | |
619 | sc->sc_flags &= ~STF_MOVED; | |
620 | ||
621 | #ifdef TTI | |
622 | /* make stats available, also lit up TTi display */ | |
623 | sc->sc_tticntdwn = 100; | |
624 | #endif | |
625 | stxsense(ctlr, slave, unit, sc); | |
626 | ||
627 | return(0); | |
628 | } | |
629 | ||
630 | /*ARGSUSED*/ | |
631 | stclose(dev, flag) | |
632 | dev_t dev; | |
633 | int flag; | |
634 | { | |
635 | register struct st_softc *sc = &st_softc[UNIT(dev)]; | |
636 | register int hit = 0; | |
637 | ||
638 | if ((sc->sc_flags & (STF_WMODE|STF_WRTTN)) == (STF_WMODE|STF_WRTTN)) { | |
639 | /* | |
640 | * XXX driver only supports cartridge tapes. | |
641 | * Cartridge tapes don't do double EOFs on EOT. | |
642 | */ | |
643 | stcommand(dev, MTWEOF, 1); | |
644 | hit++; | |
645 | } | |
646 | if ((minor(dev) & STDEV_NOREWIND) == 0) { | |
647 | stcommand(dev, MTREW, 1); | |
648 | hit++; | |
649 | } | |
650 | #ifdef NOTDEF | |
651 | /* wait until more stable before trying [XXX Needed ?] */ | |
652 | if (!hit && (sc->sc_flags & SFT_WMODE)) | |
653 | /* force out any any bufferd write data */ | |
654 | stcommand(dev, MTFSR, 0); | |
655 | #endif | |
656 | /* make stats available */ | |
657 | stxsense(sc->sc_dq.dq_ctlr, sc->sc_dq.dq_slave, sc->sc_punit, sc); | |
658 | ||
659 | sc->sc_flags &= ~(STF_OPEN|STF_WMODE|STF_WRTTN); | |
660 | sc->sc_ctty = NULL; | |
661 | return(0); /* XXX */ | |
662 | } | |
663 | ||
664 | ststrategy(bp) | |
665 | register struct buf *bp; | |
666 | { | |
667 | struct buf *dp; | |
668 | int unit, s; | |
669 | ||
670 | unit = UNIT(bp->b_dev); | |
671 | dp = &sttab[unit]; | |
672 | bp->av_forw = NULL; | |
673 | s = splbio(); | |
674 | if (dp->b_actf == NULL) | |
675 | dp->b_actf = bp; | |
676 | else | |
677 | dp->b_actl->av_forw = bp; | |
678 | dp->b_actl = bp; | |
679 | if (dp->b_active == 0) { | |
680 | dp->b_active = 1; | |
681 | stustart(unit); | |
682 | } | |
683 | splx(s); | |
684 | } | |
685 | ||
686 | stustart(unit) | |
687 | int unit; | |
688 | { | |
689 | if (scsireq(&st_softc[unit].sc_dq)) | |
690 | ststart(unit); | |
691 | } | |
692 | ||
693 | ststart(unit) | |
694 | int unit; | |
695 | { | |
696 | struct hp_device *hp = st_softc[unit].sc_hd; | |
697 | ||
698 | if (scsiustart(hp->hp_ctlr)) | |
699 | stgo(unit); | |
700 | } | |
701 | ||
702 | stgo(unit) | |
703 | int unit; | |
704 | { | |
705 | register struct st_softc *sc = &st_softc[unit]; | |
706 | register struct scsi_fmt_cdb *cmd; | |
707 | register struct buf *bp = sttab[unit].b_actf; | |
708 | struct hp_device *hp = sc->sc_hd; | |
709 | int pad, stat; | |
710 | long nblks; | |
711 | ||
712 | if (sc->sc_flags & STF_CMD) { | |
713 | cmd = &stcmd[unit]; | |
714 | pad = 0; | |
715 | } else { | |
716 | cmd = bp->b_flags & B_READ ? &st_read_cmd : &st_write_cmd; | |
717 | if (sc->sc_blklen) | |
718 | cmd->cdb[1] |= 0x01; /* fixed mode */ | |
719 | else | |
720 | cmd->cdb[1] &= 0xfe; | |
721 | if (bp->b_flags & B_READ) | |
722 | sc->sc_flags &= ~STF_WRTTN; | |
723 | else | |
724 | sc->sc_flags |= STF_WRTTN; | |
725 | ||
726 | if (sc->sc_blklen) { /* fixed mode */ | |
727 | nblks = bp->b_bcount / sc->sc_blklen; | |
728 | if (bp->b_bcount % sc->sc_blklen) { | |
729 | tprintf(sc->sc_ctty, | |
730 | "st%d: I/O not block aligned %d/%ld\n", | |
731 | unit, sc->sc_blklen, bp->b_bcount); | |
732 | cmd->cdb[1] &= 0xfe; /* force error */ | |
733 | } | |
734 | } else /* variable len */ | |
735 | nblks = bp->b_bcount; | |
736 | ||
737 | *(u_char *)(&cmd->cdb[2]) = (u_char) (nblks >> 16); | |
738 | *(u_char *)(&cmd->cdb[3]) = (u_char) (nblks >> 8); | |
739 | *(u_char *)(&cmd->cdb[4]) = (u_char) nblks; | |
740 | /* | |
741 | * Always Zero. We are either writing in variable | |
742 | * length mode we are writing in fixed block mode, | |
743 | * or we are going to do odd length IO and are not | |
744 | * going to use DMA. | |
745 | */ | |
746 | pad = 0; | |
747 | } | |
748 | ||
749 | #ifdef DEBUG | |
750 | if (st_debug & ST_GO) | |
751 | printf("stgo: cmd len %d [0]0x%x [1]0x%x [2]0x%x [3]0x%x [4]0x%x [5]0x%x\n", | |
752 | cmd->len, cmd->cdb[0], cmd->cdb[1], cmd->cdb[2], | |
753 | cmd->cdb[3], cmd->cdb[4], cmd->cdb[5]); | |
754 | #endif | |
755 | ||
756 | sc->sc_flags |= STF_MOVED; | |
757 | if (bp->b_bcount & 1) { | |
758 | #ifdef DEBUG | |
759 | if (st_debug & ST_ODDIO) | |
760 | printf("stgo%d: odd count %d using manual transfer\n", | |
761 | unit, bp->b_bcount); | |
762 | #endif | |
763 | stat = scsi_tt_oddio(hp->hp_ctlr, hp->hp_slave, sc->sc_punit, | |
764 | bp->b_un.b_addr, bp->b_bcount, | |
765 | bp->b_flags, 1); | |
766 | if (stat == 0) { | |
767 | bp->b_resid = 0; | |
768 | stfinish(unit, sc, bp); | |
769 | } | |
770 | } else | |
771 | stat = scsigo(hp->hp_ctlr, hp->hp_slave, sc->sc_punit, | |
772 | bp, cmd, pad); | |
773 | if (stat) { | |
774 | bp->b_error = EIO; | |
775 | bp->b_flags |= B_ERROR; | |
776 | stxsense(sc->sc_dq.dq_ctlr, sc->sc_dq.dq_slave, | |
777 | sc->sc_punit, sc); | |
778 | sterror(unit, sc, stat); | |
779 | stfinish(unit, sc, bp); | |
780 | } | |
781 | } | |
782 | ||
783 | stfinish(unit, sc, bp) | |
784 | int unit; | |
785 | struct st_softc *sc; | |
786 | struct buf *bp; | |
787 | { | |
788 | sttab[unit].b_errcnt = 0; | |
789 | sttab[unit].b_actf = bp->b_actf; | |
790 | iodone(bp); | |
791 | scsifree(&sc->sc_dq); | |
792 | if (sttab[unit].b_actf) | |
793 | stustart(unit); | |
794 | else | |
795 | sttab[unit].b_active = 0; | |
796 | } | |
797 | ||
798 | stread(dev, uio) | |
799 | dev_t dev; | |
800 | struct uio *uio; | |
801 | { | |
802 | int unit = UNIT(dev); | |
803 | ||
804 | return(physio(ststrategy, &stbuf[unit], dev, B_READ, minphys, uio)); | |
805 | } | |
806 | ||
807 | stwrite(dev, uio) | |
808 | dev_t dev; | |
809 | struct uio *uio; | |
810 | { | |
811 | int unit = UNIT(dev); | |
812 | ||
813 | return(physio(ststrategy, &stbuf[unit], dev, B_WRITE, minphys, uio)); | |
814 | } | |
815 | ||
816 | /*ARGSUSED*/ | |
817 | stdump(dev) | |
818 | dev_t dev; | |
819 | { | |
820 | return(ENXIO); | |
821 | } | |
822 | ||
823 | /*ARGSUSED*/ | |
824 | stioctl(dev, cmd, data, flag) | |
825 | dev_t dev; | |
826 | int cmd; | |
827 | caddr_t data; | |
828 | int flag; | |
829 | { | |
830 | register struct st_softc *sc = &st_softc[UNIT(dev)]; | |
831 | register int cnt; | |
832 | register struct mtget *mtget; | |
833 | register struct st_xsense *xp = &st_xsense[UNIT(dev)]; | |
834 | register struct mtop *op; | |
835 | long resid; | |
836 | ||
837 | switch (cmd) { | |
838 | ||
839 | /* tape operation */ | |
840 | case MTIOCTOP: | |
841 | op = (struct mtop *)data; | |
842 | switch (op->mt_op) { | |
843 | ||
844 | case MTBSR: | |
845 | case MTFSR: | |
846 | if (sc->sc_tapeid == MT_ISAR) | |
847 | return(ENXIO); | |
848 | case MTWEOF: | |
849 | case MTFSF: | |
850 | case MTBSF: | |
851 | cnt = (int)op->mt_count; | |
852 | break; | |
853 | ||
854 | case MTREW: | |
855 | case MTOFFL: | |
856 | cnt = 1; | |
857 | break; | |
858 | ||
859 | case MTNOP: | |
860 | return(0); | |
861 | default: | |
862 | return(EINVAL); | |
863 | } | |
864 | if (cnt <= 0) | |
865 | return(EINVAL); | |
866 | stcommand(dev, (u_int)op->mt_op, cnt); | |
867 | break; | |
868 | ||
869 | /* drive status */ | |
870 | case MTIOCGET: | |
871 | mtget = (struct mtget *)data; | |
872 | stxsense(sc->sc_dq.dq_ctlr, sc->sc_dq.dq_slave, | |
873 | sc->sc_punit, sc); | |
874 | mtget->mt_type = sc->sc_tapeid; | |
875 | mtget->mt_dsreg = 0; | |
876 | mtget->mt_erreg = ((xp->sc_xsense.valid << 15) | | |
877 | (xp->sc_xsense.filemark << 14) | | |
878 | (xp->sc_xsense.eom << 13) | | |
879 | (xp->sc_xsense.ili << 12) | | |
880 | (xp->sc_xsense.key << 8)); | |
881 | ||
882 | if (sc->sc_tapeid == MT_ISEXABYTE) { | |
883 | mtget->mt_dsreg = sc->sc_flags; | |
884 | resid = (xp->exb_xsense.tplft2 << 16 | | |
885 | xp->exb_xsense.tplft1 << 8 | | |
886 | xp->exb_xsense.tplft0); | |
887 | mtget->mt_resid = resid / 1000; | |
888 | mtget->mt_erreg |= (((xp->exb_xsense.rwerrcnt2 << 16 | | |
889 | xp->exb_xsense.rwerrcnt1 << 8 | | |
890 | xp->exb_xsense.rwerrcnt0) * 100) / | |
891 | (sc->sc_numblks - resid)) & 0xff; | |
892 | } else if (xp->sc_xsense.valid) { | |
893 | resid = ((xp->sc_xsense.info1 << 24) | | |
894 | (xp->sc_xsense.info2 << 16) | | |
895 | (xp->sc_xsense.info3 << 8) | | |
896 | (xp->sc_xsense.info4)); | |
897 | if (sc->sc_blklen) /* if fixed mode */ | |
898 | resid *= sc->sc_blklen; | |
899 | mtget->mt_resid = resid; | |
900 | } else | |
901 | mtget->mt_resid = 0; | |
902 | break; | |
903 | ||
904 | default: | |
905 | return(ENXIO); | |
906 | } | |
907 | return(0); | |
908 | } | |
909 | ||
910 | stintr(unit, stat) | |
911 | int unit, stat; | |
912 | { | |
913 | register struct st_softc *sc = &st_softc[unit]; | |
914 | register struct st_xsense *xp = &st_xsense[unit]; | |
915 | register struct buf *bp = sttab[unit].b_actf; | |
916 | struct hp_device *hp = sc->sc_hd; | |
917 | ||
918 | #ifdef DEBUG | |
919 | if (bp == NULL) { | |
920 | printf("st%d: bp == NULL\n", unit); | |
921 | return; | |
922 | } | |
923 | #endif | |
924 | switch (stat) { | |
925 | /* scsi command completed ok */ | |
926 | case 0: | |
927 | bp->b_resid = 0; | |
928 | break; | |
929 | ||
930 | /* more status */ | |
931 | case STS_CHECKCOND: | |
932 | stxsense(sc->sc_dq.dq_ctlr, sc->sc_dq.dq_slave, | |
933 | sc->sc_punit, sc); | |
934 | if (xp->sc_xsense.valid) { | |
935 | bp->b_resid = (u_long)((xp->sc_xsense.info1 << 24) | | |
936 | (xp->sc_xsense.info2 << 16) | | |
937 | (xp->sc_xsense.info3 << 8) | | |
938 | (xp->sc_xsense.info4)); | |
939 | if (sc->sc_blklen) /* fixed mode */ | |
940 | bp->b_resid *= sc->sc_blklen; | |
941 | } | |
942 | if (xp->sc_xsense.filemark) { | |
943 | sc->sc_filepos++; | |
944 | break; | |
945 | } | |
946 | if (xp->sc_xsense.key) { | |
947 | sterror(unit, sc, stat); | |
948 | bp->b_flags |= B_ERROR; | |
949 | bp->b_error = EIO; | |
950 | break; | |
951 | } | |
952 | if (xp->sc_xsense.ili) { | |
953 | /* | |
954 | * Fixed length blocks, an error. | |
955 | */ | |
956 | if (sc->sc_blklen) { | |
957 | tprintf(sc->sc_ctty, | |
958 | "st%d: Incorrect Length Indicator, blkcnt diff %d\n", | |
959 | unit, sc->sc_blklen - bp->b_resid); | |
960 | bp->b_flags |= B_ERROR; | |
961 | bp->b_error = EIO; | |
962 | break; | |
963 | } | |
964 | /* | |
965 | * Variable length but read more than requested, | |
966 | * an error. | |
967 | */ | |
968 | if (bp->b_resid < 0) { | |
969 | bp->b_resid = 0; | |
970 | bp->b_flags |= B_ERROR; | |
971 | bp->b_error = ENOMEM; | |
972 | break; | |
973 | } | |
974 | /* | |
975 | * Variable length and odd, may require special | |
976 | * handling. | |
977 | */ | |
978 | if (bp->b_resid & 1 && sc->sc_tapeid != MT_ISAR) { | |
979 | /* | |
980 | * Normal behavior, treat as an error. | |
981 | */ | |
982 | if (!st_dmaoddretry) { | |
983 | tprintf(sc->sc_ctty, | |
984 | "st%d: Odd length read %d\n", | |
985 | UNIT(bp->b_dev), | |
986 | bp->b_bcount - bp->b_resid); | |
987 | bp->b_error = EIO; | |
988 | bp->b_flags |= B_ERROR; | |
989 | break; | |
990 | } | |
991 | /* | |
992 | * Attempt to back up and re-read using oddio. | |
993 | */ | |
994 | #ifdef DEBUG | |
995 | if (st_debug & ST_ODDIO) | |
996 | printf("st%d: stintr odd count %d, do BSR then oddio\n", | |
997 | UNIT(bp->b_dev), | |
998 | bp->b_bcount - bp->b_resid); | |
999 | #endif | |
1000 | stat = scsi_tt_oddio(hp->hp_ctlr, hp->hp_slave, | |
1001 | sc->sc_punit, 0, -1, 0, 0); | |
1002 | if (stat == 0) | |
1003 | stat = scsi_tt_oddio(hp->hp_ctlr, | |
1004 | hp->hp_slave, | |
1005 | sc->sc_punit, | |
1006 | bp->b_un.b_addr, | |
1007 | bp->b_bcount - bp->b_resid, | |
1008 | bp->b_flags, 0); | |
1009 | if (stat) { | |
1010 | bp->b_error = EIO; | |
1011 | bp->b_flags |= B_ERROR; | |
1012 | stxsense(sc->sc_dq.dq_ctlr, sc->sc_dq.dq_slave, | |
1013 | sc->sc_punit, sc); | |
1014 | sterror(unit, sc, stat); | |
1015 | } | |
1016 | } | |
1017 | break; | |
1018 | } | |
1019 | if (xp->sc_xsense.eom) { | |
1020 | bp->b_flags |= B_ERROR; | |
1021 | bp->b_error = ENOSPC; | |
1022 | break; | |
1023 | } | |
1024 | tprintf(sc->sc_ctty, "st%d: unknown scsi error\n", unit); | |
1025 | bp->b_flags |= B_ERROR; | |
1026 | bp->b_error = EIO; | |
1027 | break; | |
1028 | ||
1029 | default: | |
1030 | printf("st%d: stintr unknown stat 0x%x\n", unit, stat); | |
1031 | break; | |
1032 | } | |
1033 | #ifdef DEBUG | |
1034 | if ((st_debug & ST_BRESID) && bp->b_resid != 0) | |
1035 | printf("b_resid %d b_flags 0x%x b_error 0x%x\n", | |
1036 | bp->b_resid, bp->b_flags, bp->b_error); | |
1037 | #endif | |
1038 | /* asked for more filemarks then on tape */ | |
1039 | if (bp->b_resid != 0 && | |
1040 | (sc->sc_flags & STF_CMD) && sc->sc_cmd == CMD_SPACE) { | |
1041 | sc->sc_filepos -= bp->b_resid; | |
1042 | if (sc->sc_filepos < 0) | |
1043 | sc->sc_filepos = 0; | |
1044 | } | |
1045 | ||
1046 | #ifdef TTI | |
1047 | if (st_extti & (1<<unit) && | |
1048 | sc->sc_type == MT_ISEXABYTE) /* to make display lit up */ | |
1049 | /* | |
1050 | * XXX severe performance penality for this. | |
1051 | * Try and throttle by not calling stxsense on every intr. | |
1052 | * Mostly for TTi we, get a stxsense call in open and close. | |
1053 | */ | |
1054 | if (sc->sc_tticntdwn-- == 0) { | |
1055 | stxsense(sc->sc_dq.dq_ctlr, sc->sc_dq.dq_slave, | |
1056 | sc->sc_punit, sc); | |
1057 | sc->sc_tticntdwn = 100; | |
1058 | } | |
1059 | #endif | |
1060 | ||
1061 | stfinish(unit, sc, bp); | |
1062 | } | |
1063 | ||
1064 | stcommand(dev, command, cnt) | |
1065 | dev_t dev; | |
1066 | u_int command; | |
1067 | int cnt; | |
1068 | { | |
1069 | register struct st_softc *sc = &st_softc[UNIT(dev)]; | |
1070 | register struct buf *bp = &stbuf[UNIT(dev)]; | |
1071 | register struct scsi_fmt_cdb *cmd = &stcmd[UNIT(dev)]; | |
1072 | register cmdcnt; | |
1073 | int s; | |
1074 | ||
1075 | cmd->len = 6; /* all tape commands are cdb6 */ | |
1076 | cmd->cdb[1] = sc->sc_punit; | |
1077 | cmd->cdb[2] = cmd->cdb[3] = cmd->cdb[4] = cmd->cdb[5] = 0; | |
1078 | cmdcnt = 0; | |
1079 | ||
1080 | /* | |
1081 | * XXX Assumption is that everything except Archive can take | |
1082 | * repeat count in cdb block. | |
1083 | */ | |
1084 | switch (command) { | |
1085 | case MTWEOF: | |
1086 | cmd->cdb[0] = CMD_WRITE_FILEMARK; | |
1087 | if (sc->sc_tapeid != MT_ISAR) { | |
1088 | cmdcnt = cnt; | |
1089 | cnt = 1; | |
1090 | } else | |
1091 | cmdcnt = 1; | |
1092 | *(u_char *)(&cmd->cdb[2]) = (u_char) (cmdcnt >> 16); | |
1093 | *(u_char *)(&cmd->cdb[3]) = (u_char) (cmdcnt >> 8); | |
1094 | *(u_char *)(&cmd->cdb[4]) = (u_char) cmdcnt; | |
1095 | ||
1096 | if (sc->sc_tapeid == MT_ISEXABYTE && | |
1097 | (minor(dev) & STDEV_EXSFMK)) /* short filemarks */ | |
1098 | cmd->cdb[5] |= 0x80; | |
1099 | else | |
1100 | cmd->cdb[5] &= 0x7f; | |
1101 | break; | |
1102 | case MTBSF: | |
1103 | /* Archive can't back up, will not get to BSR case */ | |
1104 | if (sc->sc_tapeid == MT_ISAR) { | |
1105 | if ((sc->sc_filepos - cnt) < 0) { | |
1106 | stcommand(dev, MTREW, 1); | |
1107 | return; | |
1108 | } | |
1109 | cmdcnt = sc->sc_filepos - cnt + 1; | |
1110 | stcommand(dev, MTREW, 1); | |
1111 | stcommand(dev, MTFSF, cmdcnt); | |
1112 | return; | |
1113 | } | |
1114 | case MTBSR: | |
1115 | case MTFSR: | |
1116 | case MTFSF: | |
1117 | if (command == MTBSF || command == MTBSR) | |
1118 | cnt = cnt * (-1); /* backward move */ | |
1119 | if (command == MTFSF || command == MTBSF) | |
1120 | cmd->cdb[1] |= 0x01; /* filemarks */ | |
1121 | else | |
1122 | cmd->cdb[1] |= 0x00; /* logical blocks */ | |
1123 | if (sc->sc_tapeid != MT_ISAR) { | |
1124 | cmdcnt = cnt; | |
1125 | cnt = 1; | |
1126 | } else | |
1127 | cmdcnt = 1; | |
1128 | *(u_char *)(&cmd->cdb[2]) = (u_char) (cmdcnt >> 16); | |
1129 | *(u_char *)(&cmd->cdb[3]) = (u_char) (cmdcnt >> 8); | |
1130 | *(u_char *)(&cmd->cdb[4]) = (u_char) cmdcnt; | |
1131 | cmd->cdb[0] = CMD_SPACE; | |
1132 | break; | |
1133 | case MTREW: | |
1134 | cmd->cdb[0] = CMD_REWIND; | |
1135 | sc->sc_filepos = 0; | |
1136 | break; | |
1137 | case MTOFFL: | |
1138 | cmd->cdb[0] = CMD_LOADUNLOAD; | |
1139 | sc->sc_filepos = 0; | |
1140 | break; | |
1141 | default: | |
1142 | printf("st%d: stcommand bad command 0x%x\n", | |
1143 | UNIT(dev), command); | |
1144 | } | |
1145 | ||
1146 | sc->sc_flags |= STF_CMD; | |
1147 | sc->sc_cmd = cmd->cdb[0]; | |
1148 | ||
1149 | sc->sc_bp = bp; | |
1150 | again: | |
1151 | #ifdef DEBUG | |
1152 | if (st_debug & ST_FMKS) | |
1153 | printf("st%d: stcommand filepos %d cmdcnt %d cnt %d\n", | |
1154 | UNIT(dev), sc->sc_filepos, cmdcnt, cnt); | |
1155 | #endif | |
1156 | s = splbio(); | |
1157 | while (bp->b_flags & B_BUSY) { | |
1158 | if (bp->b_flags & B_DONE) | |
1159 | break; | |
1160 | bp->b_flags |= B_WANTED; | |
1161 | sleep((caddr_t)bp, PRIBIO); | |
1162 | } | |
1163 | bp->b_flags = B_BUSY|B_READ; | |
1164 | splx(s); | |
1165 | bp->b_dev = dev; | |
1166 | bp->b_bcount = 0; | |
1167 | bp->b_resid = 0; | |
1168 | bp->b_blkno = 0; | |
1169 | bp->b_error = 0; | |
1170 | ststrategy(bp); | |
1171 | iowait(bp); | |
1172 | if (bp->b_flags & B_WANTED) | |
1173 | wakeup((caddr_t)bp); | |
1174 | bp->b_flags &= B_ERROR; | |
1175 | ||
1176 | if (command == MTWEOF || command == MTFSF || command == MTBSF) | |
1177 | sc->sc_filepos += cmdcnt; | |
1178 | ||
1179 | if (--cnt > 0) | |
1180 | goto again; | |
1181 | ||
1182 | sc->sc_flags |= STF_MOVED; | |
1183 | sc->sc_flags &= ~(STF_CMD|STF_WRTTN); | |
1184 | } | |
1185 | ||
1186 | sterror(unit, sc, stat) | |
1187 | int unit, stat; | |
1188 | struct st_softc *sc; | |
1189 | { | |
1190 | /* stxsense must have been called before sterror() */ | |
1191 | if (stat & STS_CHECKCOND) | |
1192 | prtkey(unit, sc); | |
1193 | else if (stat) | |
1194 | tprintf(sc->sc_ctty, | |
1195 | "st%d: bad scsi status 0x%x\n", unit, stat); | |
1196 | ||
1197 | if ((sc->sc_flags & STF_CMD) && sc->sc_cmd == CMD_SPACE) /* fsf */ | |
1198 | sc->sc_filepos--; | |
1199 | } | |
1200 | ||
1201 | stxsense(ctlr, slave, unit, sc) | |
1202 | int ctlr, slave, unit; | |
1203 | struct st_softc *sc; | |
1204 | { | |
1205 | u_char *sensebuf; | |
1206 | unsigned len; | |
1207 | ||
1208 | sensebuf = (u_char *)&st_xsense[sc->sc_dq.dq_unit]; | |
1209 | len = sc->sc_datalen[CMD_REQUEST_SENSE]; | |
1210 | scsi_request_sense(ctlr, slave, unit, sensebuf, len); | |
1211 | } | |
1212 | ||
1213 | prtkey(unit, sc) | |
1214 | int unit; | |
1215 | struct st_softc *sc; | |
1216 | { | |
1217 | register struct st_xsense *xp = &st_xsense[unit]; | |
1218 | ||
1219 | switch (xp->sc_xsense.key) { | |
1220 | case XSK_NOSENCE: | |
1221 | break; | |
1222 | case XSK_NOTUSED1: | |
1223 | case XSK_NOTUSEDC: | |
1224 | case XSK_NOTUSEDE: | |
1225 | break; | |
1226 | case XSK_REVERVED: | |
1227 | tprintf(sc->sc_ctty, "st%d: Reserved sense key 0x%x\n", | |
1228 | unit, xp->sc_xsense.key); | |
1229 | break; | |
1230 | case XSK_NOTRDY: | |
1231 | tprintf(sc->sc_ctty, "st%d: NOT READY\n", unit); | |
1232 | break; | |
1233 | case XSK_MEDERR: | |
1234 | tprintf(sc->sc_ctty, "st%d: MEDIUM ERROR\n", unit); | |
1235 | break; | |
1236 | case XSK_HRDWERR: | |
1237 | tprintf(sc->sc_ctty, "st%d: HARDWARE ERROR\n", unit); | |
1238 | break; | |
1239 | case XSK_ILLREQ: | |
1240 | tprintf(sc->sc_ctty, "st%d: ILLEGAL REQUEST\n", unit); | |
1241 | break; | |
1242 | case XSK_UNTATTEN: | |
1243 | tprintf(sc->sc_ctty, "st%d: UNIT ATTENTION\n", unit); | |
1244 | break; | |
1245 | case XSK_DATAPROT: | |
1246 | tprintf(sc->sc_ctty, "st%d: DATA PROTECT\n", unit); | |
1247 | break; | |
1248 | case XSK_BLNKCHK: | |
1249 | tprintf(sc->sc_ctty, "st%d: BLANK CHECK\n", unit); | |
1250 | break; | |
1251 | case XSK_VENDOR: | |
1252 | tprintf(sc->sc_ctty, "st%d: VENDER UNIQUE SENSE KEY ", unit); | |
1253 | switch (sc->sc_tapeid) { | |
1254 | case MT_ISEXABYTE: | |
1255 | tprintf(sc->sc_ctty, "Exabyte: "); | |
1256 | if (xp->exb_xsense.xfr) | |
1257 | tprintf(sc->sc_ctty, | |
1258 | "Transfer Abort Error\n"); | |
1259 | if (xp->exb_xsense.tmd) | |
1260 | tprintf(sc->sc_ctty, | |
1261 | "Tape Mark Detect Error\n"); | |
1262 | break; | |
1263 | default: | |
1264 | tprintf(sc->sc_ctty, "\n"); | |
1265 | } | |
1266 | break; | |
1267 | case XSK_CPYABORT: | |
1268 | tprintf(sc->sc_ctty, "st%d: COPY ABORTED\n", unit); | |
1269 | break; | |
1270 | case XSK_ABORTCMD: | |
1271 | tprintf(sc->sc_ctty, "st%d: ABORTED COMMAND\n", unit); | |
1272 | break; | |
1273 | case XSK_VOLOVER: | |
1274 | tprintf(sc->sc_ctty, "st%d: VOLUME OVERFLOW\n", unit); | |
1275 | break; | |
1276 | default: | |
1277 | tprintf(sc->sc_ctty, "st%d: unknown sense key 0x%x\n", | |
1278 | unit, xp->sc_xsense.key); | |
1279 | } | |
1280 | if (sc->sc_tapeid == MT_ISEXABYTE) { | |
1281 | if (xp->exb_xsense.bpe) | |
1282 | tprintf(sc->sc_ctty, "st%d: Bus Parity Errorn", unit); | |
1283 | if (xp->exb_xsense.fpe) | |
1284 | tprintf(sc->sc_ctty, | |
1285 | "st%d: Formatted Buffer Parity Errorn", unit); | |
1286 | if (xp->exb_xsense.eco) | |
1287 | tprintf(sc->sc_ctty, "st%d: Error Counter Overflown", | |
1288 | unit); | |
1289 | if (xp->exb_xsense.tme) | |
1290 | tprintf(sc->sc_ctty, "st%d: Tape Motion Errorn", unit); | |
1291 | if (xp->exb_xsense.xfr) | |
1292 | tprintf(sc->sc_ctty, "st%d: Transfer About Errorn", | |
1293 | unit); | |
1294 | if (xp->exb_xsense.tmd) | |
1295 | tprintf(sc->sc_ctty, "st%d: Tape Mark Detect Errorn", | |
1296 | unit); | |
1297 | if (xp->exb_xsense.fmke) | |
1298 | tprintf(sc->sc_ctty, "st%d: Filemark Errorn", unit); | |
1299 | if (xp->exb_xsense.ure) | |
1300 | tprintf(sc->sc_ctty, "st%d: Under Run Errorn", unit); | |
1301 | if (xp->exb_xsense.sse) | |
1302 | tprintf(sc->sc_ctty, "st%d: Servo System Errorn", | |
1303 | unit); | |
1304 | if (xp->exb_xsense.fe) | |
1305 | tprintf(sc->sc_ctty, "st%d: Formatter Errorn", unit); | |
1306 | if (xp->exb_xsense.wseb) | |
1307 | tprintf(sc->sc_ctty, "st%d: WSEB Errorn", unit); | |
1308 | if (xp->exb_xsense.wseo) | |
1309 | tprintf(sc->sc_ctty, "st%d: WSEO Errorn", unit); | |
1310 | } | |
1311 | } | |
1312 | ||
1313 | #ifdef DEBUG | |
1314 | ||
1315 | dumpxsense(sensebuf) | |
1316 | struct st_xsense *sensebuf; | |
1317 | { | |
1318 | struct st_xsense *xp = sensebuf; | |
1319 | ||
1320 | printf("valid 0x%x errorclass 0x%x errorcode 0x%x\n", | |
1321 | xp->sc_xsense.valid, | |
1322 | xp->sc_xsense.class, xp->sc_xsense.code); | |
1323 | printf("seg number 0x%x\n", xp->sc_xsense.segment); | |
1324 | printf("FMK 0x%x EOM 0x%x ILI 0x%x RSVD 0x%x sensekey 0x%x\n", | |
1325 | xp->sc_xsense.filemark, xp->sc_xsense.eom, xp->sc_xsense.ili, | |
1326 | xp->sc_xsense.rsvd, xp->sc_xsense.key); | |
1327 | printf("info 0x%lx\n", | |
1328 | (u_long)((xp->sc_xsense.info1<<24)|(xp->sc_xsense.info2<<16)| | |
1329 | (xp->sc_xsense.info3<<8)|(xp->sc_xsense.info4)) ); | |
1330 | printf("ASenseL 0x%x\n", xp->sc_xsense.len); | |
1331 | ||
1332 | if (xp->sc_xsense.len != 0x12) /* MT_ISEXB Exabyte only ?? */ | |
1333 | return; /* What about others */ | |
1334 | ||
1335 | printf("ASenseC 0x%x\n", xp->exb_xsense.addsens); | |
1336 | printf("AsenseQ 0x%x\n", xp->exb_xsense.addsensq); | |
1337 | printf("R/W Errors 0x%lx\n", | |
1338 | (u_long)((xp->exb_xsense.rwerrcnt2<<16)| | |
1339 | (xp->exb_xsense.rwerrcnt1<<8)| | |
1340 | (xp->exb_xsense.rwerrcnt1)) ); | |
1341 | printf("PF 0x%x BPE 0x%x FPE 0x%x ME 0x%x ECO 0x%x TME 0x%x TNP 0x%x BOT 0x%x\n", | |
1342 | xp->exb_xsense.pf, xp->exb_xsense.bpe, xp->exb_xsense.fpe, | |
1343 | xp->exb_xsense.me, xp->exb_xsense.eco, xp->exb_xsense.tme, | |
1344 | xp->exb_xsense.tnp, xp->exb_xsense.bot); | |
1345 | printf("XFR 0x%x TMD 0x%x WP 0x%x FMKE 0x%x URE 0x%x WE1 0x%x SSE 0x%x FE 0x%x\n", | |
1346 | xp->exb_xsense.xfr, xp->exb_xsense.tmd, xp->exb_xsense.wp, | |
1347 | xp->exb_xsense.fmke, xp->exb_xsense.ure, xp->exb_xsense.we1, | |
1348 | xp->exb_xsense.sse, xp->exb_xsense.fe); | |
1349 | printf("WSEB 0x%x WSEO 0x%x\n", | |
1350 | xp->exb_xsense.wseb, xp->exb_xsense.wseo); | |
1351 | printf("Remaining Tape 0x%lx\n", | |
1352 | (u_long)((xp->exb_xsense.tplft2<<16)| | |
1353 | (xp->exb_xsense.tplft1<<8)| | |
1354 | (xp->exb_xsense.tplft0)) ); | |
1355 | } | |
1356 | ||
1357 | prtmodsel(msd, modlen) | |
1358 | struct mode_select_data *msd; | |
1359 | int modlen; | |
1360 | { | |
1361 | printf("Modsel command. len is 0x%x.\n", modlen); | |
1362 | printf("rsvd1 0x%x rsvd2 0x%x rsvd3 0x%x bufferd 0x%x speed 0x%x bckdeslen 0x%x\n", | |
1363 | msd->rsvd1,msd->rsvd2,msd->rsvd3,msd->buff,msd->speed,msd->blkdeslen); | |
1364 | printf("density 0x%x blks2 0x%x blks1 0x%x blks0 0x%x rsvd 0x%x blklen2 0x%x blklen1 0x%x blklen0 0x%x\n", | |
1365 | msd->density,msd->blks2,msd->blks1,msd->blks0,msd->rsvd4,msd->blklen2,msd->blklen1,msd->blklen0); | |
1366 | printf("vupb 0x%x rsvd 0x%x p5 0x%x motionthres 0x%x reconthres 0x%x gapthres 0x%x \n", | |
1367 | msd->vupb,msd->rsvd5,msd->p5,msd->motionthres,msd->reconthres,msd->gapthres); | |
1368 | } | |
1369 | ||
1370 | prtmodstat(mode) | |
1371 | struct mode_sense *mode; | |
1372 | { | |
1373 | printf("Mode Status\n"); | |
1374 | printf("sdl 0x%x medtype 0x%x wp 0x%x bfmd 0x%x speed 0x%x bdl 0x%x\n", | |
1375 | mode->md.sdl, mode->md.medtype, mode->md.wp, mode->md.bfmd, | |
1376 | mode->md.speed, mode->md.bdl); | |
1377 | printf("dencod 0x%x numblk 0x%x blklen 0x%x\n", | |
1378 | mode->md.dencod, | |
1379 | (mode->md.numblk2<<16)|(mode->md.numblk1<<8)|(mode->md.numblk0), | |
1380 | (mode->md.blklen2<<16)|(mode->md.blklen1<<8)|(mode->md.blklen0) ); | |
1381 | printf("ct 0x%x nd 0x%x nbe 0x%x edb 0x%x pe 0x%x nal 0x%x p5 0x%x\n", | |
1382 | mode->ex.ct, mode->ex.nd, mode->ex.nbe, | |
1383 | mode->ex.ebd, mode->ex.pe, mode->ex.nal, mode->ex.p5); | |
1384 | printf("motionthres 0x%x reconthres 0x%x gapthres 0x%x\n", | |
1385 | mode->ex.motionthres, mode->ex.reconthres, mode->ex.gapthres); | |
1386 | } | |
1387 | #endif /* DEBUG */ | |
1388 | ||
1389 | #endif |