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