Lines Matching refs:STp
245 struct scsi_tape *STp = NULL;
250 STp = idr_find(&st_index_idr, dev);
251 if (!STp) goto out;
253 kref_get(&STp->kref);
255 if (!STp->device)
258 if (scsi_device_get(STp->device))
264 kref_put(&STp->kref, scsi_tape_release);
265 STp = NULL;
269 return STp;
272 static void scsi_tape_put(struct scsi_tape *STp)
274 struct scsi_device *sdev = STp->device;
277 kref_put(&STp->kref, scsi_tape_release);
363 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
368 char *name = tape_name(STp);
374 cmdstatp = &STp->buffer->cmdstat;
378 scode = STp->buffer->cmdstat.sense_hdr.sense_key;
384 st_printk(ST_DEB_MSG, STp,
389 __scsi_print_sense(STp->device, name,
394 st_printk(KERN_WARNING, STp,
406 __scsi_print_sense(STp->device, name,
412 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */
413 if (STp->cln_sense_value)
414 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] &
415 STp->cln_sense_mask) == STp->cln_sense_value);
417 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] &
418 STp->cln_sense_mask) != 0);
422 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */
424 STp->pos_unknown |= STp->device->was_reset;
433 STp->recover_count++;
434 STp->recover_reg++;
444 st_printk(ST_DEB_MSG, STp,
446 stp, STp->recover_count);
479 static void st_do_stats(struct scsi_tape *STp, struct request *req)
485 now = ktime_sub(now, STp->stats->write_time);
486 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time);
487 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time);
488 atomic64_inc(&STp->stats->write_cnt);
490 atomic64_add(atomic_read(&STp->stats->last_write_size)
491 - STp->buffer->cmdstat.residual,
492 &STp->stats->write_byte_cnt);
493 if (STp->buffer->cmdstat.residual > 0)
494 atomic64_inc(&STp->stats->resid_cnt);
496 atomic64_add(atomic_read(&STp->stats->last_write_size),
497 &STp->stats->write_byte_cnt);
499 now = ktime_sub(now, STp->stats->read_time);
500 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time);
501 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time);
502 atomic64_inc(&STp->stats->read_cnt);
504 atomic64_add(atomic_read(&STp->stats->last_read_size)
505 - STp->buffer->cmdstat.residual,
506 &STp->stats->read_byte_cnt);
507 if (STp->buffer->cmdstat.residual > 0)
508 atomic64_inc(&STp->stats->resid_cnt);
510 atomic64_add(atomic_read(&STp->stats->last_read_size),
511 &STp->stats->read_byte_cnt);
513 now = ktime_sub(now, STp->stats->other_time);
514 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time);
515 atomic64_inc(&STp->stats->other_cnt);
517 atomic64_dec(&STp->stats->in_flight);
524 struct scsi_tape *STp = SRpnt->stp;
527 STp->buffer->cmdstat.midlevel_result = SRpnt->result = rq->result;
528 STp->buffer->cmdstat.residual = rq->resid_len;
530 st_do_stats(STp, req);
550 struct scsi_tape *STp = SRpnt->stp;
571 atomic64_inc(&STp->stats->in_flight);
573 atomic_set(&STp->stats->last_write_size, bufflen);
574 STp->stats->write_time = ktime_get();
576 atomic_set(&STp->stats->last_read_size, bufflen);
577 STp->stats->read_time = ktime_get();
579 STp->stats->other_time = ktime_get();
598 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd,
602 struct rq_map_data *mdata = &STp->buffer->map_data;
606 if (!do_wait && ((STp->buffer)->last_SRpnt)) {
607 st_printk(KERN_ERR, STp,
610 (STp->buffer)->syscall_result = (-EINTR);
612 (STp->buffer)->syscall_result = (-EBUSY);
617 SRpnt = st_allocate_request(STp);
625 (STp->buffer)->last_SRpnt = SRpnt;
627 waiting = &STp->wait;
631 if (STp->buffer->do_dio) {
633 mdata->nr_entries = STp->buffer->sg_segs;
634 mdata->pages = STp->buffer->mapped_pages;
636 mdata->page_order = STp->buffer->reserved_page_order;
639 mdata->pages = STp->buffer->reserved_pages;
644 STp->buffer->cmdstat.have_sense = 0;
645 STp->buffer->syscall_result = 0;
651 (STp->buffer)->syscall_result = (-EBUSY);
652 (STp->buffer)->last_SRpnt = NULL;
656 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
667 static int write_behind_check(struct scsi_tape * STp)
675 STbuffer = STp->buffer;
680 if (STp->write_pending)
681 STp->nbr_waits++;
683 STp->nbr_finished++;
686 wait_for_completion(&(STp->wait));
691 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
695 STps = &(STp->ps[STp->partition]);
697 if (STp->block_size == 0)
700 STps->drv_block += STbuffer->writing / STp->block_size;
721 st_printk(ST_DEB_MSG, STp,
731 static int cross_eof(struct scsi_tape * STp, int forward)
745 DEBC_printk(STp, "Stepping over filemark %s.\n",
748 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
749 STp->device->request_queue->rq_timeout,
752 return (STp->buffer)->syscall_result;
757 if ((STp->buffer)->cmdstat.midlevel_result != 0)
758 st_printk(KERN_ERR, STp,
762 return (STp->buffer)->syscall_result;
767 static int st_flush_write_buffer(struct scsi_tape * STp)
775 result = write_behind_check(STp);
780 if (STp->dirty == 1) {
782 transfer = STp->buffer->buffer_bytes;
783 DEBC_printk(STp, "Flushing %d bytes.\n", transfer);
788 blks = transfer / STp->block_size;
793 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE,
794 STp->device->request_queue->rq_timeout,
797 return (STp->buffer)->syscall_result;
799 STps = &(STp->ps[STp->partition]);
800 if ((STp->buffer)->syscall_result != 0) {
801 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
809 STp->dirty = 0;
810 (STp->buffer)->buffer_bytes = 0;
815 st_printk(KERN_ERR, STp, "Error on flush.\n");
822 STp->dirty = 0;
823 (STp->buffer)->buffer_bytes = 0;
834 static int flush_buffer(struct scsi_tape *STp, int seek_next)
843 if (STp->pos_unknown)
846 if (STp->ready != ST_READY)
848 STps = &(STp->ps[STp->partition]);
850 return st_flush_write_buffer(STp);
852 if (STp->block_size == 0)
855 backspace = ((STp->buffer)->buffer_bytes +
856 (STp->buffer)->read_pointer) / STp->block_size -
857 ((STp->buffer)->read_pointer + STp->block_size - 1) /
858 STp->block_size;
859 (STp->buffer)->buffer_bytes = 0;
860 (STp->buffer)->read_pointer = 0;
864 result = cross_eof(STp, 0); /* Back over the EOF hit */
874 result = st_int_ioctl(STp, MTBSR, backspace);
887 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
892 if (!STp->density_changed &&
894 STm->default_density != STp->density) {
898 arg = STp->density;
900 if (!STp->blksize_changed &&
902 STm->default_blksize != STp->block_size) {
906 arg |= STp->block_size;
908 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) {
909 st_printk(KERN_WARNING, STp,
921 static int do_door_lock(struct scsi_tape * STp, int do_lock)
925 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl");
927 retval = scsi_set_medium_removal(STp->device,
930 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
932 STp->door_locked = ST_LOCK_FAILS;
938 static void reset_state(struct scsi_tape *STp)
943 STp->pos_unknown = 0;
945 STps = &(STp->ps[i]);
953 if (STp->can_partitions) {
954 STp->partition = find_partition(STp);
955 if (STp->partition < 0)
956 STp->partition = 0;
957 STp->new_partition = STp->partition;
971 static int test_ready(struct scsi_tape *STp, int do_wait)
977 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
984 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
985 STp->long_timeout, MAX_READY_RETRIES, 1);
988 retval = (STp->buffer)->syscall_result;
1018 if ((STp->device)->scsi_level >= SCSI_2 &&
1028 retval = (STp->buffer)->syscall_result;
1045 static int check_tape(struct scsi_tape *STp, struct file *filp)
1056 STp->ready = ST_READY;
1058 if (mode != STp->current_mode) {
1059 DEBC_printk(STp, "Mode change from %d to %d.\n",
1060 STp->current_mode, mode);
1062 STp->current_mode = mode;
1064 STm = &(STp->modes[STp->current_mode]);
1066 saved_cleaning = STp->cleaning_req;
1067 STp->cleaning_req = 0;
1070 retval = test_ready(STp, do_wait);
1076 STp->pos_unknown = 0;
1077 STp->partition = STp->new_partition = 0;
1078 if (STp->can_partitions)
1079 STp->nbr_partitions = 1; /* This guess will be updated later
1082 STps = &(STp->ps[i]);
1093 STp->cleaning_req |= saved_cleaning;
1097 STp->ready = ST_NO_TAPE;
1099 STp->ready = ST_NOT_READY;
1101 STp->density = 0; /* Clear the erroneous "residue" */
1102 STp->write_prot = 0;
1103 STp->block_size = 0;
1104 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1);
1105 STp->partition = STp->new_partition = 0;
1106 STp->door_locked = ST_UNLOCKED;
1111 if (STp->omit_blklims)
1112 STp->min_block = STp->max_block = (-1);
1117 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE,
1118 STp->device->request_queue->rq_timeout,
1121 retval = (STp->buffer)->syscall_result;
1125 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) {
1126 STp->max_block = ((STp->buffer)->b_data[1] << 16) |
1127 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3];
1128 STp->min_block = ((STp->buffer)->b_data[4] << 8) |
1129 (STp->buffer)->b_data[5];
1130 if ( DEB( debugging || ) !STp->inited)
1131 st_printk(KERN_INFO, STp,
1133 STp->min_block, STp->max_block);
1135 STp->min_block = STp->max_block = (-1);
1136 DEBC_printk(STp, "Can't read block limits.\n");
1144 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE,
1145 STp->device->request_queue->rq_timeout,
1148 retval = (STp->buffer)->syscall_result;
1152 if ((STp->buffer)->syscall_result != 0) {
1153 DEBC_printk(STp, "No Mode Sense.\n");
1154 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */
1155 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */
1156 STp->drv_write_prot = 0;
1158 DEBC_printk(STp,"Mode sense. Length %d, "
1160 (STp->buffer)->b_data[0],
1161 (STp->buffer)->b_data[1],
1162 (STp->buffer)->b_data[2],
1163 (STp->buffer)->b_data[3]);
1165 if ((STp->buffer)->b_data[3] >= 8) {
1166 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7;
1167 STp->density = (STp->buffer)->b_data[4];
1168 STp->block_size = (STp->buffer)->b_data[9] * 65536 +
1169 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11];
1170 DEBC_printk(STp, "Density %x, tape length: %x, "
1172 STp->density,
1173 (STp->buffer)->b_data[5] * 65536 +
1174 (STp->buffer)->b_data[6] * 256 +
1175 (STp->buffer)->b_data[7],
1176 STp->drv_buffer);
1178 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0;
1179 if (!STp->drv_buffer && STp->immediate_filemark) {
1180 st_printk(KERN_WARNING, STp,
1183 STp->immediate_filemark = 0;
1188 STp->inited = 1;
1190 if (STp->block_size > 0)
1191 (STp->buffer)->buffer_blocks =
1192 (STp->buffer)->buffer_size / STp->block_size;
1194 (STp->buffer)->buffer_blocks = 1;
1195 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0;
1197 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n",
1198 STp->block_size, (STp->buffer)->buffer_size,
1199 (STp->buffer)->buffer_blocks);
1201 if (STp->drv_write_prot) {
1202 STp->write_prot = 1;
1204 DEBC_printk(STp, "Write protected\n");
1214 if (STp->can_partitions && STp->nbr_partitions < 1) {
1218 DEBC_printk(STp, "Updating partition number in status.\n");
1219 if ((STp->partition = find_partition(STp)) < 0) {
1220 retval = STp->partition;
1223 STp->new_partition = STp->partition;
1224 STp->nbr_partitions = 1; /* This guess will be updated when necessary */
1228 STp->density_changed = STp->blksize_changed = 0;
1229 STp->compression_changed = 0;
1231 (retval = set_mode_densblk(STp, STm)) < 0)
1234 if (STp->default_drvbuffer != 0xff) {
1235 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer))
1236 st_printk(KERN_WARNING, STp,
1239 STp->default_drvbuffer);
1257 struct scsi_tape *STp;
1268 if (!(STp = scsi_tape_get(dev))) {
1272 filp->private_data = STp;
1275 if (STp->in_use) {
1277 DEBC_printk(STp, "Device already in use.\n");
1278 scsi_tape_put(STp);
1282 STp->in_use = 1;
1284 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0;
1286 if (scsi_autopm_get_device(STp->device) < 0) {
1291 if (!scsi_block_when_processing_errors(STp->device)) {
1297 if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) {
1298 st_printk(KERN_WARNING, STp,
1304 (STp->buffer)->cleared = 0;
1305 (STp->buffer)->writing = 0;
1306 (STp->buffer)->syscall_result = 0;
1308 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY);
1310 STp->dirty = 0;
1312 STps = &(STp->ps[i]);
1315 STp->try_dio_now = STp->try_dio;
1316 STp->recover_count = 0;
1317 DEB( STp->nbr_waits = STp->nbr_finished = 0;
1318 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; )
1320 retval = check_tape(STp, filp);
1325 if (STp->ready == NO_TAPE)
1334 normalize_buffer(STp->buffer);
1336 STp->in_use = 0;
1339 scsi_autopm_put_device(STp->device);
1340 scsi_tape_put(STp);
1353 struct scsi_tape *STp = filp->private_data;
1354 struct st_modedef *STm = &(STp->modes[STp->current_mode]);
1355 struct st_partstat *STps = &(STp->ps[STp->partition]);
1360 if (STps->rw == ST_WRITING && !STp->pos_unknown) {
1361 result = st_flush_write_buffer(STp);
1366 if (STp->can_partitions &&
1367 (result2 = switch_partition(STp)) < 0) {
1368 DEBC_printk(STp, "switch_partition at close failed.\n");
1374 DEBC( if (STp->nbr_requests)
1375 st_printk(KERN_DEBUG, STp,
1377 "pages %d.\n", STp->nbr_requests, STp->nbr_dio,
1378 STp->nbr_pages));
1380 if (STps->rw == ST_WRITING && !STp->pos_unknown) {
1381 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
1384 DEBC_printk(STp, "Async write waits %d, finished %d.\n",
1385 STp->nbr_waits, STp->nbr_finished);
1389 if (STp->immediate_filemark)
1391 cmd[4] = 1 + STp->two_fm;
1393 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
1394 STp->device->request_queue->rq_timeout,
1397 result = (STp->buffer)->syscall_result;
1401 if (STp->buffer->syscall_result == 0 ||
1413 if (STp->two_fm)
1414 cross_eof(STp, 0);
1420 st_printk(KERN_ERR, STp,
1426 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]);
1427 } else if (!STp->rew_at_close) {
1428 STps = &(STp->ps[STp->partition]);
1430 if (STp->can_bsr)
1431 result = flush_buffer(STp, 0);
1433 result = cross_eof(STp, 0);
1443 !(result = cross_eof(STp, 1))) ||
1453 if (STp->rew_at_close) {
1454 result2 = st_int_ioctl(STp, MTREW, 1);
1466 struct scsi_tape *STp = filp->private_data;
1468 if (STp->door_locked == ST_LOCKED_AUTO)
1469 do_door_lock(STp, 0);
1471 normalize_buffer(STp->buffer);
1473 STp->in_use = 0;
1475 scsi_autopm_put_device(STp->device);
1476 scsi_tape_put(STp);
1482 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count)
1492 if (!scsi_block_when_processing_errors(STp->device)) {
1497 if (STp->ready != ST_READY) {
1498 if (STp->ready == ST_NO_TAPE)
1505 if (! STp->modes[STp->current_mode].defined) {
1515 if (STp->pos_unknown) {
1524 if (!STp->in_use) {
1525 st_printk(ST_DEB_MSG, STp,
1531 if (STp->can_partitions &&
1532 (retval = switch_partition(STp)) < 0)
1535 if (STp->block_size == 0 && STp->max_block > 0 &&
1536 (count < STp->min_block || count > STp->max_block)) {
1541 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED &&
1542 !do_door_lock(STp, 1))
1543 STp->door_locked = ST_LOCKED_AUTO;
1550 static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
1554 struct st_buffer *STbp = STp->buffer;
1557 i = STp->try_dio_now && try_rdio;
1559 i = STp->try_dio_now && try_wdio;
1562 STp->device->request_queue)) == 0) {
1574 STp->nbr_dio++;
1575 STp->nbr_pages += STbp->do_dio;
1580 DEB( STp->nbr_requests++; )
1583 if (STp->block_size)
1584 bufsize = STp->block_size > st_fixed_buffer_size ?
1585 STp->block_size : st_fixed_buffer_size;
1590 if (is_read && STp->sili && !STbp->cleared)
1595 !enlarge_buffer(STbp, bufsize, STp->restr_dma)) {
1596 st_printk(KERN_WARNING, STp,
1602 if (STp->block_size)
1603 STbp->buffer_blocks = bufsize / STp->block_size;
1612 static void release_buffering(struct scsi_tape *STp, int is_read)
1616 STbp = STp->buffer;
1637 struct scsi_tape *STp = filp->private_data;
1642 if (mutex_lock_interruptible(&STp->lock))
1645 retval = rw_checks(STp, filp, count);
1650 if (STp->block_size != 0 && (count % STp->block_size) != 0) {
1651 st_printk(KERN_WARNING, STp,
1657 STm = &(STp->modes[STp->current_mode]);
1658 STps = &(STp->ps[STp->partition]);
1660 if (STp->write_prot) {
1667 retval = flush_buffer(STp, 0);
1673 if ((retval = set_mode_densblk(STp, STm)) < 0)
1676 !(STp->compression_changed)) {
1677 if (st_compression(STp, (STm->default_compression == ST_YES))) {
1678 st_printk(KERN_WARNING, STp,
1688 STbp = STp->buffer;
1689 i = write_behind_check(STp);
1709 if (STp->block_size != 0 &&
1717 retval = setup_buffering(STp, buf, count, 0);
1725 cmd[1] = (STp->block_size != 0);
1736 if (STp->block_size == 0)
1739 do_count = STbp->buffer_blocks * STp->block_size -
1754 async_write = STp->block_size == 0 && !STbp->do_dio &&
1757 if (STp->block_size != 0 && STm->do_buffer_writes &&
1758 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK &&
1760 STp->dirty = 1;
1767 if (STp->block_size == 0)
1774 blks /= STp->block_size;
1775 transfer = blks * STp->block_size;
1781 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE,
1782 STp->device->request_queue->rq_timeout,
1790 STp->dirty = !(STbp->writing ==
1793 DEB( STp->write_pending = 1; )
1798 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
1800 DEBC_printk(STp, "Error on write:\n");
1805 else if (STp->block_size == 0 &&
1810 if (STp->block_size != 0)
1811 undone *= STp->block_size;
1817 if (STp->block_size)
1818 blks = (transfer - undone) / STp->block_size;
1824 if (STp->block_size == 0 ||
1827 DEBC_printk(STp, "EOM with %d "
1835 move_buffer_data(STp->buffer, transfer - undone);
1839 STp->block_size;
1842 DEBC_printk(STp, "Retry "
1845 STp->buffer->buffer_bytes);
1856 DEBC_printk(STp, "EOM with "
1869 if (STp->block_size == 0)
1876 STp->dirty = 0;
1894 release_buffering(STp, 0);
1895 mutex_unlock(&STp->lock);
1907 static long read_tape(struct scsi_tape *STp, long count,
1921 STm = &(STp->modes[STp->current_mode]);
1922 STps = &(STp->ps[STp->partition]);
1925 STbp = STp->buffer;
1927 if (STp->block_size == 0)
1930 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) {
1931 blks = (STp->buffer)->buffer_blocks;
1932 bytes = blks * STp->block_size;
1935 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size)
1936 bytes = (STp->buffer)->buffer_size;
1937 blks = bytes / STp->block_size;
1938 bytes = blks * STp->block_size;
1944 cmd[1] = (STp->block_size != 0);
1945 if (!cmd[1] && STp->sili)
1952 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE,
1953 STp->device->request_queue->rq_timeout,
1955 release_buffering(STp, 1);
1965 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
1968 DEBC_printk(STp,
1986 if (STp->block_size == 0)
1993 if (STp->block_size == 0 &&
1995 st_printk(KERN_NOTICE, STp,
2005 } else if (STp->block_size == 0) {
2011 st_printk(KERN_NOTICE, STp,
2016 st_int_ioctl(STp, MTBSR, 1);
2021 STp->block_size;
2022 DEBC_printk(STp, "ILI but "
2029 if (st_int_ioctl(STp, MTBSR, 1))
2037 if (STp->block_size == 0)
2041 bytes - transfer * STp->block_size;
2042 DEBC_printk(STp, "EOF detected (%d "
2050 if (STp->block_size == 0)
2054 bytes - transfer * STp->block_size;
2056 DEBC_printk(STp, "EOM detected (%d "
2063 DEBC_printk(STp, "Tape error while reading.\n");
2067 DEBC_printk(STp, "Zero returned for "
2087 if (STp->sili) /* In fixed block mode residual is always zero here */
2088 STbp->buffer_bytes -= STp->buffer->cmdstat.residual;
2092 if (STp->block_size == 0)
2095 STps->drv_block += STbp->buffer_bytes / STp->block_size;
2111 struct scsi_tape *STp = filp->private_data;
2114 struct st_buffer *STbp = STp->buffer;
2116 if (mutex_lock_interruptible(&STp->lock))
2119 retval = rw_checks(STp, filp, count);
2123 STm = &(STp->modes[STp->current_mode]);
2124 if (STp->block_size != 0 && (count % STp->block_size) != 0) {
2129 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */
2132 STps = &(STp->ps[STp->partition]);
2134 retval = flush_buffer(STp, 0);
2141 st_printk(ST_DEB_MSG, STp,
2146 retval = setup_buffering(STp, buf, count, 1);
2182 special = read_tape(STp, count - total, &SRpnt);
2193 st_printk(ST_DEB_MSG, STp,
2211 if (STp->block_size == 0)
2241 release_buffering(STp, 1);
2244 mutex_unlock(&STp->lock);
2254 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm)
2257 st_printk(KERN_INFO, STp,
2260 STp->current_mode, STm->do_buffer_writes,
2262 st_printk(KERN_INFO, STp,
2265 STp->can_bsr, STp->two_fm, STp->fast_mteom,
2266 STp->do_auto_lock);
2267 st_printk(KERN_INFO, STp,
2270 STm->defaults_for_writes, STp->omit_blklims,
2271 STp->can_partitions, STp->scsi2_logical);
2272 st_printk(KERN_INFO, STp,
2275 STm->sysv, STp->immediate, STp->sili,
2276 STp->immediate_filemark);
2277 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging);
2283 static int st_set_options(struct scsi_tape *STp, long options)
2291 STm = &(STp->modes[STp->current_mode]);
2297 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2303 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2304 STp->current_mode);
2313 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2314 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2315 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2316 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2317 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2318 if ((STp->device)->scsi_level >= SCSI_2)
2319 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2320 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2321 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2322 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2324 STp->sili = (options & MT_ST_SILI) != 0;
2326 st_log_options(STp, STm); )
2338 STp->two_fm = value;
2340 STp->fast_mteom = value;
2342 STp->do_auto_lock = value;
2344 STp->can_bsr = value;
2346 STp->omit_blklims = value;
2347 if ((STp->device)->scsi_level >= SCSI_2 &&
2349 STp->can_partitions = value;
2351 STp->scsi2_logical = value;
2353 STp->immediate = value;
2355 STp->immediate_filemark = value;
2359 STp->sili = value;
2363 st_log_options(STp, STm); )
2370 DEBC_printk(STp, "Default block size disabled.\n");
2373 DEBC_printk(STp,"Default block size set to "
2375 if (STp->ready == ST_READY) {
2376 STp->blksize_changed = 0;
2377 set_mode_densblk(STp, STm);
2383 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2384 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2387 blk_queue_rq_timeout(STp->device->request_queue,
2389 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2398 STp->cln_mode = value;
2399 STp->cln_sense_mask = (options >> 8) & 0xff;
2400 STp->cln_sense_value = (options >> 16) & 0xff;
2401 st_printk(KERN_INFO, STp,
2403 value, STp->cln_sense_mask, STp->cln_sense_value);
2410 DEBC_printk(STp,
2414 DEBC_printk(STp, "Density default set to %x\n",
2416 if (STp->ready == ST_READY) {
2417 STp->density_changed = 0;
2418 set_mode_densblk(STp, STm);
2423 STp->default_drvbuffer = 0xff;
2424 DEBC_printk(STp,
2427 STp->default_drvbuffer = value & 7;
2428 DEBC_printk(STp,
2430 STp->default_drvbuffer);
2431 if (STp->ready == ST_READY)
2432 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2437 DEBC_printk(STp,
2441 STp->c_algo = (value & 0xff00) >> 8;
2442 DEBC_printk(STp, "Compression "
2444 STp->c_algo);
2448 DEBC_printk(STp, "Compression default "
2451 if (STp->ready == ST_READY) {
2452 STp->compression_changed = 0;
2453 st_compression(STp, (STm->default_compression == ST_YES));
2487 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2499 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE,
2500 STp->device->request_queue->rq_timeout, 0, 1);
2502 return (STp->buffer)->syscall_result;
2506 return STp->buffer->syscall_result;
2512 static int write_mode_page(struct scsi_tape *STp, int page, int slow)
2522 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH];
2523 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2;
2526 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0;
2527 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0;
2528 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP;
2529 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR;
2532 STp->long_timeout : STp->device->request_queue->rq_timeout;
2533 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE,
2536 return (STp->buffer)->syscall_result;
2540 return STp->buffer->syscall_result;
2561 static int st_compression(struct scsi_tape * STp, int state)
2565 unsigned char *b_data = (STp->buffer)->b_data;
2567 if (STp->ready != ST_READY)
2571 retval = read_mode_page(STp, COMPRESSION_PAGE, 0);
2573 DEBC_printk(STp, "Compression mode page not supported.\n");
2578 DEBC_printk(STp, "Compression state is %d.\n",
2583 DEBC_printk(STp, "Compression not supported.\n");
2590 if (STp->c_algo != 0)
2591 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo;
2595 if (STp->c_algo != 0)
2599 retval = write_mode_page(STp, COMPRESSION_PAGE, 0);
2601 DEBC_printk(STp, "Compression change failed.\n");
2604 DEBC_printk(STp, "Compression state changed to %d.\n", state);
2606 STp->compression_changed = 1;
2612 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code)
2619 if (STp->ready != ST_READY && !load_code) {
2620 if (STp->ready == ST_NO_TAPE)
2635 DEBC_printk(STp, " Enhanced %sload slot %2d.\n",
2640 if (STp->immediate) {
2642 timeout = STp->device->request_queue->rq_timeout;
2645 timeout = STp->long_timeout;
2649 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n");
2651 st_printk(ST_DEB_MSG, STp, "Loading tape.\n");
2654 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
2657 return (STp->buffer)->syscall_result;
2659 retval = (STp->buffer)->syscall_result;
2665 STp->rew_at_close = 0;
2666 STp->ready = ST_NO_TAPE;
2669 STp->rew_at_close = STp->autorew_dev;
2670 retval = check_tape(STp, filp);
2676 STps = &(STp->ps[STp->partition]);
2687 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd)
2697 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n",
2703 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) {}
2708 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg)
2720 WARN_ON(STp->buffer->do_dio != 0);
2721 if (STp->ready != ST_READY) {
2722 if (STp->ready == ST_NO_TAPE)
2727 timeout = STp->long_timeout;
2728 STps = &(STp->ps[STp->partition]);
2744 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd);
2760 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd);
2772 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd);
2784 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd);
2795 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd);
2808 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd);
2817 if (STp->write_prot)
2823 (cmd_in == MTWEOF && STp->immediate_filemark))
2828 timeout = STp->device->request_queue->rq_timeout;
2831 st_printk(ST_DEB_MSG, STp,
2837 st_printk(ST_DEB_MSG, STp,
2850 if (STp->immediate) {
2852 timeout = STp->device->request_queue->rq_timeout;
2854 DEBC_printk(STp, "Rewinding tape.\n");
2858 DEBC_printk(STp, "No op on tape.\n");
2863 if (STp->immediate) {
2865 timeout = STp->device->request_queue->rq_timeout;
2868 DEBC_printk(STp, "Retensioning tape.\n");
2872 if (!STp->fast_mteom) {
2874 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff);
2886 DEBC_printk(STp, "Spacing to end of recorded medium.\n");
2891 if (STp->write_prot)
2895 if (STp->immediate) {
2897 timeout = STp->device->request_queue->rq_timeout;
2900 timeout = STp->long_timeout * 8;
2902 DEBC_printk(STp, "Erasing tape.\n");
2910 if (STp->dirty || (STp->buffer)->buffer_bytes != 0)
2914 STp->max_block > 0 &&
2915 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block ||
2916 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) {
2917 st_printk(KERN_WARNING, STp, "Illegal block size.\n");
2921 if ((STp->use_pf & USE_PF))
2926 memset((STp->buffer)->b_data, 0, 12);
2928 (STp->buffer)->b_data[2] = (arg & 7) << 4;
2930 (STp->buffer)->b_data[2] =
2931 STp->drv_buffer << 4;
2932 (STp->buffer)->b_data[3] = 8; /* block descriptor length */
2934 (STp->buffer)->b_data[4] = arg;
2935 STp->density_changed = 1; /* At least we tried ;-) */
2937 (STp->buffer)->b_data[4] = arg >> 24;
2939 (STp->buffer)->b_data[4] = STp->density;
2943 STp->blksize_changed = 1; /* At least we tried ;-) */
2945 ltmp = STp->block_size;
2946 (STp->buffer)->b_data[9] = (ltmp >> 16);
2947 (STp->buffer)->b_data[10] = (ltmp >> 8);
2948 (STp->buffer)->b_data[11] = ltmp;
2949 timeout = STp->device->request_queue->rq_timeout;
2952 st_printk(ST_DEB_MSG, STp,
2954 (STp->buffer)->b_data[9] * 65536 +
2955 (STp->buffer)->b_data[10] * 256 +
2956 (STp->buffer)->b_data[11]);
2958 st_printk(ST_DEB_MSG, STp,
2960 (STp->buffer)->b_data[4]);
2962 st_printk(ST_DEB_MSG, STp,
2964 ((STp->buffer)->b_data[2] >> 4) & 7);
2971 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction,
2974 return (STp->buffer)->syscall_result;
2976 ioctl_result = (STp->buffer)->syscall_result;
2986 ioctl_result = st_int_ioctl(STp, MTFSF, 1);
2988 ioctl_result = st_int_ioctl(STp, MTBSF, 1);
2991 STp->block_size = arg & MT_ST_BLKSIZE_MASK;
2992 if (STp->block_size != 0) {
2993 (STp->buffer)->buffer_blocks =
2994 (STp->buffer)->buffer_size / STp->block_size;
2996 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0;
2998 STp->density = arg >> MT_ST_DENSITY_SHIFT;
3000 STp->drv_buffer = (arg & 7);
3002 STp->density = arg;
3015 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
3090 !(STp->use_pf & PF_TESTED)) {
3093 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED;
3096 return st_int_ioctl(STp, cmd_in, arg);
3116 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition,
3123 if (STp->ready != ST_READY)
3127 if ((STp->device)->scsi_level < SCSI_2) {
3132 if (!logical && !STp->scsi2_logical)
3135 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE,
3136 STp->device->request_queue->rq_timeout,
3139 return (STp->buffer)->syscall_result;
3141 if ((STp->buffer)->syscall_result != 0 ||
3142 (STp->device->scsi_level >= SCSI_2 &&
3143 ((STp->buffer)->b_data[0] & 4) != 0)) {
3145 DEBC_printk(STp, " Can't read tape position.\n");
3149 if ((STp->device)->scsi_level < SCSI_2) {
3150 *block = ((STp->buffer)->b_data[0] << 16)
3151 + ((STp->buffer)->b_data[1] << 8)
3152 + (STp->buffer)->b_data[2];
3155 *block = ((STp->buffer)->b_data[4] << 24)
3156 + ((STp->buffer)->b_data[5] << 16)
3157 + ((STp->buffer)->b_data[6] << 8)
3158 + (STp->buffer)->b_data[7];
3159 *partition = (STp->buffer)->b_data[1];
3160 if (((STp->buffer)->b_data[0] & 0x80) &&
3161 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */
3162 STp->ps[0].drv_block = STp->ps[0].drv_file = 0;
3164 DEBC_printk(STp, "Got tape pos. blk %d part %d.\n",
3176 static int set_location(struct scsi_tape *STp, unsigned int block, int partition,
3186 if (STp->ready != ST_READY)
3188 timeout = STp->long_timeout;
3189 STps = &(STp->ps[STp->partition]);
3191 DEBC_printk(STp, "Setting block to %d and partition to %d.\n",
3197 if ((!STp->can_partitions && partition != 0) ||
3200 if (partition != STp->partition) {
3201 if (get_location(STp, &blk, &p, 1))
3206 DEBC_printk(STp, "Visited block %d for "
3208 blk, STp->partition);
3213 if ((STp->device)->scsi_level < SCSI_2) {
3225 if (!logical && !STp->scsi2_logical)
3227 if (STp->partition != partition) {
3230 DEBC_printk(STp, "Trying to change partition "
3231 "from %d to %d\n", STp->partition,
3235 if (STp->immediate) {
3237 timeout = STp->device->request_queue->rq_timeout;
3240 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE,
3243 return (STp->buffer)->syscall_result;
3247 if ((STp->buffer)->syscall_result != 0) {
3249 if (STp->can_partitions &&
3250 (STp->device)->scsi_level >= SCSI_2 &&
3251 (p = find_partition(STp)) >= 0)
3252 STp->partition = p;
3254 if (STp->can_partitions) {
3255 STp->partition = partition;
3256 STps = &(STp->ps[partition]);
3278 static int find_partition(struct scsi_tape *STp)
3283 if ((i = get_location(STp, &block, &partition, 1)) < 0)
3292 static int switch_partition(struct scsi_tape *STp)
3296 if (STp->partition == STp->new_partition)
3298 STps = &(STp->ps[STp->new_partition]);
3301 return set_location(STp, STps->last_block_visited, STp->new_partition, 1);
3324 static int nbr_partitions(struct scsi_tape *STp)
3328 if (STp->ready != ST_READY)
3331 result = read_mode_page(STp, PART_PAGE, 1);
3334 DEBC_printk(STp, "Can't read medium partition page.\n");
3337 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH +
3339 DEBC_printk(STp, "Number of partitions %d.\n", result);
3346 static int format_medium(struct scsi_tape *STp, int format)
3349 int timeout = STp->long_timeout;
3356 if (STp->immediate) {
3358 timeout = STp->device->request_queue->rq_timeout;
3360 DEBC_printk(STp, "Sending FORMAT MEDIUM\n");
3361 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE,
3364 result = STp->buffer->syscall_result;
3390 static int partition_tape(struct scsi_tape *STp, int size)
3394 bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false;
3399 result = read_mode_page(STp, PART_PAGE, 0);
3401 DEBC_printk(STp, "Can't read partition mode page.\n");
3411 bp = (STp->buffer)->b_data;
3413 DEBC_printk(STp, "Partition page length is %d bytes.\n",
3424 DEBC_printk(STp, "Formatting tape with one partition.\n");
3425 result = format_medium(STp, 0);
3467 DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n",
3475 DEBC_printk(STp, "Formatting tape with one partition.\n");
3484 DEBC_printk(STp,
3499 result = write_mode_page(STp, PART_PAGE, 1);
3502 result = format_medium(STp, 1);
3505 st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n");
3522 struct scsi_tape *STp = file->private_data;
3526 if (mutex_lock_interruptible(&STp->lock))
3530 if (debugging && !STp->in_use) {
3531 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n");
3536 STm = &(STp->modes[STp->current_mode]);
3537 STps = &(STp->ps[STp->partition]);
3545 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in,
3568 st_printk(KERN_WARNING, STp,
3580 if (!STp->pos_unknown) {
3598 i = !STp->can_partitions ||
3599 (STp->new_partition != STp->partition);
3608 i = flush_buffer(STp, i);
3617 i = st_int_ioctl(STp, MTWEOF, 1);
3642 reset_state(STp);
3644 STp->device->was_reset = 0;
3652 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED)
3653 do_door_lock(STp, 0); /* Ignore result! */
3657 retval = st_set_options(STp, mtc.mt_count);
3662 if (!STp->can_partitions ||
3667 if (mtc.mt_count >= STp->nbr_partitions &&
3668 (STp->nbr_partitions = nbr_partitions(STp)) < 0) {
3672 if (mtc.mt_count >= STp->nbr_partitions) {
3676 STp->new_partition = mtc.mt_count;
3682 if (!STp->can_partitions) {
3686 i = do_load_unload(STp, file, 1);
3691 i = partition_tape(STp, mtc.mt_count);
3697 STp->ps[i].rw = ST_IDLE;
3698 STp->ps[i].at_sm = 0;
3699 STp->ps[i].last_block_valid = 0;
3701 STp->partition = STp->new_partition = 0;
3702 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1;
3709 i = set_location(STp, mtc.mt_count, STp->new_partition, 0);
3710 if (!STp->can_partitions)
3711 STp->ps[0].rw = ST_IDLE;
3717 retval = do_load_unload(STp, file, 0);
3722 retval = do_load_unload(STp, file, max(1, mtc.mt_count));
3727 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK));
3731 if (STp->can_partitions && STp->ready == ST_READY &&
3732 (i = switch_partition(STp)) < 0) {
3738 retval = st_compression(STp, (mtc.mt_count & 1));
3740 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count);
3748 if ((i = flush_buffer(STp, 0)) < 0) {
3752 if (STp->can_partitions &&
3753 (i = switch_partition(STp)) < 0) {
3766 mt_status.mt_type = STp->tape_type;
3768 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) |
3769 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK);
3772 if (STp->block_size != 0) {
3775 (STp->buffer)->buffer_bytes / STp->block_size;
3778 ((STp->buffer)->buffer_bytes +
3779 STp->block_size - 1) / STp->block_size;
3783 if (STp->drv_write_prot)
3791 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT);
3792 mt_status.mt_resid = STp->partition;
3797 if (STp->density == 1)
3799 else if (STp->density == 2)
3801 else if (STp->density == 3)
3803 if (STp->ready == ST_READY)
3805 if (STp->ready == ST_NO_TAPE)
3810 (STm->do_buffer_writes && STp->block_size != 0) ||
3811 STp->drv_buffer != 0)
3813 if (STp->cleaning_req)
3820 STp->recover_reg = 0; /* Clear after read */
3829 if ((i = get_location(STp, &blk, &bt, 0)) < 0) {
3837 mutex_unlock(&STp->lock);
3841 retval = scsi_ioctl(STp->device, cmd_in, p);
3843 STp->rew_at_close = 0;
3844 STp->ready = ST_NO_TAPE;
3859 i = scsi_cmd_ioctl(STp->disk->queue, STp->disk,
3868 mutex_unlock(&STp->lock);
3875 struct scsi_tape *STp = file->private_data;
3882 return scsi_ioctl(STp->device, cmd_in, p);
3889 struct scsi_tape *STp = file->private_data;
3904 return scsi_compat_ioctl(STp->device, cmd_in, p);
4690 struct scsi_tape *STp = STm->tape;
4698 options |= STp->two_fm ? MT_ST_TWO_FM : 0;
4699 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0;
4701 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0;
4702 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0;
4703 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0;
4704 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0;
4706 options |= STp->immediate ? MT_ST_NOWAIT : 0;
4707 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0;
4708 options |= STp->sili ? MT_ST_SILI : 0;