Lines Matching refs:st
382 struct st_softc *st = device_private(self); in stattach() local
387 st->sc_dev = self; in stattach()
390 st->sc_periph = periph; in stattach()
391 periph->periph_dev = st->sc_dev; in stattach()
395 st->flags = ST_INIT_FLAGS; in stattach()
398 bufq_alloc(&st->buf_queue, "fcfs", 0); in stattach()
399 bufq_alloc(&st->buf_defer, "fcfs", 0); in stattach()
400 callout_init(&st->sc_callout, 0); in stattach()
401 mutex_init(&st->sc_iolock, MUTEX_DEFAULT, IPL_VM); in stattach()
407 st_identify_drive(st, &sa->sa_inqbuf); in stattach()
411 aprint_normal_dev(self, "%s", st->quirkdata ? "quirks apply, " : ""); in stattach()
414 st->ops(st, ST_OPS_MODESENSE, in stattach()
418 aprint_normal("density code %d, ", st->media_density); in stattach()
419 if (st->media_blksize > 0) in stattach()
420 aprint_normal("%d-byte", st->media_blksize); in stattach()
424 (st->flags & ST_READONLY) ? "protected" : "enabled"); in stattach()
427 st->stats = iostat_alloc(IOSTAT_TAPE, parent, in stattach()
428 device_xname(st->sc_dev)); in stattach()
430 rnd_attach_source(&st->rnd_source, device_xname(st->sc_dev), in stattach()
437 struct st_softc *st = device_private(self); in stdetach() local
438 struct scsipi_periph *periph = st->sc_periph; in stdetach()
447 callout_halt(&st->sc_callout, NULL); in stdetach()
452 bufq_drain(st->buf_defer); in stdetach()
453 bufq_drain(st->buf_queue); in stdetach()
456 scsipi_kill_pending(st->sc_periph); in stdetach()
460 bufq_free(st->buf_defer); in stdetach()
461 bufq_free(st->buf_queue); in stdetach()
462 mutex_destroy(&st->sc_iolock); in stdetach()
469 iostat_free(st->stats); in stdetach()
472 rnd_detach_source(&st->rnd_source); in stdetach()
482 st_identify_drive(struct st_softc *st, struct scsipi_inquiry_pattern *inqbuf) in st_identify_drive() argument
492 st->quirkdata = &finger->quirkdata; in st_identify_drive()
493 st->drive_quirks = finger->quirkdata.quirks; in st_identify_drive()
494 st->quirks = finger->quirkdata.quirks; /* start value */ in st_identify_drive()
495 st->page_0_size = finger->quirkdata.page_0_size; in st_identify_drive()
496 KASSERT(st->page_0_size <= MAX_PAGE_0_SIZE); in st_identify_drive()
497 st_loadquirks(st); in st_identify_drive()
507 st_loadquirks(struct st_softc *st) in st_loadquirks() argument
513 mode = st->quirkdata->modes; in st_loadquirks()
514 mode2 = st->modes; in st_loadquirks()
517 st->modeflags[i] &= ~(BLKSIZE_SET_BY_QUIRK | in st_loadquirks()
520 if ((mode->quirks | st->drive_quirks) & ST_Q_FORCE_BLKSIZE) { in st_loadquirks()
522 st->modeflags[i] |= BLKSIZE_SET_BY_QUIRK; in st_loadquirks()
526 st->modeflags[i] |= DENSITY_SET_BY_QUIRK; in st_loadquirks()
540 struct st_softc *st; in stopen() local
545 st = device_lookup_private(&st_cd, unit); in stopen()
546 if (st == NULL) in stopen()
552 periph = st->sc_periph; in stopen()
561 aprint_error_dev(st->sc_dev, "already open\n"); in stopen()
569 st->mt_resid = 0; in stopen()
570 st->mt_erreg = 0; in stopen()
571 st->asc = 0; in stopen()
572 st->ascq = 0; in stopen()
579 if ((st->flags & ST_MOUNTED) == 0 || stmode == CTRL_MODE) { in stopen()
594 if ((st->flags & ST_MOUNTED) || ST_MOUNT_DELAY == 0) in stopen()
617 if ((st->flags & ST_MOUNTED) || ST_MOUNT_DELAY == 0 || in stopen()
618 (st->mt_key != SKEY_NOT_READY)) { in stopen()
619 device_printf(st->sc_dev, in stopen()
622 st->mt_key); in stopen()
628 if (st->flags & ST_WRITTEN && in stopen()
629 st->mt_key == SKEY_UNIT_ATTENTION) { in stopen()
636 st->flags &= ~(ST_WRITTEN|ST_FM_WRITTEN); in stopen()
638 device_printf(st->sc_dev, in stopen()
641 st->asc, st->ascq); in stopen()
647 st->mt_resid = 0; in stopen()
648 st->mt_erreg = 0; in stopen()
649 st->asc = 0; in stopen()
650 st->ascq = 0; in stopen()
663 device_printf(st->sc_dev, "load interrupted\n"); in stopen()
677 st->mt_key != SKEY_NO_SENSE && in stopen()
678 st->mt_key != SKEY_UNIT_ATTENTION) { in stopen()
699 if (st->last_dsty != dsty || in stopen()
701 st_unmount(st, NOEJECT); in stopen()
707 if (!(st->flags & ST_MOUNTED)) { in stopen()
710 st->last_dsty = dsty; in stopen()
712 if (!(st->quirks & ST_Q_NOPREVENT)) { in stopen()
721 st_unmount(st, NOEJECT); in stopen()
731 struct st_softc *st = device_lookup_private(&st_cd, STUNIT(dev)); in stclose() local
732 struct scsipi_periph *periph = st->sc_periph; in stclose()
735 SC_DEBUG(st->sc_periph, SCSIPI_DB1, ("closing\n")); in stclose()
752 stxx = st->flags & (ST_WRITTEN | ST_FM_WRITTEN); in stclose()
762 st->flags |= ST_WRITTEN; in stclose()
763 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in stclose()
767 error = st_check_eod(st, FALSE, &nm, 0); in stclose()
768 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in stclose()
773 if (!(st->quirks & ST_Q_NOPREVENT)) { in stclose()
780 st_unmount(st, NOEJECT); in stclose()
795 st_unmount(st, NOEJECT); in stclose()
811 stxx |= (st->flags & ST_2FM_AT_EOD); in stclose()
814 error = st_space(st, -1, SP_FILEMARKS, 0); in stclose()
815 … SC_DEBUG(st->sc_periph, SCSIPI_DB3, ("st_space(-1) error=%d\n", error)); in stclose()
817 …SC_DEBUG(st->sc_periph, SCSIPI_DB3, ("no backspacing - flags = 0x%x, stxx=0x%x, st->flags=0x%x\n",… in stclose()
820 … SC_DEBUG(st->sc_periph, SCSIPI_DB3, ("error %d from st_check_eod\n", error)); in stclose()
825 st_unmount(st, EJECT); in stclose()
829 KASSERTMSG((st->flags & ST_WRITTEN) == 0, in stclose()
830 "pending ST_WRITTEN flag NOT cleared (flags=0x%x)", st->flags); in stclose()
850 struct st_softc *st; in st_mount_tape() local
856 st = device_lookup_private(&st_cd, unit); in st_mount_tape()
857 periph = st->sc_periph; in st_mount_tape()
859 if (st->flags & ST_MOUNTED) in st_mount_tape()
863 st->flags |= ST_NEW_MOUNT; in st_mount_tape()
864 st->quirks = st->drive_quirks | st->modes[dsty].quirks; in st_mount_tape()
869 if ((error = st_load(st, LD_LOAD, XS_CTL_SILENT)) != 0) in st_mount_tape()
883 if (st->quirks & ST_Q_SENSE_HELP) in st_mount_tape()
884 if ((error = st_touch_tape(st)) != 0) in st_mount_tape()
890 if ((error = st->ops(st, ST_OPS_RBL, 0)) != 0) in st_mount_tape()
898 if ((error = st->ops(st, ST_OPS_MODESENSE, 0)) != 0) in st_mount_tape()
905 if (st->modeflags[dsty] & (DENSITY_SET_BY_QUIRK | DENSITY_SET_BY_USER)) in st_mount_tape()
906 st->density = st->modes[dsty].density; in st_mount_tape()
908 st->density = st->media_density; in st_mount_tape()
914 st->flags &= ~ST_FIXEDBLOCKS; in st_mount_tape()
915 if (st->modeflags[dsty] & in st_mount_tape()
917 st->blksize = st->modes[dsty].blksize; in st_mount_tape()
918 if (st->blksize) in st_mount_tape()
919 st->flags |= ST_FIXEDBLOCKS; in st_mount_tape()
921 if ((error = st_decide_mode(st, FALSE)) != 0) in st_mount_tape()
924 if ((error = st->ops(st, ST_OPS_MODESELECT, 0)) != 0) { in st_mount_tape()
927 aprint_error_dev(st->sc_dev, in st_mount_tape()
932 st->flags &= ~ST_NEW_MOUNT; in st_mount_tape()
933 st->flags |= ST_MOUNTED; in st_mount_tape()
935 st->blkno = st->fileno = (daddr_t) 0; in st_mount_tape()
946 st_unmount(struct st_softc *st, boolean eject) in st_unmount() argument
948 struct scsipi_periph *periph = st->sc_periph; in st_unmount()
951 if ((st->flags & ST_MOUNTED) == 0) in st_unmount()
954 st_check_eod(st, FALSE, &nmarks, XS_CTL_IGNORE_NOT_READY); in st_unmount()
955 st_rewind(st, 0, XS_CTL_IGNORE_NOT_READY); in st_unmount()
967 st->density = 0; in st_unmount()
968 if (st->ops(st, ST_OPS_MODESELECT, 0) != 0) { in st_unmount()
969 aprint_error_dev(st->sc_dev, in st_unmount()
974 if (!(st->quirks & ST_Q_NOPREVENT)) { in st_unmount()
979 st_load(st, LD_UNLOAD, XS_CTL_IGNORE_NOT_READY); in st_unmount()
980 st->blkno = st->fileno = (daddr_t) -1; in st_unmount()
982 st->blkno = st->fileno = (daddr_t) 0; in st_unmount()
984 st->flags &= ~(ST_MOUNTED | ST_NEW_MOUNT); in st_unmount()
994 st_decide_mode(struct st_softc *st, boolean first_read) in st_decide_mode() argument
997 SC_DEBUG(st->sc_periph, SCSIPI_DB2, ("starting block mode decision\n")); in st_decide_mode()
1003 if (st->blkmin && (st->blkmin == st->blkmax)) { in st_decide_mode()
1004 st->flags |= ST_FIXEDBLOCKS; in st_decide_mode()
1005 st->blksize = st->blkmin; in st_decide_mode()
1006 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_decide_mode()
1007 ("blkmin == blkmax of %d\n", st->blkmin)); in st_decide_mode()
1014 switch (st->density) { in st_decide_mode()
1019 st->flags &= ~ST_FIXEDBLOCKS; in st_decide_mode()
1020 st->blksize = 0; in st_decide_mode()
1021 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_decide_mode()
1032 st->flags |= ST_FIXEDBLOCKS; in st_decide_mode()
1033 if (st->media_blksize > 0) in st_decide_mode()
1034 st->blksize = st->media_blksize; in st_decide_mode()
1036 st->blksize = DEF_FIXED_BSIZE; in st_decide_mode()
1037 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_decide_mode()
1047 (!(st->quirks & ST_Q_BLKSIZE) || (st->media_blksize == 0) || in st_decide_mode()
1048 (st->media_blksize == DEF_FIXED_BSIZE) || in st_decide_mode()
1049 (st->media_blksize == 1024))) { in st_decide_mode()
1050 if (st->media_blksize > 0) in st_decide_mode()
1051 st->flags |= ST_FIXEDBLOCKS; in st_decide_mode()
1053 st->flags &= ~ST_FIXEDBLOCKS; in st_decide_mode()
1054 st->blksize = st->media_blksize; in st_decide_mode()
1055 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_decide_mode()
1056 ("Used media_blksize of %d\n", st->media_blksize)); in st_decide_mode()
1063 st->flags &= ~ST_FIXEDBLOCKS; in st_decide_mode()
1064 st->blksize = 0; in st_decide_mode()
1065 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_decide_mode()
1077 switch (st->density) { in st_decide_mode()
1087 st->flags &= ~ST_2FM_AT_EOD; in st_decide_mode()
1090 st->flags |= ST_2FM_AT_EOD; in st_decide_mode()
1104 struct st_softc *st = device_lookup_private(&st_cd, STUNIT(bp->b_dev)); in ststrategy() local
1105 struct scsipi_periph *periph = st->sc_periph; in ststrategy()
1124 if (st->flags & ST_FIXEDBLOCKS) { in ststrategy()
1125 if (bp->b_bcount % st->blksize) { in ststrategy()
1126 aprint_error_dev(st->sc_dev, "bad request, must be multiple of %d\n", in ststrategy()
1127 st->blksize); in ststrategy()
1133 else if (bp->b_bcount < st->blkmin || in ststrategy()
1134 (st->blkmax && bp->b_bcount > st->blkmax)) { in ststrategy()
1135 aprint_error_dev(st->sc_dev, "bad request, must be between %d and %d\n", in ststrategy()
1136 st->blkmin, st->blkmax); in ststrategy()
1147 bufq_put(st->buf_queue, bp); in ststrategy()
1188 struct st_softc *st = device_private(periph->periph_dev); in ststart1() local
1215 if (__predict_false((st->flags & ST_MOUNTED) == 0 || in ststart1()
1224 if (st->flags & ST_FIXEDBLOCKS) { in ststart1()
1229 if (st->flags & ST_AT_FILEMARK) { in ststart1()
1237 if (st_space(st, 0, SP_FILEMARKS, 0)) { in ststart1()
1243 st->flags &= ~ST_AT_FILEMARK; in ststart1()
1252 if (st->flags & (ST_EOM_PENDING|ST_EIO_PENDING)) { in ststart1()
1254 if (st->flags & ST_EIO_PENDING) in ststart1()
1256 st->flags &= ~(ST_EOM_PENDING|ST_EIO_PENDING); in ststart1()
1265 st->flags &= ~ST_FM_WRITTEN; in ststart1()
1276 if (st->flags & ST_FIXEDBLOCKS) { in ststart1()
1278 _lto3b(bp->b_bcount / st->blksize, cmd.len); in ststart1()
1283 st->flags &= ~ST_POSUPDATED; in ststart1()
1295 callout_reset(&st->sc_callout, hz / 2, strestart, in ststart1()
1317 struct st_softc *st = device_private(periph->periph_dev); in ststart() local
1325 mutex_enter(&st->sc_iolock); in ststart()
1327 while ((bp = bufq_get(st->buf_defer)) != NULL in ststart()
1328 || (bp = bufq_get(st->buf_queue)) != NULL) { in ststart()
1330 iostat_busy(st->stats); in ststart()
1331 mutex_exit(&st->sc_iolock); in ststart()
1335 mutex_enter(&st->sc_iolock); in ststart()
1337 iostat_unbusy(st->stats, 0, in ststart()
1340 bufq_put(st->buf_defer, bp); in ststart()
1344 mutex_exit(&st->sc_iolock); in ststart()
1352 mutex_enter(&st->sc_iolock); in ststart()
1355 mutex_exit(&st->sc_iolock); in ststart()
1373 struct st_softc *st = device_private(xs->xs_periph->periph_dev); in stdone() local
1387 mutex_enter(&st->sc_iolock); in stdone()
1390 st->flags |= ST_WRITTEN; in stdone()
1392 st->flags &= ~ST_WRITTEN; in stdone()
1394 iostat_unbusy(st->stats, bp->b_bcount, in stdone()
1397 if ((st->flags & ST_POSUPDATED) == 0) { in stdone()
1399 st->fileno = st->blkno = -1; in stdone()
1400 } else if (st->blkno != -1) { in stdone()
1401 if (st->flags & ST_FIXEDBLOCKS) in stdone()
1402 st->blkno += in stdone()
1403 (bp->b_bcount / st->blksize); in stdone()
1405 st->blkno++; in stdone()
1409 mutex_exit(&st->sc_iolock); in stdone()
1411 rnd_add_uint32(&st->rnd_source, bp->b_blkno); in stdone()
1420 struct st_softc *st = device_lookup_private(&st_cd, STUNIT(dev)); in stread() local
1423 st->sc_periph->periph_channel->chan_adapter->adapt_minphys, uio); in stread()
1425 SC_DEBUG(st->sc_periph, SCSIPI_DB1, ("[stread: result=%d]\n", r)); in stread()
1433 struct st_softc *st = device_lookup_private(&st_cd, STUNIT(dev)); in stwrite() local
1436 st->sc_periph->periph_channel->chan_adapter->adapt_minphys, uio); in stwrite()
1438 SC_DEBUG(st->sc_periph, SCSIPI_DB1, ("[stwrite: result=%d]\n", r)); in stwrite()
1454 struct st_softc *st; in stioctl() local
1463 st = device_lookup_private(&st_cd, unit); in stioctl()
1464 hold_blksize = st->blksize; in stioctl()
1465 hold_density = st->density; in stioctl()
1473 error = st->ops(st, ST_OPS_MODESENSE, XS_CTL_SILENT); in stioctl()
1483 SC_DEBUG(st->sc_periph, SCSIPI_DB1, ("[ioctl: get status]\n")); in stioctl()
1486 g->mt_blksiz = st->blksize; in stioctl()
1487 g->mt_density = st->density; in stioctl()
1488 g->mt_mblksiz[0] = st->modes[0].blksize; in stioctl()
1489 g->mt_mblksiz[1] = st->modes[1].blksize; in stioctl()
1490 g->mt_mblksiz[2] = st->modes[2].blksize; in stioctl()
1491 g->mt_mblksiz[3] = st->modes[3].blksize; in stioctl()
1492 g->mt_mdensity[0] = st->modes[0].density; in stioctl()
1493 g->mt_mdensity[1] = st->modes[1].density; in stioctl()
1494 g->mt_mdensity[2] = st->modes[2].density; in stioctl()
1495 g->mt_mdensity[3] = st->modes[3].density; in stioctl()
1496 g->mt_fileno = st->fileno; in stioctl()
1497 g->mt_blkno = st->blkno; in stioctl()
1498 if (st->flags & ST_READONLY) in stioctl()
1500 if (st->flags & ST_MOUNTED) in stioctl()
1502 g->mt_resid = st->mt_resid; in stioctl()
1503 g->mt_erreg = st->mt_erreg; in stioctl()
1507 st->mt_resid = 0; in stioctl()
1508 st->mt_erreg = 0; in stioctl()
1509 st->asc = 0; in stioctl()
1510 st->ascq = 0; in stioctl()
1514 SC_DEBUG(st->sc_periph, SCSIPI_DB1, in stioctl()
1522 error = st_write_filemarks(st, number, flags); in stioctl()
1528 error = st_check_eod(st, FALSE, &nmarks, flags); in stioctl()
1530 error = st_space(st, number - nmarks, in stioctl()
1537 error = st_check_eod(st, true, &nmarks, flags); in stioctl()
1539 error = st_space(st, number, SP_BLKS, flags); in stioctl()
1542 error = st_rewind(st, 0, flags); in stioctl()
1545 st_unmount(st, EJECT); in stioctl()
1550 error = st_load(st, LD_RETENSION, flags); in stioctl()
1552 error = st_load(st, LD_LOAD, flags); in stioctl()
1555 error = st_check_eod(st, FALSE, &nmarks, flags); in stioctl()
1557 error = st_space(st, 1, SP_EOM, flags); in stioctl()
1560 st->flags &= ~ST_DONTBUFFER; in stioctl()
1563 st->flags |= ST_DONTBUFFER; in stioctl()
1566 error = st_erase(st, number, flags); in stioctl()
1570 if (!(st->flags & ST_NEW_MOUNT)) { in stioctl()
1578 st->flags &= ~ST_FIXEDBLOCKS; in stioctl()
1580 if ((st->blkmin || st->blkmax) && in stioctl()
1581 (number < st->blkmin || in stioctl()
1582 number > st->blkmax)) { in stioctl()
1586 st->flags |= ST_FIXEDBLOCKS; in stioctl()
1588 st->blksize = number; in stioctl()
1589 st->flags |= ST_BLOCK_SET; /*XXX */ in stioctl()
1600 st->density = number; in stioctl()
1603 error = st->ops(st, (number == 0) ? in stioctl()
1609 st->flags |= ST_EARLYWARN; in stioctl()
1611 st->flags &= ~ST_EARLYWARN; in stioctl()
1623 error = st_rdpos(st, 0, (uint32_t *)arg); in stioctl()
1626 error = st_rdpos(st, 1, (uint32_t *)arg); in stioctl()
1629 error = st_setpos(st, 0, (uint32_t *)arg); in stioctl()
1632 error = st_setpos(st, 1, (uint32_t *)arg); in stioctl()
1635 error = scsipi_do_ioctl(st->sc_periph, dev, cmd, arg, flag, l); in stioctl()
1648 if ((STMODE(dev) != CTRL_MODE || (st->flags & ST_MOUNTED) != 0) && in stioctl()
1649 (error = st->ops(st, ST_OPS_MODESELECT, 0)) != 0) { in stioctl()
1651 aprint_error_dev(st->sc_dev, "cannot set selected mode\n"); in stioctl()
1652 st->density = hold_density; in stioctl()
1653 st->blksize = hold_blksize; in stioctl()
1654 if (st->blksize) in stioctl()
1655 st->flags |= ST_FIXEDBLOCKS; in stioctl()
1657 st->flags &= ~ST_FIXEDBLOCKS; in stioctl()
1671 st->modes[dsty].blksize = st->blksize; in stioctl()
1672 st->modeflags[dsty] |= BLKSIZE_SET_BY_USER; in stioctl()
1675 st->modes[dsty].density = st->density; in stioctl()
1676 st->modeflags[dsty] |= DENSITY_SET_BY_USER; in stioctl()
1685 st_read(struct st_softc *st, char *bf, int size, int flags) in st_read() argument
1694 if (st->flags & ST_FIXEDBLOCKS) { in st_read()
1696 _lto3b(size / (st->blksize ? st->blksize : DEF_FIXED_BSIZE), in st_read()
1700 return scsipi_command(st->sc_periph, in st_read()
1707 st_erase(struct st_softc *st, int full, int flags) in st_erase() argument
1730 if ((st->quirks & ST_Q_ERASE_NOIMM) == 0) in st_erase()
1733 return scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0, 0, in st_erase()
1739 st_space(struct st_softc *st, int number, u_int what, int flags) in st_space() argument
1746 if (st->flags & ST_PER_ACTION) { in st_space()
1748 st->flags &= ~ST_PER_ACTION; in st_space()
1751 if (st->flags & ST_AT_FILEMARK) { in st_space()
1757 error = st_space(st, 0, SP_FILEMARKS, in st_space()
1762 if (st->flags & ST_BLANK_READ) { in st_space()
1763 st->flags &= ~ST_BLANK_READ; in st_space()
1766 st->flags &= ~(ST_EIO_PENDING|ST_EOM_PENDING); in st_space()
1771 if (st->flags & ST_EIO_PENDING) { in st_space()
1774 st->flags &= ~ST_EIO_PENDING; in st_space()
1778 st->flags &= ~ST_EIO_PENDING; in st_space()
1781 if (st->flags & ST_AT_FILEMARK) { in st_space()
1782 st->flags &= ~ST_AT_FILEMARK; in st_space()
1785 if ((st->flags & ST_BLANK_READ) && (number < 0)) { in st_space()
1787 st->flags &= ~ST_BLANK_READ; in st_space()
1792 if (st->flags & ST_EOM_PENDING) { in st_space()
1794 st->flags &= ~ST_EOM_PENDING; in st_space()
1797 if (st->flags & ST_EIO_PENDING) { in st_space()
1799 st->flags &= ~ST_EIO_PENDING; in st_space()
1802 if (st->flags & ST_AT_FILEMARK) in st_space()
1803 st->flags &= ~ST_AT_FILEMARK; in st_space()
1814 st->flags &= ~ST_POSUPDATED; in st_space()
1815 st->last_ctl_resid = 0; in st_space()
1816 error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0, 0, in st_space()
1819 if (error == 0 && (st->flags & ST_POSUPDATED) == 0) { in st_space()
1820 number = number - st->last_ctl_resid; in st_space()
1822 if (st->blkno != -1) in st_space()
1823 st->blkno += number; in st_space()
1825 if (st->fileno != -1) { in st_space()
1826 st->fileno += number; in st_space()
1828 st->blkno = 0; in st_space()
1830 st->blkno = -1; in st_space()
1833 st_updatefilepos(st); in st_space()
1843 st_write_filemarks(struct st_softc *st, int number, int flags) in st_write_filemarks() argument
1853 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_write_filemarks()
1862 if (st->flags & ST_FM_WRITTEN) /* already have one down */ in st_write_filemarks()
1863 st->flags &= ~ST_WRITTEN; in st_write_filemarks()
1865 st->flags |= ST_FM_WRITTEN; in st_write_filemarks()
1866 st->flags &= ~ST_PER_ACTION; in st_write_filemarks()
1869 st->flags &= ~(ST_PER_ACTION | ST_WRITTEN); in st_write_filemarks()
1874 if (SCSIPI_BUSTYPE_TYPE(scsipi_periph_bustype(st->sc_periph)) == in st_write_filemarks()
1881 if ((st->quirks & ST_Q_NOFILEMARKS) == 0) in st_write_filemarks()
1885 error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0, 0, in st_write_filemarks()
1887 if (error == 0 && st->fileno != -1) in st_write_filemarks()
1888 st->fileno += number; in st_write_filemarks()
1901 st_check_eod(struct st_softc *st, boolean position, int *nmarks, int flags) in st_check_eod() argument
1905 switch (st->flags & (ST_WRITTEN | ST_FM_WRITTEN | ST_2FM_AT_EOD)) { in st_check_eod()
1916 error = st_write_filemarks(st, *nmarks, flags); in st_check_eod()
1918 error = st_space(st, -*nmarks, SP_FILEMARKS, flags); in st_check_eod()
1924 st_load(struct st_softc *st, u_int type, int flags) in st_load() argument
1932 error = st_check_eod(st, FALSE, &nmarks, flags); in st_load()
1934 aprint_error_dev(st->sc_dev, in st_load()
1940 if (st->quirks & ST_Q_IGNORE_LOADS) { in st_load()
1945 return st_rewind(st, 0, flags); in st_load()
1951 if (SCSIPI_BUSTYPE_TYPE(scsipi_periph_bustype(st->sc_periph)) == in st_load()
1956 error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0, 0, in st_load()
1959 aprint_error_dev(st->sc_dev, "error %d in st_load (op %d)\n", in st_load()
1967 st_rewind(struct st_softc *st, u_int immediate, int flags) in st_rewind() argument
1974 error = st_check_eod(st, FALSE, &nmarks, flags); in st_rewind()
1976 aprint_error_dev(st->sc_dev, in st_rewind()
1981 st->flags &= ~ST_PER_ACTION; in st_rewind()
1987 if (scsipi_periph_bustype(st->sc_periph) == SCSIPI_BUSTYPE_ATAPI) in st_rewind()
1994 error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0, 0, in st_rewind()
1997 aprint_error_dev(st->sc_dev, "error %d trying to rewind\n", in st_rewind()
2000 st->fileno = st->blkno = -1; in st_rewind()
2002 st->fileno = st->blkno = 0; in st_rewind()
2007 st_updatefilepos(struct st_softc *st) in st_updatefilepos() argument
2018 error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), in st_updatefilepos()
2024 if (st->sc_periph->periph_dbflags & SCSIPI_DB3) { in st_updatefilepos()
2034 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_updatefilepos()
2038 st->fileno = _8btol(&posdata[16]); in st_updatefilepos()
2039 st->blkno = 0; in st_updatefilepos()
2040 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_updatefilepos()
2042 st->fileno)); in st_updatefilepos()
2046 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_updatefilepos()
2050 st->fileno = -1; in st_updatefilepos()
2051 st->blkno = -1; in st_updatefilepos()
2055 st_rdpos(struct st_softc *st, int hard, uint32_t *blkptr) in st_rdpos() argument
2071 if (hard && (st->flags & ST_WRITTEN)) { in st_rdpos()
2073 error = st_write_filemarks(st, 0, XS_CTL_SILENT); in st_rdpos()
2089 error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), in st_rdpos()
2101 SC_DEBUG(st->sc_periph, SCSIPI_DB3, in st_rdpos()
2112 st_setpos(struct st_softc *st, int hard, uint32_t *blkptr) in st_setpos() argument
2132 error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0, 0, in st_setpos()
2138 st->fileno = st->blkno = -1; in st_setpos()
2154 struct st_softc *st = device_private(periph->periph_dev); in st_interpret_sense() local
2171 info = (st->flags & ST_FIXEDBLOCKS) ? in st_interpret_sense()
2172 xs->datalen / st->blksize : xs->datalen; in st_interpret_sense()
2174 st->mt_erreg = key; in st_interpret_sense()
2175 st->asc = sense->asc; in st_interpret_sense()
2176 st->ascq = sense->ascq; in st_interpret_sense()
2177 st->mt_resid = (short) info; in st_interpret_sense()
2179 if (key == SKEY_NOT_READY && st->asc == 0x4 && st->ascq == 0x1) { in st_interpret_sense()
2193 if (st->flags & ST_FIXEDBLOCKS) { in st_interpret_sense()
2195 xs->resid *= st->blksize; in st_interpret_sense()
2196 st->last_io_resid = xs->resid; in st_interpret_sense()
2198 st->last_ctl_resid = xs->resid; in st_interpret_sense()
2200 st->flags |= ST_EIO_PENDING; in st_interpret_sense()
2204 if ((st->flags & ST_EARLYWARN) == 0) in st_interpret_sense()
2205 st->flags |= ST_EIO_PENDING; in st_interpret_sense()
2206 st->flags |= ST_EOM_PENDING; in st_interpret_sense()
2222 st->flags |= ST_AT_FILEMARK; in st_interpret_sense()
2225 if (st->fileno != (daddr_t) -1) { in st_interpret_sense()
2226 st->fileno++; in st_interpret_sense()
2227 st->blkno = 0; in st_interpret_sense()
2228 st->flags |= ST_POSUPDATED; in st_interpret_sense()
2232 st->flags |= ST_EIO_PENDING; in st_interpret_sense()
2237 aprint_error_dev(st->sc_dev, in st_interpret_sense()
2248 if ((st->quirks & ST_Q_SENSE_HELP) && in st_interpret_sense()
2250 st->blksize -= 512; in st_interpret_sense()
2251 else if ((st->flags & ST_POSUPDATED) == 0) { in st_interpret_sense()
2252 if (st->blkno != (daddr_t) -1) { in st_interpret_sense()
2253 st->blkno += in st_interpret_sense()
2254 (xs->datalen / st->blksize); in st_interpret_sense()
2255 st->flags |= ST_POSUPDATED; in st_interpret_sense()
2263 if (st->flags & ST_EIO_PENDING) in st_interpret_sense()
2265 if (st->flags & ST_AT_FILEMARK) { in st_interpret_sense()
2273 st->last_io_resid = xs->resid; in st_interpret_sense()
2275 st->last_ctl_resid = xs->resid; in st_interpret_sense()
2285 if (st->flags & ST_EARLYWARN) { in st_interpret_sense()
2286 st->flags |= ST_EOM_PENDING; in st_interpret_sense()
2307 if (st->fileno != (daddr_t) -1) { in st_interpret_sense()
2308 st->fileno++; in st_interpret_sense()
2309 st->blkno = 0; in st_interpret_sense()
2310 st->flags |= ST_POSUPDATED; in st_interpret_sense()
2319 aprint_error_dev(st->sc_dev, in st_interpret_sense()
2327 if (st->blkno != (daddr_t) -1) { in st_interpret_sense()
2328 st->blkno++; in st_interpret_sense()
2329 st->flags |= ST_POSUPDATED; in st_interpret_sense()
2348 if ((st->quirks & ST_Q_SENSE_HELP) && in st_interpret_sense()
2351 st->blksize -= 512; in st_interpret_sense()
2352 } else if (!(st->flags & (ST_2FM_AT_EOD | ST_BLANK_READ))) { in st_interpret_sense()
2353 st->flags |= ST_BLANK_READ; in st_interpret_sense()
2361 st->fileno = st->blkno = -1; in st_interpret_sense()
2429 st_touch_tape(struct st_softc *st) in st_touch_tape() argument
2436 if ((error = st->ops(st, ST_OPS_MODESENSE, 0)) != 0) in st_touch_tape()
2443 if (st->media_blksize > 0) in st_touch_tape()
2444 st->blksize = st->media_blksize; in st_touch_tape()
2446 st->blksize = 1024; in st_touch_tape()
2449 switch (st->blksize) { in st_touch_tape()
2452 readsize = st->blksize; in st_touch_tape()
2453 st->flags |= ST_FIXEDBLOCKS; in st_touch_tape()
2457 st->flags &= ~ST_FIXEDBLOCKS; in st_touch_tape()
2459 if ((error = st->ops(st, ST_OPS_MODESELECT, XS_CTL_SILENT)) in st_touch_tape()
2468 st->blksize -= 512; in st_touch_tape()
2471 st_read(st, bf, readsize, XS_CTL_SILENT); /* XXX */ in st_touch_tape()
2472 if ((error = st_rewind(st, 0, 0)) != 0) { in st_touch_tape()
2476 } while (readsize != 1 && readsize > st->blksize); in st_touch_tape()
2494 st_mode_select(struct st_softc *st, int flags) in st_mode_select() argument
2502 struct scsipi_periph *periph = st->sc_periph; in st_mode_select()
2505 st->page_0_size; in st_mode_select()
2512 if (st->quirks & ST_Q_UNIMODAL) { in st_mode_select()
2515 st->density, st->blksize)); in st_mode_select()
2524 select.blk_desc.density = st->density; in st_mode_select()
2525 if (st->flags & ST_DONTBUFFER) in st_mode_select()
2529 if (st->flags & ST_FIXEDBLOCKS) in st_mode_select()
2530 _lto3b(st->blksize, select.blk_desc.blklen); in st_mode_select()
2531 if (st->page_0_size) in st_mode_select()
2532 memcpy(select.sense_data, st->sense_data, st->page_0_size); in st_mode_select()