Lines Matching refs:STp
245 struct scsi_tape *STp = NULL; in scsi_tape_get() local
250 STp = idr_find(&st_index_idr, dev); in scsi_tape_get()
251 if (!STp) goto out; in scsi_tape_get()
253 kref_get(&STp->kref); in scsi_tape_get()
255 if (!STp->device) in scsi_tape_get()
258 if (scsi_device_get(STp->device)) in scsi_tape_get()
264 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_get()
265 STp = NULL; in scsi_tape_get()
269 return STp; in scsi_tape_get()
272 static void scsi_tape_put(struct scsi_tape *STp) in scsi_tape_put() argument
274 struct scsi_device *sdev = STp->device; in scsi_tape_put()
277 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_put()
357 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) in st_chk_result() argument
362 char *name = STp->name; in st_chk_result()
368 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
372 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
378 st_printk(ST_DEB_MSG, STp, in st_chk_result()
383 __scsi_print_sense(STp->device, name, in st_chk_result()
388 st_printk(KERN_WARNING, STp, in st_chk_result()
400 __scsi_print_sense(STp->device, name, in st_chk_result()
406 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
407 if (STp->cln_sense_value) in st_chk_result()
408 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
409 STp->cln_sense_mask) == STp->cln_sense_value); in st_chk_result()
411 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
412 STp->cln_sense_mask) != 0); in st_chk_result()
416 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
418 STp->pos_unknown = 1; /* ASC => power on / reset */ in st_chk_result()
420 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
429 STp->recover_count++; in st_chk_result()
430 STp->recover_reg++; in st_chk_result()
440 st_printk(ST_DEB_MSG, STp, in st_chk_result()
442 stp, STp->recover_count); in st_chk_result()
475 static void st_do_stats(struct scsi_tape *STp, struct request *req) in st_do_stats() argument
482 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
483 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
484 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
485 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
487 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
488 - STp->buffer->cmdstat.residual, in st_do_stats()
489 &STp->stats->write_byte_cnt); in st_do_stats()
490 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
491 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
493 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
494 &STp->stats->write_byte_cnt); in st_do_stats()
496 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
497 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time); in st_do_stats()
498 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
499 atomic64_inc(&STp->stats->read_cnt); in st_do_stats()
501 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
502 - STp->buffer->cmdstat.residual, in st_do_stats()
503 &STp->stats->read_byte_cnt); in st_do_stats()
504 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
505 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
507 atomic64_add(atomic_read(&STp->stats->last_read_size), in st_do_stats()
508 &STp->stats->read_byte_cnt); in st_do_stats()
510 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
511 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
512 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
514 atomic64_dec(&STp->stats->in_flight); in st_do_stats()
522 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end() local
525 STp->buffer->cmdstat.midlevel_result = SRpnt->result = scmd->result; in st_scsi_execute_end()
526 STp->buffer->cmdstat.residual = scmd->resid_len; in st_scsi_execute_end()
528 st_do_stats(STp, req); in st_scsi_execute_end()
548 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute() local
570 atomic64_inc(&STp->stats->in_flight); in st_scsi_execute()
572 atomic_set(&STp->stats->last_write_size, bufflen); in st_scsi_execute()
573 STp->stats->write_time = ktime_get(); in st_scsi_execute()
575 atomic_set(&STp->stats->last_read_size, bufflen); in st_scsi_execute()
576 STp->stats->read_time = ktime_get(); in st_scsi_execute()
578 STp->stats->other_time = ktime_get(); in st_scsi_execute()
597 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, in st_do_scsi() argument
601 struct rq_map_data *mdata = &STp->buffer->map_data; in st_do_scsi()
605 if (!do_wait && ((STp->buffer)->last_SRpnt)) { in st_do_scsi()
606 st_printk(KERN_ERR, STp, in st_do_scsi()
609 (STp->buffer)->syscall_result = (-EINTR); in st_do_scsi()
611 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
616 SRpnt = st_allocate_request(STp); in st_do_scsi()
624 (STp->buffer)->last_SRpnt = SRpnt; in st_do_scsi()
626 waiting = &STp->wait; in st_do_scsi()
630 if (STp->buffer->do_dio) { in st_do_scsi()
632 mdata->nr_entries = STp->buffer->sg_segs; in st_do_scsi()
633 mdata->pages = STp->buffer->mapped_pages; in st_do_scsi()
635 mdata->page_order = STp->buffer->reserved_page_order; in st_do_scsi()
638 mdata->pages = STp->buffer->reserved_pages; in st_do_scsi()
643 STp->buffer->cmdstat.have_sense = 0; in st_do_scsi()
644 STp->buffer->syscall_result = 0; in st_do_scsi()
650 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
651 (STp->buffer)->last_SRpnt = NULL; in st_do_scsi()
655 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in st_do_scsi()
666 static int write_behind_check(struct scsi_tape * STp) in write_behind_check() argument
674 STbuffer = STp->buffer; in write_behind_check()
679 if (STp->write_pending) in write_behind_check()
680 STp->nbr_waits++; in write_behind_check()
682 STp->nbr_finished++; in write_behind_check()
685 wait_for_completion(&(STp->wait)); in write_behind_check()
690 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in write_behind_check()
694 STps = &(STp->ps[STp->partition]); in write_behind_check()
696 if (STp->block_size == 0) in write_behind_check()
699 STps->drv_block += STbuffer->writing / STp->block_size; in write_behind_check()
720 st_printk(ST_DEB_MSG, STp, in write_behind_check()
730 static int cross_eof(struct scsi_tape * STp, int forward) in cross_eof() argument
744 DEBC_printk(STp, "Stepping over filemark %s.\n", in cross_eof()
747 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in cross_eof()
748 STp->device->request_queue->rq_timeout, in cross_eof()
751 return (STp->buffer)->syscall_result; in cross_eof()
756 if ((STp->buffer)->cmdstat.midlevel_result != 0) in cross_eof()
757 st_printk(KERN_ERR, STp, in cross_eof()
761 return (STp->buffer)->syscall_result; in cross_eof()
766 static int st_flush_write_buffer(struct scsi_tape * STp) in st_flush_write_buffer() argument
774 result = write_behind_check(STp); in st_flush_write_buffer()
779 if (STp->dirty == 1) { in st_flush_write_buffer()
781 transfer = STp->buffer->buffer_bytes; in st_flush_write_buffer()
782 DEBC_printk(STp, "Flushing %d bytes.\n", transfer); in st_flush_write_buffer()
787 blks = transfer / STp->block_size; in st_flush_write_buffer()
792 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE, in st_flush_write_buffer()
793 STp->device->request_queue->rq_timeout, in st_flush_write_buffer()
796 return (STp->buffer)->syscall_result; in st_flush_write_buffer()
798 STps = &(STp->ps[STp->partition]); in st_flush_write_buffer()
799 if ((STp->buffer)->syscall_result != 0) { in st_flush_write_buffer()
800 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush_write_buffer()
808 STp->dirty = 0; in st_flush_write_buffer()
809 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
814 st_printk(KERN_ERR, STp, "Error on flush.\n"); in st_flush_write_buffer()
821 STp->dirty = 0; in st_flush_write_buffer()
822 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
833 static int flush_buffer(struct scsi_tape *STp, int seek_next) in flush_buffer() argument
838 if (STp->ready != ST_READY) in flush_buffer()
845 if (STp->pos_unknown) in flush_buffer()
848 STps = &(STp->ps[STp->partition]); in flush_buffer()
850 return st_flush_write_buffer(STp); in flush_buffer()
852 if (STp->block_size == 0) in flush_buffer()
855 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
856 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
857 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
858 STp->block_size; in flush_buffer()
859 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
860 (STp->buffer)->read_pointer = 0; in flush_buffer()
864 result = cross_eof(STp, 0); /* Back over the EOF hit */ in flush_buffer()
874 result = st_int_ioctl(STp, MTBSR, backspace); in flush_buffer()
886 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) in set_mode_densblk() argument
891 if (!STp->density_changed && in set_mode_densblk()
893 STm->default_density != STp->density) { in set_mode_densblk()
897 arg = STp->density; in set_mode_densblk()
899 if (!STp->blksize_changed && in set_mode_densblk()
901 STm->default_blksize != STp->block_size) { in set_mode_densblk()
905 arg |= STp->block_size; in set_mode_densblk()
907 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { in set_mode_densblk()
908 st_printk(KERN_WARNING, STp, in set_mode_densblk()
920 static int do_door_lock(struct scsi_tape * STp, int do_lock) in do_door_lock() argument
924 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); in do_door_lock()
926 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
929 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
931 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
937 static void reset_state(struct scsi_tape *STp) in reset_state() argument
942 STp->pos_unknown = 0; in reset_state()
944 STps = &(STp->ps[i]); in reset_state()
952 if (STp->can_partitions) { in reset_state()
953 STp->partition = find_partition(STp); in reset_state()
954 if (STp->partition < 0) in reset_state()
955 STp->partition = 0; in reset_state()
956 STp->new_partition = STp->partition; in reset_state()
969 static int test_ready(struct scsi_tape *STp, int do_wait) in test_ready() argument
975 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
982 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, in test_ready()
983 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
986 retval = (STp->buffer)->syscall_result; in test_ready()
1016 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
1026 retval = (STp->buffer)->syscall_result; in test_ready()
1031 if (STp->first_tur) { in test_ready()
1033 STp->pos_unknown = 0; in test_ready()
1034 STp->first_tur = 0; in test_ready()
1048 static int check_tape(struct scsi_tape *STp, struct file *filp) in check_tape() argument
1059 STp->ready = ST_READY; in check_tape()
1061 if (mode != STp->current_mode) { in check_tape()
1062 DEBC_printk(STp, "Mode change from %d to %d.\n", in check_tape()
1063 STp->current_mode, mode); in check_tape()
1065 STp->current_mode = mode; in check_tape()
1067 STm = &(STp->modes[STp->current_mode]); in check_tape()
1069 saved_cleaning = STp->cleaning_req; in check_tape()
1070 STp->cleaning_req = 0; in check_tape()
1073 retval = test_ready(STp, do_wait); in check_tape()
1079 STp->pos_unknown = 0; in check_tape()
1080 STp->partition = STp->new_partition = 0; in check_tape()
1081 if (STp->can_partitions) in check_tape()
1082 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1085 STps = &(STp->ps[i]); in check_tape()
1096 STp->cleaning_req |= saved_cleaning; in check_tape()
1100 STp->ready = ST_NO_TAPE; in check_tape()
1102 STp->ready = ST_NOT_READY; in check_tape()
1104 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1105 STp->write_prot = 0; in check_tape()
1106 STp->block_size = 0; in check_tape()
1107 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1108 STp->partition = STp->new_partition = 0; in check_tape()
1109 STp->door_locked = ST_UNLOCKED; in check_tape()
1114 if (STp->omit_blklims) in check_tape()
1115 STp->min_block = STp->max_block = (-1); in check_tape()
1120 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE, in check_tape()
1121 STp->device->request_queue->rq_timeout, in check_tape()
1124 retval = (STp->buffer)->syscall_result; in check_tape()
1128 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1129 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1130 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1131 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1132 (STp->buffer)->b_data[5]; in check_tape()
1133 if ( DEB( debugging || ) !STp->inited) in check_tape()
1134 st_printk(KERN_INFO, STp, in check_tape()
1136 STp->min_block, STp->max_block); in check_tape()
1138 STp->min_block = STp->max_block = (-1); in check_tape()
1139 DEBC_printk(STp, "Can't read block limits.\n"); in check_tape()
1147 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE, in check_tape()
1148 STp->device->request_queue->rq_timeout, in check_tape()
1151 retval = (STp->buffer)->syscall_result; in check_tape()
1155 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1156 DEBC_printk(STp, "No Mode Sense.\n"); in check_tape()
1157 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1158 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1159 STp->drv_write_prot = 0; in check_tape()
1161 DEBC_printk(STp,"Mode sense. Length %d, " in check_tape()
1163 (STp->buffer)->b_data[0], in check_tape()
1164 (STp->buffer)->b_data[1], in check_tape()
1165 (STp->buffer)->b_data[2], in check_tape()
1166 (STp->buffer)->b_data[3]); in check_tape()
1168 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1169 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1170 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1171 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1172 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1173 DEBC_printk(STp, "Density %x, tape length: %x, " in check_tape()
1175 STp->density, in check_tape()
1176 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1177 (STp->buffer)->b_data[6] * 256 + in check_tape()
1178 (STp->buffer)->b_data[7], in check_tape()
1179 STp->drv_buffer); in check_tape()
1181 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1182 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1183 st_printk(KERN_WARNING, STp, in check_tape()
1186 STp->immediate_filemark = 0; in check_tape()
1191 STp->inited = 1; in check_tape()
1193 if (STp->block_size > 0) in check_tape()
1194 (STp->buffer)->buffer_blocks = in check_tape()
1195 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1197 (STp->buffer)->buffer_blocks = 1; in check_tape()
1198 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1200 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n", in check_tape()
1201 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1202 (STp->buffer)->buffer_blocks); in check_tape()
1204 if (STp->drv_write_prot) { in check_tape()
1205 STp->write_prot = 1; in check_tape()
1207 DEBC_printk(STp, "Write protected\n"); in check_tape()
1217 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1221 DEBC_printk(STp, "Updating partition number in status.\n"); in check_tape()
1222 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1223 retval = STp->partition; in check_tape()
1226 STp->new_partition = STp->partition; in check_tape()
1227 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1231 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1232 STp->compression_changed = 0; in check_tape()
1234 (retval = set_mode_densblk(STp, STm)) < 0) in check_tape()
1237 if (STp->default_drvbuffer != 0xff) { in check_tape()
1238 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1239 st_printk(KERN_WARNING, STp, in check_tape()
1242 STp->default_drvbuffer); in check_tape()
1259 struct scsi_tape *STp; in st_open() local
1270 if (!(STp = scsi_tape_get(dev))) { in st_open()
1274 filp->private_data = STp; in st_open()
1277 if (STp->in_use) { in st_open()
1279 DEBC_printk(STp, "Device already in use.\n"); in st_open()
1280 scsi_tape_put(STp); in st_open()
1284 STp->in_use = 1; in st_open()
1286 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1288 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1293 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1299 if (!enlarge_buffer(STp->buffer, PAGE_SIZE)) { in st_open()
1300 st_printk(KERN_WARNING, STp, in st_open()
1306 (STp->buffer)->cleared = 0; in st_open()
1307 (STp->buffer)->writing = 0; in st_open()
1308 (STp->buffer)->syscall_result = 0; in st_open()
1310 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1312 STp->dirty = 0; in st_open()
1314 STps = &(STp->ps[i]); in st_open()
1317 STp->try_dio_now = STp->try_dio; in st_open()
1318 STp->recover_count = 0; in st_open()
1319 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1320 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1322 retval = check_tape(STp, filp); in st_open()
1327 if (STp->ready == NO_TAPE) in st_open()
1336 normalize_buffer(STp->buffer); in st_open()
1338 STp->in_use = 0; in st_open()
1341 scsi_autopm_put_device(STp->device); in st_open()
1342 scsi_tape_put(STp); in st_open()
1354 struct scsi_tape *STp = filp->private_data; in st_flush() local
1355 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1356 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1361 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1362 result = st_flush_write_buffer(STp); in st_flush()
1367 if (STp->can_partitions && in st_flush()
1368 (result2 = switch_partition(STp)) < 0) { in st_flush()
1369 DEBC_printk(STp, "switch_partition at close failed.\n"); in st_flush()
1375 DEBC( if (STp->nbr_requests) in st_flush()
1376 st_printk(KERN_DEBUG, STp, in st_flush()
1378 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1379 STp->nbr_pages)); in st_flush()
1381 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1382 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1385 DEBC_printk(STp, "Async write waits %d, finished %d.\n", in st_flush()
1386 STp->nbr_waits, STp->nbr_finished); in st_flush()
1390 if (STp->immediate_filemark) in st_flush()
1392 cmd[4] = 1 + STp->two_fm; in st_flush()
1394 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in st_flush()
1395 STp->device->request_queue->rq_timeout, in st_flush()
1398 result = (STp->buffer)->syscall_result; in st_flush()
1402 if (STp->buffer->syscall_result == 0 || in st_flush()
1414 if (STp->two_fm) in st_flush()
1415 cross_eof(STp, 0); in st_flush()
1421 st_printk(KERN_ERR, STp, in st_flush()
1427 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]); in st_flush()
1428 } else if (!STp->rew_at_close) { in st_flush()
1429 STps = &(STp->ps[STp->partition]); in st_flush()
1431 if (STp->can_bsr) in st_flush()
1432 result = flush_buffer(STp, 0); in st_flush()
1434 result = cross_eof(STp, 0); in st_flush()
1444 !(result = cross_eof(STp, 1))) || in st_flush()
1454 if (STp->rew_at_close) { in st_flush()
1455 result2 = st_int_ioctl(STp, MTREW, 1); in st_flush()
1467 struct scsi_tape *STp = filp->private_data; in st_release() local
1469 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1470 do_door_lock(STp, 0); in st_release()
1472 normalize_buffer(STp->buffer); in st_release()
1474 STp->in_use = 0; in st_release()
1476 scsi_autopm_put_device(STp->device); in st_release()
1477 scsi_tape_put(STp); in st_release()
1483 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) in rw_checks() argument
1493 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1498 if (STp->ready != ST_READY) { in rw_checks()
1499 if (STp->ready == ST_NO_TAPE) in rw_checks()
1506 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1516 if (STp->pos_unknown) { in rw_checks()
1525 if (!STp->in_use) { in rw_checks()
1526 st_printk(ST_DEB_MSG, STp, in rw_checks()
1532 if (STp->can_partitions && in rw_checks()
1533 (retval = switch_partition(STp)) < 0) in rw_checks()
1536 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1537 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1542 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1543 !do_door_lock(STp, 1)) in rw_checks()
1544 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1551 static int setup_buffering(struct scsi_tape *STp, const char __user *buf, in setup_buffering() argument
1555 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1558 i = STp->try_dio_now && try_rdio; in setup_buffering()
1560 i = STp->try_dio_now && try_wdio; in setup_buffering()
1563 STp->device->request_queue)) == 0) { in setup_buffering()
1575 STp->nbr_dio++; in setup_buffering()
1576 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1581 DEB( STp->nbr_requests++; ) in setup_buffering()
1584 if (STp->block_size) in setup_buffering()
1585 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1586 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1591 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1597 st_printk(KERN_WARNING, STp, in setup_buffering()
1603 if (STp->block_size) in setup_buffering()
1604 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1613 static void release_buffering(struct scsi_tape *STp, int is_read) in release_buffering() argument
1617 STbp = STp->buffer; in release_buffering()
1638 struct scsi_tape *STp = filp->private_data; in st_write() local
1643 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1646 retval = rw_checks(STp, filp, count); in st_write()
1651 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1652 st_printk(KERN_WARNING, STp, in st_write()
1658 STm = &(STp->modes[STp->current_mode]); in st_write()
1659 STps = &(STp->ps[STp->partition]); in st_write()
1661 if (STp->write_prot) { in st_write()
1668 retval = flush_buffer(STp, 0); in st_write()
1674 if ((retval = set_mode_densblk(STp, STm)) < 0) in st_write()
1677 !(STp->compression_changed)) { in st_write()
1678 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1679 st_printk(KERN_WARNING, STp, in st_write()
1689 STbp = STp->buffer; in st_write()
1690 i = write_behind_check(STp); in st_write()
1710 if (STp->block_size != 0 && in st_write()
1718 retval = setup_buffering(STp, buf, count, 0); in st_write()
1726 cmd[1] = (STp->block_size != 0); in st_write()
1737 if (STp->block_size == 0) in st_write()
1740 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1755 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1758 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1759 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1761 STp->dirty = 1; in st_write()
1768 if (STp->block_size == 0) in st_write()
1775 blks /= STp->block_size; in st_write()
1776 transfer = blks * STp->block_size; in st_write()
1782 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE, in st_write()
1783 STp->device->request_queue->rq_timeout, in st_write()
1791 STp->dirty = !(STbp->writing == in st_write()
1794 DEB( STp->write_pending = 1; ) in st_write()
1799 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1801 DEBC_printk(STp, "Error on write:\n"); in st_write()
1806 else if (STp->block_size == 0 && in st_write()
1811 if (STp->block_size != 0) in st_write()
1812 undone *= STp->block_size; in st_write()
1818 if (STp->block_size) in st_write()
1819 blks = (transfer - undone) / STp->block_size; in st_write()
1825 if (STp->block_size == 0 || in st_write()
1828 DEBC_printk(STp, "EOM with %d " in st_write()
1836 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1840 STp->block_size; in st_write()
1843 DEBC_printk(STp, "Retry " in st_write()
1846 STp->buffer->buffer_bytes); in st_write()
1857 DEBC_printk(STp, "EOM with " in st_write()
1870 if (STp->block_size == 0) in st_write()
1877 STp->dirty = 0; in st_write()
1895 release_buffering(STp, 0); in st_write()
1896 mutex_unlock(&STp->lock); in st_write()
1907 static long read_tape(struct scsi_tape *STp, long count, in read_tape() argument
1921 STm = &(STp->modes[STp->current_mode]); in read_tape()
1922 STps = &(STp->ps[STp->partition]); in read_tape()
1925 STbp = STp->buffer; in read_tape()
1927 if (STp->block_size == 0) in read_tape()
1930 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1931 blks = (STp->buffer)->buffer_blocks; in read_tape()
1932 bytes = blks * STp->block_size; in read_tape()
1935 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1936 bytes = (STp->buffer)->buffer_size; in read_tape()
1937 blks = bytes / STp->block_size; in read_tape()
1938 bytes = blks * STp->block_size; in read_tape()
1944 cmd[1] = (STp->block_size != 0); in read_tape()
1945 if (!cmd[1] && STp->sili) in read_tape()
1952 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, in read_tape()
1953 STp->device->request_queue->rq_timeout, in read_tape()
1955 release_buffering(STp, 1); in read_tape()
1965 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1968 DEBC_printk(STp, in read_tape()
1986 if (STp->block_size == 0) in read_tape()
1993 if (STp->block_size == 0 && in read_tape()
1995 st_printk(KERN_NOTICE, STp, in read_tape()
2005 } else if (STp->block_size == 0) { in read_tape()
2011 st_printk(KERN_NOTICE, STp, in read_tape()
2016 st_int_ioctl(STp, MTBSR, 1); in read_tape()
2021 STp->block_size; in read_tape()
2022 DEBC_printk(STp, "ILI but " in read_tape()
2029 if (st_int_ioctl(STp, MTBSR, 1)) in read_tape()
2037 if (STp->block_size == 0) in read_tape()
2041 bytes - transfer * STp->block_size; in read_tape()
2042 DEBC_printk(STp, "EOF detected (%d " in read_tape()
2050 if (STp->block_size == 0) in read_tape()
2054 bytes - transfer * STp->block_size; in read_tape()
2056 DEBC_printk(STp, "EOM detected (%d " in read_tape()
2063 DEBC_printk(STp, "Tape error while reading.\n"); in read_tape()
2067 DEBC_printk(STp, "Zero returned for " in read_tape()
2087 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2088 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2092 if (STp->block_size == 0) in read_tape()
2095 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2110 struct scsi_tape *STp = filp->private_data; in st_read() local
2113 struct st_buffer *STbp = STp->buffer; in st_read()
2115 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2118 retval = rw_checks(STp, filp, count); in st_read()
2122 STm = &(STp->modes[STp->current_mode]); in st_read()
2123 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2128 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2131 STps = &(STp->ps[STp->partition]); in st_read()
2133 retval = flush_buffer(STp, 0); in st_read()
2140 st_printk(ST_DEB_MSG, STp, in st_read()
2145 retval = setup_buffering(STp, buf, count, 1); in st_read()
2181 special = read_tape(STp, count - total, &SRpnt); in st_read()
2192 st_printk(ST_DEB_MSG, STp, in st_read()
2210 if (STp->block_size == 0) in st_read()
2240 release_buffering(STp, 1); in st_read()
2243 mutex_unlock(&STp->lock); in st_read()
2252 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm) in DEB() argument
2255 st_printk(KERN_INFO, STp, in DEB()
2258 STp->current_mode, STm->do_buffer_writes, in DEB()
2260 st_printk(KERN_INFO, STp, in DEB()
2263 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2264 STp->do_auto_lock); in DEB()
2265 st_printk(KERN_INFO, STp, in DEB()
2268 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2269 STp->can_partitions, STp->scsi2_logical); in DEB()
2270 st_printk(KERN_INFO, STp, in DEB()
2273 STm->sysv, STp->immediate, STp->sili, in DEB()
2274 STp->immediate_filemark); in DEB()
2275 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging); in DEB()
2281 static int st_set_options(struct scsi_tape *STp, long options)
2289 STm = &(STp->modes[STp->current_mode]);
2295 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2301 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2302 STp->current_mode);
2311 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2312 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2313 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2314 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2315 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2316 if ((STp->device)->scsi_level >= SCSI_2)
2317 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2318 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2319 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2320 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2322 STp->sili = (options & MT_ST_SILI) != 0;
2324 st_log_options(STp, STm); )
2336 STp->two_fm = value;
2338 STp->fast_mteom = value;
2340 STp->do_auto_lock = value;
2342 STp->can_bsr = value;
2344 STp->omit_blklims = value;
2345 if ((STp->device)->scsi_level >= SCSI_2 &&
2347 STp->can_partitions = value;
2349 STp->scsi2_logical = value;
2351 STp->immediate = value;
2353 STp->immediate_filemark = value;
2357 STp->sili = value;
2361 st_log_options(STp, STm); )
2368 DEBC_printk(STp, "Default block size disabled.\n");
2371 DEBC_printk(STp,"Default block size set to "
2373 if (STp->ready == ST_READY) {
2374 STp->blksize_changed = 0;
2375 set_mode_densblk(STp, STm);
2381 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2382 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2385 blk_queue_rq_timeout(STp->device->request_queue,
2387 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2396 STp->cln_mode = value;
2397 STp->cln_sense_mask = (options >> 8) & 0xff;
2398 STp->cln_sense_value = (options >> 16) & 0xff;
2399 st_printk(KERN_INFO, STp,
2401 value, STp->cln_sense_mask, STp->cln_sense_value);
2408 DEBC_printk(STp,
2412 DEBC_printk(STp, "Density default set to %x\n",
2414 if (STp->ready == ST_READY) {
2415 STp->density_changed = 0;
2416 set_mode_densblk(STp, STm);
2421 STp->default_drvbuffer = 0xff;
2422 DEBC_printk(STp,
2425 STp->default_drvbuffer = value & 7;
2426 DEBC_printk(STp,
2428 STp->default_drvbuffer);
2429 if (STp->ready == ST_READY)
2430 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2435 DEBC_printk(STp,
2439 STp->c_algo = (value & 0xff00) >> 8;
2440 DEBC_printk(STp, "Compression "
2442 STp->c_algo);
2446 DEBC_printk(STp, "Compression default "
2449 if (STp->ready == ST_READY) {
2450 STp->compression_changed = 0;
2451 st_compression(STp, (STm->default_compression == ST_YES));
2484 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) in read_mode_page() argument
2496 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE, in read_mode_page()
2497 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2499 return (STp->buffer)->syscall_result; in read_mode_page()
2503 return STp->buffer->syscall_result; in read_mode_page()
2509 static int write_mode_page(struct scsi_tape *STp, int page, int slow) in write_mode_page() argument
2519 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2520 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2523 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2524 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2525 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2526 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2529 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2530 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE, in write_mode_page()
2533 return (STp->buffer)->syscall_result; in write_mode_page()
2537 return STp->buffer->syscall_result; in write_mode_page()
2558 static int st_compression(struct scsi_tape * STp, int state) in st_compression() argument
2562 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2564 if (STp->ready != ST_READY) in st_compression()
2568 retval = read_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2570 DEBC_printk(STp, "Compression mode page not supported.\n"); in st_compression()
2575 DEBC_printk(STp, "Compression state is %d.\n", in st_compression()
2580 DEBC_printk(STp, "Compression not supported.\n"); in st_compression()
2587 if (STp->c_algo != 0) in st_compression()
2588 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2592 if (STp->c_algo != 0) in st_compression()
2596 retval = write_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2598 DEBC_printk(STp, "Compression change failed.\n"); in st_compression()
2601 DEBC_printk(STp, "Compression state changed to %d.\n", state); in st_compression()
2603 STp->compression_changed = 1; in st_compression()
2609 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) in do_load_unload() argument
2616 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2617 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2632 DEBC_printk(STp, " Enhanced %sload slot %2d.\n", in do_load_unload()
2637 if (STp->immediate) { in do_load_unload()
2639 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2642 timeout = STp->long_timeout; in do_load_unload()
2646 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n"); in do_load_unload()
2648 st_printk(ST_DEB_MSG, STp, "Loading tape.\n"); in do_load_unload()
2651 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in do_load_unload()
2654 return (STp->buffer)->syscall_result; in do_load_unload()
2656 retval = (STp->buffer)->syscall_result; in do_load_unload()
2662 STp->rew_at_close = 0; in do_load_unload()
2663 STp->ready = ST_NO_TAPE; in do_load_unload()
2666 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2667 retval = check_tape(STp, filp); in do_load_unload()
2673 STps = &(STp->ps[STp->partition]); in do_load_unload()
2683 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) in deb_space_print() argument
2693 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n", in deb_space_print()
2699 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) … in deb_space_print() argument
2704 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg) in st_int_ioctl() argument
2716 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2717 if (STp->ready != ST_READY) { in st_int_ioctl()
2718 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2723 timeout = STp->long_timeout; in st_int_ioctl()
2724 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2740 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd); in st_int_ioctl()
2756 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd); in st_int_ioctl()
2768 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd); in st_int_ioctl()
2780 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd); in st_int_ioctl()
2791 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd); in st_int_ioctl()
2804 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd); in st_int_ioctl()
2813 if (STp->write_prot) in st_int_ioctl()
2819 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2824 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2827 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2833 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2846 if (STp->immediate) { in st_int_ioctl()
2848 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2850 DEBC_printk(STp, "Rewinding tape.\n"); in st_int_ioctl()
2854 DEBC_printk(STp, "No op on tape.\n"); in st_int_ioctl()
2858 if (STp->immediate) { in st_int_ioctl()
2860 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2863 DEBC_printk(STp, "Retensioning tape.\n"); in st_int_ioctl()
2867 if (!STp->fast_mteom) { in st_int_ioctl()
2869 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff); in st_int_ioctl()
2881 DEBC_printk(STp, "Spacing to end of recorded medium.\n"); in st_int_ioctl()
2886 if (STp->write_prot) in st_int_ioctl()
2890 if (STp->immediate) { in st_int_ioctl()
2892 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2895 timeout = STp->long_timeout * 8; in st_int_ioctl()
2897 DEBC_printk(STp, "Erasing tape.\n"); in st_int_ioctl()
2905 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in st_int_ioctl()
2909 STp->max_block > 0 && in st_int_ioctl()
2910 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || in st_int_ioctl()
2911 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { in st_int_ioctl()
2912 st_printk(KERN_WARNING, STp, "Illegal block size.\n"); in st_int_ioctl()
2916 if ((STp->use_pf & USE_PF)) in st_int_ioctl()
2921 memset((STp->buffer)->b_data, 0, 12); in st_int_ioctl()
2923 (STp->buffer)->b_data[2] = (arg & 7) << 4; in st_int_ioctl()
2925 (STp->buffer)->b_data[2] = in st_int_ioctl()
2926 STp->drv_buffer << 4; in st_int_ioctl()
2927 (STp->buffer)->b_data[3] = 8; /* block descriptor length */ in st_int_ioctl()
2929 (STp->buffer)->b_data[4] = arg; in st_int_ioctl()
2930 STp->density_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2932 (STp->buffer)->b_data[4] = arg >> 24; in st_int_ioctl()
2934 (STp->buffer)->b_data[4] = STp->density; in st_int_ioctl()
2938 STp->blksize_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2940 ltmp = STp->block_size; in st_int_ioctl()
2941 (STp->buffer)->b_data[9] = (ltmp >> 16); in st_int_ioctl()
2942 (STp->buffer)->b_data[10] = (ltmp >> 8); in st_int_ioctl()
2943 (STp->buffer)->b_data[11] = ltmp; in st_int_ioctl()
2944 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2947 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2949 (STp->buffer)->b_data[9] * 65536 + in st_int_ioctl()
2950 (STp->buffer)->b_data[10] * 256 + in st_int_ioctl()
2951 (STp->buffer)->b_data[11]); in st_int_ioctl()
2953 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2955 (STp->buffer)->b_data[4]); in st_int_ioctl()
2957 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2959 ((STp->buffer)->b_data[2] >> 4) & 7); in st_int_ioctl()
2966 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction, in st_int_ioctl()
2969 return (STp->buffer)->syscall_result; in st_int_ioctl()
2971 ioctl_result = (STp->buffer)->syscall_result; in st_int_ioctl()
2981 ioctl_result = st_int_ioctl(STp, MTFSF, 1); in st_int_ioctl()
2983 ioctl_result = st_int_ioctl(STp, MTBSF, 1); in st_int_ioctl()
2986 STp->block_size = arg & MT_ST_BLKSIZE_MASK; in st_int_ioctl()
2987 if (STp->block_size != 0) { in st_int_ioctl()
2988 (STp->buffer)->buffer_blocks = in st_int_ioctl()
2989 (STp->buffer)->buffer_size / STp->block_size; in st_int_ioctl()
2991 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in st_int_ioctl()
2993 STp->density = arg >> MT_ST_DENSITY_SHIFT; in st_int_ioctl()
2995 STp->drv_buffer = (arg & 7); in st_int_ioctl()
2997 STp->density = arg; in st_int_ioctl()
3010 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_int_ioctl()
3085 !(STp->use_pf & PF_TESTED)) { in st_int_ioctl()
3088 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED; in st_int_ioctl()
3091 return st_int_ioctl(STp, cmd_in, arg); in st_int_ioctl()
3110 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition, in get_location() argument
3117 if (STp->ready != ST_READY) in get_location()
3121 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3126 if (!logical && !STp->scsi2_logical) in get_location()
3129 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE, in get_location()
3130 STp->device->request_queue->rq_timeout, in get_location()
3133 return (STp->buffer)->syscall_result; in get_location()
3135 if ((STp->buffer)->syscall_result != 0 || in get_location()
3136 (STp->device->scsi_level >= SCSI_2 && in get_location()
3137 ((STp->buffer)->b_data[0] & 4) != 0)) { in get_location()
3139 DEBC_printk(STp, " Can't read tape position.\n"); in get_location()
3143 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3144 *block = ((STp->buffer)->b_data[0] << 16) in get_location()
3145 + ((STp->buffer)->b_data[1] << 8) in get_location()
3146 + (STp->buffer)->b_data[2]; in get_location()
3149 *block = ((STp->buffer)->b_data[4] << 24) in get_location()
3150 + ((STp->buffer)->b_data[5] << 16) in get_location()
3151 + ((STp->buffer)->b_data[6] << 8) in get_location()
3152 + (STp->buffer)->b_data[7]; in get_location()
3153 *partition = (STp->buffer)->b_data[1]; in get_location()
3154 if (((STp->buffer)->b_data[0] & 0x80) && in get_location()
3155 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ in get_location()
3156 STp->ps[0].drv_block = STp->ps[0].drv_file = 0; in get_location()
3158 DEBC_printk(STp, "Got tape pos. blk %d part %d.\n", in get_location()
3170 static int set_location(struct scsi_tape *STp, unsigned int block, int partition, in set_location() argument
3180 if (STp->ready != ST_READY) in set_location()
3182 timeout = STp->long_timeout; in set_location()
3183 STps = &(STp->ps[STp->partition]); in set_location()
3185 DEBC_printk(STp, "Setting block to %d and partition to %d.\n", in set_location()
3191 if ((!STp->can_partitions && partition != 0) || in set_location()
3194 if (partition != STp->partition) { in set_location()
3195 if (get_location(STp, &blk, &p, 1)) in set_location()
3200 DEBC_printk(STp, "Visited block %d for " in set_location()
3202 blk, STp->partition); in set_location()
3207 if ((STp->device)->scsi_level < SCSI_2) { in set_location()
3219 if (!logical && !STp->scsi2_logical) in set_location()
3221 if (STp->partition != partition) { in set_location()
3224 DEBC_printk(STp, "Trying to change partition " in set_location()
3225 "from %d to %d\n", STp->partition, in set_location()
3229 if (STp->immediate) { in set_location()
3231 timeout = STp->device->request_queue->rq_timeout; in set_location()
3234 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in set_location()
3237 return (STp->buffer)->syscall_result; in set_location()
3241 if ((STp->buffer)->syscall_result != 0) { in set_location()
3243 if (STp->can_partitions && in set_location()
3244 (STp->device)->scsi_level >= SCSI_2 && in set_location()
3245 (p = find_partition(STp)) >= 0) in set_location()
3246 STp->partition = p; in set_location()
3248 if (STp->can_partitions) { in set_location()
3249 STp->partition = partition; in set_location()
3250 STps = &(STp->ps[partition]); in set_location()
3272 static int find_partition(struct scsi_tape *STp) in find_partition() argument
3277 if ((i = get_location(STp, &block, &partition, 1)) < 0) in find_partition()
3286 static int switch_partition(struct scsi_tape *STp) in switch_partition() argument
3290 if (STp->partition == STp->new_partition) in switch_partition()
3292 STps = &(STp->ps[STp->new_partition]); in switch_partition()
3295 return set_location(STp, STps->last_block_visited, STp->new_partition, 1); in switch_partition()
3317 static int nbr_partitions(struct scsi_tape *STp) in nbr_partitions() argument
3321 if (STp->ready != ST_READY) in nbr_partitions()
3324 result = read_mode_page(STp, PART_PAGE, 1); in nbr_partitions()
3327 DEBC_printk(STp, "Can't read medium partition page.\n"); in nbr_partitions()
3330 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + in nbr_partitions()
3332 DEBC_printk(STp, "Number of partitions %d.\n", result); in nbr_partitions()
3339 static int format_medium(struct scsi_tape *STp, int format) in format_medium() argument
3342 int timeout = STp->long_timeout; in format_medium()
3349 if (STp->immediate) { in format_medium()
3351 timeout = STp->device->request_queue->rq_timeout; in format_medium()
3353 DEBC_printk(STp, "Sending FORMAT MEDIUM\n"); in format_medium()
3354 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in format_medium()
3357 result = STp->buffer->syscall_result; in format_medium()
3383 static int partition_tape(struct scsi_tape *STp, int size) in partition_tape() argument
3387 bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false; in partition_tape()
3392 result = read_mode_page(STp, PART_PAGE, 0); in partition_tape()
3394 DEBC_printk(STp, "Can't read partition mode page.\n"); in partition_tape()
3404 bp = (STp->buffer)->b_data; in partition_tape()
3406 DEBC_printk(STp, "Partition page length is %d bytes.\n", in partition_tape()
3417 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3418 result = format_medium(STp, 0); in partition_tape()
3460 DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n", in partition_tape()
3468 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3477 DEBC_printk(STp, in partition_tape()
3492 result = write_mode_page(STp, PART_PAGE, 1); in partition_tape()
3495 result = format_medium(STp, 1); in partition_tape()
3498 st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n"); in partition_tape()
3516 struct scsi_tape *STp = file->private_data; in st_ioctl() local
3520 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl()
3524 if (debugging && !STp->in_use) { in st_ioctl()
3525 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n"); in st_ioctl()
3530 STm = &(STp->modes[STp->current_mode]); in st_ioctl()
3531 STps = &(STp->ps[STp->partition]); in st_ioctl()
3539 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl()
3562 st_printk(KERN_WARNING, STp, in st_ioctl()
3574 if (!STp->pos_unknown) { in st_ioctl()
3592 i = !STp->can_partitions || in st_ioctl()
3593 (STp->new_partition != STp->partition); in st_ioctl()
3602 i = flush_buffer(STp, i); in st_ioctl()
3611 i = st_int_ioctl(STp, MTWEOF, 1); in st_ioctl()
3637 reset_state(STp); in st_ioctl()
3639 STp->device->was_reset = 0; in st_ioctl()
3647 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl()
3648 do_door_lock(STp, 0); /* Ignore result! */ in st_ioctl()
3652 retval = st_set_options(STp, mtc.mt_count); in st_ioctl()
3657 if (!STp->can_partitions || in st_ioctl()
3662 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl()
3663 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl()
3667 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl()
3671 STp->new_partition = mtc.mt_count; in st_ioctl()
3677 if (!STp->can_partitions) { in st_ioctl()
3681 i = do_load_unload(STp, file, 1); in st_ioctl()
3686 i = partition_tape(STp, mtc.mt_count); in st_ioctl()
3692 STp->ps[i].rw = ST_IDLE; in st_ioctl()
3693 STp->ps[i].at_sm = 0; in st_ioctl()
3694 STp->ps[i].last_block_valid = 0; in st_ioctl()
3696 STp->partition = STp->new_partition = 0; in st_ioctl()
3697 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl()
3704 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl()
3705 if (!STp->can_partitions) in st_ioctl()
3706 STp->ps[0].rw = ST_IDLE; in st_ioctl()
3712 retval = do_load_unload(STp, file, 0); in st_ioctl()
3717 retval = do_load_unload(STp, file, max(1, mtc.mt_count)); in st_ioctl()
3722 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK)); in st_ioctl()
3726 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl()
3727 (i = switch_partition(STp)) < 0) { in st_ioctl()
3733 retval = st_compression(STp, (mtc.mt_count & 1)); in st_ioctl()
3735 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count); in st_ioctl()
3745 if ((i = flush_buffer(STp, 0)) < 0) { in st_ioctl()
3746 if (cmd_mtiocget && STp->pos_unknown) { in st_ioctl()
3748 reset_state(STp); in st_ioctl()
3749 STp->pos_unknown = 1; in st_ioctl()
3755 if (STp->can_partitions) { in st_ioctl()
3756 i = switch_partition(STp); in st_ioctl()
3772 mt_status.mt_type = STp->tape_type; in st_ioctl()
3774 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl()
3775 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl()
3778 if (STp->block_size != 0 && mt_status.mt_blkno >= 0) { in st_ioctl()
3781 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl()
3784 ((STp->buffer)->buffer_bytes + in st_ioctl()
3785 STp->block_size - 1) / STp->block_size; in st_ioctl()
3789 if (STp->drv_write_prot) in st_ioctl()
3797 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl()
3798 mt_status.mt_resid = STp->partition; in st_ioctl()
3803 if (STp->density == 1) in st_ioctl()
3805 else if (STp->density == 2) in st_ioctl()
3807 else if (STp->density == 3) in st_ioctl()
3809 if (STp->ready == ST_READY) in st_ioctl()
3811 if (STp->ready == ST_NO_TAPE) in st_ioctl()
3816 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl()
3817 STp->drv_buffer != 0) in st_ioctl()
3819 if (STp->cleaning_req) in st_ioctl()
3826 STp->recover_reg = 0; /* Clear after read */ in st_ioctl()
3835 if ((i = get_location(STp, &blk, &bt, 0)) < 0) { in st_ioctl()
3843 mutex_unlock(&STp->lock); in st_ioctl()
3856 retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, cmd_in, p); in st_ioctl()
3859 STp->rew_at_close = 0; in st_ioctl()
3860 STp->ready = ST_NO_TAPE; in st_ioctl()
3865 mutex_unlock(&STp->lock); in st_ioctl()
4641 struct scsi_tape *STp = STm->tape; in options_show() local
4649 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4650 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4652 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4653 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4654 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4655 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4657 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4658 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4659 options |= STp->sili ? MT_ST_SILI : 0; in options_show()