Lines Matching refs:un

46 #define	IOSP	KSTAT_IO_PTR(un->un_stats)
53 if ((bp != un->un_sbufp) && un->un_stats && IS_RW(bp)) { \
57 #define ST_DO_ERRSTATS(un, x) \
58 if (un->un_errstats) { \
60 stp = (struct st_errstats *)un->un_errstats->ks_data; \
84 #define ST_GET_CONTIG_MEM_HEAD(un, cp, len, big_enough) { \
86 for ((cp) = (un)->un_contig_mem; \
92 (un)->un_contig_mem = (cp)->cm_next; \
97 (un)->un_contig_mem_available_num--; \
290 {"un", MT_DENSITY4 | MT_NOREWIND},
492 static void st_known_tape_type(struct scsi_tape *un);
509 static int st_find_eod(struct scsi_tape *un);
511 static int st_uscsi_cmd(struct scsi_tape *un, struct uscsi_cmd *, int flag);
512 static int st_mtioctop(struct scsi_tape *un, intptr_t arg, int flag);
513 static int st_mtiocltop(struct scsi_tape *un, intptr_t arg, int flag);
514 static int st_do_mtioctop(struct scsi_tape *un, struct mtlop *mtop);
515 static void st_start(struct scsi_tape *un);
516 static int st_handle_start_busy(struct scsi_tape *un, struct buf *bp,
518 static int st_handle_intr_busy(struct scsi_tape *un, struct buf *bp,
520 static int st_handle_intr_retry_lcmd(struct scsi_tape *un, struct buf *bp);
521 static void st_done_and_mutex_exit(struct scsi_tape *un, struct buf *bp);
522 static void st_init(struct scsi_tape *un);
523 static void st_make_cmd(struct scsi_tape *un, struct buf *bp,
528 static void st_set_state(struct scsi_tape *un, buf_t *bp);
531 static int st_cmd(struct scsi_tape *un, int com, int64_t count, int wait);
532 static int st_setup_cmd(struct scsi_tape *un, buf_t *bp, int com,
534 static int st_set_compression(struct scsi_tape *un);
536 static int st_determine_generic(struct scsi_tape *un);
537 static int st_determine_density(struct scsi_tape *un, int rw);
538 static int st_get_density(struct scsi_tape *un);
539 static int st_set_density(struct scsi_tape *un);
540 static int st_loadtape(struct scsi_tape *un);
541 static int st_modesense(struct scsi_tape *un);
542 static int st_modeselect(struct scsi_tape *un);
543 static errstate st_handle_incomplete(struct scsi_tape *un, struct buf *bp);
544 static int st_wrongtapetype(struct scsi_tape *un);
545 static errstate st_check_error(struct scsi_tape *un, struct scsi_pkt *pkt);
546 static errstate st_handle_sense(struct scsi_tape *un, struct buf *bp,
548 static errstate st_handle_autosense(struct scsi_tape *un, struct buf *bp,
550 static int st_get_error_entry(struct scsi_tape *un, intptr_t arg, int flag);
551 static void st_update_error_stack(struct scsi_tape *un, struct scsi_pkt *pkt,
553 static void st_empty_error_stack(struct scsi_tape *un);
554 static errstate st_decode_sense(struct scsi_tape *un, struct buf *bp, int amt,
562 static int st_gen_mode_sense(struct scsi_tape *un, ubufunc_t ubf, int page,
564 static int st_change_block_size(struct scsi_tape *un, uint32_t nblksz);
565 static int st_gen_mode_select(struct scsi_tape *un, ubufunc_t ubf,
567 static int st_read_block_limits(struct scsi_tape *un,
569 static int st_report_density_support(struct scsi_tape *un,
571 static int st_report_supported_operation(struct scsi_tape *un,
573 static int st_tape_init(struct scsi_tape *un);
574 static void st_flush(struct scsi_tape *un);
575 static void st_set_pe_errno(struct scsi_tape *un);
576 static void st_hba_unflush(struct scsi_tape *un);
577 static void st_turn_pe_on(struct scsi_tape *un);
578 static void st_turn_pe_off(struct scsi_tape *un);
579 static void st_set_pe_flag(struct scsi_tape *un);
580 static void st_clear_pe(struct scsi_tape *un);
581 static void st_wait_for_io(struct scsi_tape *un);
582 static int st_set_devconfig_page(struct scsi_tape *un, int compression_on);
583 static int st_set_datacomp_page(struct scsi_tape *un, int compression_on);
584 static int st_reserve_release(struct scsi_tape *un, int command, ubufunc_t ubf);
585 static int st_check_cdb_for_need_to_reserve(struct scsi_tape *un, uchar_t *cdb);
586 static int st_check_cmd_for_need_to_reserve(struct scsi_tape *un, uchar_t cmd,
588 static int st_take_ownership(struct scsi_tape *un, ubufunc_t ubf);
589 static int st_check_asc_ascq(struct scsi_tape *un);
590 static int st_check_clean_bit(struct scsi_tape *un);
591 static int st_check_alert_flags(struct scsi_tape *un);
592 static int st_check_sequential_clean_bit(struct scsi_tape *un);
593 static int st_check_sense_clean_bit(struct scsi_tape *un);
595 static void st_calculate_timeouts(struct scsi_tape *un);
596 static writablity st_is_drive_worm(struct scsi_tape *un);
597 static int st_read_attributes(struct scsi_tape *un, uint16_t attribute,
599 static int st_get_special_inquiry(struct scsi_tape *un, uchar_t size,
601 static int st_update_block_pos(struct scsi_tape *un, bufunc_t bf,
603 static int st_interpret_read_pos(struct scsi_tape const *un, tapepos_t *dest,
605 static int st_get_read_pos(struct scsi_tape *un, buf_t *bp);
606 static int st_logical_block_locate(struct scsi_tape *un, ubufunc_t ubf,
608 static int st_mtfsf_ioctl(struct scsi_tape *un, int64_t files);
609 static int st_mtfsr_ioctl(struct scsi_tape *un, int64_t count);
610 static int st_mtbsf_ioctl(struct scsi_tape *un, int64_t files);
611 static int st_mtnbsf_ioctl(struct scsi_tape *un, int64_t count);
612 static int st_mtbsr_ioctl(struct scsi_tape *un, int64_t num);
613 static int st_mtfsfm_ioctl(struct scsi_tape *un, int64_t cnt);
614 static int st_mtbsfm_ioctl(struct scsi_tape *un, int64_t cnt);
615 static int st_backward_space_files(struct scsi_tape *un, int64_t count,
617 static int st_forward_space_files(struct scsi_tape *un, int64_t files);
618 static int st_scenic_route_to_begining_of_file(struct scsi_tape *un,
620 static int st_space_to_begining_of_file(struct scsi_tape *un);
621 static int st_space_records(struct scsi_tape *un, int64_t records);
622 static int st_get_media_identification(struct scsi_tape *un, ubufunc_t bufunc);
623 static errstate st_command_recovery(struct scsi_tape *un, struct scsi_pkt *pkt,
627 static int st_rcmd(struct scsi_tape *un, int com, int64_t count, int wait);
628 static int st_uscsi_rcmd(struct scsi_tape *un, struct uscsi_cmd *ucmd,
630 static void st_add_recovery_info_to_pkt(struct scsi_tape *un, buf_t *bp,
632 static int st_check_mode_for_change(struct scsi_tape *un, ubufunc_t ubf);
633 static int st_test_path_to_device(struct scsi_tape *un);
634 static int st_recovery_read_pos(struct scsi_tape *un, read_p_types type,
636 static int st_recovery_get_position(struct scsi_tape *un, tapepos_t *read,
638 static int st_compare_expected_position(struct scsi_tape *un, st_err_info *ei,
642 static int st_transport(struct scsi_tape *un, struct scsi_pkt *pkt);
645 static int st_reset(struct scsi_tape *un, int reset_type);
649 static int st_set_target_TLR_mode(struct scsi_tape *un, ubufunc_t ubf);
650 static int st_make_sure_mode_data_is_correct(struct scsi_tape *un,
657 static void st_release_contig_mem(struct scsi_tape *un, struct contig_mem *cp);
658 static struct contig_mem *st_get_contig_mem(struct scsi_tape *un, size_t len,
670 static int st_validate_tapemarks(struct scsi_tape *un, ubufunc_t ubf,
674 static void st_debug_cmds(struct scsi_tape *un, int com, int count, int wait);
872 struct scsi_tape *un;
899 if (!(un = ddi_get_soft_state(st_state, instance))) {
902 dev_instance = ((un->un_dev == 0) ? MTMINOR(instance) :
903 un->un_dev);
907 un->un_throttle = un->un_max_throttle;
908 un->un_tids_at_suspend = 0;
909 un->un_pwr_mgmt = ST_PWR_NORMAL;
911 if (un->un_swr_token) {
912 scsi_watch_resume(un->un_swr_token);
918 if ((un->un_tids_at_suspend & ST_DELAY_TID) != 0) {
920 un->un_delay_tid = timeout(
921 st_delayed_cv_broadcast, un,
927 if (un->un_tids_at_suspend & ST_HIB_TID) {
929 un->un_hib_tid = timeout(st_intr_restart, un,
939 if ((un->un_suspend_pos.pmode != invalid) &&
940 ((un->un_suspend_pos.fileno > 0) ||
941 (un->un_suspend_pos.blkno > 0)) ||
942 (un->un_suspend_pos.lgclblkno > 0)) {
953 (void) st_validate_tapemarks(un,
954 st_uscsi_cmd, &un->un_suspend_pos);
960 un->un_suspend_pos.pmode = invalid;
964 if (un->un_ncmds || un->un_quef) {
965 st_start(un);
968 cv_broadcast(&un->un_suspend_cv);
976 un = ddi_get_soft_state(st_state, instance);
1008 un->un_arq_enabled = 1;
1010 un->un_arq_enabled =
1015 (un->un_arq_enabled ? "enabled" : "disabled"));
1017 un->un_untagged_qing =
1024 if (un->un_arq_enabled && un->un_untagged_qing) {
1038 un->un_max_throttle = un->un_throttle = un->un_last_throttle = 1;
1039 un->un_flush_on_errors = 0;
1040 un->un_mkr_pkt = (struct scsi_pkt *)NULL;
1044 un->un_throttle, un->un_max_throttle);
1047 un->un_persistence = 0;
1048 un->un_persist_errors = 0;
1053 un->un_maxdma = scsi_ifgetcap(&devp->sd_address, "dma-max", 1);
1054 if (un->un_maxdma == -1) {
1057 un->un_maxdma = (64 * ONE_K);
1075 un->un_maxdma_arch = scsi_ifgetcap(&devp->sd_address, "dma-max-arch",
1082 if ((un->un_maxdma_arch == -1) ||
1083 ((uint_t)un->un_maxdma < (uint_t)un->un_maxdma_arch)) {
1084 un->un_maxdma_arch = un->un_maxdma;
1091 un->un_max_cdb_sz =
1093 if (un->un_max_cdb_sz < CDB_GROUP0) {
1095 "HBA reported max-cdb-length as %d\n", un->un_max_cdb_sz);
1096 un->un_max_cdb_sz = CDB_GROUP4; /* optimistic default */
1100 un->un_multipath = 0;
1102 un->un_multipath = 1;
1105 un->un_maxbsize = MAXBSIZE_UNKNOWN;
1107 un->un_mediastate = MTIO_NONE;
1108 un->un_HeadClean = TAPE_ALERT_SUPPORT_UNKNOWN;
1113 un->un_stats = kstat_create("st", instance, NULL, "tape",
1115 if (un->un_stats) {
1116 un->un_stats->ks_lock = ST_MUTEX;
1117 kstat_install(un->un_stats);
1119 (void) st_create_errstats(un, instance);
1125 un->un_dev = MTMINOR(instance);
1126 st_known_tape_type(un);
1127 un->un_dev = 0;
1142 minor |= un->un_dp->default_density;
1154 st_reset_notification, (caddr_t)un);
1155 cv_destroy(&un->un_clscv);
1156 cv_destroy(&un->un_sbuf_cv);
1157 cv_destroy(&un->un_queue_cv);
1158 cv_destroy(&un->un_state_cv);
1160 cv_destroy(&un->un_contig_mem_cv);
1162 cv_destroy(&un->un_suspend_cv);
1163 cv_destroy(&un->un_tape_busy_cv);
1164 cv_destroy(&un->un_recov_buf_cv);
1165 if (un->un_recov_taskq) {
1166 ddi_taskq_destroy(un->un_recov_taskq);
1168 if (un->un_sbufp) {
1169 freerbuf(un->un_sbufp);
1171 if (un->un_recov_buf) {
1172 freerbuf(un->un_recov_buf);
1174 if (un->un_uscsi_rqs_buf) {
1175 kmem_free(un->un_uscsi_rqs_buf, SENSE_LENGTH);
1177 if (un->un_mspl) {
1178 i_ddi_mem_free((caddr_t)un->un_mspl, NULL);
1180 if (un->un_dp_size) {
1181 kmem_free(un->un_dp, un->un_dp_size);
1183 if (un->un_state) {
1184 kstat_delete(un->un_stats);
1186 if (un->un_errstats) {
1187 kstat_delete(un->un_errstats);
1190 scsi_destroy_pkt(un->un_rqs);
1191 scsi_free_consistent_buf(un->un_rqs_bp);
1222 struct scsi_tape *un;
1229 if (!(un = ddi_get_soft_state(st_state, instance))) {
1238 st_empty_error_stack(un);
1254 "st_detach: instance=%x, un=%p\n", instance,
1255 (void *)un);
1257 if (((un->un_dp->options & ST_UNLOADABLE) == 0) ||
1258 ((un->un_rsvd_status & ST_APPLICATION_RESERVATIONS) != 0) ||
1259 (un->un_ncmds != 0) || (un->un_quef != NULL) ||
1260 (un->un_state != ST_STATE_CLOSED)) {
1268 un->un_unit_attention_flags |= 4;
1280 if ((un->un_dev) && /* Been opened since attach */
1281 ((un->un_pos.pmode == legacy) &&
1282 (un->un_pos.fileno > 0) || /* Known position not rewound */
1283 (un->un_pos.blkno != 0)) || /* Or within first file */
1284 ((un->un_pos.pmode == logical) &&
1285 (un->un_pos.lgclblkno > 0))) {
1296 result = st_cmd(un, SCMD_TEST_UNIT_READY, 0, SYNC_CMD);
1301 un->un_state = ST_STATE_CLOSED;
1306 un->un_status, un->un_pos.fileno, un->un_pos.blkno);
1312 if ((un->un_dev) && /* Been opened since attach */
1314 ((((un->un_pos.pmode == legacy) &&
1315 (un->un_pos.fileno > 0) || /* Known position not rewound */
1316 (un->un_pos.blkno != 0)) || /* Or within first file */
1317 ((un->un_pos.pmode == logical) &&
1318 (un->un_pos.lgclblkno > 0))) &&
1319 ((un->un_state == ST_STATE_CLOSED) &&
1320 (un->un_laststate == ST_STATE_CLOSING)))) {
1324 " lgclblkno=0x%"PRIx64"\n", un->un_pos.pmode,
1325 un->un_pos.fileno, un->un_pos.blkno,
1326 un->un_pos.lgclblkno);
1327 un->un_unit_attention_flags |= 4;
1335 if (un->un_dev && (un->un_rsvd_status & ST_RESERVE) &&
1338 (void) st_reserve_release(un, ST_RELEASE, st_uscsi_cmd);
1349 st_reset_notification, (caddr_t)un);
1350 cv_destroy(&un->un_clscv);
1351 cv_destroy(&un->un_sbuf_cv);
1352 cv_destroy(&un->un_queue_cv);
1353 cv_destroy(&un->un_suspend_cv);
1354 cv_destroy(&un->un_tape_busy_cv);
1355 cv_destroy(&un->un_recov_buf_cv);
1357 if (un->un_recov_taskq) {
1358 ddi_taskq_destroy(un->un_recov_taskq);
1361 if (un->un_hib_tid) {
1362 (void) untimeout(un->un_hib_tid);
1363 un->un_hib_tid = 0;
1366 if (un->un_delay_tid) {
1367 (void) untimeout(un->un_delay_tid);
1368 un->un_delay_tid = 0;
1370 cv_destroy(&un->un_state_cv);
1373 cv_destroy(&un->un_contig_mem_cv);
1375 if (un->un_contig_mem_hdl != NULL) {
1376 ddi_dma_free_handle(&un->un_contig_mem_hdl);
1379 if (un->un_sbufp) {
1380 freerbuf(un->un_sbufp);
1382 if (un->un_recov_buf) {
1383 freerbuf(un->un_recov_buf);
1385 if (un->un_uscsi_rqs_buf) {
1386 kmem_free(un->un_uscsi_rqs_buf, SENSE_LENGTH);
1388 if (un->un_mspl) {
1389 i_ddi_mem_free((caddr_t)un->un_mspl, NULL);
1391 if (un->un_rqs) {
1392 scsi_destroy_pkt(un->un_rqs);
1393 scsi_free_consistent_buf(un->un_rqs_bp);
1395 if (un->un_mkr_pkt) {
1396 scsi_destroy_pkt(un->un_mkr_pkt);
1398 if (un->un_arq_enabled) {
1401 if (un->un_dp_size) {
1402 kmem_free(un->un_dp, un->un_dp_size);
1404 if (un->un_stats) {
1405 kstat_delete(un->un_stats);
1406 un->un_stats = (kstat_t *)0;
1408 if (un->un_errstats) {
1409 kstat_delete(un->un_errstats);
1410 un->un_errstats = (kstat_t *)0;
1412 if (un->un_media_id_len) {
1413 kmem_free(un->un_media_id, un->un_media_id_len);
1449 if (un->un_dev == 0)
1450 un->un_dev = MTMINOR(instance);
1457 if (un->un_pwr_mgmt == ST_PWR_SUSPENDED) {
1461 if (un->un_state != ST_STATE_CLOSED) {
1478 while (un->un_ncmds || un->un_quef ||
1479 (un->un_state == ST_STATE_RESOURCE_WAIT)) {
1481 if (cv_timedwait(&un->un_tape_busy_cv, ST_MUTEX,
1486 if (st_reset(un, RESET_LUN) == 0) {
1487 if (un->un_last_throttle) {
1488 un->un_throttle =
1489 un->un_last_throttle;
1505 (void) st_update_block_pos(un, st_cmd, 0);
1506 COPY_POS(&un->un_suspend_pos, &un->un_pos);
1513 (void) st_cmd(un, SCMD_WRITE_FILE_MARK, 0, SYNC_CMD);
1522 (void) st_cmd(un, SCMD_REWIND, 0, SYNC_CMD);
1525 un->un_pwr_mgmt = ST_PWR_SUSPENDED;
1526 un->un_throttle = 0;
1531 if (un->un_delay_tid) {
1532 timeout_id_t temp_id = un->un_delay_tid;
1533 un->un_delay_tid = 0;
1534 un->un_tids_at_suspend |= ST_DELAY_TID;
1540 if (un->un_hib_tid) {
1541 timeout_id_t temp_id = un->un_hib_tid;
1542 un->un_hib_tid = 0;
1543 un->un_tids_at_suspend |= ST_HIB_TID;
1552 if (un->un_swr_token) {
1553 opaque_t temp_token = un->un_swr_token;
1574 struct scsi_tape *un;
1583 if ((un = ddi_get_soft_state(st_state, instance)) == NULL)
1603 struct scsi_tape *un = NULL;
1654 un = ddi_get_soft_state(st_state, instance);
1656 ASSERT(un != NULL);
1658 un->un_rqs_bp = scsi_alloc_consistent_buf(&devp->sd_address, NULL,
1660 if (un->un_rqs_bp == NULL) {
1663 un->un_rqs = scsi_init_pkt(&devp->sd_address, NULL, un->un_rqs_bp,
1665 if (!un->un_rqs) {
1668 ASSERT(un->un_rqs->pkt_resid == 0);
1670 (struct scsi_extended_sense *)un->un_rqs_bp->b_un.b_addr;
1671 ASSERT(geterror(un->un_rqs_bp) == NULL);
1673 (void) scsi_setup_cdb((union scsi_cdb *)un->un_rqs->pkt_cdbp,
1675 FILL_SCSI1_LUN(devp, un->un_rqs);
1676 un->un_rqs->pkt_flags |= (FLAG_SENSING | FLAG_HEAD | FLAG_NODISCON);
1677 un->un_rqs->pkt_time = st_io_time;
1678 un->un_rqs->pkt_comp = st_intr;
1679 ri = (recov_info *)un->un_rqs->pkt_private;
1686 un->un_sbufp = getrbuf(km_flags);
1687 un->un_recov_buf = getrbuf(km_flags);
1689 un->un_uscsi_rqs_buf = kmem_alloc(SENSE_LENGTH, KM_SLEEP);
1697 NULL, (caddr_t *)&un->un_mspl, &rlen, NULL);
1701 NULL, (caddr_t *)&un->un_read_pos_data, &rlen, NULL);
1703 if (!un->un_sbufp || !un->un_mspl || !un->un_read_pos_data) {
1709 bzero(un->un_mspl, sizeof (struct seq_mode));
1711 cv_init(&un->un_sbuf_cv, NULL, CV_DRIVER, NULL);
1712 cv_init(&un->un_queue_cv, NULL, CV_DRIVER, NULL);
1713 cv_init(&un->un_clscv, NULL, CV_DRIVER, NULL);
1714 cv_init(&un->un_state_cv, NULL, CV_DRIVER, NULL);
1716 cv_init(&un->un_contig_mem_cv, NULL, CV_DRIVER, NULL);
1720 cv_init(&un->un_suspend_cv, NULL, CV_DRIVER, NULL);
1721 cv_init(&un->un_tape_busy_cv, NULL, CV_DRIVER, NULL);
1722 cv_init(&un->un_recov_buf_cv, NULL, CV_DRIVER, NULL);
1724 un->un_recov_taskq = ddi_taskq_create(devp->sd_dev,
1727 ASSERT(un->un_recov_taskq != NULL);
1729 un->un_pos.pmode = invalid;
1730 un->un_sd = devp;
1731 un->un_swr_token = (opaque_t)NULL;
1732 un->un_comp_page = ST_DEV_DATACOMP_PAGE | ST_DEV_CONFIG_PAGE;
1733 un->un_wormable = st_is_drive_worm;
1734 un->un_media_id_method = st_get_media_identification;
1739 un->un_read_pos_type = LONG_POS;
1741 un->un_suspend_pos.pmode = invalid;
1743 st_add_recovery_info_to_pkt(un, un->un_rqs_bp, un->un_rqs);
1747 DDI_DMA_SLEEP, NULL, &un->un_contig_mem_hdl) != DDI_SUCCESS) {
1750 un->un_contig_mem_hdl = NULL;
1782 st_reset_notification, (caddr_t)un);
1791 if (un) {
1792 if (un->un_mspl) {
1793 i_ddi_mem_free((caddr_t)un->un_mspl, NULL);
1795 if (un->un_read_pos_data) {
1796 i_ddi_mem_free((caddr_t)un->un_read_pos_data, 0);
1798 if (un->un_sbufp) {
1799 freerbuf(un->un_sbufp);
1801 if (un->un_recov_buf) {
1802 freerbuf(un->un_recov_buf);
1804 if (un->un_uscsi_rqs_buf) {
1805 kmem_free(un->un_uscsi_rqs_buf, SENSE_LENGTH);
1808 if (un->un_contig_mem_hdl != NULL) {
1809 ddi_dma_free_handle(&un->un_contig_mem_hdl);
1812 if (un->un_rqs) {
1813 scsi_destroy_pkt(un->un_rqs);
1816 if (un->un_rqs_bp) {
1817 scsi_free_consistent_buf(un->un_rqs_bp);
1846 st_known_tape_type(struct scsi_tape *un)
1854 reserved = (un->un_rsvd_status & ST_RESERVE) ? ST_RESERVE
1866 if (un->un_dp_size == 0) {
1867 un->un_dp_size = sizeof (struct st_drivetype);
1868 dp = kmem_zalloc((size_t)un->un_dp_size, KM_SLEEP);
1869 un->un_dp = dp;
1871 dp = un->un_dp;
1874 un->un_dp->non_motion_timeout = st_io_time;
1879 if ((*config_funct)(un, ST_INQUIRY->inq_vid, dp)) {
1907 un->un_status = 0;
1908 un->un_attached = 1;
1909 un->un_init_options = dp->options;
1912 st_calculate_timeouts(un);
1915 if (un->un_dp->type != ST_TYPE_INVALID) {
1919 un->un_tlr_flag = TLR_SAS_ONE_DEVICE;
1920 result = st_set_target_TLR_mode(un, st_uscsi_cmd);
1926 un->un_dp->type = ST_TYPE_INVALID;
1927 un->un_tlr_flag = TLR_NOT_KNOWN;
1929 if (scsi_ifgetcap(&un->un_sd->sd_address,
1931 un->un_tlr_flag = TLR_NOT_SUPPORTED;
1932 (void) st_set_target_TLR_mode(un, st_uscsi_cmd);
1934 un->un_tlr_flag = TLR_SAS_ONE_DEVICE;
1937 un->un_tlr_flag = TLR_NOT_SUPPORTED;
1946 if (reserved != ((un->un_rsvd_status & ST_RESERVE) ? ST_RESERVE
1948 (void) st_reserve_release(un, reserved, st_uscsi_cmd);
1951 un->un_unit_attention_flags |= 1;
1984 st_validate_conf_data(struct scsi_tape *un, int *list, int list_len,
2073 st_get_conf_from_st_dot_conf(struct scsi_tape *un, char *vidpid,
2182 if (st_validate_conf_data(un, data_ptr,
2242 st_get_conf_from_st_conf_dot_c(struct scsi_tape *un, char *vidpid,
2271 st_get_conf_from_tape_drive(struct scsi_tape *un, char *vidpid,
2313 un->un_dp->options |= ST_MODE_SEL_COMP | ST_UNLOADABLE;
2314 rval = st_modesense(un);
2317 un->un_dp->type = ST_TYPE_INVALID;
2320 un->un_dp->options &= ~ST_MODE_SEL_COMP;
2330 bsize = (un->un_mspl->high_bl << 16) |
2331 (un->un_mspl->mid_bl << 8) |
2332 (un->un_mspl->low_bl);
2338 rval = st_change_block_size(un, 0);
2341 un->un_dp->type = ST_TYPE_INVALID;
2354 rval = st_change_block_size(un, 0);
2361 un->un_dp->type = ST_TYPE_INVALID;
2372 rval = st_read_block_limits(un, blklim);
2392 rval = st_get_special_inquiry(un, 6, buf, 0xb0);
2415 if (st_get_densities_from_tape_drive(un, tem_dp) == 0) {
2423 rval = st_get_timeout_values_from_tape_drive(un, tem_dp);
2432 un->un_status = KEY_NO_SENSE;
2438 st_get_densities_from_tape_drive(struct scsi_tape *un,
2463 if (st_report_density_support(un, den_header, buflen) != 0) {
2478 if (st_report_density_support(un, den_header, buflen) != 0) {
2591 st_get_timeout_values_from_tape_drive(struct scsi_tape *un,
2599 rval = st_get_timeouts_value(un, SCMD_ERASE, &timeout, 0);
2602 un->un_dp->type = ST_TYPE_INVALID;
2610 rval = st_get_timeouts_value(un, SCMD_READ, &timeout, 0);
2613 un->un_dp->type = ST_TYPE_INVALID;
2621 rval = st_get_timeouts_value(un, SCMD_WRITE, &timeout, 0);
2624 un->un_dp->type = ST_TYPE_INVALID;
2632 rval = st_get_timeouts_value(un, SCMD_SPACE, &timeout, 0);
2635 un->un_dp->type = ST_TYPE_INVALID;
2643 rval = st_get_timeouts_value(un, SCMD_LOAD, &timeout, 0);
2646 un->un_dp->type = ST_TYPE_INVALID;
2655 rval = st_get_timeouts_value(un, SCMD_REWIND, &timeout, 0);
2658 un->un_dp->type = ST_TYPE_INVALID;
2666 rval = st_get_timeouts_value(un, SCMD_INQUIRY, &timeout, 0);
2669 un->un_dp->type = ST_TYPE_INVALID;
2681 st_get_timeouts_value(struct scsi_tape *un, uchar_t option_code,
2697 rval = st_report_supported_operation(un, oper, option_code,
2747 st_get_default_conf(struct scsi_tape *un, char *vidpid, struct st_drivetype *dp)
2812 if (!un->un_attached) {
2813 st_known_tape_type(un);
2814 if (!un->un_attached) {
2829 if (!(flag & (FNDELAY | FNONBLOCK)) && IS_CLOSING(un)) {
2830 un->un_laststate = un->un_state;
2831 un->un_state = ST_STATE_CLOSE_PENDING_OPEN;
2832 while (IS_CLOSING(un) ||
2833 un->un_state == ST_STATE_CLOSE_PENDING_OPEN) {
2834 if (cv_wait_sig(&un->un_clscv, ST_MUTEX) == 0) {
2836 un->un_state = un->un_laststate;
2840 } else if (un->un_state != ST_STATE_CLOSED) {
2848 un->un_dev = dev;
2849 un->un_oflags = flag; /* save for use in st_tape_init() */
2850 un->un_errno = 0; /* no errors yet */
2851 un->un_restore_pos = 0;
2852 un->un_rqs_state = 0;
2859 switch (un->un_pos.pmode) {
2862 un->un_state = ST_STATE_OFFLINE;
2869 if (un->un_pos.fileno != 0 || un->un_pos.blkno != 0) {
2882 un->un_read_only =
2883 (un->un_oflags & FWRITE) ? RDWR : RDONLY;
2884 un->un_state = ST_STATE_OPEN_PENDING_IO;
2886 un->un_state = ST_STATE_OFFLINE;
2890 if (un->un_pos.lgclblkno == 0) {
2891 un->un_state = ST_STATE_OFFLINE;
2893 un->un_read_only =
2894 (un->un_oflags & FWRITE) ? RDWR : RDONLY;
2895 un->un_state = ST_STATE_OPEN_PENDING_IO;
2904 un->un_state = ST_STATE_OPENING;
2909 st_empty_error_stack(un);
2911 rval = st_tape_init(un);
2912 if ((rval == EACCES) && (un->un_read_only & WORM)) {
2913 un->un_state = ST_STATE_OPEN_PENDING_IO;
2920 if ((un->un_rsvd_status &
2922 (void) st_reserve_release(un, ST_RELEASE,
2926 un->un_state = ST_STATE_OPEN_PENDING_IO;
2938 un->un_state = ST_STATE_CLOSED;
2940 un->un_err_resid = 0;
2941 un->un_retry_ct = 0;
2945 "st_open: return val = %x, state = %d\n", rval, un->un_state);
2952 st_tape_init(struct scsi_tape *un)
2962 "st_tape_init(un = 0x%p, oflags = %d)\n", (void*)un, un->un_oflags);
2968 if (un->un_state != ST_STATE_INITIALIZING) {
2969 un->un_laststate = un->un_state;
2970 un->un_state = ST_STATE_OPENING;
2973 un->un_kbytes_xferred = 0;
2978 err = st_cmd(un, SCMD_TEST_UNIT_READY, 0, SYNC_CMD);
2985 if (un->un_rsvd_status & ST_RESERVATION_CONFLICT) {
2986 un->un_state = ST_STATE_CLOSED;
2991 } else if ((un->un_rsvd_status &
2996 un->un_state = ST_STATE_CLOSED;
3008 if (un->un_dp->type == ST_TYPE_INVALID) {
3009 un->un_comp_page = ST_DEV_DATACOMP_PAGE | ST_DEV_CONFIG_PAGE;
3010 st_known_tape_type(un);
3017 if (un->un_dp->type == ST_TYPE_INVALID) {
3018 rval = st_determine_generic(un);
3023 un->un_state = ST_STATE_CLOSED;
3035 un->un_allow_large_xfer = (uchar_t)st_allow_large_xfer;
3045 un->un_allow_large_xfer = st_allow_large_xfer &&
3046 (un->un_dp->options & ST_NO_RECSIZE_LIMIT);
3051 if (un->un_maxbsize == MAXBSIZE_UNKNOWN) {
3055 * if un->un_allow_large_xfer = 0 , then make sure
3058 un->un_rbl = kmem_zalloc(RBLSIZE, KM_SLEEP);
3060 err = st_cmd(un, SCMD_READ_BLKLIM, RBLSIZE, SYNC_CMD);
3063 err = st_cmd(un, SCMD_READ_BLKLIM, RBLSIZE, SYNC_CMD);
3070 un->un_maxbsize = (un->un_rbl->max_hi << 16) +
3071 (un->un_rbl->max_mid << 8) +
3072 un->un_rbl->max_lo;
3073 un->un_minbsize = (un->un_rbl->min_hi << 8) +
3074 un->un_rbl->min_lo;
3075 un->un_data_mod = 1 << un->un_rbl->granularity;
3076 if ((un->un_maxbsize == 0) ||
3077 (un->un_allow_large_xfer == 0 &&
3078 un->un_maxbsize > ST_MAXRECSIZE_FIXED)) {
3079 un->un_maxbsize = ST_MAXRECSIZE_FIXED;
3081 } else if (un->un_dp->type == ST_TYPE_DEFAULT) {
3087 if (un->un_maxbsize > ST_MAXRECSIZE_FIXED) {
3088 un->un_dp->options |=
3095 if (un->un_maxbsize == un->un_minbsize) {
3096 un->un_dp->options &= ~ST_VARIABLE;
3100 if (un->un_minbsize == 0) {
3101 un->un_minbsize = 1;
3109 err, un->un_rsvd_status);
3116 if (un->un_rsvd_status & ST_RESERVATION_CONFLICT) {
3119 un->un_allow_large_xfer = 0;
3126 if (un->un_bsize) {
3127 un->un_maxbsize = un->un_minbsize =
3128 un->un_bsize;
3130 un->un_maxbsize = ST_MAXRECSIZE_FIXED;
3131 un->un_minbsize = 1;
3138 un->un_data_mod = 1;
3141 if (un->un_rbl) {
3142 kmem_free(un->un_rbl, RBLSIZE);
3143 un->un_rbl = NULL;
3153 un->un_maxdma, un->un_maxbsize, un->un_minbsize,
3154 (un->un_allow_large_xfer ? "ALLOW": "DON'T ALLOW"));
3156 err = st_cmd(un, SCMD_TEST_UNIT_READY, 0, SYNC_CMD);
3160 un->un_laststate = un->un_state;
3161 un->un_state = ST_STATE_CLOSED;
3168 un->un_pos.pmode = invalid;
3169 if (un->un_status != KEY_UNIT_ATTENTION) {
3175 un->un_laststate = un->un_state;
3176 if (un->un_oflags & (FNONBLOCK|FNDELAY)) {
3177 un->un_mediastate = MTIO_EJECTED;
3178 un->un_state = ST_STATE_OFFLINE;
3182 un->un_state = ST_STATE_CLOSED;
3201 un->un_bsize = un->un_dp->bsize;
3206 if (un->un_restore_pos) {
3207 un->un_restore_pos = 0;
3208 un->un_pos.fileno = un->un_save_fileno;
3209 un->un_pos.blkno = un->un_save_blkno;
3210 rval = st_validate_tapemarks(un, st_uscsi_cmd, &un->un_pos);
3215 un->un_laststate = un->un_state;
3216 un->un_state = ST_STATE_CLOSED;
3221 if (un->un_pos.pmode == invalid) {
3222 rval = st_loadtape(un);
3227 un->un_laststate = un->un_state;
3228 un->un_state = ST_STATE_CLOSED;
3240 if (un->un_unit_attention_flags) {
3241 rval = st_modesense(un);
3251 if (un->un_oflags & FWRITE) {
3253 if (un->un_mspl->wp) {
3254 un->un_status = KEY_WRITE_PROTECT;
3255 un->un_laststate = un->un_state;
3256 un->un_state = ST_STATE_CLOSED;
3261 if ((un->un_dp->type == MT_ISSTK9840) &&
3262 (un->un_dp->options & ST_WORMABLE)) {
3263 un->un_read_only = RDONLY;
3268 un->un_read_only = RDWR;
3271 un->un_read_only = RDONLY;
3274 if (un->un_dp->options & ST_WORMABLE &&
3275 un->un_unit_attention_flags) {
3276 un->un_read_only |= un->un_wormable(un);
3278 if (((un->un_read_only == WORM) ||
3279 (un->un_read_only == RDWORM)) &&
3280 ((un->un_oflags & FWRITE) == FWRITE)) {
3281 un->un_status = KEY_DATA_PROTECT;
3285 un->un_read_only, un->un_pos.eof, un->un_oflags);
3294 if ((un->un_read_only == RDWR) ||
3295 (un->un_read_only == WORM) && (un->un_oflags & FWRITE)) {
3296 if (un->un_dp->options & ST_REEL) {
3297 un->un_fmneeded = 2;
3299 un->un_fmneeded = 1;
3302 un->un_fmneeded = 0;
3306 "fmneeded = %x\n", un->un_fmneeded);
3314 if (st_determine_density(un,
3315 un->un_read_only == RDWR ? B_WRITE : B_READ)) {
3316 un->un_status = KEY_ILLEGAL_REQUEST;
3317 un->un_laststate = un->un_state;
3318 un->un_state = ST_STATE_CLOSED;
3331 un->un_density_known = 0;
3339 un->un_laststate = un->un_state;
3340 un->un_lastop = ST_OP_NIL;
3341 un->un_mediastate = MTIO_INSERTED;
3342 cv_broadcast(&un->un_state_cv);
3348 un->un_test_append = (un->un_oflags & FWRITE);
3354 if (un->un_unit_attention_flags) {
3355 rval = st_get_media_identification(un, st_uscsi_cmd);
3359 un->un_unit_attention_flags = 0;
3363 un->un_err_resid = 0;
3364 un->un_last_resid = 0;
3365 un->un_last_count = 0;
3398 st_wait_for_io(un);
3401 st_turn_pe_off(un);
3406 last_state = un->un_laststate = un->un_state;
3407 un->un_state = ST_STATE_CLOSING;
3409 ST_POS(ST_DEVINFO, "st_close1:", &un->un_pos);
3416 if ((minor & MT_BSD) && (un->un_pos.eof == ST_EOF)) {
3417 if (un->un_pos.pmode != invalid) {
3418 un->un_pos.fileno++;
3419 un->un_pos.blkno = 0;
3421 un->un_pos.eof = ST_NO_EOF;
3434 (un->un_mediastate == MTIO_INSERTED) && /* tape loaded */
3435 (un->un_pos.pmode != invalid) && /* XXX position known */
3436 ((un->un_pos.blkno != 0) && /* inside a file */
3437 (un->un_lastop != ST_OP_WRITE) && /* Didn't just write */
3438 (un->un_lastop != ST_OP_WEOF))) { /* or write filemarks */
3439 switch (un->un_pos.eof) {
3448 if ((un->un_dp->options & ST_REEL) &&
3449 (!(un->un_dp->options & ST_READ_IGNORE_EOFS)) &&
3450 (un->un_pos.blkno == 0)) {
3451 if (st_cmd(un, SCMD_SPACE, Blk(1), SYNC_CMD)) {
3458 if (un->un_pos.eof >= ST_EOF_PENDING) {
3459 un->un_pos.eof = ST_EOT_PENDING;
3460 un->un_pos.fileno += 1;
3461 un->un_pos.blkno = 0;
3465 if (st_cmd(un, SCMD_SPACE, Fmk(1), SYNC_CMD)) {
3473 un->un_pos.fileno, un->un_pos.blkno,
3474 un->un_pos.eof);
3475 un->un_pos.eof = ST_NO_EOF;
3481 un->un_pos.fileno += 1;
3482 un->un_pos.lgclblkno += 1;
3483 un->un_pos.blkno = 0;
3484 un->un_pos.eof = ST_NO_EOF;
3494 "Undefined state 0x%x", un->un_pos.eof);
3522 flag, un->un_fmneeded, un->un_lastop, un->un_pos.eof);
3524 if (un->un_pos.eof == ST_EOT_PENDING) {
3526 if (st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD)) {
3532 un->un_pos.blkno = 0;
3533 un->un_pos.eof = ST_EOT;
3536 un->un_pos.eof = ST_NO_EOF;
3549 } else if ((un->un_pos.pmode != invalid) &&
3550 (un->un_fmneeded > 0) &&
3552 ((un->un_lastop == ST_OP_WRITE)||(un->un_lastop == ST_OP_WEOF))) ||
3553 ((flag == FWRITE) && (un->un_lastop == ST_OP_NIL)))) {
3556 int was_at_eom = (un->un_pos.eof == ST_EOM) ? 1 : 0;
3567 count = un->un_fmneeded;
3569 if (st_cmd(un, SCMD_WRITE_FILE_MARK, count, SYNC_CMD)) {
3575 if ((un->un_dp->options & ST_REEL) &&
3577 if (st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD)) {
3584 un->un_pos.eof = ST_NO_EOF;
3586 un->un_pos.blkno = 0;
3599 un->un_pos.eof = ST_EOM;
3609 (un->un_dp->options & ST_SOFT_ERROR_REPORTING) &&
3622 un->un_pos.pmode != invalid && err == 0) {
3653 if (un->un_sd->sd_inq->inq_ansi < 2) {
3654 if (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD)) {
3659 if (st_cmd(un, SCMD_WRITE_FILE_MARK, 0, SYNC_CMD)) {
3663 if ((un->un_rsvd_status &
3666 if (st_reserve_release(un, ST_RELEASE,
3673 if (st_cmd(un, SCMD_REWIND, 1, ASYNC_CMD)) {
3688 un->un_pos.pmode = invalid;
3689 un->un_running.pmode = invalid;
3699 if (un->un_eject_tape_on_failure) {
3700 un->un_eject_tape_on_failure = 0;
3701 if (st_cmd(un, SCMD_LOAD, LD_UNLOAD, SYNC_CMD)) {
3709 un->un_pos.eof = ST_NO_EOF;
3710 un->un_mediastate = MTIO_EJECTED;
3717 if ((un->un_rsvd_status &
3720 (void) st_reserve_release(un, ST_RELEASE, st_uscsi_cmd);
3726 un->un_laststate = un->un_state;
3727 un->un_state = ST_STATE_CLOSED;
3728 un->un_lastop = ST_OP_NIL;
3729 un->un_throttle = 1; /* assume one request at time, for now */
3730 un->un_retry_ct = 0;
3731 un->un_errno = 0;
3732 un->un_swr_token = (opaque_t)NULL;
3733 un->un_rsvd_status &= ~(ST_INIT_RESERVE);
3736 if (un->un_init_options & ST_READ_IGNORE_ILI) {
3737 un->un_dp->options |= ST_READ_IGNORE_ILI;
3739 un->un_dp->options &= ~ST_READ_IGNORE_ILI;
3742 if (un->un_init_options & ST_READ_IGNORE_EOFS) {
3743 un->un_dp->options |= ST_READ_IGNORE_EOFS;
3745 un->un_dp->options &= ~ST_READ_IGNORE_EOFS;
3748 if (un->un_init_options & ST_SHORT_FILEMARKS) {
3749 un->un_dp->options |= ST_SHORT_FILEMARKS;
3751 un->un_dp->options &= ~ST_SHORT_FILEMARKS;
3759 cv_signal(&un->un_clscv);
3764 if (err && un->un_status != KEY_ILLEGAL_REQUEST) {
3769 un->un_density_known = 0;
3776 cp = un->un_contig_mem;
3786 un->un_contig_mem_total_num = 0;
3787 un->un_contig_mem_available_num = 0;
3788 un->un_contig_mem = NULL;
3789 un->un_max_contig_mem_len = 0;
3794 err, un->un_pos.fileno, un->un_pos.blkno, un->un_pos.eof);
3866 struct scsi_tape *un;
3868 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
3876 if (un->un_allow_large_xfer) {
3881 if (un->un_bsize == 0 && bp->b_bcount > un->un_maxbsize) {
3882 bp->b_bcount = un->un_maxbsize;
3888 if (bp->b_bcount > un->un_maxdma) {
3889 bp->b_bcount = un->un_maxdma;
3896 if (un->un_bsize == 0) {
3912 if (bp != un->un_sbufp && un->un_bsize) {
3913 bp->b_bcount -= (bp->b_bcount % un->un_bsize);
3939 st_empty_error_stack(un);
3945 if ((un->un_bsize != 0) && (len % un->un_bsize != 0)) {
3948 (flag == B_WRITE) ? wr_str : rd_str, un->un_bsize);
3953 if ((un->un_data_mod != 0) && (len % un->un_data_mod != 0)) {
3956 (flag == B_WRITE) ? wr_str : rd_str, un->un_data_mod);
3960 if (st_recov_sz != sizeof (recov_info) && un->un_multipath) {
3966 un->un_errno = rval;
3974 un->un_silent_skip = 0;
3988 if (un->un_pos.eof > ST_NO_EOF) {
3990 "eof=%d resid=%lx\n", un->un_pos.eof, uio->uio_resid);
3992 if (un->un_pos.eof >= ST_EOM && (flag == B_WRITE)) {
3994 un->un_pos.eof = ST_EOM;
3996 un->un_pos.eof = ST_NO_EOF;
4000 if (un->un_silent_skip && uio->uio_resid != len) {
4001 un->un_pos.eof = ST_EOF;
4002 un->un_pos.blkno = un->un_save_blkno;
4003 un->un_pos.fileno--;
4006 un->un_errno = rval;
4037 if ((un->un_bsize != 0) && (len % un->un_bsize != 0)) {
4040 (flag == B_WRITE) ? wr_str : rd_str, un->un_bsize);
4045 if ((un->un_data_mod != 0) && (len % un->un_data_mod != 0)) {
4048 (flag == B_WRITE) ? wr_str : rd_str, un->un_data_mod);
4052 if (st_recov_sz != sizeof (recov_info) && un->un_multipath) {
4058 un->un_errno = rval;
4080 if (un->un_pos.eof > ST_NO_EOF) {
4082 "eof=%d resid=%lx\n", un->un_pos.eof, uio->uio_resid);
4084 if (un->un_pos.eof >= ST_EOM && (flag == B_WRITE)) {
4086 un->un_pos.eof = ST_EOM;
4088 !(un->un_persistence && un->un_persist_errors)) {
4089 un->un_pos.eof = ST_NO_EOF;
4092 un->un_errno = rval;
4103 struct scsi_tape *un;
4110 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
4111 if (un == NULL) {
4124 while (un->un_pwr_mgmt == ST_PWR_SUSPENDED) {
4125 cv_wait(&un->un_suspend_cv, ST_MUTEX);
4130 bp->b_bcount, un->un_pos.fileno, un->un_pos.blkno, un->un_pos.eof);
4136 if (un->un_persistence && un->un_persist_errors) {
4143 while (un->un_sbuf_busy) {
4144 cv_wait(&un->un_sbuf_cv, ST_MUTEX);
4146 if (un->un_persistence && un->un_persist_errors) {
4154 ASSERT(bp != un->un_recov_buf);
4155 ASSERT(bp != un->un_sbufp);
4161 if ((un->un_rsvd_status &
4163 if ((un->un_dp->options & ST_NO_RESERVE_RELEASE) == 0) {
4164 if (st_reserve_release(un, ST_RESERVE, st_uscsi_cmd)) {
4165 st_bioerror(bp, un->un_errno);
4168 } else if (un->un_state == ST_STATE_OPEN_PENDING_IO) {
4174 un->un_state = ST_STATE_INITIALIZING;
4175 (void) st_cmd(un, SCMD_TEST_UNIT_READY,
4177 un->un_state = ST_STATE_OPEN_PENDING_IO;
4179 un->un_rsvd_status |= ST_INIT_RESERVE;
4189 if (un->un_state == ST_STATE_OFFLINE || un->un_restore_pos) {
4193 un->un_laststate = un->un_state;
4194 un->un_state = ST_STATE_INITIALIZING;
4195 if (st_tape_init(un)) {
4198 un->un_state = ST_STATE_OFFLINE;
4199 un->un_pos.pmode = invalid;
4203 un->un_state = ST_STATE_OPEN_PENDING_IO;
4204 un->un_restore_pos = 0;
4209 if (un->un_pos.pmode == invalid) {
4211 "strategy with un->un_pos.pmode invalid\n");
4227 if (un->un_pos.eof == ST_EOT_PENDING) {
4228 if (st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD)) {
4229 un->un_pos.pmode = invalid;
4230 un->un_density_known = 0;
4233 un->un_pos.blkno = 0; /* fix up block number.. */
4234 un->un_pos.eof = ST_EOT;
4247 if ((un->un_state == ST_STATE_OPEN_PENDING_IO) ||
4248 (un->un_test_append && (un->un_dp->options & ST_QIC))) {
4250 if (un->un_state == ST_STATE_OPEN_PENDING_IO) {
4251 if (st_determine_density(un, (int)reading)) {
4258 un->un_pos.fileno, (int)reading,
4259 (un->un_dp->options & ST_QIC) ? 1 : 0,
4260 un->un_pos.eof);
4262 if (!reading && un->un_pos.eof != ST_EOM) {
4263 if (un->un_pos.eof == ST_EOT) {
4264 un->un_pos.eof = ST_NO_EOF;
4265 } else if (un->un_pos.pmode != invalid &&
4266 (un->un_dp->options & ST_QIC)) {
4275 if (un->un_state == ST_STATE_OPEN_PENDING_IO) {
4278 un->un_laststate = un->un_state;
4279 un->un_state = ST_STATE_OPEN;
4289 un->un_pos.eof, wasopening);
4291 switch (un->un_pos.eof) {
4326 un->un_pos.eof = ST_WRITE_AFTER_EOM;
4328 un->un_status = SUN_KEY_EOT;
4334 un->un_status = SUN_KEY_EOT;
4342 un->un_pos.eof = ST_NO_EOF;
4348 un->un_status = SUN_KEY_EOF;
4350 un->un_pos.eof = ST_EOF;
4356 un->un_status = SUN_KEY_EOF;
4362 un->un_pos.eof = ST_NO_EOF;
4363 un->un_pos.fileno += 1;
4364 un->un_pos.blkno = 0;
4370 un->un_pos.fileno);
4374 "now file %d (write)\n", un->un_pos.fileno);
4377 un->un_status = 0;
4397 * if the requested xfer size is bigger than un->un_maxdma_arch
4402 if (bp->b_bcount > un->un_maxdma_arch &&
4415 "st_queued_strategy: un->un_quef = 0x%p, bp = 0x%p\n",
4416 (void *)un->un_quef, (void *)bp);
4418 st_add_to_queue(&un->un_quef, &un->un_quel, un->un_quel, bp);
4422 st_start(un);
4441 st_wait_for_io(un);
4442 un->un_err_resid = bp->b_resid = bp->b_bcount;
4445 if (un->un_persistence && un->un_persist_errors)
4446 bioerror(bp, un->un_errno);
4459 struct scsi_tape *un;
4464 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
4465 if (un == NULL) {
4480 while (un->un_pwr_mgmt == ST_PWR_SUSPENDED) {
4481 cv_wait(&un->un_suspend_cv, ST_MUTEX);
4486 bp->b_bcount, un->un_pos.fileno, un->un_pos.blkno, un->un_pos.eof);
4488 ASSERT((bp == un->un_recov_buf) || (bp == un->un_sbufp));
4504 st_start(un);
4514 st_space_fmks(struct scsi_tape *un, int64_t count)
4522 un->un_dev, count);
4535 if ((un->un_dp->options & ST_KNOWS_EOD) &&
4536 !((un->un_dp->type == ST_TYPE_EXB8500 &&
4537 MT_DENSITY(un->un_dev) == 0))) {
4538 if (st_cmd(un, SCMD_SPACE, Fmk(count), SYNC_CMD)) {
4545 if (st_cmd(un, SCMD_SPACE, Fmk(1), SYNC_CMD)) {
4558 if (st_cmd(un, SCMD_SPACE, Blk(1), SYNC_CMD)) {
4566 if ((un->un_pos.eof >= ST_EOF_PENDING) &&
4567 (un->un_dp->options & ST_REEL)) {
4568 un->un_status = SUN_KEY_EOT;
4574 } else if (IN_EOF(un->un_pos)) {
4575 un->un_pos.eof = ST_NO_EOF;
4576 un->un_pos.fileno++;
4577 un->un_pos.blkno = 0;
4579 } else if (un->un_pos.eof > ST_EOF) {
4589 un->un_err_resid = count;
4590 COPY_POS(&un->un_pos, &un->un_err_pos);
4608 st_find_eod(struct scsi_tape *un)
4614 if (un == NULL) {
4621 "st_find_eod(dev = 0x%lx): fileno = %d\n", un->un_dev,
4622 un->un_pos.fileno);
4626 COPY_POS(&savepos, &un->un_pos);
4636 if ((un->un_dp->options & ST_KNOWS_EOD) != 0) {
4637 if ((un->un_dp->type == ST_TYPE_EXB8500) &&
4638 (MT_DENSITY(un->un_dev) == 0)) {
4640 } else if (un->un_pos.pmode == logical) {
4650 result = st_cmd(un, SCMD_SPACE, sp_type, SYNC_CMD);
4653 COPY_POS(&savepos, &un->un_pos);
4673 return (un->un_pos.fileno);
4682 SPACE_CNT(sp_type), un->un_pos.eof, un->un_status);
4695 if (st_cmd(un, SCMD_SPACE, Blk((1)), SYNC_CMD)) {
4698 if ((un->un_pos.eof >= ST_EOF_PENDING) &&
4699 (un->un_dp->options & ST_REEL)) {
4700 un->un_status = KEY_BLANK_CHECK;
4701 un->un_pos.fileno++;
4702 un->un_pos.blkno = 0;
4705 if (IN_EOF(un->un_pos)) {
4706 un->un_pos.eof = ST_NO_EOF;
4707 un->un_pos.fileno++;
4708 un->un_pos.blkno = 0;
4710 if (un->un_pos.eof > ST_EOF) {
4714 if (un->un_pos.eof > ST_EOF) {
4720 if (un->un_dp->options & ST_KNOWS_EOD) {
4721 COPY_POS(&savepos, &un->un_pos);
4768 if (un->un_state == ST_STATE_OPEN_PENDING_IO) {
4769 if (st_determine_density(un, mode)) {
4773 un->un_errno = EIO;
4781 un->un_laststate = un->un_state;
4782 un->un_state = ST_STATE_OPEN;
4784 } else if (un->un_pos.pmode != invalid && un->un_fmneeded > 0 &&
4785 ((un->un_lastop == ST_OP_WEOF && wfm) ||
4786 (un->un_lastop == ST_OP_WRITE && wfm))) {
4790 COPY_POS(&spos, &un->un_pos);
4798 if ((un->un_fmneeded > 0) || (un->un_lastop == ST_OP_WEOF)) {
4799 wfm = un->un_fmneeded;
4800 un->un_fmneeded = 0;
4804 un->un_pos.pmode = invalid;
4805 un->un_density_known = 0;
4808 un->un_errno = EIO;
4813 if (st_cmd(un, SCMD_SPACE, Fmk(-wfm), SYNC_CMD)) {
4817 un->un_errno = EIO;
4820 COPY_POS(&un->un_pos, &spos);
4828 un->un_pos.eof = ST_NO_EOF;
4834 if (un->un_read_only == RDWR) {
4835 un->un_test_append = 1;
4851 st_wait_for_io(struct scsi_tape *un)
4855 while ((un->un_ncmds) || (un->un_quef) || (un->un_runqf)) {
4856 cv_wait(&un->un_queue_cv, ST_MUTEX);
4877 ASSERT(un->un_recov_buf_busy == 0);
4882 un->un_pos.fileno, un->un_pos.blkno, un->un_pos.eof, un->un_state,
4883 un->un_persistence && un->un_persist_errors);
4901 st_empty_error_stack(un);
4909 st_wait_for_io(un);
4915 if (un->un_persistence && un->un_persist_errors) {
4921 rval = un->un_errno;
4926 ASSERT(un->un_throttle != 0);
4927 un->un_throttle = 1; /* > 1 will never happen here */
4928 un->un_errno = 0; /* start clean from here */
4934 if (un->un_pos.eof == ST_EOT_PENDING) {
4935 int resid = un->un_err_resid;
4936 uchar_t status = un->un_status;
4937 uchar_t lastop = un->un_lastop;
4939 if (st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD)) {
4945 un->un_lastop = lastop; /* restore last operation */
4947 un->un_status = SUN_KEY_EOT;
4949 un->un_status = status;
4951 un->un_err_resid = resid;
4953 un->un_err_pos.blkno = un->un_pos.blkno = 0;
4955 un->un_pos.eof = ST_EOT;
4981 mtget->mt_erreg = un->un_status;
4982 mtget->mt_resid = un->un_err_resid;
4983 mtget->mt_dsreg = un->un_retry_ct;
4984 if (un->un_err_pos.pmode == legacy) {
4985 mtget->mt_fileno = un->un_err_pos.fileno;
4994 if (un->un_err_pos.blkno >= 0) {
4995 mtget->mt_blkno = un->un_err_pos.blkno;
4997 mtget->mt_blkno = INF + 1 - (-un->un_err_pos.blkno);
4999 mtget->mt_type = un->un_dp->type;
5001 if (un->un_read_pos_type != NO_POS) {
5004 if (un->un_dp->options & ST_REEL) {
5024 if ((un->un_allow_large_xfer) &&
5025 (un->un_dp->options & ST_NO_RECSIZE_LIMIT)) {
5026 mtget->mt_bf = min(un->un_maxbsize,
5027 un->un_maxdma) / SECSIZE;
5030 if (un->un_read_only == WORM ||
5031 un->un_read_only == RDWORM) {
5040 if (un->un_persistence) {
5043 rval = st_check_clean_bit(un);
5050 if ((un->un_HeadClean & (TAPE_ALERT_SUPPORTED |
5055 if (un->un_HeadClean & (TAPE_PREVIOUSLY_DIRTY |
5064 un->un_status = 0; /* Reset status */
5065 un->un_err_resid = 0;
5112 rval = st_get_error_entry(un, arg, flag);
5139 if (ddi_copyout(&un->un_mediastate, (void *)arg,
5162 struct st_drivetype *stdt = un->un_dp;
5262 st_turn_pe_on(un);
5264 st_turn_pe_off(un);
5269 un->un_persistence);
5274 tmp = (int)un->un_persistence;
5281 un->un_persistence);
5292 st_clear_pe(un);
5317 if (un->un_dp->options & ST_NO_RESERVE_RELEASE) {
5322 rval = st_reserve_release(un, ST_RESERVE, st_uscsi_cmd);
5325 un->un_rsvd_status |= ST_PRESERVE_RESERVE;
5338 if (un->un_dp->options & ST_NO_RESERVE_RELEASE) {
5351 rval = st_reserve_release(un, ST_RELEASE, st_uscsi_cmd);
5353 un->un_rsvd_status &= ~ST_PRESERVE_RESERVE;
5366 if (un->un_dp->options & ST_NO_RESERVE_RELEASE) {
5383 (void) st_reserve_release(un, ST_RESERVE, st_uscsi_cmd);
5385 rval = st_take_ownership(un, st_uscsi_cmd);
5401 rval = st_uscsi_cmd(un, (struct uscsi_cmd *)arg, flag);
5408 rval = st_mtioctop(un, arg, flag);
5414 rval = st_mtiocltop(un, arg, flag);
5427 if (un->un_bsize) {
5434 un->un_dp->options &= ~ST_READ_IGNORE_ILI;
5438 un->un_dp->options |= ST_READ_IGNORE_ILI;
5458 if (!(un->un_dp->options & ST_REEL)) {
5465 un->un_dp->options &= ~ST_READ_IGNORE_EOFS;
5469 un->un_dp->options |= ST_READ_IGNORE_EOFS;
5489 switch (un->un_dp->type) {
5493 un->un_dp->options &= ~ST_SHORT_FILEMARKS;
5495 un->un_dp->options |= ST_SHORT_FILEMARKS;
5509 rval = st_update_block_pos(un, st_cmd, 0);
5511 if (ddi_copyout((void *)&un->un_pos, (void *)arg,
5531 rval = st_validate_tapemarks(un, st_uscsi_cmd, &dest);
5544 if (!(un->un_persistence && un->un_persist_errors)) {
5545 un->un_errno = rval;
5558 st_mtioctop(struct scsi_tape *un, intptr_t arg, int flag)
5605 rval = st_do_mtioctop(un, &local);
5649 "st_ioctl: fileno=%x, blkno=%x, eof=%x\n", un->un_pos.fileno,
5650 un->un_pos.blkno, un->un_pos.eof);
5652 if (un->un_pos.pmode == invalid) {
5653 un->un_density_known = 0;
5661 st_mtiocltop(struct scsi_tape *un, intptr_t arg, int flag)
5671 rval = st_do_mtioctop(un, &local);
5681 st_do_mtioctop(struct scsi_tape *un, struct mtlop *mtop)
5683 dev_t dev = un->un_dev;
5693 un->un_pos.fileno, un->un_pos.blkno, un->un_pos.eof);
5695 un->un_status = 0;
5703 if (un->un_state == ST_STATE_OFFLINE) {
5711 un->un_state = ST_STATE_INITIALIZING;
5714 un->un_state);
5720 rval = st_tape_init(un);
5722 un->un_state = ST_STATE_INITIALIZING;
5725 un->un_state = ST_STATE_OFFLINE;
5726 un->un_pos.pmode = invalid;
5732 un->un_state = ST_STATE_OPEN_PENDING_IO;
5742 if (un->un_pos.pmode == invalid) {
5781 if (un->un_mspl->wp || un->un_read_only & WORM) {
5782 un->un_status = KEY_WRITE_PROTECT;
5783 un->un_err_resid = mtop->mt_count;
5784 COPY_POS(&un->un_err_pos, &un->un_pos);
5787 if (un->un_dp->options & ST_REEL) {
5788 un->un_fmneeded = 2;
5790 un->un_fmneeded = 1;
5794 st_cmd(un, SCMD_REWIND, 0, SYNC_CMD) ||
5795 st_cmd(un, SCMD_ERASE, mtop->mt_count, SYNC_CMD)) {
5796 un->un_pos.pmode = invalid;
5803 if (un->un_dp->options & ST_REEL) {
5804 (void) st_cmd(un, SCMD_REWIND, 0, ASYNC_CMD);
5813 if (un->un_mspl->wp || un->un_read_only & RDONLY) {
5814 un->un_status = KEY_WRITE_PROTECT;
5815 un->un_err_resid = mtop->mt_count;
5816 COPY_POS(&un->un_err_pos, &un->un_pos);
5829 if (un->un_read_only == RDWR) {
5830 un->un_test_append = 1;
5833 if (un->un_state == ST_STATE_OPEN_PENDING_IO) {
5834 if (st_determine_density(un, B_WRITE)) {
5860 st_cmd(un, SCMD_LOAD, LD_LOAD | LD_RETEN, SYNC_CMD)) {
5861 un->un_pos.pmode = invalid;
5878 if (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD)) {
5896 (void) st_cmd(un, SCMD_REWIND, 0, SYNC_CMD);
5897 if (st_cmd(un, SCMD_LOAD, LD_UNLOAD, SYNC_CMD)) {
5902 un->un_pos.eof = ST_NO_EOF;
5903 un->un_laststate = un->un_state;
5904 un->un_state = ST_STATE_OFFLINE;
5905 un->un_mediastate = MTIO_EJECTED;
5922 if (un->un_state > ST_STATE_INITIALIZING) {
5925 rval = st_cmd(un, SCMD_LOAD, LD_LOAD, SYNC_CMD);
5928 ((un->un_status == KEY_NOT_READY) &&
5930 (un->un_uscsi_rqs_buf->es_add_code == 0x3a) ||
5931 ((un->un_status == KEY_ILLEGAL_REQUEST) &&
5932 (un->un_dp->type == MT_ISSTK9840) &&
5934 (un->un_uscsi_rqs_buf->es_add_code == 0x80)))) {
5947 un->un_pos.pmode = invalid;
5955 un->un_state = ST_STATE_INITIALIZING;
5957 rval = st_tape_init(un);
5958 if ((rval == EACCES) && (un->un_read_only & WORM)) {
5968 un->un_state = ST_STATE_OFFLINE;
5974 un->un_status = 0; /* Reset status */
5975 un->un_err_resid = 0;
5986 if ((un->un_pos.pmode == legacy && un->un_pos.eof >= ST_EOT) ||
5987 (un->un_lastop == ST_OP_WRITE) ||
5988 (un->un_lastop == ST_OP_WEOF)) {
6007 if (IN_EOF(un->un_pos)) {
6008 un->un_pos.fileno++;
6009 un->un_pos.blkno = 0;
6022 savefile = st_find_eod(un);
6024 if ((un->un_status != KEY_BLANK_CHECK) &&
6025 (un->un_status != SUN_KEY_EOT)) {
6026 un->un_pos.pmode = invalid;
6036 if (un->un_dp->options & ST_REEL) {
6037 if (st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD)) {
6038 un->un_pos.pmode = invalid;
6049 un->un_pos.blkno = 0;
6050 un->un_err_pos.blkno = 0;
6052 un->un_err_resid = 0;
6053 un->un_pos.fileno = savefile;
6054 un->un_pos.eof = ST_EOT;
6056 un->un_status = 0;
6061 rval = st_mtfsf_ioctl(un, mtop->mt_count);
6066 rval = st_mtfsr_ioctl(un, mtop->mt_count);
6071 rval = st_mtbsf_ioctl(un, mtop->mt_count);
6076 rval = st_mtnbsf_ioctl(un, mtop->mt_count);
6081 rval = st_mtbsr_ioctl(un, mtop->mt_count);
6086 rval = st_mtbsfm_ioctl(un, mtop->mt_count);
6091 rval = st_mtfsfm_ioctl(un, mtop->mt_count);
6104 ((un->un_dp->options & ST_VARIABLE) == 0)) {
6113 (mtop->mt_count < un->un_minbsize)) {
6118 if ((mtop->mt_count > min(un->un_maxbsize, un->un_maxdma)) &&
6119 (un->un_maxbsize != 0)) {
6124 if ((mtop->mt_count % un->un_data_mod) != 0) {
6128 if (st_change_block_size(un, (uint32_t)mtop->mt_count) != 0) {
6140 mtop->mt_count = un->un_bsize;
6145 rval = st_update_block_pos(un, st_cmd, 0);
6146 mtop->mt_count = un->un_pos.lgclblkno;
6150 rval = st_logical_block_locate(un, st_uscsi_cmd, &un->un_pos,
6151 (uint64_t)mtop->mt_count, un->un_pos.partition);
6158 if ((uint64_t)mtop->mt_count != un->un_pos.lgclblkno) {
6160 mtop->mt_count = un->un_pos.lgclblkno;
6166 if (st_cmd(un, SCMD_DOORLOCK, MR_LOCK, SYNC_CMD)) {
6174 if (st_cmd(un, SCMD_DOORLOCK, MR_UNLOCK, SYNC_CMD)) {
6193 st_uscsi_cmd(struct scsi_tape *un, struct uscsi_cmd *ucmd, int flag)
6200 dev_t dev = un->un_dev;
6205 "st_uscsi_cmd(dev = 0x%lx)\n", un->un_dev);
6214 * will hang the process waiting for un->un_sbuf_busy to be cleared,
6224 if (un->un_state == ST_STATE_OFFLINE) {
6225 un->un_laststate = ST_STATE_OFFLINE;
6226 un->un_state = ST_STATE_INITIALIZING;
6243 err = st_check_cdb_for_need_to_reserve(un,
6254 (void) st_update_block_pos(un, st_cmd, 0);
6261 ASSERT(un->un_recov_buf_busy == 0);
6266 while (un->un_sbuf_busy)
6267 cv_wait(&un->un_sbuf_cv, ST_MUTEX);
6268 un->un_sbuf_busy = 1;
6293 un->un_srqbufp = uscmd->uscsi_rqbuf;
6294 bp = un->un_sbufp;
6310 un->un_fmneeded = 0;
6317 un->un_sbuf_busy = 0;
6318 un->un_srqbufp = NULL;
6329 (un->un_pos.pmode != invalid)) {
6330 un->un_running.pmode = invalid;
6331 (void) st_update_block_pos(un, st_cmd, 1);
6336 un->un_running.pmode = invalid;
6338 cv_signal(&un->un_sbuf_cv);
6348 un->un_state = ST_STATE_OFFLINE;
6373 if (un->un_pos.eof >= ST_EOT) {
6375 rval = st_cmd(un, SCMD_WRITE_FILE_MARK, 1, SYNC_CMD);
6386 rval = st_cmd(un, SCMD_WRITE_FILE_MARK, wfm, SYNC_CMD);
6403 st_start_dump(struct scsi_tape *un, struct buf *bp)
6420 un->un_pos.fileno, un->un_pos.blkno);
6444 st_start(struct scsi_tape *un)
6454 "st_start(): dev = 0x%lx\n", un->un_dev);
6456 if (un->un_recov_buf_busy) {
6458 bp = un->un_recov_buf;
6460 } else if (un->un_sbuf_busy) {
6462 ASSERT(un->un_quef == NULL);
6463 ASSERT(un->un_runqf == NULL);
6464 bp = un->un_sbufp;
6466 } else if (un->un_quef != NULL) {
6467 if (un->un_persistence && un->un_persist_errors) {
6470 bp = un->un_quef;
6483 if ((un->un_throttle <= 0) || (un->un_ncmds >= un->un_throttle)) {
6487 if (bp != un->un_recov_buf) {
6490 un->un_throttle, un->un_ncmds);
6491 if (un->un_ncmds == 0) {
6498 (void) timeout(fnc, un, drv_usectohz(1000000));
6511 st_make_cmd(un, bp, st_runout);
6545 if (un->un_state != ST_STATE_RESOURCE_WAIT) {
6546 un->un_laststate = un->un_state;
6547 un->un_state = ST_STATE_RESOURCE_WAIT;
6554 if (un->un_persistence) {
6555 st_set_pe_flag(un);
6561 if (un->un_state == ST_STATE_RESOURCE_WAIT) {
6562 un->un_state = un->un_laststate;
6573 if (un->un_state == ST_STATE_RESOURCE_WAIT) {
6574 un->un_state = un->un_laststate;
6582 (void) st_remove_from_queue(&un->un_quef, &un->un_quel, bp);
6583 st_add_to_queue(&un->un_runqf, &un->un_runql, un->un_runql, bp);
6588 st_start_dump(un, bp);
6592 un->un_last_throttle = un->un_throttle;
6593 un->un_throttle = 0; /* so nothing else will come in here */
6594 un->un_ncmds++;
6598 status = st_transport(un, BP_PKT(bp));
6600 if (un->un_last_throttle) {
6601 un->un_throttle = un->un_last_throttle;
6617 bp != un->un_recov_buf) {
6620 if (st_command_recovery(un, BP_PKT(bp),
6626 if (st_handle_start_busy(un, bp,
6642 ST_DO_ERRSTATS(un, st_transerrs);
6643 if ((bp == un->un_recov_buf) && (status == TRAN_BUSY)) {
6647 st_set_pe_flag(un);
6649 st_done_and_mutex_exit(un, bp);
6660 st_handle_start_busy(struct scsi_tape *un, struct buf *bp,
6679 ((queued) && (un->un_runql != bp))) {
6686 st_add_to_queue(&un->un_quef, &un->un_quel, un->un_quef, bp);
6693 un->un_ncmds--;
6701 (void) st_remove_from_queue(&un->un_runqf, &un->un_runql, bp);
6706 st_hba_unflush(un);
6714 (void) timeout(st_start_restart, un, timeout_interval);
6727 struct scsi_tape *un = (struct scsi_tape *)arg;
6731 ASSERT(un != NULL);
6739 if (un->un_recov_buf_busy != 0) {
6740 bp = un->un_recov_buf;
6742 } else if (un->un_sbuf_busy != 0) {
6744 ASSERT(un->un_quef == NULL);
6745 ASSERT(un->un_runqf == NULL);
6746 bp = un->un_sbufp;
6748 } else if (un->un_quef != NULL) {
6749 bp = un->un_quef;
6750 if (un->un_persistence && un->un_persist_errors) {
6774 (void) st_remove_from_queue(&un->un_quef, &un->un_quel,
6790 st_start(un);
6816 st_done_and_mutex_exit(struct scsi_tape *un, struct buf *bp)
6822 ASSERT(MUTEX_HELD(&un->un_sd->sd_mutex));
6824 _NOTE(LOCK_RELEASED_AS_SIDE_EFFECT(&un->un_sd->sd_mutex))
6831 (void) st_remove_from_queue(&un->un_runqf, &un->un_runql, bp);
6833 un->un_ncmds--;
6834 cv_signal(&un->un_queue_cv);
6845 if (un->un_stats && (bp != un->un_sbufp) && IS_RW(bp)) {
6862 if ((pe_flagged = (un->un_persistence && un->un_persist_errors)) != 0) {
6863 un->un_last_resid = bp->b_resid;
6864 un->un_last_count = bp->b_bcount;
6867 if (un->un_pwr_mgmt == ST_PWR_SUSPENDED) {
6868 cv_broadcast(&un->un_tape_busy_cv);
6869 } else if (un->un_quef && un->un_throttle && !pe_flagged &&
6870 (bp != un->un_recov_buf)) {
6871 st_start(un);
6874 un->un_retry_ct = max(pktinfo->pkt_retry_cnt, pktinfo->str_retry_cnt);
6876 if (bp == un->un_sbufp && (bp->b_flags & B_ASYNC)) {
6893 un->un_sbuf_busy = 0;
6894 cv_signal(&un->un_sbuf_cv);
6899 if (bp == un->un_sbufp && BP_UCMD(bp)) {
6910 (((un->un_pos.blkno % 100) == 0) ||
6911 (un->un_persistence && un->un_persist_errors))) {
6916 un->un_ncmds, un->un_throttle, un->un_errno,
6917 un->un_persist_errors);
6937 st_flush(un);
6945 st_flush(struct scsi_tape *un)
6955 un->un_ncmds, (void *)un->un_quef);
6961 if (un->un_ncmds || !un->un_quef)
6972 while ((bp = un->un_quef) != NULL) {
6973 un->un_quef = bp->b_actf;
6979 un->un_pos.blkno, un->un_errno, bp->b_bcount);
6981 st_set_pe_errno(un);
6983 bioerror(bp, un->un_errno);
6998 un->un_quel = NULL;
7002 cv_signal(&un->un_queue_cv);
7011 st_determine_generic(struct scsi_tape *un)
7020 "st_determine_generic(un = 0x%p)\n", (void*)un);
7024 if (st_modesense(un)) {
7028 bsize = (un->un_mspl->high_bl << 16) |
7029 (un->un_mspl->mid_bl << 8) |
7030 (un->un_mspl->low_bl);
7033 un->un_dp->options |= ST_VARIABLE;
7034 un->un_dp->bsize = 0;
7035 un->un_bsize = 0;
7042 un->un_dp->options |= ST_VARIABLE;
7043 if (st_change_block_size(un, 0) != 0) {
7048 un->un_dp->options &= ~ST_VARIABLE;
7051 } else if (st_change_block_size(un, 0) == 0) {
7057 un->un_dp->options |= ST_VARIABLE;
7058 un->un_dp->bsize = 0;
7059 un->un_bsize = 0;
7061 un->un_dp->bsize = bsize;
7062 un->un_bsize = bsize;
7066 switch (un->un_mspl->density) {
7074 un->un_dp->type = ST_TYPE_DEFAULT;
7075 un->un_dp->options |= (ST_AUTODEN_OVERRIDE|ST_QIC);
7085 un->un_dp->type = ST_TYPE_REEL;
7086 un->un_dp->options |= ST_REEL;
7087 un->un_dp->densities[0] = 0x1;
7088 un->un_dp->densities[1] = 0x2;
7089 un->un_dp->densities[2] = 0x6;
7090 un->un_dp->densities[3] = 0x3;
7101 un->un_dp->type = ST_TYPE_DEFAULT;
7102 un->un_dp->options |= ST_QIC;
7104 un->un_dp->densities[1] = 0x4;
7105 un->un_dp->densities[2] = 0x5;
7106 un->un_dp->densities[3] = 0x7;
7107 un->un_dp->densities[0] = 0x0b;
7118 un->un_dp->type = ST_TYPE_DEFAULT;
7119 un->un_dp->options |= ST_QIC;
7120 un->un_dp->densities[0] = 0x0f;
7121 un->un_dp->densities[1] = 0x10;
7122 un->un_dp->densities[2] = 0x11;
7123 un->un_dp->densities[3] = 0x12;
7136 un->un_dp->type = ST_TYPE_HIC;
7137 un->un_dp->densities[0] = 0x09;
7138 un->un_dp->densities[1] = 0x0a;
7139 un->un_dp->densities[2] = 0x0c;
7140 un->un_dp->densities[3] = 0x0d;
7149 un->un_dp->type = ST_TYPE_DAT;
7150 un->un_dp->options |= ST_AUTODEN_OVERRIDE;
7158 un->un_dp->type = ST_TYPE_EXABYTE;
7159 un->un_dp->options |= ST_AUTODEN_OVERRIDE;
7167 un->un_dp->options |=
7173 if (un->un_mspl->bufm == 0)
7174 un->un_dp->options |= ST_NOBUF;
7180 un->un_dp->max_rretries = un->un_dp->max_wretries = 1000;
7188 if ((un->un_dp->options & ST_REEL) && un->un_bsize != 0 &&
7189 (un->un_dp->options & ST_VARIABLE)) {
7190 if (st_change_block_size(un, 0) == 0) {
7191 un->un_dp->bsize = 0;
7192 un->un_mspl->high_bl = un->un_mspl->mid_bl =
7193 un->un_mspl->low_bl = 0;
7201 "Generic Drive, Vendor=%s\n\t%s", un->un_dp->name,
7203 if (un->un_dp->options & ST_VARIABLE) {
7209 un->un_dp->bsize);
7216 st_determine_density(struct scsi_tape *un, int rw)
7223 "st_determine_density(un = 0x%p, rw = %s)\n",
7224 (void*)un, (rw == B_WRITE ? wr_str: rd_str));
7231 if (un->un_pos.pmode == logical) {
7232 if (un->un_pos.lgclblkno != 0) {
7235 } else if (un->un_pos.pmode == legacy) {
7236 if ((un->un_pos.fileno != 0) || (un->un_pos.blkno != 0)) {
7246 if ((un->un_pos.pmode == logical) &&
7247 (un->un_pos.lgclblkno != 0)) {
7257 un->un_curdens = MT_DENSITY(un->un_dev);
7258 if (st_set_density(un)) {
7268 if (!un->un_density_known) {
7269 if (st_get_density(un)) {
7287 st_get_density(struct scsi_tape *un)
7296 "st_get_density(un = 0x%p)\n", (void*)un);
7309 * utilities that do positioning via uscsi find the un-
7319 if ((un->un_dp->options & ST_AUTODEN_OVERRIDE) ||
7320 (un->un_sd->sd_inq->inq_ansi > 1)) {
7321 un->un_density_known = 1;
7331 size = (unsigned)(un->un_dp->bsize ? un->un_dp->bsize : SECSIZE);
7332 un->un_tmpbuf = kmem_alloc(size, KM_SLEEP);
7338 dens = olddens = un->un_curdens = MT_DENSITY(un->un_dev);
7340 for (i = 0; i < NDENSITIES; i++, ((un->un_curdens == NDENSITIES - 1) ?
7341 (un->un_curdens = 0) : (un->un_curdens += 1))) {
7346 dens = un->un_dp->densities[un->un_curdens];
7352 if (st_set_density(un)) {
7360 succes = (st_cmd(un, SCMD_READ, (int)size, SYNC_CMD) == 0);
7361 if (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD)) {
7365 st_init(un);
7367 un->un_density_known = 1;
7371 kmem_free(un->un_tmpbuf, size);
7372 un->un_tmpbuf = 0;
7380 st_set_density(struct scsi_tape *un)
7387 "st_set_density(un = 0x%p): density = 0x%x\n", (void*)un,
7388 un->un_dp->densities[un->un_curdens]);
7392 un->un_mspl->density = un->un_dp->densities[un->un_curdens];
7394 if ((un->un_dp->options & ST_AUTODEN_OVERRIDE) == 0) {
7399 if (st_modeselect(un)) {
7402 } else if ((un->un_dp->options & ST_MODE_SEL_COMP) != 0) {
7409 rval = st_set_compression(un);
7419 un->un_density_known = 1;
7427 st_loadtape(struct scsi_tape *un)
7434 "st_loadtape(un = 0x%p)\n", (void*) un);
7438 rval = st_update_block_pos(un, st_cmd, 0);
7446 rval = st_cmd(un, SCMD_REWIND, 1, SYNC_CMD);
7448 st_init(un);
7449 un->un_density_known = 0;
7475 struct scsi_tape *un;
7479 un = ddi_get_soft_state(st_state, MTUNIT(dev));
7486 "st_test_append(): fileno %d\n", un->un_pos.fileno);
7488 un->un_laststate = un->un_state;
7489 un->un_state = ST_STATE_APPEND_TESTING;
7490 un->un_test_append = 0;
7501 un->un_tmpbuf = kmem_alloc((unsigned)bp->b_bcount, KM_SLEEP);
7502 bcopy(bp->b_un.b_addr, un->un_tmpbuf, (uint_t)bp->b_bcount);
7508 if (st_cmd(un, (int)SCMD_WRITE, (int)bp->b_bcount, SYNC_CMD) == 0) {
7512 bp->b_resid = un->un_sbufp->b_resid;
7517 un->un_laststate = un->un_state;
7518 un->un_state = ST_STATE_OPEN;
7519 kmem_free(un->un_tmpbuf, bcount);
7520 un->un_tmpbuf = NULL;
7533 status = un->un_status;
7534 un->un_status = 0;
7535 (void) st_cmd(un, SCMD_READ, SECSIZE, SYNC_CMD);
7536 if (un->un_status == KEY_BLANK_CHECK) {
7544 un->un_laststate = un->un_state;
7545 un->un_state = ST_STATE_OPEN;
7546 bcopy(bp->b_un.b_addr, un->un_tmpbuf, (uint_t)bp->b_bcount);
7547 if (st_cmd(un, (int)SCMD_WRITE, (int)bp->b_bcount,
7564 if (st_cmd(un, SCMD_SPACE, Blk(-1), SYNC_CMD)) {
7565 un->un_pos.pmode = invalid;
7568 un->un_err_resid = bp->b_resid;
7569 un->un_status = status;
7578 un->un_laststate = un->un_state;
7579 un->un_state = ST_STATE_OPEN_PENDING_IO;
7580 kmem_free(un->un_tmpbuf, bcount);
7581 un->un_tmpbuf = NULL;
7594 st_cmd(struct scsi_tape *un, int com, int64_t count, int wait)
7604 un->un_dev, com, count, wait);
7606 ASSERT(MUTEX_HELD(&un->un_sd->sd_mutex));
7611 st_debug_cmds(un, com, count, wait);
7615 st_wait_for_io(un);
7618 err = st_check_cmd_for_need_to_reserve(un, com, count);
7629 (void) st_update_block_pos(un, st_cmd, 0);
7635 ASSERT(un->un_recov_buf_busy == 0);
7637 while (un->un_sbuf_busy)
7638 cv_wait(&un->un_sbuf_cv, ST_MUTEX);
7639 un->un_sbuf_busy = 1;
7641 bp = un->un_sbufp;
7646 err = st_setup_cmd(un, bp, com, count);
7648 un->un_sbuf_busy = 0;
7656 (un->un_pos.pmode != invalid)) {
7657 un->un_running.pmode = invalid;
7658 last_err_resid = un->un_err_resid;
7659 (void) st_update_block_pos(un, st_cmd, 1);
7664 un->un_running.pmode = invalid;
7665 un->un_err_resid = last_err_resid;
7668 cv_signal(&un->un_sbuf_cv);
7674 st_setup_cmd(struct scsi_tape *un, buf_t *bp, int com, int64_t count)
7677 dev_t dev = un->un_dev;
7691 bp->b_un.b_addr = un->un_tmpbuf;
7697 bp->b_un.b_addr = un->un_tmpbuf;
7758 bp->b_un.b_addr = (caddr_t)(un->un_mspl);
7764 bp->b_un.b_addr = (caddr_t)(un->un_mspl);
7772 bp->b_un.b_addr = (caddr_t)(un->un_rbl);
7791 switch (un->un_read_pos_type) {
7804 "st_make_cmd()\n", un->un_read_pos_type);
7808 bp->b_un.b_addr = (caddr_t)un->un_read_pos_data;
7904 st_set_compression(struct scsi_tape *un)
7917 if ((un->un_dp->options & ST_MODE_SEL_COMP) == 0) {
7918 un->un_comp_page = 0;
7923 minor = MT_DENSITY(un->un_dev);
7933 (un->un_dp->densities[0] == un->un_dp->densities[1]) &&
7934 (un->un_dp->densities[2] == un->un_dp->densities[3]) &&
7935 (un->un_dp->densities[0] != un->un_dp->densities[2])) {
7942 un->un_mspl->high_bl = (uchar_t)(un->un_bsize >> 16);
7943 un->un_mspl->mid_bl = (uchar_t)(un->un_bsize >> 8);
7944 un->un_mspl->low_bl = (uchar_t)(un->un_bsize);
7952 if ((un->un_comp_page & ST_DEV_DATACOMP_PAGE) == ST_DEV_DATACOMP_PAGE) {
7953 rval = st_set_datacomp_page(un, turn_compression_on);
7958 if (un->un_status == KEY_ILLEGAL_REQUEST) {
7963 un->un_comp_page = ST_DEV_CONFIG_PAGE;
7964 } else if (un->un_state >= ST_STATE_OPEN) {
7965 un->un_pos.pmode = invalid;
7971 un->un_comp_page = ST_DEV_DATACOMP_PAGE;
7975 if ((un->un_comp_page & ST_DEV_CONFIG_PAGE) == ST_DEV_CONFIG_PAGE) {
7976 rval = st_set_devconfig_page(un, turn_compression_on);
7981 if (un->un_status == KEY_ILLEGAL_REQUEST) {
7987 un->un_dp->options &= ~ST_MODE_SEL_COMP;
7988 un->un_comp_page = 0;
7991 } else if (un->un_state >= ST_STATE_OPEN) {
7992 un->un_pos.pmode = invalid;
8007 st_set_devconfig_page(struct scsi_tape *un, int compression_on)
8020 if (un->un_mspl->page_code != ST_DEV_CONFIG_PAGE) {
8021 rval = st_gen_mode_sense(un, st_uscsi_cmd, ST_DEV_CONFIG_PAGE,
8022 un->un_mspl, sizeof (struct seq_mode));
8032 if (un->un_dp->type == ST_TYPE_FUJI) {
8045 if ((cflag == un->un_mspl->page.dev.comp_alg) &&
8046 (un->un_comp_page == ST_DEV_CONFIG_PAGE)) {
8050 un->un_mspl->page.dev.comp_alg = cflag;
8060 (char *)un->un_mspl, sizeof (struct seq_mode));
8063 rval = st_gen_mode_select(un, st_uscsi_cmd, un->un_mspl,
8073 st_set_datacomp_page(struct scsi_tape *un, int compression_on)
8086 if (un->un_mspl->page_code != ST_DEV_DATACOMP_PAGE) {
8087 rval = st_gen_mode_sense(un, st_uscsi_cmd, ST_DEV_DATACOMP_PAGE,
8088 un->un_mspl, sizeof (struct seq_mode));
8101 if (un->un_mspl->page.comp.dcc == 0) {
8106 if (un->un_mspl->page.comp.dce) {
8117 (un->un_comp_page == ST_DEV_DATACOMP_PAGE)) {
8127 un->un_mspl->page.comp.dce = 1;
8129 un->un_mspl->page.comp.dce = 0;
8137 (char *)un->un_mspl, sizeof (struct seq_mode));
8140 rval = st_gen_mode_select(un, st_uscsi_cmd, un->un_mspl,
8147 st_modesense(struct scsi_tape *un)
8154 page = un->un_comp_page;
8159 rval = st_gen_mode_sense(un, st_uscsi_cmd, page, un->un_mspl,
8164 if (un->un_dp->options & ST_MODE_SEL_COMP) {
8166 rval = st_gen_mode_sense(un, st_uscsi_cmd, page,
8167 un->un_mspl, sizeof (struct seq_mode));
8168 if (rval == 0 && un->un_mspl->page_code == page) {
8169 un->un_comp_page = page;
8173 rval = st_gen_mode_sense(un, st_uscsi_cmd, page,
8174 un->un_mspl, sizeof (struct seq_mode));
8175 if (rval == 0 && un->un_mspl->page_code == page) {
8176 un->un_comp_page = page;
8179 un->un_dp->options &= ~ST_MODE_SEL_COMP;
8180 un->un_comp_page = 0;
8182 un->un_comp_page = 0;
8186 rval = st_cmd(un, SCMD_MODE_SENSE, MSIZE, SYNC_CMD);
8192 st_modeselect(struct scsi_tape *un)
8201 un->un_dev, un->un_mspl->density);
8211 rval = st_modesense(un);
8215 un->un_mspl->bd_len = 8;
8216 un->un_mspl->high_nb = 0;
8217 un->un_mspl->mid_nb = 0;
8218 un->un_mspl->low_nb = 0;
8220 un->un_mspl->high_bl = (uchar_t)(un->un_bsize >> 16);
8221 un->un_mspl->mid_bl = (uchar_t)(un->un_bsize >> 8);
8222 un->un_mspl->low_bl = (uchar_t)(un->un_bsize);
8231 if (un->un_dp->options & ST_KNOWS_MEDIA) {
8235 if (un->un_mspl->media_type ==
8236 un->un_dp->mediatype[ix]) {
8243 if (ix < un->un_curdens) {
8246 un->un_curdens = ix;
8254 un->un_mspl->media_type,
8255 un->un_dp->densities[best]);
8256 un->un_mspl->density = un->un_dp->densities[best];
8259 un->un_mspl->density =
8260 un->un_dp->densities[un->un_curdens];
8263 un->un_mspl->density = un->un_dp->densities[un->un_curdens];
8266 if (un->un_dp->options & ST_NOBUF) {
8267 un->un_mspl->bufm = 0;
8269 un->un_mspl->bufm = 1;
8272 rval = st_set_compression(un);
8282 un->un_mspl->data_len = 0;
8283 un->un_mspl->media_type = 0;
8284 un->un_mspl->wp = 0;
8287 rval = st_cmd(un, SCMD_MODE_SELECT, MSIZE, SYNC_CMD);
8289 if (un->un_state >= ST_STATE_OPEN) {
8292 un->un_pos.pmode = invalid;
8303 (void) st_modesense(un);
8316 st_gen_mode_sense(struct scsi_tape *un, ubufunc_t ubf, int page,
8340 com->uscsi_timeout = un->un_dp->non_motion_timeout;
8343 r = ubf(un, com, FKIOCTL);
8354 st_gen_mode_select(struct scsi_tape *un, ubufunc_t ubf,
8394 com->uscsi_timeout = un->un_dp->non_motion_timeout;
8397 r = ubf(un, com, FKIOCTL);
8404 st_read_block_limits(struct scsi_tape *un, struct read_blklim *read_blk)
8424 com->uscsi_timeout = un->un_dp->non_motion_timeout;
8427 rval = st_uscsi_cmd(un, com, FKIOCTL);
8437 st_report_density_support(struct scsi_tape *un, uchar_t *density_data,
8460 com->uscsi_timeout = un->un_dp->non_motion_timeout;
8463 rval = st_uscsi_cmd(un, com, FKIOCTL);
8473 st_report_supported_operation(struct scsi_tape *un, uchar_t *oper_data,
8511 com->uscsi_timeout = un->un_dp->non_motion_timeout;
8514 rval = st_uscsi_cmd(un, com, FKIOCTL);
8528 st_change_block_size(struct scsi_tape *un, uint32_t nblksz)
8541 if (un->un_comp_page == (ST_DEV_DATACOMP_PAGE | ST_DEV_CONFIG_PAGE)) {
8542 (void) st_modesense(un);
8546 rval = st_gen_mode_sense(un, st_uscsi_cmd, 0, current, MSIZE);
8561 un->un_bsize = nblksz;
8572 rval = st_gen_mode_select(un, st_uscsi_cmd, current, MSIZE);
8580 rval = st_modesense(un);
8582 un->un_bsize =
8583 (un->un_mspl->high_bl << 16) |
8584 (un->un_mspl->mid_bl << 8) |
8585 (un->un_mspl->low_bl);
8587 if (un->un_bsize != nblksz) {
8590 "(read: %u requested: %u)\n", nblksz, un->un_bsize);
8601 st_init(struct scsi_tape *un)
8609 un->un_dev);
8611 un->un_pos.blkno = 0;
8612 un->un_pos.fileno = 0;
8613 un->un_lastop = ST_OP_NIL;
8614 un->un_pos.eof = ST_NO_EOF;
8615 un->un_pwr_mgmt = ST_PWR_NORMAL;
8627 st_make_cmd(struct scsi_tape *un, struct buf *bp, int (*func)(caddr_t))
8642 optype prev_op = un->un_lastop;
8644 (un->un_arq_enabled ? sizeof (struct scsi_arq_status) : 1);
8651 "st_make_cmd(): dev = 0x%lx\n", un->un_dev);
8662 if ((bp != un->un_sbufp) && (bp != un->un_recov_buf)) {
8665 (caddr_t)un);
8678 if (un->un_bsize == 0) {
8682 count = bp->b_bcount / un->un_bsize;
8687 un->un_lastop = ST_OP_READ;
8688 if ((un->un_bsize == 0) && /* Not Fixed Block */
8689 (un->un_dp->options & ST_READ_IGNORE_ILI)) {
8694 un->un_lastop = ST_OP_WRITE;
8696 tval = un->un_dp->io_timeout;
8706 wr_str: rd_str, un->un_pos.blkno, bp->b_bcount);
8712 st_make_uscsi_cmd(un, ucmd, bp, func);
8724 if (un->un_bsize == 0) {
8728 count /= un->un_bsize;
8731 un->un_lastop = ST_OP_READ;
8732 tval = un->un_dp->io_timeout;
8738 if (un->un_bsize != 0) {
8740 count /= un->un_bsize;
8745 un->un_lastop = ST_OP_WRITE;
8746 tval = un->un_dp->io_timeout;
8752 un->un_lastop = ST_OP_WEOF;
8754 tval = un->un_dp->io_timeout;
8760 if ((un->un_dp->options & ST_SHORT_FILEMARKS) &&
8761 ((un->un_dp->type == ST_TYPE_EXB8500) ||
8762 (un->un_dp->type == ST_TYPE_EXABYTE))) {
8788 un->un_lastop = ST_OP_CTL;
8789 tval = un->un_dp->rewind_timeout;
8802 un->un_pos.fileno, un->un_pos.blkno);
8807 un->un_lastop = ST_OP_CTL;
8808 tval = un->un_dp->space_timeout;
8818 un->un_pos.fileno, un->un_pos.blkno);
8820 un->un_lastop = ST_OP_CTL;
8821 tval = un->un_dp->space_timeout;
8832 tval = un->un_dp->load_timeout;
8834 tval = un->un_dp->unload_timeout;
8838 tval += un->un_dp->rewind_timeout;
8840 un->un_lastop = ST_OP_CTL;
8854 tval = un->un_dp->erase_timeout;
8857 tval = un->un_dp->erase_timeout;
8860 un->un_lastop = ST_OP_CTL;
8869 tval = un->un_dp->non_motion_timeout;
8870 un->un_lastop = ST_OP_CTL;
8878 tval = un->un_dp->non_motion_timeout;
8879 un->un_lastop = ST_OP_CTL;
8886 tval = un->un_dp->non_motion_timeout;
8887 un->un_lastop = ST_OP_CTL;
8894 tval = un->un_dp->non_motion_timeout;
8895 un->un_lastop = ST_OP_CTL;
8903 tval = un->un_dp->non_motion_timeout;
8904 un->un_lastop = ST_OP_CTL;
8911 tval = un->un_dp->non_motion_timeout;
8912 un->un_lastop = ST_OP_CTL;
8919 tval = un->un_dp->non_motion_timeout;
8920 un->un_lastop = ST_OP_CTL;
8926 fixbit = un->un_read_pos_type;
8928 tval = un->un_dp->non_motion_timeout;
8930 un->un_lastop = ST_OP_CTL;
8931 switch (un->un_read_pos_type) {
8944 " st_make_cmd()\n", un->un_read_pos_type);
8955 st_recov_sz, 0, func, (caddr_t)un);
8978 FILL_SCSI1_LUN(un->un_sd, pkt);
8988 if (bp == un->un_recov_buf) {
8994 st_add_recovery_info_to_pkt(un, bp, pkt);
9010 un->un_lastop = prev_op;
9023 st_make_uscsi_cmd(struct scsi_tape *un, struct uscsi_cmd *ucmd,
9036 "st_make_uscsi_cmd(): dev = 0x%lx\n", un->un_dev);
9039 if (un->un_arq_enabled) {
9061 cdblen, stat_size, st_recov_sz, flags, func, (caddr_t)un);
9092 if (bp == un->un_recov_buf) {
9098 st_add_recovery_info_to_pkt(un, bp, pkt);
9115 struct scsi_tape *un = arg;
9125 "st_intr_restart(), un = 0x%p\n", (void *)un);
9127 un->un_hib_tid = 0;
9129 if (un->un_recov_buf_busy != 0) {
9130 bp = un->un_recov_buf;
9132 } else if (un->un_sbuf_busy != 0) {
9133 bp = un->un_sbufp;
9135 } else if (un->un_quef != NULL) {
9136 bp = un->un_quef;
9152 (void) st_remove_from_queue(&un->un_quef, &un->un_quef, bp);
9154 if (un->un_runqf) {
9161 un->un_runqf = bp;
9162 un->un_runql = bp;
9171 status = st_transport(un, BP_PKT(bp));
9180 un->un_unit_attention_flags &&
9181 bp != un->un_recov_buf) {
9182 un->un_unit_attention_flags = 0;
9185 if (st_command_recovery(un, BP_PKT(bp),
9192 if (st_handle_intr_busy(un, bp,
9203 if (un->un_last_throttle) {
9204 un->un_throttle = un->un_last_throttle;
9207 ST_DO_ERRSTATS(un, st_transerrs);
9212 st_set_pe_flag(un);
9214 st_done_and_mutex_exit(un, bp);
9216 if (un->un_last_throttle) {
9217 un->un_throttle = un->un_last_throttle;
9246 state, un->un_mediastate);
9248 prev_state = un->un_mediastate;
9254 if (state == un->un_mediastate || un->un_mediastate == MTIO_NONE) {
9269 un->un_swr_token = token;
9270 un->un_specified_mediastate = state;
9281 while (un->un_mediastate == state) {
9282 if (cv_wait_sig(&un->un_state_cv, ST_MUTEX) == 0) {
9292 un->un_mediastate);
9302 if ((un->un_mediastate == MTIO_INSERTED) &&
9303 (un->un_state == ST_STATE_OFFLINE)) {
9313 un->un_state = ST_STATE_INITIALIZING;
9319 if ((un->un_rsvd_status &
9325 rval = st_cmd(un, SCMD_TEST_UNIT_READY, 0, SYNC_CMD);
9335 un->un_mediastate = prev_state;
9336 un->un_state = ST_STATE_OFFLINE;
9343 rval = st_tape_init(un);
9347 un->un_state = ST_STATE_OFFLINE;
9348 un->un_pos.pmode = invalid;
9350 un->un_state = ST_STATE_OPEN_PENDING_IO;
9352 } else if ((un->un_mediastate == MTIO_EJECTED) &&
9353 (un->un_state != ST_STATE_OFFLINE)) {
9358 un->un_laststate = un->un_state;
9359 un->un_state = ST_STATE_OFFLINE;
9367 un->un_swr_token = (opaque_t)NULL;
9386 struct scsi_tape *un;
9392 if ((un = ddi_get_soft_state(st_state, instance)) == NULL) {
9415 switch (un->un_dp->type) {
9419 "default to ST_TYPE_HP\n", un->un_dp->type);
9425 if (un->un_dp->type == ST_TYPE_FUJI) {
9503 state = un->un_specified_mediastate;
9518 state, un->un_specified_mediastate);
9525 if (state != un->un_specified_mediastate) {
9526 un->un_mediastate = state;
9534 un->un_delay_tid = timeout(st_delayed_cv_broadcast,
9535 un, drv_usectohz((clock_t)MEDIA_ACCESS_DELAY));
9539 cv_broadcast(&un->un_state_cv);
9553 struct scsi_tape *un = arg;
9561 cv_broadcast(&un->un_state_cv);
9571 struct scsi_tape *un = arg;
9575 ASSERT(un != NULL);
9581 st_start(un);
9596 struct scsi_tape *un;
9601 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
9605 ASSERT(un != NULL);
9609 ASSERT(bp != un->un_recov_buf);
9611 un->un_rqs_state &= ~(ST_RQS_ERROR);
9623 } else if ((pkt == un->un_rqs) ||
9624 (un->un_state == ST_STATE_SENSING)) {
9625 ASSERT(pkt == un->un_rqs);
9626 ASSERT(un->un_state == ST_STATE_SENSING);
9627 un->un_state = un->un_laststate;
9628 rcv->cmd_bp = un->un_rqs_bp;
9629 ST_DO_ERRSTATS(un, st_transerrs);
9632 action = st_handle_incomplete(un, bp);
9638 } else if ((pkt == un->un_rqs) || (un->un_state == ST_STATE_SENSING)) {
9643 ASSERT(pkt == un->un_rqs);
9644 ASSERT(un->un_state == ST_STATE_SENSING);
9646 action = st_handle_sense(un, bp, &un->un_pos);
9656 rcv->cmd_bp = un->un_rqs_bp;
9661 un->un_state = un->un_laststate;
9664 } else if (un->un_arq_enabled && (pkt->pkt_state & STATE_ARQ_DONE)) {
9668 action = st_handle_autosense(un, bp, &un->un_pos);
9678 action = st_check_error(un, pkt);
9681 if (un->un_pwr_mgmt == ST_PWR_SUSPENDED) {
9689 st_add_to_queue(&un->un_runqf, &un->un_runql,
9690 un->un_runqf, bp);
9707 if (un->un_multipath) {
9731 (un->un_last_path_instance != pkt->pkt_path_instance)) {
9738 (un->un_state > ST_STATE_OPENING)) {
9746 un->un_last_path_instance = pkt->pkt_path_instance;
9753 if (un->un_state == ST_STATE_SENSING && action != QUE_SENSE) {
9754 un->un_state = un->un_laststate;
9768 un->un_pos.pmode = invalid;
9772 if (un->un_pos.eof < ST_EOT_PENDING &&
9773 un->un_state >= ST_STATE_OPEN) {
9779 if (un->un_status != KEY_ILLEGAL_REQUEST) {
9780 un->un_pos.pmode = invalid;
9784 un->un_err_resid = bp->b_resid = bp->b_bcount;
9793 st_set_pe_flag(un);
9794 if (!(un->un_rqs_state & ST_RQS_ERROR) &&
9795 (un->un_errno == EIO)) {
9796 un->un_rqs_state &= ~(ST_RQS_VALID);
9801 un->un_err_resid = bp->b_resid = bp->b_bcount;
9807 st_set_pe_flag(un);
9808 if (!(un->un_rqs_state & ST_RQS_ERROR) &&
9809 (un->un_errno == EIO)) {
9810 un->un_rqs_state &= ~(ST_RQS_VALID);
9814 st_set_state(un, bp);
9818 if ((un->un_ncmds > 1) && !un->un_flush_on_errors)
9821 if (un->un_state != ST_STATE_SENSING) {
9822 un->un_laststate = un->un_state;
9823 un->un_state = ST_STATE_SENSING;
9829 bzero(un->un_rqs->pkt_scbp, SENSE_LENGTH);
9835 if (pkt != un->un_rqs) {
9836 ((recov_info *)un->un_rqs->pkt_private)->cmd_bp = bp;
9839 if (un->un_throttle) {
9840 un->un_last_throttle = un->un_throttle;
9841 un->un_throttle = 0;
9851 status = st_transport(un, un->un_rqs);
9853 if (un->un_last_throttle) {
9854 un->un_throttle = un->un_last_throttle;
9862 ST_DO_ERRSTATS(un, st_transerrs);
9864 un->un_pos.pmode = invalid;
9866 st_set_pe_flag(un);
9887 if (un->un_throttle) {
9888 un->un_last_throttle = un->un_throttle;
9891 if (st_handle_intr_busy(un, bp, timout) == 0)
9895 un->un_pos.pmode = invalid;
9896 un->un_err_resid = bp->b_resid = bp->b_bcount;
9898 st_set_pe_flag(un);
9903 if ((un->un_ncmds > 1) && !un->un_flush_on_errors) {
9905 "un_ncmds: %d can't retry cmd \n", un->un_ncmds);
9909 if (st_handle_intr_retry_lcmd(un, bp) == 0)
9913 un->un_err_resid = bp->b_resid = bp->b_bcount;
9914 un->un_pos.pmode = invalid;
9916 st_set_pe_flag(un);
9927 action = st_command_recovery(un, pkt, action);
9940 st_done_and_mutex_exit(un, bp);
9944 st_handle_incomplete(struct scsi_tape *un, struct buf *bp)
9949 struct scsi_pkt *pkt = (un->un_state == ST_STATE_SENSING) ?
9950 un->un_rqs : BP_PKT(bp);
9958 "st_handle_incomplete(): dev = 0x%lx\n", un->un_dev);
9986 if ((un->un_ncmds > 1) || (pkt->pkt_state != STATE_GOT_BUS)) {
9995 if ((un->un_laststate > ST_STATE_OPENING) &&
10000 ST_DO_ERRSTATS(un, st_transerrs);
10008 if (!un->un_flush_on_errors) {
10009 un->un_status = SUN_KEY_FATAL;
10013 st_set_pe_errno(un);
10014 bioerror(bp, un->un_errno);
10015 if (un->un_errno)
10021 un->un_status = SUN_KEY_TIMEOUT;
10027 if ((un->un_rsvd_status &
10030 un->un_rsvd_status |= ST_LOST_RESERVE;
10051 ST_DO_ERRSTATS(un, st_transerrs);
10059 if ((un->un_rsvd_status &
10067 un->un_pos.pmode = invalid;
10069 result = st_reset(un, RESET_LUN);
10071 if ((result == 0) && (un->un_state >= ST_STATE_OPEN)) {
10081 if (un->un_pwr_mgmt == ST_PWR_SUSPENDED) {
10083 } else if (bp == un->un_sbufp) {
10101 if (un->un_state >= ST_STATE_OPEN) {
10121 st_handle_intr_busy(struct scsi_tape *un, struct buf *bp,
10134 "st_handle_intr_busy(), un = 0x%p\n", (void *)un);
10136 if ((bp != un->un_sbufp) && (bp != un->un_recov_buf)) {
10151 ((un->un_runqf != bp) && (un->un_runql != bp) && (queued))) {
10158 (void) st_remove_from_queue(&un->un_runqf, &un->un_runql, bp);
10159 st_add_to_queue(&un->un_quef, &un->un_quel, un->un_quef, bp);
10167 un->un_throttle = 0;
10172 st_hba_unflush(un);
10178 un->un_hib_tid = timeout(st_intr_restart, un, timeout_interval);
10189 st_get_error_entry(struct scsi_tape *un, intptr_t arg, int flag)
10214 if (un->un_error_entry_stk == NULL) {
10224 err_link_entry_p = un->un_error_entry_stk;
10358 un->un_error_entry_stk = err_link_entry_p->mtees_nextp;
10396 st_update_error_stack(struct scsi_tape *un,
10448 err_entry_tmp->mtees_nextp = un->un_error_entry_stk;
10449 un->un_error_entry_stk = err_entry_tmp;
10457 st_empty_error_stack(struct scsi_tape *un)
10468 while (un->un_error_entry_stk != NULL) {
10469 linkp = un->un_error_entry_stk;
10470 un->un_error_entry_stk =
10471 un->un_error_entry_stk->mtees_nextp;
10487 st_handle_sense(struct scsi_tape *un, struct buf *bp, tapepos_t *pos)
10490 struct scsi_pkt *rqpkt = un->un_rqs;
10552 st_update_error_stack(un, pkt, &arqstat);
10553 return (st_decode_sense(un, bp, amt, &arqstat, pos));
10557 st_handle_autosense(struct scsi_tape *un, struct buf *bp, tapepos_t *pos)
10588 if (st_reset(un, RESET_LUN) == 0) {
10628 st_update_error_stack(un, pkt, arqstat);
10630 return (st_decode_sense(un, bp, amt, arqstat, pos));
10634 st_decode_sense(struct scsi_tape *un, struct buf *bp, int amt,
10659 if (ucmd->uscsi_rqlen && un->un_srqbufp) {
10662 bcopy(ST_RQSENSE, un->un_srqbufp, rqlen);
10683 if (un->un_dp->type == ST_TYPE_EMULEX) {
10694 if (bp != un->un_sbufp && bp != un->un_recov_buf) {
10702 if (un->un_bsize) {
10703 resid *= un->un_bsize;
10761 if ((un->un_state >= ST_STATE_OPEN) &&
10772 switch (un->un_status = sensep->es_key) {
10797 if (un->un_dp->options &
10802 un->un_err_pos.lgclblkno, scsi_cmds,
10809 ST_DO_ERRSTATS(un, st_softerrs);
10812 un->un_err_pos.lgclblkno, scsi_cmds,
10833 if (un->un_bsize == 0 && resid > 0) {
10842 } else if (un->un_bsize == 0 && resid < 0) {
10850 ST_DO_ERRSTATS(un, st_softerrs);
10854 un->un_running.pmode = invalid;
10867 un->un_status = SUN_KEY_EOF;
10869 st_set_pe_flag(un);
10881 un->un_status = SUN_KEY_BOT;
10891 un->un_status = SUN_KEY_EOT;
10894 st_set_pe_flag(un);
10901 if (un->un_laststate >= ST_STATE_OPEN) {
10902 ST_DO_ERRSTATS(un, st_softerrs);
10910 ST_DO_ERRSTATS(un, st_harderrs);
10912 un->un_pos.pmode = invalid;
10913 un->un_running.pmode = invalid;
10925 if (un->un_bsize == 0 && resid > 0) {
10930 } else if (un->un_bsize == 0 && resid < 0) {
10941 un->un_status = SUN_KEY_EOF;
10943 st_set_pe_flag(un);
10952 un->un_status = SUN_KEY_EOT;
10954 st_set_pe_flag(un);
10960 ST_DO_ERRSTATS(un, st_softerrs);
10967 ST_DO_ERRSTATS(un, st_harderrs);
10970 if (un->un_dp->options & ST_EJECT_ON_CHANGER_FAILURE)
10971 un->un_eject_tape_on_failure = st_check_asc_ascq(un);
10975 ST_DO_ERRSTATS(un, st_softerrs);
10982 if (bp != un->un_sbufp && (bp->b_flags & B_READ)) {
10986 un->un_status = SUN_KEY_EOT;
10989 un->un_running.pmode = invalid;
10990 st_set_pe_flag(un);
10992 } else if (bp != un->un_sbufp &&
10999 if (un->un_laststate >= ST_STATE_OPEN) {
11007 (un->un_dp->options & ST_KNOWS_EOD)) {
11016 st_set_pe_flag(un);
11020 if (st_wrongtapetype(un)) {
11021 un->un_status = SUN_KEY_WRONGMEDIA;
11029 ST_DO_ERRSTATS(un, st_harderrs);
11036 "KEY_UNIT_ATTENTION : un_state = %d\n", un->un_state);
11038 un->un_unit_attention_flags |= 1;
11045 if ((un->un_rsvd_status &
11048 un->un_rsvd_status |= ST_LOST_RESERVE;
11057 if (bp == un->un_recov_buf) {
11076 if ((un->un_rsvd_status &
11099 if (un->un_state <= ST_STATE_OPENING) {
11109 (un->un_restore_pos != 1)) {
11110 un->un_save_fileno = pos->fileno;
11111 un->un_save_blkno = pos->blkno;
11112 un->un_restore_pos = 1;
11173 if (un->un_state >= ST_STATE_OPEN) {
11174 ST_DO_ERRSTATS(un, st_harderrs);
11197 (un->un_dp->rewind_timeout / 10)) {
11228 un->un_state > ST_STATE_OPENING) {
11229 ST_DO_ERRSTATS(un, st_harderrs);
11236 un->un_mediastate = MTIO_EJECTED;
11237 cv_broadcast(&un->un_state_cv);
11239 if ((un->un_dp->options & ST_EJECT_ON_CHANGER_FAILURE) &&
11241 un->un_eject_tape_on_failure = st_check_asc_ascq(un);
11258 ST_DO_ERRSTATS(un, st_harderrs);
11271 sense_keys[un->un_status]);
11272 ST_DO_ERRSTATS(un, st_harderrs);
11279 un->un_state >= ST_STATE_OPEN) && (DEBUGGING ||
11280 (un->un_laststate > ST_STATE_OPENING) &&
11284 pos->lgclblkno, un->un_err_pos.lgclblkno,
11303 un->un_rqs_state |= (ST_RQS_ERROR | ST_RQS_VALID);
11304 bcopy(ST_RQSENSE, un->un_uscsi_rqs_buf, SENSE_LENGTH);
11305 if (un->un_rqs_state & ST_RQS_READ) {
11306 un->un_rqs_state &= ~(ST_RQS_READ);
11308 un->un_rqs_state |= ST_RQS_OVR;
11317 st_handle_intr_retry_lcmd(struct scsi_tape *un, struct buf *bp)
11327 "st_handle_intr_rtr_lcmd(), un = 0x%p\n", (void *)un);
11338 ((un->un_runqf != bp) && (un->un_runql != bp))) {
11342 if (un->un_throttle) {
11343 un->un_last_throttle = un->un_throttle;
11344 un->un_throttle = 0;
11355 status = st_transport(un, BP_PKT(bp));
11358 if (un->un_last_throttle) {
11359 un->un_throttle = un->un_last_throttle;
11372 if (st_handle_intr_busy(un, bp, ST_TRAN_BUSY_TIMEOUT) == 0) {
11379 ST_DO_ERRSTATS(un, st_transerrs);
11380 if (un->un_last_throttle) {
11381 un->un_throttle = un->un_last_throttle;
11389 st_wrongtapetype(struct scsi_tape *un)
11401 if (un->un_dp && (un->un_dp->options & ST_QIC) && un->un_mspl) {
11402 switch (un->un_dp->type) {
11421 if (un->un_status == KEY_WRITE_PROTECT &&
11422 un->un_mspl->wp == 0) {
11434 st_check_error(struct scsi_tape *un, struct scsi_pkt *pkt)
11455 (bp != un->un_recov_buf) &&
11456 (un->un_state > ST_STATE_OPEN_PENDING_IO) &&
11457 ((un->un_rsvd_status & (ST_RESERVE |
11460 un->un_rsvd_status |= ST_LOST_RESERVE;
11463 un->un_rsvd_status |= ST_RESERVATION_CONFLICT;
11470 un->un_multipath && (pkt->pkt_state == (STATE_GOT_BUS |
11489 } else if ((un->un_rsvd_status &
11499 (void) st_reset(un, RESET_ALL);
11511 if (un->un_arq_enabled &&
11520 action = st_decode_sense(un, bp, MAX_SENSE_LENGTH -
11521 pkt->pkt_resid, stat, &un->un_pos);
11546 st_calc_bnum(struct scsi_tape *un, struct buf *bp, struct scsi_pkt *pkt)
11573 ASSERT(un->un_pos.eof == ST_EOM);
11577 ASSERT(un->un_pos.eof == ST_EOF_PENDING);
11581 } else if (un->un_bsize == 0) {
11588 un->un_kbytes_xferred += (count / ONE_K);
11596 nblks = (count / un->un_bsize);
11597 un->un_kbytes_xferred += (nblks * un->un_bsize) / ONE_K;
11607 if (un->un_pos.eof == ST_EOF_PENDING && bp->b_resid) {
11619 if (un->un_persistence && un->un_persist_errors) {
11620 ASSERT(un->un_pos.pmode != invalid);
11624 un->un_pos.blkno += nblks;
11625 un->un_pos.lgclblkno += nblks;
11626 un->un_pos.lgclblkno += nfiles;
11628 un->un_pos.blkno -= nblks;
11629 un->un_pos.lgclblkno -= nblks;
11630 un->un_pos.lgclblkno -= nfiles;
11637 un->un_running.pmode = invalid;
11644 if (un->un_pos.eof != ST_EOF_PENDING) {
11651 ((un->un_pos.blkno != ri->pos.blkno) ||
11652 (un->un_pos.lgclblkno != ri->pos.lgclblkno))) {
11657 "But Got", &un->un_pos);
11659 un->un_running.pmode = invalid;
11663 if (un->un_running.pmode != invalid) {
11670 un->un_running.fileno++;
11671 un->un_running.blkno = 0;
11673 un->un_running.fileno--;
11674 un->un_running.blkno = LASTBLK;
11681 st_set_state(struct scsi_tape *un, struct buf *bp)
11689 ASSERT(bp != un->un_recov_buf);
11693 un->un_pos.eof, un->un_fmneeded, sp->pkt_resid, sp->pkt_resid);
11695 if (bp != un->un_sbufp) {
11705 st_calc_bnum(un, bp, sp);
11708 un->un_lastop = ST_OP_READ;
11709 un->un_fmneeded = 0;
11711 un->un_lastop = ST_OP_WRITE;
11712 if (un->un_dp->options & ST_REEL) {
11713 un->un_fmneeded = 2;
11715 un->un_fmneeded = 1;
11723 if (un->un_throttle) {
11724 un->un_throttle = un->un_max_throttle;
11738 st_calc_bnum(un, bp, sp);
11739 if (un->un_dp->options & ST_REEL) {
11740 un->un_fmneeded = 2;
11742 un->un_fmneeded = 1;
11749 un->un_lastop = ST_OP_READ;
11753 st_calc_bnum(un, bp, sp);
11754 un->un_fmneeded = 0;
11761 if (un->un_pos.eof != ST_EOM) {
11762 un->un_pos.eof = ST_NO_EOF;
11766 un->un_lastop = new_lastop = ST_OP_WEOF;
11767 un->un_pos.lgclblkno += fmdone;
11768 un->un_pos.fileno += fmdone;
11769 un->un_pos.blkno = 0;
11775 if (fmdone > un->un_fmneeded) {
11776 un->un_fmneeded = 0;
11778 un->un_fmneeded -= fmdone;
11783 un->un_pos.eof = ST_NO_EOF;
11784 un->un_pos.fileno = 0;
11785 un->un_pos.blkno = 0;
11786 un->un_pos.lgclblkno = 0;
11787 if (un->un_pos.pmode != legacy)
11788 un->un_pos.pmode = legacy;
11790 un->un_restore_pos = 0;
11818 un->un_lastop = new_lastop = ST_OP_CTL;
11834 un->un_pos.fileno, un->un_pos.blkno);
11840 if (un->un_pos.eof <= ST_EOF) {
11841 un->un_pos.eof = ST_NO_EOF;
11843 un->un_pos.fileno += done;
11844 un->un_pos.blkno = 0;
11848 if (done > un->un_pos.fileno) {
11849 un->un_pos.fileno = 0;
11850 un->un_pos.blkno = 0;
11852 un->un_pos.fileno -= done;
11853 un->un_pos.blkno = LASTBLK;
11854 un->un_running.pmode = invalid;
11860 un->un_pos.blkno += done;
11864 if (un->un_pos.eof >= ST_EOF_PENDING) {
11873 if (done > un->un_pos.blkno) {
11874 un->un_pos.blkno = 0;
11876 un->un_pos.fileno--;
11877 un->un_pos.blkno = LASTBLK;
11878 un->un_running.pmode = invalid;
11881 un->un_pos.blkno -= done;
11885 un->un_pos.pmode = logical;
11886 un->un_pos.blkno = 0;
11887 un->un_lastop = new_lastop = ST_OP_CTL;
11890 un->un_pos.pmode = logical;
11891 un->un_pos.eof = ST_EOM;
11892 un->un_status = KEY_BLANK_CHECK;
11895 un->un_pos.pmode = invalid;
11900 un->un_lastop = new_lastop = ST_OP_CTL;
11905 resid, un->un_pos.fileno, un->un_pos.blkno);
11911 un->un_pos.fileno = 0;
11912 if (un->un_pos.pmode != legacy)
11913 un->un_pos.pmode = legacy;
11915 un->un_state = ST_STATE_OFFLINE;
11916 un->un_pos.pmode = invalid;
11923 if (un->un_media_id != bogusID && un->un_media_id_len) {
11924 kmem_free(un->un_media_id, un->un_media_id_len);
11925 un->un_media_id = NULL;
11926 un->un_media_id_len = 0;
11928 un->un_density_known = 0;
11929 un->un_pos.eof = ST_NO_EOF;
11930 un->un_pos.blkno = 0;
11931 un->un_lastop = new_lastop = ST_OP_CTL;
11934 un->un_pos.eof = ST_NO_EOF;
11935 un->un_pos.blkno = 0;
11936 un->un_pos.fileno = 0;
11937 un->un_pos.lgclblkno = 0;
11938 if (un->un_pos.pmode != legacy)
11939 un->un_pos.pmode = legacy;
11943 un->un_rsvd_status |= ST_RESERVE;
11944 un->un_rsvd_status &=
11950 un->un_rsvd_status |= ST_RELEASE;
11951 un->un_rsvd_status &=
11966 un->un_rsvd_status |=
11968 un->un_rsvd_status &= ~(ST_RELEASE |
11978 un->un_rsvd_status |= ST_INIT_RESERVE;
11981 un->un_rsvd_status &= ~ST_INIT_RESERVE;
11984 un->un_rsvd_status &=
11988 un->un_rsvd_status |= ST_RELEASE;
12025 (void) st_get_read_pos(un, bp);
12031 un->un_lastop = new_lastop = ST_OP_CTL;
12064 un->un_pos.pmode = invalid;
12065 un->un_lastop = new_lastop = ST_OP_CTL;
12073 if (((un->un_lastop == ST_OP_WRITE) ||
12074 (un->un_lastop == ST_OP_WEOF)) &&
12076 un->un_lastop = new_lastop;
12093 un->un_err_resid = bp->b_resid;
12094 COPY_POS(&un->un_err_pos, &un->un_pos);
12108 if (un->un_lastop == ST_OP_READ && un->un_pos.eof == ST_EOF_PENDING) {
12118 if ((un->un_dp->options & ST_REEL) &&
12119 !(un->un_dp->options & ST_READ_IGNORE_EOFS) &&
12120 un->un_pos.blkno == 0 && un->un_pos.fileno > 0) {
12121 un->un_pos.eof = ST_EOT_PENDING;
12124 un->un_pos.fileno++;
12125 un->un_pos.blkno = 0;
12134 un->un_pos.eof = ST_EOF;
12137 un->un_pos.fileno++;
12140 un->un_pos.blkno = 0;
12142 un->un_pos.eof = ST_NO_EOF;
12159 un->un_pos.eof = ST_EOF;
12161 un->un_silent_skip = 1;
12162 un->un_pos.eof = ST_NO_EOF;
12163 un->un_pos.fileno++;
12164 un->un_pos.lgclblkno++;
12165 un->un_save_blkno = un->un_pos.blkno;
12166 un->un_pos.blkno = 0;
12170 un->un_pos.fileno, un->un_pos.eof);
12181 un->un_pos.eof = ST_EOF;
12185 un->un_pos.fileno, un->un_pos.eof);
12194 st_set_pe_errno(struct scsi_tape *un)
12201 if (un->un_errno)
12214 if (un->un_last_resid == un->un_last_count) {
12215 switch (un->un_pos.eof) {
12217 un->un_errno = ENOMEM;
12221 un->un_errno = EIO;
12229 un->un_last_resid = un->un_last_count = 0;
12239 st_hba_unflush(struct scsi_tape *un)
12245 if (!un->un_flush_on_errors)
12250 if (!un->un_mkr_pkt) {
12251 un->un_mkr_pkt = scsi_init_pkt(ROUTE, NULL, (struct buf *)NULL,
12258 st_transport(un, un->un_mkr_pkt);
12282 struct scsi_tape *un;
12285 un = ddi_get_soft_state(st_state, instance);
12292 st_dev_name(un->un_dev), st_print_scsi_cmd(*cdb));
12347 st_debug_cmds(struct scsi_tape *un, int com, int count, int wait)
12367 struct scsi_tape *un;
12376 un = ddi_get_soft_state(st_state, instance);
12377 if (un) {
12439 com->uscsi_timeout = un->un_dp->non_motion_timeout;
12441 rval = st_uscsi_cmd(un, com, FKIOCTL);
12451 if ((amt >= 19) && un->un_kbytes_xferred) {
12459 if (un->un_kbytes_xferred < (EXABYTE_MIN_TRANSFER/ONE_K)) {
12467 error_rate = (count * 100)/un->un_kbytes_xferred;
12477 un->un_kbytes_xferred);
12569 com->uscsi_timeout = un->un_dp->non_motion_timeout;
12570 rval = st_uscsi_cmd(un, com, FKIOCTL);
12584 if ((amt >= MIN_LOG_SENSE_LENGTH) && un->un_kbytes_xferred) {
12700 rval = st_uscsi_cmd(un, com, FKIOCTL);
12723 switch (un->un_dp->type) {
12732 un->un_dp->options &= ~ST_SOFT_ERROR_REPORTING;
12746 st_turn_pe_on(struct scsi_tape *un)
12753 un->un_persistence = 1;
12760 if (un->un_arq_enabled && un->un_untagged_qing) {
12768 un->un_flush_on_errors = f_o_e;
12770 un->un_flush_on_errors = 0;
12773 if (un->un_flush_on_errors)
12774 un->un_max_throttle = (uchar_t)st_max_throttle;
12776 un->un_max_throttle = 1;
12778 if (un->un_dp->options & ST_RETRY_ON_RECOVERED_DEFERRED_ERROR)
12779 un->un_max_throttle = 1;
12782 st_clear_pe(un);
12789 st_turn_pe_off(struct scsi_tape *un)
12796 un->un_persistence = 0;
12799 st_clear_pe(un);
12802 if (un->un_flush_on_errors) {
12809 un->un_flush_on_errors = 0;
12817 st_clear_pe(struct scsi_tape *un)
12823 un->un_persist_errors = 0;
12824 un->un_throttle = un->un_last_throttle = 1;
12825 un->un_errno = 0;
12826 st_hba_unflush(un);
12834 st_set_pe_flag(struct scsi_tape *un)
12839 if (un->un_persistence) {
12841 un->un_persist_errors = 1;
12842 un->un_throttle = un->un_last_throttle = 0;
12843 cv_broadcast(&un->un_sbuf_cv);
12848 st_do_reserve(struct scsi_tape *un)
12851 int was_lost = un->un_rsvd_status & ST_LOST_RESERVE;
12869 rval = st_reserve_release(un, ST_RESERVE, st_uscsi_cmd);
12871 if ((un->un_rsvd_status & ST_LOST_RESERVE_BETWEEN_OPENS) ==
12873 un->un_rsvd_status &= ~(ST_LOST_RESERVE | ST_RESERVE);
12874 un->un_errno = EACCES;
12877 rval = st_reserve_release(un, ST_RESERVE, st_uscsi_cmd);
12880 un->un_rsvd_status |= ST_INIT_RESERVE;
12883 un->un_running.pmode = invalid;
12890 st_check_cdb_for_need_to_reserve(struct scsi_tape *un, uchar_t *cdb)
12901 if ((un->un_rsvd_status & (ST_APPLICATION_RESERVATIONS)) ||
12902 ((un->un_rsvd_status & (ST_RESERVE | ST_LOST_RESERVE)) ==
12903 ST_RESERVE) || (un->un_dp->options & ST_NO_RESERVE_RELEASE)) {
12935 rval = st_do_reserve(un);
12942 st_check_cmd_for_need_to_reserve(struct scsi_tape *un, uchar_t cmd, int cnt)
12953 if ((un->un_rsvd_status & (ST_APPLICATION_RESERVATIONS)) ||
12954 ((un->un_rsvd_status & (ST_RESERVE | ST_LOST_RESERVE)) ==
12955 ST_RESERVE) || (un->un_dp->options & ST_NO_RESERVE_RELEASE) ||
12956 ((un->un_state == ST_STATE_CLOSING) && (cmd == SCMD_REWIND))) {
12986 rval = st_do_reserve(un);
12993 st_reserve_release(struct scsi_tape *un, int cmd, ubufunc_t ubf)
13020 uscsi_cmd.uscsi_timeout = un->un_dp->non_motion_timeout;
13024 rval = ubf(un, &uscsi_cmd, FKIOCTL);
13038 if (un->un_status == KEY_ILLEGAL_REQUEST) {
13039 if ((un->un_dp->options & ST_NO_RESERVE_RELEASE) == 0) {
13040 un->un_dp->options |= ST_NO_RESERVE_RELEASE;
13052 st_take_ownership(struct scsi_tape *un, ubufunc_t ubf)
13064 rval = st_reserve_release(un, ST_RESERVE, ubf);
13070 if (st_reset(un, RESET_LUN) == 0) {
13073 un->un_rsvd_status &=
13082 (void) st_reserve_release(un, ST_RESERVE, ubf);
13083 rval = st_reserve_release(un, ST_RESERVE, ubf);
13085 if ((st_reserve_release(un, ST_RESERVE, ubf))
13087 rval = (un->un_rsvd_status &
13097 un->un_state = ST_STATE_OFFLINE;
13098 un->un_rsvd_status |= ST_INIT_RESERVE;
13104 st_create_errstats(struct scsi_tape *un, int instance)
13114 if (un->un_errstats == (kstat_t *)0) {
13116 un->un_errstats = kstat_create("sterr", instance, kstatname,
13121 if (un->un_errstats) {
13124 stp = (struct st_errstats *)un->un_errstats->ks_data;
13139 un->un_errstats->ks_private = un;
13140 un->un_errstats->ks_update = nulldev;
13141 kstat_install(un->un_errstats);
13163 st_validate_tapemarks(struct scsi_tape *un, ubufunc_t ubf, tapepos_t *pos)
13170 ASSERT(MUTEX_HELD(&un->un_sd->sd_mutex));
13187 if (pos->pmode == logical || un->un_read_pos_type != NO_POS) {
13197 if (st_logical_block_locate(un, st_uscsi_cmd, &un->un_pos,
13200 if (un->un_pos.lgclblkno == pos->lgclblkno) {
13201 COPY_POS(&un->un_pos, pos);
13225 rval = bf(un, SCMD_REWIND, 0, SYNC_CMD);
13230 un->un_pos.pmode = invalid;
13244 rval = st_cmd(un, SCMD_SPACE, Fmk(pos->fileno), SYNC_CMD);
13250 un->un_pos.pmode = invalid;
13263 rval = bf(un, SCMD_SPACE, Fmk(-1), SYNC_CMD);
13269 un->un_pos.pmode = invalid;
13279 un->un_pos.eof = pos->eof;
13280 un->un_pos.lgclblkno = pos->lgclblkno;
13291 st_check_asc_ascq(struct scsi_tape *un)
13318 st_logpage_supported(struct scsi_tape *un, uchar_t page)
13353 com->uscsi_timeout = un->un_dp->non_motion_timeout;
13354 rval = st_uscsi_cmd(un, com, FKIOCTL);
13395 st_check_clean_bit(struct scsi_tape *un)
13403 if (un->un_HeadClean & TAPE_ALERT_NOT_SUPPORTED) {
13407 if (un->un_HeadClean == TAPE_ALERT_SUPPORT_UNKNOWN) {
13409 rval = st_logpage_supported(un, TAPE_SEQUENTIAL_PAGE);
13415 un->un_HeadClean |= TAPE_SEQUENTIAL_SUPPORTED;
13418 rval = st_logpage_supported(un, TAPE_ALERT_PAGE);
13424 un->un_HeadClean |= TAPE_ALERT_SUPPORTED;
13427 if (un->un_HeadClean == TAPE_ALERT_SUPPORT_UNKNOWN) {
13429 un->un_HeadClean = TAPE_ALERT_NOT_SUPPORTED;
13435 if (un->un_HeadClean & TAPE_SEQUENTIAL_SUPPORTED) {
13437 rval = st_check_sequential_clean_bit(un);
13443 if ((rval == 0) && (un->un_HeadClean & TAPE_ALERT_SUPPORTED)) {
13445 rval = st_check_alert_flags(un);
13451 if ((rval == 0) && (un->un_dp->options & ST_CLN_MASK)) {
13453 rval = st_check_sense_clean_bit(un);
13473 if ((un->un_HeadClean & TAPE_PREVIOUSLY_DIRTY) == 0) {
13478 un->un_HeadClean |= TAPE_PREVIOUSLY_DIRTY;
13483 un->un_HeadClean &= ~TAPE_PREVIOUSLY_DIRTY;
13492 st_check_sequential_clean_bit(struct scsi_tape *un)
13521 cmd->uscsi_timeout = un->un_dp->non_motion_timeout;
13529 rval = st_uscsi_cmd(un, cmd, FKIOCTL);
13573 st_check_alert_flags(struct scsi_tape *un)
13607 com->uscsi_timeout = un->un_dp->non_motion_timeout;
13609 rval = st_uscsi_cmd(un, com, FKIOCTL);
13655 (un->un_dp->type == ST_TYPE_STK9840))) {
13662 un->un_HeadClean |= TAPE_ALERT_STILL_DIRTY;
13669 un->un_HeadClean &= ~TAPE_ALERT_STILL_DIRTY;
13677 if (un->un_HeadClean & TAPE_ALERT_STILL_DIRTY) {
13692 st_check_sense_clean_bit(struct scsi_tape *un)
13711 if ((un->un_dp->options & ST_CLN_MASK) == ST_CLN_TYPE_1) {
13715 } else if ((un->un_dp->options & ST_CLN_MASK) == ST_CLN_TYPE_2) {
13719 } else if ((un->un_dp->options & ST_CLN_MASK) == ST_CLN_TYPE_3) {
13748 com->uscsi_timeout = un->un_dp->non_motion_timeout;
13750 rval = st_uscsi_cmd(un, com, FKIOCTL);
13789 rval = st_cmd(un, SCMD_TEST_UNIT_READY, 0, SYNC_CMD);
13795 st_calculate_timeouts(struct scsi_tape *un)
13799 if (un->un_dp->non_motion_timeout == 0) {
13800 if (un->un_dp->options & ST_LONG_TIMEOUTS) {
13801 un->un_dp->non_motion_timeout =
13804 un->un_dp->non_motion_timeout = (ushort_t)st_io_time;
13808 if (un->un_dp->io_timeout == 0) {
13809 if (un->un_dp->options & ST_LONG_TIMEOUTS) {
13810 un->un_dp->io_timeout = st_io_time * st_long_timeout_x;
13812 un->un_dp->io_timeout = (ushort_t)st_io_time;
13816 if (un->un_dp->rewind_timeout == 0) {
13817 if (un->un_dp->options & ST_LONG_TIMEOUTS) {
13818 un->un_dp->rewind_timeout =
13821 un->un_dp->rewind_timeout = (ushort_t)st_space_time;
13825 if (un->un_dp->space_timeout == 0) {
13826 if (un->un_dp->options & ST_LONG_TIMEOUTS) {
13827 un->un_dp->space_timeout =
13830 un->un_dp->space_timeout = (ushort_t)st_space_time;
13834 if (un->un_dp->load_timeout == 0) {
13835 if (un->un_dp->options & ST_LONG_TIMEOUTS) {
13836 un->un_dp->load_timeout =
13839 un->un_dp->load_timeout = (ushort_t)st_space_time;
13843 if (un->un_dp->unload_timeout == 0) {
13844 if (un->un_dp->options & ST_LONG_TIMEOUTS) {
13845 un->un_dp->unload_timeout =
13848 un->un_dp->unload_timeout = (ushort_t)st_space_time;
13852 if (un->un_dp->erase_timeout == 0) {
13853 if (un->un_dp->options & ST_LONG_ERASE) {
13854 un->un_dp->erase_timeout =
13857 un->un_dp->erase_timeout = (ushort_t)st_space_time;
13864 st_is_not_wormable(struct scsi_tape *un)
13871 st_is_hp_dat_tape_worm(struct scsi_tape *un)
13878 if (un->un_mspl->media_type == 1) {
13892 st_is_hp_dat_worm(struct scsi_tape *un)
13902 result = st_get_special_inquiry(un, HP_DAT_INQUIRY, buf, 0);
13912 un->un_dp->options &= ~ST_WORMABLE;
13914 un->un_wormable = st_is_not_wormable;
13918 un->un_wormable = st_is_hp_dat_tape_worm;
13919 wrt = un->un_wormable(un);
13931 st_is_hp_lto_tape_worm(struct scsi_tape *un)
13938 switch (un->un_mspl->media_type) {
13940 switch (un->un_mspl->density) {
13960 un->un_mspl->density);
13977 un->un_mspl->media_type);
13986 st_is_hp_lto_worm(struct scsi_tape *un)
13996 result = st_get_special_inquiry(un, LTO_REQ_INQUIRY, buf, 0);
14006 un->un_dp->options &= ~ST_WORMABLE;
14008 un->un_wormable = st_is_not_wormable;
14012 un->un_wormable = st_is_hp_lto_tape_worm;
14013 wrt = un->un_wormable(un);
14025 st_is_t10_worm_device(struct scsi_tape *un)
14031 if (un->un_mspl->media_type == 0x3c) {
14045 st_is_t10_worm(struct scsi_tape *un)
14055 result = st_get_special_inquiry(un, 6, buf, SEQ_CAP_PAGE);
14067 un->un_dp->options &= ~ST_WORMABLE;
14069 un->un_wormable = st_is_not_wormable;
14073 un->un_wormable = st_is_t10_worm_device;
14074 wrt = un->un_wormable(un);
14086 st_is_stk_worm(struct scsi_tape *un)
14102 cmd->uscsi_timeout = un->un_dp->non_motion_timeout;
14110 result = st_uscsi_cmd(un, cmd, FKIOCTL);
14121 un->un_wormable = st_is_not_wormable;
14126 un->un_wormable = st_is_stk_worm;
14131 un->un_wormable = st_is_stk_worm;
14142 st_is_dlt_tape_worm(struct scsi_tape *un)
14154 result = st_read_attributes(un, 0x0408, buf, 10, st_uscsi_cmd);
14161 if (result == EINVAL && un->un_max_cdb_sz < CDB_GROUP4) {
14166 un->un_wormable = st_is_not_wormable;
14175 un->un_dp->options &= ~ST_WORMABLE;
14195 st_is_dlt_worm(struct scsi_tape *un)
14205 result = st_get_special_inquiry(un, DLT_INQ_SZ, buf, 0xC0);
14218 un->un_dp->options &= ~ST_WORMABLE;
14219 un->un_wormable = st_is_not_wormable;
14224 un->un_wormable = st_is_dlt_tape_worm;
14225 wrt = un->un_wormable(un);
14277 st_is_sony_worm(struct scsi_tape *un)
14287 result = st_gen_mode_sense(un, st_uscsi_cmd, AIT_DEV_PAGE,
14297 un->un_wormable = st_is_not_wormable;
14301 un->un_wormable = st_is_sony_worm;
14320 un->un_dp->options &= ~ST_WORMABLE;
14329 un->un_wormable = st_is_not_wormable;
14337 st_is_drive_worm(struct scsi_tape *un)
14343 switch (un->un_dp->type) {
14345 wrt = st_is_dlt_worm(un);
14349 wrt = st_is_stk_worm(un);
14354 wrt = st_is_sony_worm(un);
14358 if (strncmp("HP ", un->un_dp->vid, 3) == 0) {
14359 wrt = st_is_hp_lto_worm(un);
14361 wrt = st_is_t10_worm(un);
14366 if (strncmp("HP ", un->un_dp->vid, 3) == 0) {
14367 wrt = st_is_hp_dat_worm(un);
14369 wrt = st_is_t10_worm(un);
14382 wrt = st_is_t10_worm(un);
14392 un->un_dp->options &= ~ST_WORMABLE;
14399 st_read_attributes(struct scsi_tape *un, uint16_t attribute, void *pnt,
14411 if (un->un_sd->sd_inq->inq_ansi < 3) {
14436 cmd->uscsi_timeout = un->un_dp->non_motion_timeout;
14444 result = bufunc(un, cmd, FKIOCTL);
14453 if (un->un_sd->sd_sense->es_key == KEY_ILLEGAL_REQUEST &&
14454 un->un_sd->sd_sense->es_add_code == 0x20) {
14481 st_get_special_inquiry(struct scsi_tape *un, uchar_t size, caddr_t dest,
14502 cmd->uscsi_timeout = un->un_dp->non_motion_timeout;
14510 result = st_uscsi_cmd(un, cmd, FKIOCTL);
14528 st_update_block_pos(struct scsi_tape *un, bufunc_t bf, int post_space)
14531 uchar_t status = un->un_status;
14532 posmode previous_pmode = un->un_running.pmode;
14536 while (un->un_read_pos_type != NO_POS) {
14537 rval = bf(un, SCMD_READ_POSITION, 32, SYNC_CMD);
14544 ((rval = st_interpret_read_pos(un, &un->un_pos,
14545 un->un_read_pos_type, 32, (caddr_t)un->un_read_pos_data,
14554 rval = st_interpret_read_pos(un, &un->un_running,
14555 un->un_read_pos_type, 32,
14556 (caddr_t)un->un_read_pos_data, post_space);
14557 un->un_status = status;
14559 } else if (un->un_status == KEY_UNIT_ATTENTION) {
14560 un->un_running.pmode = previous_pmode;
14562 } else if (un->un_status != KEY_ILLEGAL_REQUEST) {
14566 un->un_read_pos_type, rval, un->un_status);
14576 " returned %x", un->un_read_pos_type, rval);
14577 un->un_running.pmode = previous_pmode;
14580 switch (un->un_read_pos_type) {
14582 un->un_read_pos_type = NO_POS;
14586 un->un_read_pos_type = EXT_POS;
14590 un->un_read_pos_type = SHORT_POS;
14596 un->un_read_pos_type);
14598 un->un_status = KEY_NO_SENSE;
14605 st_get_read_pos(struct scsi_tape *un, buf_t *bp)
14652 result = st_interpret_read_pos(un, &un->un_pos, cmd->uscsi_cdb[1],
14655 COPY_POS(&un->un_running, &un->un_pos);
14727 st_interpret_read_pos(struct scsi_tape const *un, tapepos_t *dest,
14740 if ((dest != &un->un_pos) && (post_space == 0) &&
15105 st_logical_block_locate(struct scsi_tape *un, ubufunc_t ubf, tapepos_t *pos,
15139 if (un->un_read_pos_type != LONG_POS) {
15166 cmd->uscsi_timeout = un->un_dp->space_timeout;
15169 rval = ubf(un, cmd, FKIOCTL);
15181 if (un->un_status == KEY_ILLEGAL_REQUEST) {
15185 un->un_status = 0;
15187 } else if ((un->un_pos.pmode == invalid) || (rval != 0)) {
15192 un->un_status = 0;
15194 } else if (st_update_block_pos(un, bf, 1)) {
15199 } else if (lblk > un->un_pos.lgclblkno) {
15203 PRIx64"\n", un->un_pos.lgclblkno);
15204 un->un_err_resid = lblk - un->un_pos.lgclblkno;
15205 un->un_status = KEY_BLANK_CHECK;
15207 } else if (lblk == un->un_pos.lgclblkno) {
15211 un->un_err_resid = 0;
15216 un->un_err_resid = lblk;
15228 un->un_err_resid = cmd->uscsi_resid;
15229 un->un_status = KEY_BLANK_CHECK;
15232 } else if (st_update_block_pos(un, bf, 1) == 0) {
15234 un->un_err_resid = lblk - pos->lgclblkno;
15235 un->un_status = KEY_BLANK_CHECK;
15242 un->un_err_resid = lblk;
15243 un->un_status = KEY_ILLEGAL_REQUEST;
15254 st_mtfsf_ioctl(struct scsi_tape *un, int64_t files)
15262 "st_mtfsf_ioctl: count=%"PRIx64", eof=%x\n", files, un->un_pos.eof);
15264 if ((IN_EOF(un->un_pos)) && (files == 1)) {
15265 un->un_pos.fileno++;
15266 un->un_pos.blkno = 0;
15271 if (un->un_pos.pmode == legacy) {
15280 if ((un->un_pos.eof >= ST_EOT) &&
15282 ((un->un_dp->options & ST_REEL) == 0)) {
15284 un->un_err_resid = files;
15285 un->un_status = KEY_BLANK_CHECK;
15295 if (IN_EOF(un->un_pos)) {
15296 un->un_pos.fileno++;
15297 un->un_pos.blkno = 0;
15308 if (st_check_density_or_wfm(un->un_dev, 1, B_READ, STEPBACK)) {
15321 rval = st_backward_space_files(un, -files, 0);
15323 rval = st_forward_space_files(un, files);
15330 st_forward_space_files(struct scsi_tape *un, int64_t count)
15337 "fspace: count=%"PRIx64", eof=%x\n", count, un->un_pos.eof);
15340 ASSERT(un->un_pos.pmode != invalid);
15348 if (un->un_pos.pmode == legacy && un->un_pos.blkno == 0) {
15349 un->un_err_resid = 0;
15350 COPY_POS(&un->un_err_pos, &un->un_pos);
15358 if (un->un_pos.pmode == legacy && un->un_pos.fileno == 0) {
15359 rval = st_cmd(un, SCMD_REWIND, 0, SYNC_CMD);
15365 } else if (un->un_dp->options & ST_BSF) {
15366 rval = st_space_to_begining_of_file(un);
15372 } else if (un->un_pos.pmode == legacy) {
15373 rval = st_scenic_route_to_begining_of_file(un,
15374 un->un_pos.fileno);
15381 } else if (un->un_read_pos_type == LONG_POS) {
15382 rval = st_cmd(un, SCMD_READ_POSITION, 0, SYNC_CMD);
15390 rval = st_space_to_begining_of_file(un);
15392 rval = st_interpret_read_pos(un, &un->un_pos, LONG_POS,
15393 32, (caddr_t)un->un_read_pos_data, 0);
15394 if ((rval) && (un->un_pos.pmode == invalid)) {
15395 rval = st_space_to_begining_of_file(un);
15397 rval = st_scenic_route_to_begining_of_file(un,
15398 un->un_pos.fileno);
15407 un->un_pos.pmode = invalid;
15415 rval = st_space_fmks(un, count);
15423 rval = st_backward_space_files(un, 1, 1);
15430 st_scenic_route_to_begining_of_file(struct scsi_tape *un, int32_t fileno)
15436 if (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD)) {
15438 } else if (st_cmd(un, SCMD_SPACE, Fmk(fileno), SYNC_CMD)) {
15446 st_space_to_begining_of_file(struct scsi_tape *un)
15455 rval = st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD);
15464 if (un->un_status == SUN_KEY_BOT) {
15468 un->un_running.pmode = invalid;
15474 rval = st_cmd(un, SCMD_SPACE, Fmk(1), SYNC_CMD);
15483 st_mtfsr_ioctl(struct scsi_tape *un, int64_t count)
15494 "st_ioctl_fsr: count=%"PRIx64", eof=%x\n", count, un->un_pos.eof);
15496 if (un->un_pos.pmode == legacy) {
15501 if ((un->un_pos.eof >= ST_EOT) && (count > 0)) {
15503 un->un_err_resid = count;
15504 un->un_status = KEY_BLANK_CHECK;
15514 un->un_err_pos.fileno = un->un_pos.fileno;
15515 un->un_err_pos.blkno = un->un_pos.blkno;
15516 un->un_err_resid = 0;
15517 if (IN_EOF(un->un_pos) && SVR4_BEHAVIOR) {
15518 un->un_status = SUN_KEY_EOF;
15527 if (IN_EOF(un->un_pos)) {
15528 daddr_t blkno = un->un_pos.blkno;
15529 int fileno = un->un_pos.fileno;
15531 optype lastop = un->un_lastop;
15532 if (st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD)
15539 un->un_pos.blkno = blkno;
15540 un->un_pos.fileno = fileno;
15541 un->un_lastop = lastop;
15545 if (st_check_density_or_wfm(un->un_dev, 1, B_READ, STEPBACK)) {
15551 return (st_space_records(un, count));
15555 st_space_records(struct scsi_tape *un, int64_t count)
15564 count, un->un_pos.eof);
15566 if (un->un_pos.pmode == logical) {
15567 rval = st_cmd(un, SCMD_SPACE, Blk(count), SYNC_CMD);
15574 dblk = count + un->un_pos.blkno;
15577 if (dblk == un->un_pos.blkno) {
15578 un->un_err_resid = 0;
15579 COPY_POS(&un->un_err_pos, &un->un_pos);
15587 if (un->un_pos.blkno < dblk || (un->un_dp->options & ST_BSR)) {
15593 dblk -= un->un_pos.blkno;
15594 if (st_cmd(un, SCMD_SPACE, Blk(dblk), SYNC_CMD)) {
15598 } else if (un->un_pos.eof >= ST_EOF_PENDING) {
15602 if (dblk < 0 && un->un_pos.eof == ST_EOM) {
15603 un->un_status = SUN_KEY_BOT;
15604 un->un_pos.eof = ST_NO_EOF;
15606 un->un_pos.eof == ST_EOF_PENDING) {
15607 int residue = un->un_err_resid;
15612 if (st_cmd(un, SCMD_SPACE, Fmk(1), SYNC_CMD)) {
15618 un->un_err_resid = residue;
15634 int dfile = un->un_pos.fileno; /* save current file */
15640 if (un->un_pos.blkno != 0 &&
15641 (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD) ||
15642 st_cmd(un, SCMD_SPACE, Fmk(dfile), SYNC_CMD))) {
15643 un->un_pos.pmode = invalid;
15645 un->un_err_resid = -dblk;
15646 if (un->un_pos.fileno == 0 && un->un_pos.blkno == 0) {
15647 un->un_status = SUN_KEY_BOT;
15648 un->un_pos.eof = ST_NO_EOF;
15649 } else if (un->un_pos.fileno > 0) {
15650 un->un_status = SUN_KEY_EOF;
15651 un->un_pos.eof = ST_NO_EOF;
15653 COPY_POS(&un->un_err_pos, &un->un_pos);
15657 } else if (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD) ||
15658 st_cmd(un, SCMD_SPACE, Fmk(dfile), SYNC_CMD) ||
15659 st_cmd(un, SCMD_SPACE, Blk(dblk), SYNC_CMD)) {
15663 un->un_pos.pmode = invalid;
15672 st_mtbsf_ioctl(struct scsi_tape *un, int64_t files)
15677 "st_mtbsf_ioctl: count=%"PRIx64", eof=%x\n", files, un->un_pos.eof);
15683 if ((un->un_dp->options & ST_BSF) == 0) {
15687 if (un->un_pos.pmode == legacy) {
15695 if (un->un_pos.eof >= ST_EOT && files < 0) {
15696 un->un_err_resid = files;
15697 un->un_status = SUN_KEY_EOT;
15706 if (IN_EOF(un->un_pos)) {
15707 un->un_pos.fileno++;
15708 un->un_pos.blkno = 0;
15717 if (st_check_density_or_wfm(un->un_dev, 1, 0, STEPBACK)) {
15729 return (st_forward_space_files(un, files));
15731 return (st_backward_space_files(un, files, 1));
15735 st_backward_space_files(struct scsi_tape *un, int64_t count, int infront)
15745 count, un->un_pos.eof);
15755 * (un->un_pos.fileno - count), rewind,
15764 * desired filenumber (un->un_pos.fileno - count),
15769 if (un->un_pos.pmode == logical) {
15774 un->un_pos.lgclblkno);
15778 if ((un->un_dp->options & ST_BSF) == 0) {
15783 (st_cmd(un, SCMD_SPACE, Fmk(-count), SYNC_CMD))) {
15787 (st_cmd(un, SCMD_SPACE, Fmk((-count)-1), SYNC_CMD)) &&
15788 (st_cmd(un, SCMD_SPACE, Fmk(1), SYNC_CMD))) {
15798 infront?MTBSF:MTNBSF, count, un->un_pos.fileno, un->un_pos.blkno);
15816 end_fileno = un->un_pos.fileno - count;
15824 if (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD)) {
15835 un->un_err_resid = -end_fileno;
15836 un->un_status = SUN_KEY_BOT;
15841 if (un->un_dp->options & ST_BSF) {
15852 if (st_cmd(un, SCMD_SPACE, Fmk(end_fileno), SYNC_CMD)) {
15858 if (st_cmd(un, SCMD_REWIND, 0, SYNC_CMD)) {
15872 if (st_cmd(un, SCMD_SPACE, Fmk(skip_cnt), SYNC_CMD)) {
15883 if ((un->un_dp->options & ST_BSF) == 0) {
15884 un->un_pos.eof = ST_EOF_PENDING;
15885 un->un_pos.fileno -= 1;
15886 un->un_pos.blkno = LASTBLK;
15887 un->un_running.pmode = invalid;
15893 un->un_pos.pmode = invalid;
15900 st_mtnbsf_ioctl(struct scsi_tape *un, int64_t count)
15907 "nbsf: count=%"PRIx64", eof=%x\n", count, un->un_pos.eof);
15909 if (un->un_pos.pmode == legacy) {
15918 if (un->un_pos.eof >= ST_EOT && count < 0) {
15919 un->un_err_resid = count;
15920 un->un_status = SUN_KEY_EOT;
15929 if (IN_EOF(un->un_pos)) {
15930 un->un_pos.fileno++;
15931 un->un_pos.blkno = 0;
15936 if (st_check_density_or_wfm(un->un_dev, 1, 0, STEPBACK)) {
15943 "mtnbsf: count=%"PRIx64", eof=%x\n", count, un->un_pos.eof);
15946 rval = st_forward_space_files(un, -count);
15948 rval = st_backward_space_files(un, count, 0);
15954 st_mtbsr_ioctl(struct scsi_tape *un, int64_t num)
15959 "bsr: count=%"PRIx64", eof=%x\n", num, un->un_pos.eof);
15961 if (un->un_pos.pmode == legacy) {
15969 if (un->un_pos.eof >= ST_EOT && num < 0) {
15970 un->un_err_resid = num;
15971 un->un_status = SUN_KEY_EOT;
15978 COPY_POS(&un->un_err_pos, &un->un_pos);
15979 un->un_err_resid = 0;
15980 if (IN_EOF(un->un_pos) && SVR4_BEHAVIOR) {
15981 un->un_status = SUN_KEY_EOF;
15995 if (IN_EOF(un->un_pos)) {
15997 optype lastop = un->un_lastop;
15999 COPY_POS(&save, &un->un_pos);
16000 if (st_cmd(un, SCMD_SPACE, Fmk(-1), SYNC_CMD) == -1) {
16006 COPY_POS(&un->un_pos, &save);
16007 un->un_lastop = lastop;
16011 un->un_pos.eof = ST_NO_EOF;
16013 if (st_check_density_or_wfm(un->un_dev, 1, 0, STEPBACK)) {
16020 return (st_space_records(un, num));
16024 st_mtfsfm_ioctl(struct scsi_tape *un, int64_t cnt)
16030 rval = st_cmd(un, SCMD_SPACE, SPACE(SP_SQFLM, cnt), SYNC_CMD);
16032 un->un_pos.pmode = logical;
16033 } else if ((un->un_status == KEY_ILLEGAL_REQUEST) &&
16034 (un->un_sd->sd_sense->es_add_code == 0x24)) {
16039 un->un_err_resid = cnt;
16040 un->un_status = 0;
16043 un->un_err_resid = cnt;
16044 un->un_pos.pmode = invalid;
16050 st_mtbsfm_ioctl(struct scsi_tape *un, int64_t cnt)
16056 rval = st_cmd(un, SCMD_SPACE, SPACE(SP_SQFLM, -cnt), SYNC_CMD);
16058 un->un_pos.pmode = logical;
16059 } else if ((un->un_status == KEY_ILLEGAL_REQUEST) &&
16060 (un->un_sd->sd_sense->es_add_code == 0x24)) {
16065 un->un_err_resid = cnt;
16066 un->un_status = 0;
16069 un->un_err_resid = cnt;
16070 un->un_pos.pmode = invalid;
16081 st_release_contig_mem(struct scsi_tape *un, struct contig_mem *cp)
16087 cp->cm_next = un->un_contig_mem;
16088 un->un_contig_mem = cp;
16089 un->un_contig_mem_available_num++;
16090 cv_broadcast(&un->un_contig_mem_cv);
16103 st_get_contig_mem(struct scsi_tape *un, size_t len, int alloc_flags)
16118 if (un->un_contig_mem_available_num > 0) {
16119 ST_GET_CONTIG_MEM_HEAD(un, cp, len, big_enough);
16120 } else if (un->un_contig_mem_total_num < st_max_contig_mem_num) {
16138 un->un_contig_mem_total_num++; /* one more available */
16145 while (un->un_contig_mem_available_num <= 0) {
16146 cv_wait(&un->un_contig_mem_cv, ST_MUTEX);
16148 ST_GET_CONTIG_MEM_HEAD(un, cp, len, big_enough);
16161 if (ddi_dma_mem_alloc(un->un_contig_mem_hdl, len, &st_acc_attr,
16166 st_release_contig_mem(un, cp);
16174 un->un_max_contig_mem_len =
16175 un->un_max_contig_mem_len >= len ?
16176 un->un_max_contig_mem_len : len;
16193 if ((un->un_max_contig_mem_len < len) ||
16206 cv_wait(&un->un_contig_mem_cv, ST_MUTEX);
16207 ST_GET_CONTIG_MEM_HEAD(un, cp, len, big_enough);
16231 struct scsi_tape *un;
16238 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
16239 if (un == NULL) {
16252 ASSERT(un->un_sbuf_busy);
16254 un->un_sbufp = orig_bp;
16268 st_release_contig_mem(un, cp);
16283 struct scsi_tape *un;
16286 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
16287 if (un == NULL) {
16294 cp = st_get_contig_mem(un, bp->b_bcount, KM_SLEEP);
16305 if (bp == un->un_sbufp) {
16307 ASSERT(un->un_sbuf_busy);
16309 un->un_sbufp = cont_bp;
16389 st_check_if_media_changed(struct scsi_tape *un, caddr_t data, int size)
16420 if (un->un_media_id_len == 0) {
16421 un->un_media_id = kmem_zalloc(size, KM_SLEEP);
16422 un->un_media_id_len = size;
16423 (void) strncpy(un->un_media_id, data, min(size, strlen(data)));
16424 un->un_media_id[min(size, strlen(data))] = 0;
16426 "Found Media Id %s length = %d\n", un->un_media_id, size);
16427 } else if (size > un->un_media_id_len) {
16428 if (strncmp(un->un_media_id, data, size) != 0) {
16433 un->un_media_id, data);
16434 kmem_free(un->un_media_id, un->un_media_id_len);
16435 un->un_media_id = kmem_zalloc(size, KM_SLEEP);
16436 un->un_media_id_len = size;
16437 (void) strncpy(un->un_media_id, data, size);
16438 un->un_media_id[size] = 0;
16439 } else if (strncmp(data, un->un_media_id,
16440 min(size, un->un_media_id_len)) != 0) {
16443 un->un_media_id, un->un_media_id_len, data, size);
16444 bzero(un->un_media_id, un->un_media_id_len);
16445 (void) strncpy(un->un_media_id, data, min(size, strlen(data)));
16446 un->un_media_id[min(size, strlen(data))] = 0;
16450 "Media Id still %s\n", un->un_media_id);
16453 ASSERT(strlen(un->un_media_id) <= size);
16485 st_handle_hex_media_id(struct scsi_tape *un, void *pnt, int size)
16506 result = st_check_if_media_changed(un, buf, newsize);
16515 st_get_media_id_via_read_attribute(struct scsi_tape *un, ubufunc_t bufunc)
16523 size = sizeof (attribute_header) + max(un->un_media_id_len, ID_SIZE);
16526 result = st_read_attributes(un, 0x0401, buffer, size, bufunc);
16542 un->un_media_id_method = st_get_media_id_via_read_attribute;
16545 st_handle_hex_media_id(un, buffer->data, newsize);
16547 result = st_check_if_media_changed(un, buffer->data,
16550 } else if (result == EINVAL && un->un_max_cdb_sz < CDB_GROUP4) {
16558 un->un_status = 0;
16565 st_get_media_id_via_media_serial_cmd(struct scsi_tape *un, ubufunc_t bufunc)
16571 int size = max(un->un_media_id_len, ID_SIZE);
16576 if (un->un_sd->sd_inq->inq_ansi < 3) {
16598 ucmd->uscsi_timeout = un->un_dp->non_motion_timeout;
16606 rval = bufunc(un, ucmd, FKIOCTL);
16622 un->un_status = 0;
16651 un->un_status = 0;
16658 un->un_media_id_method =
16661 st_check_if_media_changed(un, &buf[4], act_size);
16674 st_bogus_media_id(struct scsi_tape *un, ubufunc_t bufunc)
16678 ASSERT(un->un_media_id == NULL || un->un_media_id == bogusID);
16679 ASSERT(un->un_media_id_len == 0);
16680 un->un_media_id = (char *)bogusID;
16681 un->un_media_id_len = 0;
16694 st_get_media_identification(struct scsi_tape *un, ubufunc_t bufunc)
16707 un->un_media_id_method = media_chk_functions[i];
16708 } else if (un->un_media_id_method != media_chk_functions[i] &&
16709 un->un_media_id_method != st_get_media_identification) {
16712 result = media_chk_functions[i](un, bufunc);
16726 st_command_recovery(struct scsi_tape *un, struct scsi_pkt *pkt,
16736 ASSERT(MUTEX_HELD(&un->un_sd->sd_mutex));
16738 ASSERT(un->un_recov_buf_busy == 0);
16743 if (un->un_rsvd_status & ST_INITIATED_RESET &&
16774 ret = ddi_taskq_dispatch(un->un_recov_taskq, st_recover, errinfo,
16786 st_recov_ret(struct scsi_tape *un, st_err_info *errinfo, errstate err)
16794 ASSERT(MUTEX_HELD(&un->un_sd->sd_mutex));
16796 _NOTE(LOCK_RELEASED_AS_SIDE_EFFECT(&un->un_sd->sd_mutex))
16804 mutex_exit(&un->un_sd->sd_mutex);
16818 un->un_pos.pmode = invalid;
16819 un->un_running.pmode = invalid;
16823 ST_DO_ERRSTATS(un, st_transerrs);
16825 st_set_pe_flag(un);
16831 st_done_and_mutex_exit(un, bp);
16840 struct scsi_tape *un;
16852 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
16854 ASSERT(un != NULL);
16870 rval = st_test_path_to_device(un);
16880 rval = st_rcmd(un, SCMD_WRITE_FILE_MARK, 0, SYNC_CMD);
16884 st_recov_ret(un, errinfo, COMMAND_DONE_ERROR);
16898 st_recov_ret(un, errinfo, COMMAND_DONE_ERROR);
16905 if ((un->un_rsvd_status &
16913 st_recov_ret(un, errinfo, COMMAND_DONE_ERROR);
16923 if ((un->un_rsvd_status & ST_RESERVE | ST_PRESERVE_RESERVE) &&
16928 st_recov_ret(un, errinfo, COMMAND_DONE_EACCES);
16935 if ((((un->un_rsvd_status &
16939 rval = st_reserve_release(un, ST_RESERVE,
16942 if (st_take_ownership(un, st_uscsi_rcmd) != 0) {
16943 st_recov_ret(un, errinfo,
16948 un->un_rsvd_status |= ST_RESERVE;
16949 un->un_rsvd_status &= ~(ST_RELEASE | ST_LOST_RESERVE |
16952 rval = st_make_sure_mode_data_is_correct(un, st_uscsi_rcmd);
16954 st_recov_ret(un, errinfo, COMMAND_DONE_ERROR);
16969 rval = st_make_sure_mode_data_is_correct(un,
16972 st_recov_ret(un, errinfo, COMMAND_DONE_ERROR);
16980 if (un->un_media_id != NULL && un->un_media_id != bogusID) {
16981 rval = st_get_media_identification(un, st_uscsi_rcmd);
16983 st_recov_ret(un, errinfo, COMMAND_DONE_EACCES);
17007 if (rcv->cmd_attrib->retriable || un->un_rqs_bp == bp) {
17008 status = st_recover_reissue_pkt(un, &errinfo->ei_failed_pkt);
17013 } else if (un->un_read_pos_type == NO_POS) {
17027 rval = st_compare_expected_position(un, errinfo,
17032 status = st_recover_reissue_pkt(un,
17041 st_recov_ret(un, errinfo, status);
17047 struct scsi_tape *un;
17063 un = ddi_get_soft_state(st_state, MTUNIT(bp->b_edev));
17064 ASSERT(un != NULL);
17070 ASSERT(bp == un->un_recov_buf);
17075 if (un->un_arq_enabled && pkt->pkt_state & STATE_ARQ_DONE) {
17076 action = st_handle_autosense(un, bp, &rcv->pos);
17080 action = st_check_error(un, pkt);
17092 if (un->un_multipath)
17107 if (un->un_multipath) {
17109 (un->un_last_path_instance != pkt->pkt_path_instance)) {
17110 if (un->un_state > ST_STATE_OPENING) {
17115 un->un_last_path_instance = pkt->pkt_path_instance;
17158 if (un->un_throttle) {
17159 un->un_last_throttle = un->un_throttle;
17162 if (st_handle_intr_busy(un, bp, timout) == 0) {
17166 un->un_pos.pmode = invalid;
17167 un->un_err_resid = bp->b_resid = bp->b_bcount;
17169 st_set_pe_flag(un);
17175 un->un_pos.pmode = invalid;
17176 un->un_err_resid = bp->b_resid = bp->b_bcount;
17178 st_set_pe_flag(un);
17182 st_done_and_mutex_exit(un, bp);
17186 st_rcmd(struct scsi_tape *un, int com, int64_t count, int wait)
17194 "st_rcmd(un = 0x%p, com = 0x%x, count = %"PRIx64", wait = %d)\n",
17195 (void *)un, com, count, wait);
17197 ASSERT(MUTEX_HELD(&un->un_sd->sd_mutex));
17202 st_debug_cmds(un, com, count, wait);
17206 while (un->un_recov_buf_busy)
17207 cv_wait(&un->un_recov_buf_cv, ST_MUTEX);
17208 un->un_recov_buf_busy = 1;
17210 bp = un->un_recov_buf;
17215 err = st_setup_cmd(un, bp, com, count);
17217 un->un_recov_buf_busy = 0;
17219 cv_signal(&un->un_recov_buf_cv);
17226 st_uscsi_rcmd(struct scsi_tape *un, struct uscsi_cmd *ucmd, int flag)
17237 while (un->un_recov_buf_busy)
17238 cv_wait(&un->un_recov_buf_cv, ST_MUTEX);
17239 un->un_recov_buf_busy = 1;
17241 bp = un->un_recov_buf;
17248 rval = scsi_uscsi_handle_cmd(un->un_dev, UIO_SYSSPACE, ucmd,
17257 un->un_recov_buf_busy = 0;
17258 cv_signal(&un->un_recov_buf_cv);
17267 st_add_recovery_info_to_pkt(struct scsi_tape *un, buf_t *bp,
17304 COPY_POS(&rinfo->pos, &un->un_pos);
17305 un->un_running.pmode = invalid;
17312 if (bp == un->un_recov_buf) {
17313 rinfo->pos.pmode = un->un_running.pmode;
17322 if (un->un_running.pmode == invalid) {
17323 COPY_POS(&un->un_running, &un->un_pos);
17324 COPY_POS(&rinfo->pos, &un->un_running);
17326 COPY_POS(&rinfo->pos, &un->un_running);
17354 if (bp == un->un_sbufp) {
17363 if ((lbn != un->un_running.lgclblkno) ||
17364 (pkt->pkt_cdbp[3] != un->un_running.partition)) {
17368 un->un_running.partition = pkt->pkt_cdbp[3];
17369 un->un_running.pmode = logical;
17370 un->un_running.lgclblkno = lbn;
17373 uint64_t lbn = un->un_running.lgclblkno;
17375 pkt->pkt_cdbp[3] = (uchar_t)un->un_running.partition;
17388 un->un_running.lgclblkno += count;
17395 if (un->un_mediastate == MTIO_INSERTED) {
17427 un->un_running.fileno += count;
17428 un->un_running.lgclblkno += count;
17429 un->un_running.blkno = 0;
17437 un->un_running.fileno = 0;
17438 un->un_running.lgclblkno = 0;
17439 un->un_running.blkno = 0;
17440 un->un_running.eof = ST_NO_EOF;
17441 if (un->un_running.pmode != legacy)
17442 un->un_running.pmode = legacy;
17456 un->un_running.pmode = invalid;
17462 un->un_running.eof = ST_EOT;
17463 un->un_running.pmode = invalid;
17472 un->un_running.fileno = 0;
17473 un->un_running.lgclblkno = 0;
17474 un->un_running.blkno = 0;
17475 un->un_running.eof = ST_NO_EOF;
17494 un->un_running.lgclblkno += count;
17495 un->un_running.blkno += count;
17500 un->un_running.lgclblkno -= count;
17501 un->un_running.blkno -= count;
17513 un->un_running.lgclblkno = count;
17514 un->un_running.blkno = 0;
17515 un->un_running.fileno = 0;
17516 un->un_running.pmode = logical;
17531 st_make_sure_mode_data_is_correct(struct scsi_tape *un, ubufunc_t ubf)
17540 rval = st_check_mode_for_change(un, ubf);
17542 rval = st_gen_mode_select(un, ubf, un->un_mspl,
17545 if (un->un_tlr_flag != TLR_NOT_SUPPORTED) {
17546 rval |= st_set_target_TLR_mode(un, ubf);
17552 st_check_mode_for_change(struct scsi_tape *un, ubufunc_t ubf)
17563 if (un->un_comp_page == (ST_DEV_DATACOMP_PAGE | ST_DEV_CONFIG_PAGE)) {
17571 rval = st_gen_mode_sense(un, ubf, un->un_comp_page, current,
17581 that = (caddr_t)un->un_mspl;
17606 st_test_path_to_device(struct scsi_tape *un)
17622 rval = st_rcmd(un, SCMD_TEST_UNIT_READY, 0, SYNC_CMD);
17628 if (un->un_status == KEY_NOT_READY || un->un_mediastate == MTIO_EJECTED)
17639 st_recovery_read_pos(struct scsi_tape *un, read_p_types type,
17662 cmd.uscsi_timeout = un->un_dp->non_motion_timeout;
17682 rval = st_uscsi_rcmd(un, &cmd, FKIOCTL);
17690 st_recovery_get_position(struct scsi_tape *un, tapepos_t *read,
17694 read_p_types type = un->un_read_pos_type;
17699 rval = st_recovery_read_pos(un, type, raw);
17720 if (type != un->un_read_pos_type) {
17721 un->un_read_pos_type = type;
17728 rval = st_interpret_read_pos(un, read, type,
17742 st_compare_expected_position(struct scsi_tape *un, st_err_info *ei,
17750 ASSERT(un != NULL);
17759 rval = st_recovery_get_position(un, read, readp_datap);
17841 rval = st_logical_block_locate(un,
17858 rval = st_logical_block_locate(un,
17878 rval = st_logical_block_locate(un,
17916 rval = st_logical_block_locate(un,
17929 rval = st_logical_block_locate(un,
17980 rval = st_logical_block_locate(un, st_uscsi_rcmd, read,
18003 st_recover_reissue_pkt(struct scsi_tape *un, struct scsi_pkt *oldpkt)
18015 (un->un_arq_enabled ? sizeof (struct scsi_arq_status) : 1);
18044 if (bp != un->un_sbufp && bp != un->un_recov_buf) {
18045 ASSERT(un->un_runqf == un->un_runql);
18046 ASSERT(un->un_runqf == bp);
18052 if (pkt_bp == un->un_rqs_bp) {
18087 if (oldpkt == un->un_rqs) {
18088 ASSERT(bp == un->un_rqs_bp);
18089 un->un_rqs = newpkt;
18096 rval = st_transport(un, newpkt);
18106 rval = st_handle_start_busy(un, bp, ST_TRAN_BUSY_TIMEOUT, queued);
18116 st_transport(struct scsi_tape *un, struct scsi_pkt *pkt)
18472 st_reset(struct scsi_tape *un, int reset_type)
18476 ASSERT(MUTEX_HELD(&un->un_sd->sd_mutex));
18479 un->un_rsvd_status |= ST_INITIATED_RESET;
18482 rval = scsi_reset(&un->un_sd->sd_address, reset_type);
18511 st_set_target_TLR_mode(struct scsi_tape *un, ubufunc_t ubf)
18520 ret = st_gen_mode_sense(un, ubf, 0x18, mode_data, amount);
18523 un->un_tlr_flag = TLR_NOT_SUPPORTED;
18531 un->un_tlr_flag = TLR_NOT_SUPPORTED;
18535 if (un->un_tlr_flag == TLR_SAS_ONE_DEVICE) {
18544 ret = st_gen_mode_select(un, ubf, mode_data, amount);
18547 un->un_tlr_flag = TLR_NOT_SUPPORTED;
18550 un->un_tlr_flag = TLR_NOT_KNOWN;
18552 un->un_tlr_flag = TLR_SAS_ONE_DEVICE;
18567 struct scsi_tape *un = (struct scsi_tape *)arg;
18572 un->un_unit_attention_flags |= 2;
18573 if ((un->un_rsvd_status & (ST_RESERVE | ST_APPLICATION_RESERVATIONS)) ==
18575 un->un_rsvd_status |= ST_LOST_RESERVE;
18583 if ((un->un_restore_pos == 0) &&
18584 (un->un_state == ST_STATE_CLOSED) ||
18585 (un->un_state == ST_STATE_OPEN_PENDING_IO) ||
18586 (un->un_state == ST_STATE_CLOSING)) {
18587 un->un_restore_pos = 1;
18590 "reset and state was %d\n", un->un_state);