Lines Matching full:stp

244 	struct scsi_tape *STp = NULL;  in scsi_tape_get()  local
249 STp = idr_find(&st_index_idr, dev); in scsi_tape_get()
250 if (!STp) goto out; in scsi_tape_get()
252 kref_get(&STp->kref); in scsi_tape_get()
254 if (!STp->device) in scsi_tape_get()
257 if (scsi_device_get(STp->device)) in scsi_tape_get()
263 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_get()
264 STp = NULL; in scsi_tape_get()
268 return STp; in scsi_tape_get()
271 static void scsi_tape_put(struct scsi_tape *STp) in scsi_tape_put() argument
273 struct scsi_device *sdev = STp->device; in scsi_tape_put()
276 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_put()
356 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) in st_chk_result() argument
360 DEB(const char *stp;) in st_chk_result()
361 char *name = STp->name; in st_chk_result()
367 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
371 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
377 st_printk(ST_DEB_MSG, STp, in st_chk_result()
382 __scsi_print_sense(STp->device, name, in st_chk_result()
387 st_printk(KERN_WARNING, STp, in st_chk_result()
399 __scsi_print_sense(STp->device, name, in st_chk_result()
405 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
406 if (STp->cln_sense_value) in st_chk_result()
407 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
408 STp->cln_sense_mask) == STp->cln_sense_value); in st_chk_result()
410 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
411 STp->cln_sense_mask) != 0); in st_chk_result()
415 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
417 STp->pos_unknown = 1; /* ASC => power on / reset */ in st_chk_result()
419 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
428 STp->recover_count++; in st_chk_result()
429 STp->recover_reg++; in st_chk_result()
434 stp = "read"; in st_chk_result()
436 stp = "write"; in st_chk_result()
438 stp = "ioctl"; in st_chk_result()
439 st_printk(ST_DEB_MSG, STp, in st_chk_result()
441 stp, STp->recover_count); in st_chk_result()
450 static struct st_request *st_allocate_request(struct scsi_tape *stp) in st_allocate_request() argument
456 streq->stp = stp; in st_allocate_request()
458 st_printk(KERN_ERR, stp, in st_allocate_request()
461 stp->buffer->syscall_result = -EINTR; in st_allocate_request()
463 stp->buffer->syscall_result = -EBUSY; in st_allocate_request()
474 static void st_do_stats(struct scsi_tape *STp, struct request *req) in st_do_stats() argument
481 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
482 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
483 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
484 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
486 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
487 - STp->buffer->cmdstat.residual, in st_do_stats()
488 &STp->stats->write_byte_cnt); in st_do_stats()
489 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
490 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
492 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
493 &STp->stats->write_byte_cnt); in st_do_stats()
495 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
496 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time); in st_do_stats()
497 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
498 atomic64_inc(&STp->stats->read_cnt); in st_do_stats()
500 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
501 - STp->buffer->cmdstat.residual, in st_do_stats()
502 &STp->stats->read_byte_cnt); in st_do_stats()
503 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
504 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
506 atomic64_add(atomic_read(&STp->stats->last_read_size), in st_do_stats()
507 &STp->stats->read_byte_cnt); in st_do_stats()
509 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
510 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
511 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
513 atomic64_dec(&STp->stats->in_flight); in st_do_stats()
521 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end() local
524 STp->buffer->cmdstat.midlevel_result = SRpnt->result = scmd->result; in st_scsi_execute_end()
525 STp->buffer->cmdstat.residual = scmd->resid_len; in st_scsi_execute_end()
527 st_do_stats(STp, req); in st_scsi_execute_end()
545 struct rq_map_data *mdata = &SRpnt->stp->buffer->map_data; in st_scsi_execute()
547 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute() local
550 req = scsi_alloc_request(SRpnt->stp->device->request_queue, in st_scsi_execute()
569 atomic64_inc(&STp->stats->in_flight); in st_scsi_execute()
571 atomic_set(&STp->stats->last_write_size, bufflen); in st_scsi_execute()
572 STp->stats->write_time = ktime_get(); in st_scsi_execute()
574 atomic_set(&STp->stats->last_read_size, bufflen); in st_scsi_execute()
575 STp->stats->read_time = ktime_get(); in st_scsi_execute()
577 STp->stats->other_time = ktime_get(); in st_scsi_execute()
596 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, in st_do_scsi() argument
600 struct rq_map_data *mdata = &STp->buffer->map_data; in st_do_scsi()
604 if (!do_wait && ((STp->buffer)->last_SRpnt)) { in st_do_scsi()
605 st_printk(KERN_ERR, STp, in st_do_scsi()
608 (STp->buffer)->syscall_result = (-EINTR); in st_do_scsi()
610 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
615 SRpnt = st_allocate_request(STp); in st_do_scsi()
623 (STp->buffer)->last_SRpnt = SRpnt; in st_do_scsi()
625 waiting = &STp->wait; in st_do_scsi()
629 if (STp->buffer->do_dio) { in st_do_scsi()
631 mdata->nr_entries = STp->buffer->sg_segs; in st_do_scsi()
632 mdata->pages = STp->buffer->mapped_pages; in st_do_scsi()
634 mdata->page_order = STp->buffer->reserved_page_order; in st_do_scsi()
637 mdata->pages = STp->buffer->reserved_pages; in st_do_scsi()
642 STp->buffer->cmdstat.have_sense = 0; in st_do_scsi()
643 STp->buffer->syscall_result = 0; in st_do_scsi()
649 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
650 (STp->buffer)->last_SRpnt = NULL; in st_do_scsi()
654 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in st_do_scsi()
665 static int write_behind_check(struct scsi_tape * STp) in write_behind_check() argument
673 STbuffer = STp->buffer; in write_behind_check()
678 if (STp->write_pending) in write_behind_check()
679 STp->nbr_waits++; in write_behind_check()
681 STp->nbr_finished++; in write_behind_check()
684 wait_for_completion(&(STp->wait)); in write_behind_check()
689 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in write_behind_check()
693 STps = &(STp->ps[STp->partition]); in write_behind_check()
695 if (STp->block_size == 0) in write_behind_check()
698 STps->drv_block += STbuffer->writing / STp->block_size; in write_behind_check()
719 st_printk(ST_DEB_MSG, STp, in write_behind_check()
729 static int cross_eof(struct scsi_tape * STp, int forward) in cross_eof() argument
743 DEBC_printk(STp, "Stepping over filemark %s.\n", in cross_eof()
746 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in cross_eof()
747 STp->device->request_queue->rq_timeout, in cross_eof()
750 return (STp->buffer)->syscall_result; in cross_eof()
755 if ((STp->buffer)->cmdstat.midlevel_result != 0) in cross_eof()
756 st_printk(KERN_ERR, STp, in cross_eof()
760 return (STp->buffer)->syscall_result; in cross_eof()
765 static int st_flush_write_buffer(struct scsi_tape * STp) in st_flush_write_buffer() argument
773 result = write_behind_check(STp); in st_flush_write_buffer()
778 if (STp->dirty == 1) { in st_flush_write_buffer()
780 transfer = STp->buffer->buffer_bytes; in st_flush_write_buffer()
781 DEBC_printk(STp, "Flushing %d bytes.\n", transfer); in st_flush_write_buffer()
786 blks = transfer / STp->block_size; in st_flush_write_buffer()
791 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE, in st_flush_write_buffer()
792 STp->device->request_queue->rq_timeout, in st_flush_write_buffer()
795 return (STp->buffer)->syscall_result; in st_flush_write_buffer()
797 STps = &(STp->ps[STp->partition]); in st_flush_write_buffer()
798 if ((STp->buffer)->syscall_result != 0) { in st_flush_write_buffer()
799 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush_write_buffer()
807 STp->dirty = 0; in st_flush_write_buffer()
808 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
813 st_printk(KERN_ERR, STp, "Error on flush.\n"); in st_flush_write_buffer()
820 STp->dirty = 0; in st_flush_write_buffer()
821 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
832 static int flush_buffer(struct scsi_tape *STp, int seek_next) in flush_buffer() argument
837 if (STp->ready != ST_READY) in flush_buffer()
844 if (STp->pos_unknown) in flush_buffer()
847 STps = &(STp->ps[STp->partition]); in flush_buffer()
849 return st_flush_write_buffer(STp); in flush_buffer()
851 if (STp->block_size == 0) in flush_buffer()
854 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
855 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
856 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
857 STp->block_size; in flush_buffer()
858 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
859 (STp->buffer)->read_pointer = 0; in flush_buffer()
863 result = cross_eof(STp, 0); /* Back over the EOF hit */ in flush_buffer()
873 result = st_int_ioctl(STp, MTBSR, backspace); in flush_buffer()
885 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) in set_mode_densblk() argument
890 if (!STp->density_changed && in set_mode_densblk()
892 STm->default_density != STp->density) { in set_mode_densblk()
896 arg = STp->density; in set_mode_densblk()
898 if (!STp->blksize_changed && in set_mode_densblk()
900 STm->default_blksize != STp->block_size) { in set_mode_densblk()
904 arg |= STp->block_size; in set_mode_densblk()
906 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { in set_mode_densblk()
907 st_printk(KERN_WARNING, STp, in set_mode_densblk()
919 static int do_door_lock(struct scsi_tape * STp, int do_lock) in do_door_lock() argument
923 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); in do_door_lock()
925 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
928 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
930 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
936 static void reset_state(struct scsi_tape *STp) in reset_state() argument
941 STp->pos_unknown = 0; in reset_state()
943 STps = &(STp->ps[i]); in reset_state()
951 if (STp->can_partitions) { in reset_state()
952 STp->partition = find_partition(STp); in reset_state()
953 if (STp->partition < 0) in reset_state()
954 STp->partition = 0; in reset_state()
955 STp->new_partition = STp->partition; in reset_state()
968 static int test_ready(struct scsi_tape *STp, int do_wait) in test_ready() argument
974 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
981 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, in test_ready()
982 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
985 retval = (STp->buffer)->syscall_result; in test_ready()
1015 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
1025 retval = (STp->buffer)->syscall_result; in test_ready()
1042 static int check_tape(struct scsi_tape *STp, struct file *filp) in check_tape() argument
1053 STp->ready = ST_READY; in check_tape()
1055 if (mode != STp->current_mode) { in check_tape()
1056 DEBC_printk(STp, "Mode change from %d to %d.\n", in check_tape()
1057 STp->current_mode, mode); in check_tape()
1059 STp->current_mode = mode; in check_tape()
1061 STm = &(STp->modes[STp->current_mode]); in check_tape()
1063 saved_cleaning = STp->cleaning_req; in check_tape()
1064 STp->cleaning_req = 0; in check_tape()
1067 retval = test_ready(STp, do_wait); in check_tape()
1073 STp->pos_unknown = 0; in check_tape()
1074 STp->partition = STp->new_partition = 0; in check_tape()
1075 if (STp->can_partitions) in check_tape()
1076 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1079 STps = &(STp->ps[i]); in check_tape()
1090 STp->cleaning_req |= saved_cleaning; in check_tape()
1094 STp->ready = ST_NO_TAPE; in check_tape()
1096 STp->ready = ST_NOT_READY; in check_tape()
1098 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1099 STp->write_prot = 0; in check_tape()
1100 STp->block_size = 0; in check_tape()
1101 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1102 STp->partition = STp->new_partition = 0; in check_tape()
1103 STp->door_locked = ST_UNLOCKED; in check_tape()
1108 if (STp->omit_blklims) in check_tape()
1109 STp->min_block = STp->max_block = (-1); in check_tape()
1114 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE, in check_tape()
1115 STp->device->request_queue->rq_timeout, in check_tape()
1118 retval = (STp->buffer)->syscall_result; in check_tape()
1122 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1123 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1124 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1125 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1126 (STp->buffer)->b_data[5]; in check_tape()
1127 if ( DEB( debugging || ) !STp->inited) in check_tape()
1128 st_printk(KERN_INFO, STp, in check_tape()
1130 STp->min_block, STp->max_block); in check_tape()
1132 STp->min_block = STp->max_block = (-1); in check_tape()
1133 DEBC_printk(STp, "Can't read block limits.\n"); in check_tape()
1141 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE, in check_tape()
1142 STp->device->request_queue->rq_timeout, in check_tape()
1145 retval = (STp->buffer)->syscall_result; in check_tape()
1149 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1150 DEBC_printk(STp, "No Mode Sense.\n"); in check_tape()
1151 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1152 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1153 STp->drv_write_prot = 0; in check_tape()
1155 DEBC_printk(STp,"Mode sense. Length %d, " in check_tape()
1157 (STp->buffer)->b_data[0], in check_tape()
1158 (STp->buffer)->b_data[1], in check_tape()
1159 (STp->buffer)->b_data[2], in check_tape()
1160 (STp->buffer)->b_data[3]); in check_tape()
1162 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1163 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1164 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1165 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1166 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1167 DEBC_printk(STp, "Density %x, tape length: %x, " in check_tape()
1169 STp->density, in check_tape()
1170 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1171 (STp->buffer)->b_data[6] * 256 + in check_tape()
1172 (STp->buffer)->b_data[7], in check_tape()
1173 STp->drv_buffer); in check_tape()
1175 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1176 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1177 st_printk(KERN_WARNING, STp, in check_tape()
1180 STp->immediate_filemark = 0; in check_tape()
1185 STp->inited = 1; in check_tape()
1187 if (STp->block_size > 0) in check_tape()
1188 (STp->buffer)->buffer_blocks = in check_tape()
1189 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1191 (STp->buffer)->buffer_blocks = 1; in check_tape()
1192 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1194 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n", in check_tape()
1195 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1196 (STp->buffer)->buffer_blocks); in check_tape()
1198 if (STp->drv_write_prot) { in check_tape()
1199 STp->write_prot = 1; in check_tape()
1201 DEBC_printk(STp, "Write protected\n"); in check_tape()
1211 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1215 DEBC_printk(STp, "Updating partition number in status.\n"); in check_tape()
1216 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1217 retval = STp->partition; in check_tape()
1220 STp->new_partition = STp->partition; in check_tape()
1221 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1225 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1226 STp->compression_changed = 0; in check_tape()
1228 (retval = set_mode_densblk(STp, STm)) < 0) in check_tape()
1231 if (STp->default_drvbuffer != 0xff) { in check_tape()
1232 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1233 st_printk(KERN_WARNING, STp, in check_tape()
1236 STp->default_drvbuffer); in check_tape()
1253 struct scsi_tape *STp; in st_open() local
1264 if (!(STp = scsi_tape_get(dev))) { in st_open()
1268 filp->private_data = STp; in st_open()
1271 if (STp->in_use) { in st_open()
1273 DEBC_printk(STp, "Device already in use.\n"); in st_open()
1274 scsi_tape_put(STp); in st_open()
1278 STp->in_use = 1; in st_open()
1280 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1282 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1287 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1293 if (!enlarge_buffer(STp->buffer, PAGE_SIZE)) { in st_open()
1294 st_printk(KERN_WARNING, STp, in st_open()
1300 (STp->buffer)->cleared = 0; in st_open()
1301 (STp->buffer)->writing = 0; in st_open()
1302 (STp->buffer)->syscall_result = 0; in st_open()
1304 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1306 STp->dirty = 0; in st_open()
1308 STps = &(STp->ps[i]); in st_open()
1311 STp->try_dio_now = STp->try_dio; in st_open()
1312 STp->recover_count = 0; in st_open()
1313 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1314 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1316 retval = check_tape(STp, filp); in st_open()
1321 if (STp->ready == NO_TAPE) in st_open()
1330 normalize_buffer(STp->buffer); in st_open()
1332 STp->in_use = 0; in st_open()
1335 scsi_autopm_put_device(STp->device); in st_open()
1336 scsi_tape_put(STp); in st_open()
1348 struct scsi_tape *STp = filp->private_data; in st_flush() local
1349 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1350 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1355 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1356 result = st_flush_write_buffer(STp); in st_flush()
1361 if (STp->can_partitions && in st_flush()
1362 (result2 = switch_partition(STp)) < 0) { in st_flush()
1363 DEBC_printk(STp, "switch_partition at close failed.\n"); in st_flush()
1369 DEBC( if (STp->nbr_requests) in st_flush()
1370 st_printk(KERN_DEBUG, STp, in st_flush()
1372 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1373 STp->nbr_pages)); in st_flush()
1375 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1376 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1379 DEBC_printk(STp, "Async write waits %d, finished %d.\n", in st_flush()
1380 STp->nbr_waits, STp->nbr_finished); in st_flush()
1384 if (STp->immediate_filemark) in st_flush()
1386 cmd[4] = 1 + STp->two_fm; in st_flush()
1388 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in st_flush()
1389 STp->device->request_queue->rq_timeout, in st_flush()
1392 result = (STp->buffer)->syscall_result; in st_flush()
1396 if (STp->buffer->syscall_result == 0 || in st_flush()
1408 if (STp->two_fm) in st_flush()
1409 cross_eof(STp, 0); in st_flush()
1415 st_printk(KERN_ERR, STp, in st_flush()
1421 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]); in st_flush()
1422 } else if (!STp->rew_at_close) { in st_flush()
1423 STps = &(STp->ps[STp->partition]); in st_flush()
1425 if (STp->can_bsr) in st_flush()
1426 result = flush_buffer(STp, 0); in st_flush()
1428 result = cross_eof(STp, 0); in st_flush()
1438 !(result = cross_eof(STp, 1))) || in st_flush()
1448 if (STp->rew_at_close) { in st_flush()
1449 result2 = st_int_ioctl(STp, MTREW, 1); in st_flush()
1461 struct scsi_tape *STp = filp->private_data; in st_release() local
1463 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1464 do_door_lock(STp, 0); in st_release()
1466 normalize_buffer(STp->buffer); in st_release()
1468 STp->in_use = 0; in st_release()
1470 scsi_autopm_put_device(STp->device); in st_release()
1471 scsi_tape_put(STp); in st_release()
1477 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) in rw_checks() argument
1487 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1492 if (STp->ready != ST_READY) { in rw_checks()
1493 if (STp->ready == ST_NO_TAPE) in rw_checks()
1500 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1510 if (STp->pos_unknown) { in rw_checks()
1519 if (!STp->in_use) { in rw_checks()
1520 st_printk(ST_DEB_MSG, STp, in rw_checks()
1526 if (STp->can_partitions && in rw_checks()
1527 (retval = switch_partition(STp)) < 0) in rw_checks()
1530 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1531 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1536 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1537 !do_door_lock(STp, 1)) in rw_checks()
1538 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1545 static int setup_buffering(struct scsi_tape *STp, const char __user *buf, in setup_buffering() argument
1549 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1552 i = STp->try_dio_now && try_rdio; in setup_buffering()
1554 i = STp->try_dio_now && try_wdio; in setup_buffering()
1557 STp->device->request_queue)) == 0) { in setup_buffering()
1569 STp->nbr_dio++; in setup_buffering()
1570 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1575 DEB( STp->nbr_requests++; ) in setup_buffering()
1578 if (STp->block_size) in setup_buffering()
1579 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1580 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1585 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1591 st_printk(KERN_WARNING, STp, in setup_buffering()
1597 if (STp->block_size) in setup_buffering()
1598 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1607 static void release_buffering(struct scsi_tape *STp, int is_read) in release_buffering() argument
1611 STbp = STp->buffer; in release_buffering()
1632 struct scsi_tape *STp = filp->private_data; in st_write() local
1637 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1640 retval = rw_checks(STp, filp, count); in st_write()
1645 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1646 st_printk(KERN_WARNING, STp, in st_write()
1652 STm = &(STp->modes[STp->current_mode]); in st_write()
1653 STps = &(STp->ps[STp->partition]); in st_write()
1655 if (STp->write_prot) { in st_write()
1662 retval = flush_buffer(STp, 0); in st_write()
1668 if ((retval = set_mode_densblk(STp, STm)) < 0) in st_write()
1671 !(STp->compression_changed)) { in st_write()
1672 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1673 st_printk(KERN_WARNING, STp, in st_write()
1683 STbp = STp->buffer; in st_write()
1684 i = write_behind_check(STp); in st_write()
1704 if (STp->block_size != 0 && in st_write()
1712 retval = setup_buffering(STp, buf, count, 0); in st_write()
1720 cmd[1] = (STp->block_size != 0); in st_write()
1731 if (STp->block_size == 0) in st_write()
1734 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1749 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1752 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1753 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1755 STp->dirty = 1; in st_write()
1762 if (STp->block_size == 0) in st_write()
1769 blks /= STp->block_size; in st_write()
1770 transfer = blks * STp->block_size; in st_write()
1776 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE, in st_write()
1777 STp->device->request_queue->rq_timeout, in st_write()
1785 STp->dirty = !(STbp->writing == in st_write()
1788 DEB( STp->write_pending = 1; ) in st_write()
1793 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1795 DEBC_printk(STp, "Error on write:\n"); in st_write()
1800 else if (STp->block_size == 0 && in st_write()
1805 if (STp->block_size != 0) in st_write()
1806 undone *= STp->block_size; in st_write()
1812 if (STp->block_size) in st_write()
1813 blks = (transfer - undone) / STp->block_size; in st_write()
1819 if (STp->block_size == 0 || in st_write()
1822 DEBC_printk(STp, "EOM with %d " in st_write()
1830 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1834 STp->block_size; in st_write()
1837 DEBC_printk(STp, "Retry " in st_write()
1840 STp->buffer->buffer_bytes); in st_write()
1851 DEBC_printk(STp, "EOM with " in st_write()
1864 if (STp->block_size == 0) in st_write()
1871 STp->dirty = 0; in st_write()
1889 release_buffering(STp, 0); in st_write()
1890 mutex_unlock(&STp->lock); in st_write()
1901 static long read_tape(struct scsi_tape *STp, long count, in read_tape() argument
1915 STm = &(STp->modes[STp->current_mode]); in read_tape()
1916 STps = &(STp->ps[STp->partition]); in read_tape()
1919 STbp = STp->buffer; in read_tape()
1921 if (STp->block_size == 0) in read_tape()
1924 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1925 blks = (STp->buffer)->buffer_blocks; in read_tape()
1926 bytes = blks * STp->block_size; in read_tape()
1929 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1930 bytes = (STp->buffer)->buffer_size; in read_tape()
1931 blks = bytes / STp->block_size; in read_tape()
1932 bytes = blks * STp->block_size; in read_tape()
1938 cmd[1] = (STp->block_size != 0); in read_tape()
1939 if (!cmd[1] && STp->sili) in read_tape()
1946 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, in read_tape()
1947 STp->device->request_queue->rq_timeout, in read_tape()
1949 release_buffering(STp, 1); in read_tape()
1959 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1962 DEBC_printk(STp, in read_tape()
1980 if (STp->block_size == 0) in read_tape()
1987 if (STp->block_size == 0 && in read_tape()
1989 st_printk(KERN_NOTICE, STp, in read_tape()
1999 } else if (STp->block_size == 0) { in read_tape()
2005 st_printk(KERN_NOTICE, STp, in read_tape()
2010 st_int_ioctl(STp, MTBSR, 1); in read_tape()
2015 STp->block_size; in read_tape()
2016 DEBC_printk(STp, "ILI but " in read_tape()
2023 if (st_int_ioctl(STp, MTBSR, 1)) in read_tape()
2031 if (STp->block_size == 0) in read_tape()
2035 bytes - transfer * STp->block_size; in read_tape()
2036 DEBC_printk(STp, "EOF detected (%d " in read_tape()
2044 if (STp->block_size == 0) in read_tape()
2048 bytes - transfer * STp->block_size; in read_tape()
2050 DEBC_printk(STp, "EOM detected (%d " in read_tape()
2057 DEBC_printk(STp, "Tape error while reading.\n"); in read_tape()
2061 DEBC_printk(STp, "Zero returned for " in read_tape()
2081 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2082 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2086 if (STp->block_size == 0) in read_tape()
2089 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2104 struct scsi_tape *STp = filp->private_data; in st_read() local
2107 struct st_buffer *STbp = STp->buffer; in st_read()
2109 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2112 retval = rw_checks(STp, filp, count); in st_read()
2116 STm = &(STp->modes[STp->current_mode]); in st_read()
2117 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2122 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2125 STps = &(STp->ps[STp->partition]); in st_read()
2127 retval = flush_buffer(STp, 0); in st_read()
2134 st_printk(ST_DEB_MSG, STp, in st_read()
2139 retval = setup_buffering(STp, buf, count, 1); in st_read()
2175 special = read_tape(STp, count - total, &SRpnt); in st_read()
2186 st_printk(ST_DEB_MSG, STp, in st_read()
2204 if (STp->block_size == 0) in st_read()
2234 release_buffering(STp, 1); in st_read()
2237 mutex_unlock(&STp->lock); in st_read()
2246 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm) in DEB() argument
2249 st_printk(KERN_INFO, STp, in DEB()
2252 STp->current_mode, STm->do_buffer_writes, in DEB()
2254 st_printk(KERN_INFO, STp, in DEB()
2257 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2258 STp->do_auto_lock); in DEB()
2259 st_printk(KERN_INFO, STp, in DEB()
2262 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2263 STp->can_partitions, STp->scsi2_logical); in DEB()
2264 st_printk(KERN_INFO, STp, in DEB()
2267 STm->sysv, STp->immediate, STp->sili, in DEB()
2268 STp->immediate_filemark); in DEB()
2269 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging); in DEB()
2275 static int st_set_options(struct scsi_tape *STp, long options)
2283 STm = &(STp->modes[STp->current_mode]);
2289 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2295 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2296 STp->current_mode);
2305 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2306 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2307 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2308 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2309 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2310 if ((STp->device)->scsi_level >= SCSI_2)
2311 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2312 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2313 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2314 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2316 STp->sili = (options & MT_ST_SILI) != 0;
2318 st_log_options(STp, STm); )
2330 STp->two_fm = value;
2332 STp->fast_mteom = value;
2334 STp->do_auto_lock = value;
2336 STp->can_bsr = value;
2338 STp->omit_blklims = value;
2339 if ((STp->device)->scsi_level >= SCSI_2 &&
2341 STp->can_partitions = value;
2343 STp->scsi2_logical = value;
2345 STp->immediate = value;
2347 STp->immediate_filemark = value;
2351 STp->sili = value;
2355 st_log_options(STp, STm); )
2362 DEBC_printk(STp, "Default block size disabled.\n");
2365 DEBC_printk(STp,"Default block size set to "
2367 if (STp->ready == ST_READY) {
2368 STp->blksize_changed = 0;
2369 set_mode_densblk(STp, STm);
2375 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2376 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2379 blk_queue_rq_timeout(STp->device->request_queue,
2381 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2390 STp->cln_mode = value;
2391 STp->cln_sense_mask = (options >> 8) & 0xff;
2392 STp->cln_sense_value = (options >> 16) & 0xff;
2393 st_printk(KERN_INFO, STp,
2395 value, STp->cln_sense_mask, STp->cln_sense_value);
2402 DEBC_printk(STp,
2406 DEBC_printk(STp, "Density default set to %x\n",
2408 if (STp->ready == ST_READY) {
2409 STp->density_changed = 0;
2410 set_mode_densblk(STp, STm);
2415 STp->default_drvbuffer = 0xff;
2416 DEBC_printk(STp,
2419 STp->default_drvbuffer = value & 7;
2420 DEBC_printk(STp,
2422 STp->default_drvbuffer);
2423 if (STp->ready == ST_READY)
2424 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2429 DEBC_printk(STp,
2433 STp->c_algo = (value & 0xff00) >> 8;
2434 DEBC_printk(STp, "Compression "
2436 STp->c_algo);
2440 DEBC_printk(STp, "Compression default "
2443 if (STp->ready == ST_READY) {
2444 STp->compression_changed = 0;
2445 st_compression(STp, (STm->default_compression == ST_YES));
2478 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) in read_mode_page() argument
2490 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE, in read_mode_page()
2491 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2493 return (STp->buffer)->syscall_result; in read_mode_page()
2497 return STp->buffer->syscall_result; in read_mode_page()
2503 static int write_mode_page(struct scsi_tape *STp, int page, int slow) in write_mode_page() argument
2513 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2514 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2517 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2518 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2519 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2520 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2523 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2524 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE, in write_mode_page()
2527 return (STp->buffer)->syscall_result; in write_mode_page()
2531 return STp->buffer->syscall_result; in write_mode_page()
2552 static int st_compression(struct scsi_tape * STp, int state) in st_compression() argument
2556 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2558 if (STp->ready != ST_READY) in st_compression()
2562 retval = read_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2564 DEBC_printk(STp, "Compression mode page not supported.\n"); in st_compression()
2569 DEBC_printk(STp, "Compression state is %d.\n", in st_compression()
2574 DEBC_printk(STp, "Compression not supported.\n"); in st_compression()
2581 if (STp->c_algo != 0) in st_compression()
2582 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2586 if (STp->c_algo != 0) in st_compression()
2590 retval = write_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2592 DEBC_printk(STp, "Compression change failed.\n"); in st_compression()
2595 DEBC_printk(STp, "Compression state changed to %d.\n", state); in st_compression()
2597 STp->compression_changed = 1; in st_compression()
2603 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) in do_load_unload() argument
2610 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2611 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2626 DEBC_printk(STp, " Enhanced %sload slot %2d.\n", in do_load_unload()
2631 if (STp->immediate) { in do_load_unload()
2633 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2636 timeout = STp->long_timeout; in do_load_unload()
2640 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n"); in do_load_unload()
2642 st_printk(ST_DEB_MSG, STp, "Loading tape.\n"); in do_load_unload()
2645 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in do_load_unload()
2648 return (STp->buffer)->syscall_result; in do_load_unload()
2650 retval = (STp->buffer)->syscall_result; in do_load_unload()
2656 STp->rew_at_close = 0; in do_load_unload()
2657 STp->ready = ST_NO_TAPE; in do_load_unload()
2660 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2661 retval = check_tape(STp, filp); in do_load_unload()
2667 STps = &(STp->ps[STp->partition]); in do_load_unload()
2677 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) in deb_space_print() argument
2687 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n", in deb_space_print()
2693 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) … in deb_space_print() argument
2698 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg) in st_int_ioctl() argument
2710 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2711 if (STp->ready != ST_READY) { in st_int_ioctl()
2712 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2717 timeout = STp->long_timeout; in st_int_ioctl()
2718 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2734 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd); in st_int_ioctl()
2750 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd); in st_int_ioctl()
2762 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd); in st_int_ioctl()
2774 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd); in st_int_ioctl()
2785 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd); in st_int_ioctl()
2798 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd); in st_int_ioctl()
2807 if (STp->write_prot) in st_int_ioctl()
2813 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2818 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2821 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2827 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2840 if (STp->immediate) { in st_int_ioctl()
2842 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2844 DEBC_printk(STp, "Rewinding tape.\n"); in st_int_ioctl()
2848 DEBC_printk(STp, "No op on tape.\n"); in st_int_ioctl()
2852 if (STp->immediate) { in st_int_ioctl()
2854 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2857 DEBC_printk(STp, "Retensioning tape.\n"); in st_int_ioctl()
2861 if (!STp->fast_mteom) { in st_int_ioctl()
2863 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff); in st_int_ioctl()
2875 DEBC_printk(STp, "Spacing to end of recorded medium.\n"); in st_int_ioctl()
2880 if (STp->write_prot) in st_int_ioctl()
2884 if (STp->immediate) { in st_int_ioctl()
2886 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2889 timeout = STp->long_timeout * 8; in st_int_ioctl()
2891 DEBC_printk(STp, "Erasing tape.\n"); in st_int_ioctl()
2899 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in st_int_ioctl()
2903 STp->max_block > 0 && in st_int_ioctl()
2904 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || in st_int_ioctl()
2905 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { in st_int_ioctl()
2906 st_printk(KERN_WARNING, STp, "Illegal block size.\n"); in st_int_ioctl()
2910 if ((STp->use_pf & USE_PF)) in st_int_ioctl()
2915 memset((STp->buffer)->b_data, 0, 12); in st_int_ioctl()
2917 (STp->buffer)->b_data[2] = (arg & 7) << 4; in st_int_ioctl()
2919 (STp->buffer)->b_data[2] = in st_int_ioctl()
2920 STp->drv_buffer << 4; in st_int_ioctl()
2921 (STp->buffer)->b_data[3] = 8; /* block descriptor length */ in st_int_ioctl()
2923 (STp->buffer)->b_data[4] = arg; in st_int_ioctl()
2924 STp->density_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2926 (STp->buffer)->b_data[4] = arg >> 24; in st_int_ioctl()
2928 (STp->buffer)->b_data[4] = STp->density; in st_int_ioctl()
2932 STp->blksize_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2934 ltmp = STp->block_size; in st_int_ioctl()
2935 (STp->buffer)->b_data[9] = (ltmp >> 16); in st_int_ioctl()
2936 (STp->buffer)->b_data[10] = (ltmp >> 8); in st_int_ioctl()
2937 (STp->buffer)->b_data[11] = ltmp; in st_int_ioctl()
2938 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2941 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2943 (STp->buffer)->b_data[9] * 65536 + in st_int_ioctl()
2944 (STp->buffer)->b_data[10] * 256 + in st_int_ioctl()
2945 (STp->buffer)->b_data[11]); in st_int_ioctl()
2947 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2949 (STp->buffer)->b_data[4]); in st_int_ioctl()
2951 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2953 ((STp->buffer)->b_data[2] >> 4) & 7); in st_int_ioctl()
2960 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction, in st_int_ioctl()
2963 return (STp->buffer)->syscall_result; in st_int_ioctl()
2965 ioctl_result = (STp->buffer)->syscall_result; in st_int_ioctl()
2975 ioctl_result = st_int_ioctl(STp, MTFSF, 1); in st_int_ioctl()
2977 ioctl_result = st_int_ioctl(STp, MTBSF, 1); in st_int_ioctl()
2980 STp->block_size = arg & MT_ST_BLKSIZE_MASK; in st_int_ioctl()
2981 if (STp->block_size != 0) { in st_int_ioctl()
2982 (STp->buffer)->buffer_blocks = in st_int_ioctl()
2983 (STp->buffer)->buffer_size / STp->block_size; in st_int_ioctl()
2985 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in st_int_ioctl()
2987 STp->density = arg >> MT_ST_DENSITY_SHIFT; in st_int_ioctl()
2989 STp->drv_buffer = (arg & 7); in st_int_ioctl()
2991 STp->density = arg; in st_int_ioctl()
3004 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_int_ioctl()
3079 !(STp->use_pf & PF_TESTED)) { in st_int_ioctl()
3082 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED; in st_int_ioctl()
3085 return st_int_ioctl(STp, cmd_in, arg); in st_int_ioctl()
3104 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition, in get_location() argument
3111 if (STp->ready != ST_READY) in get_location()
3115 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3120 if (!logical && !STp->scsi2_logical) in get_location()
3123 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE, in get_location()
3124 STp->device->request_queue->rq_timeout, in get_location()
3127 return (STp->buffer)->syscall_result; in get_location()
3129 if ((STp->buffer)->syscall_result != 0 || in get_location()
3130 (STp->device->scsi_level >= SCSI_2 && in get_location()
3131 ((STp->buffer)->b_data[0] & 4) != 0)) { in get_location()
3133 DEBC_printk(STp, " Can't read tape position.\n"); in get_location()
3137 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3138 *block = ((STp->buffer)->b_data[0] << 16) in get_location()
3139 + ((STp->buffer)->b_data[1] << 8) in get_location()
3140 + (STp->buffer)->b_data[2]; in get_location()
3143 *block = ((STp->buffer)->b_data[4] << 24) in get_location()
3144 + ((STp->buffer)->b_data[5] << 16) in get_location()
3145 + ((STp->buffer)->b_data[6] << 8) in get_location()
3146 + (STp->buffer)->b_data[7]; in get_location()
3147 *partition = (STp->buffer)->b_data[1]; in get_location()
3148 if (((STp->buffer)->b_data[0] & 0x80) && in get_location()
3149 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ in get_location()
3150 STp->ps[0].drv_block = STp->ps[0].drv_file = 0; in get_location()
3152 DEBC_printk(STp, "Got tape pos. blk %d part %d.\n", in get_location()
3164 static int set_location(struct scsi_tape *STp, unsigned int block, int partition, in set_location() argument
3174 if (STp->ready != ST_READY) in set_location()
3176 timeout = STp->long_timeout; in set_location()
3177 STps = &(STp->ps[STp->partition]); in set_location()
3179 DEBC_printk(STp, "Setting block to %d and partition to %d.\n", in set_location()
3185 if ((!STp->can_partitions && partition != 0) || in set_location()
3188 if (partition != STp->partition) { in set_location()
3189 if (get_location(STp, &blk, &p, 1)) in set_location()
3194 DEBC_printk(STp, "Visited block %d for " in set_location()
3196 blk, STp->partition); in set_location()
3201 if ((STp->device)->scsi_level < SCSI_2) { in set_location()
3213 if (!logical && !STp->scsi2_logical) in set_location()
3215 if (STp->partition != partition) { in set_location()
3218 DEBC_printk(STp, "Trying to change partition " in set_location()
3219 "from %d to %d\n", STp->partition, in set_location()
3223 if (STp->immediate) { in set_location()
3225 timeout = STp->device->request_queue->rq_timeout; in set_location()
3228 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in set_location()
3231 return (STp->buffer)->syscall_result; in set_location()
3235 if ((STp->buffer)->syscall_result != 0) { in set_location()
3237 if (STp->can_partitions && in set_location()
3238 (STp->device)->scsi_level >= SCSI_2 && in set_location()
3239 (p = find_partition(STp)) >= 0) in set_location()
3240 STp->partition = p; in set_location()
3242 if (STp->can_partitions) { in set_location()
3243 STp->partition = partition; in set_location()
3244 STps = &(STp->ps[partition]); in set_location()
3266 static int find_partition(struct scsi_tape *STp) in find_partition() argument
3271 if ((i = get_location(STp, &block, &partition, 1)) < 0) in find_partition()
3280 static int switch_partition(struct scsi_tape *STp) in switch_partition() argument
3284 if (STp->partition == STp->new_partition) in switch_partition()
3286 STps = &(STp->ps[STp->new_partition]); in switch_partition()
3289 return set_location(STp, STps->last_block_visited, STp->new_partition, 1); in switch_partition()
3311 static int nbr_partitions(struct scsi_tape *STp) in nbr_partitions() argument
3315 if (STp->ready != ST_READY) in nbr_partitions()
3318 result = read_mode_page(STp, PART_PAGE, 1); in nbr_partitions()
3321 DEBC_printk(STp, "Can't read medium partition page.\n"); in nbr_partitions()
3324 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + in nbr_partitions()
3326 DEBC_printk(STp, "Number of partitions %d.\n", result); in nbr_partitions()
3333 static int format_medium(struct scsi_tape *STp, int format) in format_medium() argument
3336 int timeout = STp->long_timeout; in format_medium()
3343 if (STp->immediate) { in format_medium()
3345 timeout = STp->device->request_queue->rq_timeout; in format_medium()
3347 DEBC_printk(STp, "Sending FORMAT MEDIUM\n"); in format_medium()
3348 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in format_medium()
3351 result = STp->buffer->syscall_result; in format_medium()
3377 static int partition_tape(struct scsi_tape *STp, int size) in partition_tape() argument
3381 bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false; in partition_tape()
3386 result = read_mode_page(STp, PART_PAGE, 0); in partition_tape()
3388 DEBC_printk(STp, "Can't read partition mode page.\n"); in partition_tape()
3398 bp = (STp->buffer)->b_data; in partition_tape()
3400 DEBC_printk(STp, "Partition page length is %d bytes.\n", in partition_tape()
3411 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3412 result = format_medium(STp, 0); in partition_tape()
3454 DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n", in partition_tape()
3462 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3471 DEBC_printk(STp, in partition_tape()
3486 result = write_mode_page(STp, PART_PAGE, 1); in partition_tape()
3489 result = format_medium(STp, 1); in partition_tape()
3492 st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n"); in partition_tape()
3509 struct scsi_tape *STp = file->private_data; in st_ioctl() local
3513 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl()
3517 if (debugging && !STp->in_use) { in st_ioctl()
3518 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n"); in st_ioctl()
3523 STm = &(STp->modes[STp->current_mode]); in st_ioctl()
3524 STps = &(STp->ps[STp->partition]); in st_ioctl()
3532 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl()
3555 st_printk(KERN_WARNING, STp, in st_ioctl()
3567 if (!STp->pos_unknown) { in st_ioctl()
3585 i = !STp->can_partitions || in st_ioctl()
3586 (STp->new_partition != STp->partition); in st_ioctl()
3595 i = flush_buffer(STp, i); in st_ioctl()
3604 i = st_int_ioctl(STp, MTWEOF, 1); in st_ioctl()
3629 reset_state(STp); in st_ioctl()
3631 STp->device->was_reset = 0; in st_ioctl()
3639 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl()
3640 do_door_lock(STp, 0); /* Ignore result! */ in st_ioctl()
3644 retval = st_set_options(STp, mtc.mt_count); in st_ioctl()
3649 if (!STp->can_partitions || in st_ioctl()
3654 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl()
3655 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl()
3659 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl()
3663 STp->new_partition = mtc.mt_count; in st_ioctl()
3669 if (!STp->can_partitions) { in st_ioctl()
3673 i = do_load_unload(STp, file, 1); in st_ioctl()
3678 i = partition_tape(STp, mtc.mt_count); in st_ioctl()
3684 STp->ps[i].rw = ST_IDLE; in st_ioctl()
3685 STp->ps[i].at_sm = 0; in st_ioctl()
3686 STp->ps[i].last_block_valid = 0; in st_ioctl()
3688 STp->partition = STp->new_partition = 0; in st_ioctl()
3689 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl()
3696 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl()
3697 if (!STp->can_partitions) in st_ioctl()
3698 STp->ps[0].rw = ST_IDLE; in st_ioctl()
3704 retval = do_load_unload(STp, file, 0); in st_ioctl()
3709 retval = do_load_unload(STp, file, max(1, mtc.mt_count)); in st_ioctl()
3714 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK)); in st_ioctl()
3718 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl()
3719 (i = switch_partition(STp)) < 0) { in st_ioctl()
3725 retval = st_compression(STp, (mtc.mt_count & 1)); in st_ioctl()
3727 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count); in st_ioctl()
3735 if ((i = flush_buffer(STp, 0)) < 0) { in st_ioctl()
3739 if (STp->can_partitions && in st_ioctl()
3740 (i = switch_partition(STp)) < 0) { in st_ioctl()
3753 mt_status.mt_type = STp->tape_type; in st_ioctl()
3755 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl()
3756 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl()
3759 if (STp->block_size != 0) { in st_ioctl()
3762 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl()
3765 ((STp->buffer)->buffer_bytes + in st_ioctl()
3766 STp->block_size - 1) / STp->block_size; in st_ioctl()
3770 if (STp->drv_write_prot) in st_ioctl()
3778 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl()
3779 mt_status.mt_resid = STp->partition; in st_ioctl()
3784 if (STp->density == 1) in st_ioctl()
3786 else if (STp->density == 2) in st_ioctl()
3788 else if (STp->density == 3) in st_ioctl()
3790 if (STp->ready == ST_READY) in st_ioctl()
3792 if (STp->ready == ST_NO_TAPE) in st_ioctl()
3797 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl()
3798 STp->drv_buffer != 0) in st_ioctl()
3800 if (STp->cleaning_req) in st_ioctl()
3807 STp->recover_reg = 0; /* Clear after read */ in st_ioctl()
3816 if ((i = get_location(STp, &blk, &bt, 0)) < 0) { in st_ioctl()
3824 mutex_unlock(&STp->lock); in st_ioctl()
3837 retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, cmd_in, p); in st_ioctl()
3840 STp->rew_at_close = 0; in st_ioctl()
3841 STp->ready = ST_NO_TAPE; in st_ioctl()
3846 mutex_unlock(&STp->lock); in st_ioctl()
4105 char *stp; in st_setup() local
4107 stp = get_options(str, ARRAY_SIZE(ints), ints); in st_setup()
4114 while (stp != NULL) { in st_setup()
4117 if (!strncmp(stp, parms[i].name, len) && in st_setup()
4118 (*(stp + len) == ':' || *(stp + len) == '=')) { in st_setup()
4121 simple_strtoul(stp + len + 1, NULL, 0); in st_setup()
4130 stp); in st_setup()
4131 stp = strchr(stp, ','); in st_setup()
4132 if (stp) in st_setup()
4133 stp++; in st_setup()
4621 struct scsi_tape *STp = STm->tape; in options_show() local
4629 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4630 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4632 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4633 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4634 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4635 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4637 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4638 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4639 options |= STp->sili ? MT_ST_SILI : 0; in options_show()