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