• Home
  • Raw
  • Download

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()
361 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) in st_chk_result() argument
365 DEB(const char *stp;) in st_chk_result()
366 char *name = tape_name(STp); in st_chk_result()
372 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
376 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
382 st_printk(ST_DEB_MSG, STp, in st_chk_result()
387 __scsi_print_sense(STp->device, name, in st_chk_result()
392 st_printk(KERN_WARNING, STp, in st_chk_result()
404 __scsi_print_sense(STp->device, name, in st_chk_result()
410 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
411 if (STp->cln_sense_value) in st_chk_result()
412 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
413 STp->cln_sense_mask) == STp->cln_sense_value); in st_chk_result()
415 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
416 STp->cln_sense_mask) != 0); in st_chk_result()
420 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
422 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
431 STp->recover_count++; in st_chk_result()
432 STp->recover_reg++; in st_chk_result()
437 stp = "read"; in st_chk_result()
439 stp = "write"; in st_chk_result()
441 stp = "ioctl"; in st_chk_result()
442 st_printk(ST_DEB_MSG, STp, in st_chk_result()
444 stp, STp->recover_count); in st_chk_result()
453 static struct st_request *st_allocate_request(struct scsi_tape *stp) in st_allocate_request() argument
459 streq->stp = stp; in st_allocate_request()
461 st_printk(KERN_ERR, stp, in st_allocate_request()
464 stp->buffer->syscall_result = -EINTR; in st_allocate_request()
466 stp->buffer->syscall_result = -EBUSY; in st_allocate_request()
477 static void st_do_stats(struct scsi_tape *STp, struct request *req) in st_do_stats() argument
483 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
484 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
485 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
486 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
488 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
489 - STp->buffer->cmdstat.residual, in st_do_stats()
490 &STp->stats->write_byte_cnt); in st_do_stats()
491 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
492 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
494 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
495 &STp->stats->write_byte_cnt); in st_do_stats()
497 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
498 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time); in st_do_stats()
499 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
500 atomic64_inc(&STp->stats->read_cnt); in st_do_stats()
502 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
503 - STp->buffer->cmdstat.residual, in st_do_stats()
504 &STp->stats->read_byte_cnt); in st_do_stats()
505 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
506 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
508 atomic64_add(atomic_read(&STp->stats->last_read_size), in st_do_stats()
509 &STp->stats->read_byte_cnt); in st_do_stats()
511 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
512 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
513 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
515 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 = rq->result; in st_scsi_execute_end()
526 STp->buffer->cmdstat.residual = rq->resid_len; in st_scsi_execute_end()
528 st_do_stats(STp, req); in st_scsi_execute_end()
546 struct rq_map_data *mdata = &SRpnt->stp->buffer->map_data; in st_scsi_execute()
548 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute() local
550 req = blk_get_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
841 if (STp->pos_unknown) in flush_buffer()
844 if (STp->ready != ST_READY) in flush_buffer()
846 STps = &(STp->ps[STp->partition]); in flush_buffer()
848 return st_flush_write_buffer(STp); in flush_buffer()
850 if (STp->block_size == 0) in flush_buffer()
853 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
854 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
855 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
856 STp->block_size; in flush_buffer()
857 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
858 (STp->buffer)->read_pointer = 0; in flush_buffer()
862 result = cross_eof(STp, 0); /* Back over the EOF hit */ in flush_buffer()
872 result = st_int_ioctl(STp, MTBSR, backspace); in flush_buffer()
884 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) in set_mode_densblk() argument
889 if (!STp->density_changed && in set_mode_densblk()
891 STm->default_density != STp->density) { in set_mode_densblk()
895 arg = STp->density; in set_mode_densblk()
897 if (!STp->blksize_changed && in set_mode_densblk()
899 STm->default_blksize != STp->block_size) { in set_mode_densblk()
903 arg |= STp->block_size; in set_mode_densblk()
905 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { in set_mode_densblk()
906 st_printk(KERN_WARNING, STp, in set_mode_densblk()
918 static int do_door_lock(struct scsi_tape * STp, int do_lock) in do_door_lock() argument
922 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); in do_door_lock()
924 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
927 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
929 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
935 static void reset_state(struct scsi_tape *STp) in reset_state() argument
940 STp->pos_unknown = 0; in reset_state()
942 STps = &(STp->ps[i]); in reset_state()
950 if (STp->can_partitions) { in reset_state()
951 STp->partition = find_partition(STp); in reset_state()
952 if (STp->partition < 0) in reset_state()
953 STp->partition = 0; in reset_state()
954 STp->new_partition = STp->partition; in reset_state()
967 static int test_ready(struct scsi_tape *STp, int do_wait) in test_ready() argument
973 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
980 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, in test_ready()
981 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
984 retval = (STp->buffer)->syscall_result; in test_ready()
1014 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
1024 retval = (STp->buffer)->syscall_result; in test_ready()
1041 static int check_tape(struct scsi_tape *STp, struct file *filp) in check_tape() argument
1052 STp->ready = ST_READY; in check_tape()
1054 if (mode != STp->current_mode) { in check_tape()
1055 DEBC_printk(STp, "Mode change from %d to %d.\n", in check_tape()
1056 STp->current_mode, mode); in check_tape()
1058 STp->current_mode = mode; in check_tape()
1060 STm = &(STp->modes[STp->current_mode]); in check_tape()
1062 saved_cleaning = STp->cleaning_req; in check_tape()
1063 STp->cleaning_req = 0; in check_tape()
1066 retval = test_ready(STp, do_wait); in check_tape()
1072 STp->pos_unknown = 0; in check_tape()
1073 STp->partition = STp->new_partition = 0; in check_tape()
1074 if (STp->can_partitions) in check_tape()
1075 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1078 STps = &(STp->ps[i]); in check_tape()
1089 STp->cleaning_req |= saved_cleaning; in check_tape()
1093 STp->ready = ST_NO_TAPE; in check_tape()
1095 STp->ready = ST_NOT_READY; in check_tape()
1097 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1098 STp->write_prot = 0; in check_tape()
1099 STp->block_size = 0; in check_tape()
1100 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1101 STp->partition = STp->new_partition = 0; in check_tape()
1102 STp->door_locked = ST_UNLOCKED; in check_tape()
1107 if (STp->omit_blklims) in check_tape()
1108 STp->min_block = STp->max_block = (-1); in check_tape()
1113 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE, in check_tape()
1114 STp->device->request_queue->rq_timeout, in check_tape()
1117 retval = (STp->buffer)->syscall_result; in check_tape()
1121 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1122 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1123 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1124 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1125 (STp->buffer)->b_data[5]; in check_tape()
1126 if ( DEB( debugging || ) !STp->inited) in check_tape()
1127 st_printk(KERN_INFO, STp, in check_tape()
1129 STp->min_block, STp->max_block); in check_tape()
1131 STp->min_block = STp->max_block = (-1); in check_tape()
1132 DEBC_printk(STp, "Can't read block limits.\n"); in check_tape()
1140 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE, in check_tape()
1141 STp->device->request_queue->rq_timeout, in check_tape()
1144 retval = (STp->buffer)->syscall_result; in check_tape()
1148 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1149 DEBC_printk(STp, "No Mode Sense.\n"); in check_tape()
1150 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1151 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1152 STp->drv_write_prot = 0; in check_tape()
1154 DEBC_printk(STp,"Mode sense. Length %d, " in check_tape()
1156 (STp->buffer)->b_data[0], in check_tape()
1157 (STp->buffer)->b_data[1], in check_tape()
1158 (STp->buffer)->b_data[2], in check_tape()
1159 (STp->buffer)->b_data[3]); in check_tape()
1161 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1162 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1163 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1164 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1165 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1166 DEBC_printk(STp, "Density %x, tape length: %x, " in check_tape()
1168 STp->density, in check_tape()
1169 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1170 (STp->buffer)->b_data[6] * 256 + in check_tape()
1171 (STp->buffer)->b_data[7], in check_tape()
1172 STp->drv_buffer); in check_tape()
1174 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1175 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1176 st_printk(KERN_WARNING, STp, in check_tape()
1179 STp->immediate_filemark = 0; in check_tape()
1184 STp->inited = 1; in check_tape()
1186 if (STp->block_size > 0) in check_tape()
1187 (STp->buffer)->buffer_blocks = in check_tape()
1188 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1190 (STp->buffer)->buffer_blocks = 1; in check_tape()
1191 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1193 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n", in check_tape()
1194 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1195 (STp->buffer)->buffer_blocks); in check_tape()
1197 if (STp->drv_write_prot) { in check_tape()
1198 STp->write_prot = 1; in check_tape()
1200 DEBC_printk(STp, "Write protected\n"); in check_tape()
1210 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1214 DEBC_printk(STp, "Updating partition number in status.\n"); in check_tape()
1215 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1216 retval = STp->partition; in check_tape()
1219 STp->new_partition = STp->partition; in check_tape()
1220 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1224 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1225 STp->compression_changed = 0; in check_tape()
1227 (retval = set_mode_densblk(STp, STm)) < 0) in check_tape()
1230 if (STp->default_drvbuffer != 0xff) { in check_tape()
1231 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1232 st_printk(KERN_WARNING, STp, in check_tape()
1235 STp->default_drvbuffer); in check_tape()
1252 struct scsi_tape *STp; in st_open() local
1263 if (!(STp = scsi_tape_get(dev))) { in st_open()
1267 filp->private_data = STp; in st_open()
1270 if (STp->in_use) { in st_open()
1272 DEBC_printk(STp, "Device already in use.\n"); in st_open()
1273 scsi_tape_put(STp); in st_open()
1277 STp->in_use = 1; in st_open()
1279 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1281 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1286 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1292 if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) { in st_open()
1293 st_printk(KERN_WARNING, STp, in st_open()
1299 (STp->buffer)->cleared = 0; in st_open()
1300 (STp->buffer)->writing = 0; in st_open()
1301 (STp->buffer)->syscall_result = 0; in st_open()
1303 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1305 STp->dirty = 0; in st_open()
1307 STps = &(STp->ps[i]); in st_open()
1310 STp->try_dio_now = STp->try_dio; in st_open()
1311 STp->recover_count = 0; in st_open()
1312 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1313 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1315 retval = check_tape(STp, filp); in st_open()
1320 if (STp->ready == NO_TAPE) in st_open()
1329 normalize_buffer(STp->buffer); in st_open()
1331 STp->in_use = 0; in st_open()
1334 scsi_autopm_put_device(STp->device); in st_open()
1335 scsi_tape_put(STp); in st_open()
1347 struct scsi_tape *STp = filp->private_data; in st_flush() local
1348 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1349 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1354 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1355 result = st_flush_write_buffer(STp); in st_flush()
1360 if (STp->can_partitions && in st_flush()
1361 (result2 = switch_partition(STp)) < 0) { in st_flush()
1362 DEBC_printk(STp, "switch_partition at close failed.\n"); in st_flush()
1368 DEBC( if (STp->nbr_requests) in st_flush()
1369 st_printk(KERN_DEBUG, STp, in st_flush()
1371 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1372 STp->nbr_pages)); in st_flush()
1374 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1375 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1378 DEBC_printk(STp, "Async write waits %d, finished %d.\n", in st_flush()
1379 STp->nbr_waits, STp->nbr_finished); in st_flush()
1383 if (STp->immediate_filemark) in st_flush()
1385 cmd[4] = 1 + STp->two_fm; in st_flush()
1387 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in st_flush()
1388 STp->device->request_queue->rq_timeout, in st_flush()
1391 result = (STp->buffer)->syscall_result; in st_flush()
1395 if (STp->buffer->syscall_result == 0 || in st_flush()
1407 if (STp->two_fm) in st_flush()
1408 cross_eof(STp, 0); in st_flush()
1414 st_printk(KERN_ERR, STp, in st_flush()
1420 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]); in st_flush()
1421 } else if (!STp->rew_at_close) { in st_flush()
1422 STps = &(STp->ps[STp->partition]); in st_flush()
1424 if (STp->can_bsr) in st_flush()
1425 result = flush_buffer(STp, 0); in st_flush()
1427 result = cross_eof(STp, 0); in st_flush()
1437 !(result = cross_eof(STp, 1))) || in st_flush()
1447 if (STp->rew_at_close) { in st_flush()
1448 result2 = st_int_ioctl(STp, MTREW, 1); in st_flush()
1460 struct scsi_tape *STp = filp->private_data; in st_release() local
1462 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1463 do_door_lock(STp, 0); in st_release()
1465 normalize_buffer(STp->buffer); in st_release()
1467 STp->in_use = 0; in st_release()
1469 scsi_autopm_put_device(STp->device); in st_release()
1470 scsi_tape_put(STp); in st_release()
1476 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) in rw_checks() argument
1486 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1491 if (STp->ready != ST_READY) { in rw_checks()
1492 if (STp->ready == ST_NO_TAPE) in rw_checks()
1499 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1509 if (STp->pos_unknown) { in rw_checks()
1518 if (!STp->in_use) { in rw_checks()
1519 st_printk(ST_DEB_MSG, STp, in rw_checks()
1525 if (STp->can_partitions && in rw_checks()
1526 (retval = switch_partition(STp)) < 0) in rw_checks()
1529 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1530 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1535 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1536 !do_door_lock(STp, 1)) in rw_checks()
1537 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1544 static int setup_buffering(struct scsi_tape *STp, const char __user *buf, in setup_buffering() argument
1548 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1551 i = STp->try_dio_now && try_rdio; in setup_buffering()
1553 i = STp->try_dio_now && try_wdio; in setup_buffering()
1556 STp->device->request_queue)) == 0) { in setup_buffering()
1568 STp->nbr_dio++; in setup_buffering()
1569 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1574 DEB( STp->nbr_requests++; ) in setup_buffering()
1577 if (STp->block_size) in setup_buffering()
1578 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1579 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1584 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1589 !enlarge_buffer(STbp, bufsize, STp->restr_dma)) { in setup_buffering()
1590 st_printk(KERN_WARNING, STp, in setup_buffering()
1596 if (STp->block_size) in setup_buffering()
1597 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1606 static void release_buffering(struct scsi_tape *STp, int is_read) in release_buffering() argument
1610 STbp = STp->buffer; in release_buffering()
1631 struct scsi_tape *STp = filp->private_data; in st_write() local
1636 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1639 retval = rw_checks(STp, filp, count); in st_write()
1644 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1645 st_printk(KERN_WARNING, STp, in st_write()
1651 STm = &(STp->modes[STp->current_mode]); in st_write()
1652 STps = &(STp->ps[STp->partition]); in st_write()
1654 if (STp->write_prot) { in st_write()
1661 retval = flush_buffer(STp, 0); in st_write()
1667 if ((retval = set_mode_densblk(STp, STm)) < 0) in st_write()
1670 !(STp->compression_changed)) { in st_write()
1671 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1672 st_printk(KERN_WARNING, STp, in st_write()
1682 STbp = STp->buffer; in st_write()
1683 i = write_behind_check(STp); in st_write()
1703 if (STp->block_size != 0 && in st_write()
1711 retval = setup_buffering(STp, buf, count, 0); in st_write()
1719 cmd[1] = (STp->block_size != 0); in st_write()
1730 if (STp->block_size == 0) in st_write()
1733 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1748 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1751 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1752 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1754 STp->dirty = 1; in st_write()
1761 if (STp->block_size == 0) in st_write()
1768 blks /= STp->block_size; in st_write()
1769 transfer = blks * STp->block_size; in st_write()
1775 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE, in st_write()
1776 STp->device->request_queue->rq_timeout, in st_write()
1784 STp->dirty = !(STbp->writing == in st_write()
1787 DEB( STp->write_pending = 1; ) in st_write()
1792 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1794 DEBC_printk(STp, "Error on write:\n"); in st_write()
1799 else if (STp->block_size == 0 && in st_write()
1804 if (STp->block_size != 0) in st_write()
1805 undone *= STp->block_size; in st_write()
1811 if (STp->block_size) in st_write()
1812 blks = (transfer - undone) / STp->block_size; in st_write()
1818 if (STp->block_size == 0 || in st_write()
1821 DEBC_printk(STp, "EOM with %d " in st_write()
1829 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1833 STp->block_size; in st_write()
1836 DEBC_printk(STp, "Retry " in st_write()
1839 STp->buffer->buffer_bytes); in st_write()
1850 DEBC_printk(STp, "EOM with " in st_write()
1863 if (STp->block_size == 0) in st_write()
1870 STp->dirty = 0; in st_write()
1888 release_buffering(STp, 0); in st_write()
1889 mutex_unlock(&STp->lock); in st_write()
1900 static long read_tape(struct scsi_tape *STp, long count, in read_tape() argument
1914 STm = &(STp->modes[STp->current_mode]); in read_tape()
1915 STps = &(STp->ps[STp->partition]); in read_tape()
1918 STbp = STp->buffer; in read_tape()
1920 if (STp->block_size == 0) in read_tape()
1923 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1924 blks = (STp->buffer)->buffer_blocks; in read_tape()
1925 bytes = blks * STp->block_size; in read_tape()
1928 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1929 bytes = (STp->buffer)->buffer_size; in read_tape()
1930 blks = bytes / STp->block_size; in read_tape()
1931 bytes = blks * STp->block_size; in read_tape()
1937 cmd[1] = (STp->block_size != 0); in read_tape()
1938 if (!cmd[1] && STp->sili) in read_tape()
1945 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, in read_tape()
1946 STp->device->request_queue->rq_timeout, in read_tape()
1948 release_buffering(STp, 1); in read_tape()
1958 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1961 DEBC_printk(STp, in read_tape()
1979 if (STp->block_size == 0) in read_tape()
1986 if (STp->block_size == 0 && in read_tape()
1988 st_printk(KERN_NOTICE, STp, in read_tape()
1998 } else if (STp->block_size == 0) { in read_tape()
2004 st_printk(KERN_NOTICE, STp, in read_tape()
2009 st_int_ioctl(STp, MTBSR, 1); in read_tape()
2014 STp->block_size; in read_tape()
2015 DEBC_printk(STp, "ILI but " in read_tape()
2022 if (st_int_ioctl(STp, MTBSR, 1)) in read_tape()
2030 if (STp->block_size == 0) in read_tape()
2034 bytes - transfer * STp->block_size; in read_tape()
2035 DEBC_printk(STp, "EOF detected (%d " in read_tape()
2043 if (STp->block_size == 0) in read_tape()
2047 bytes - transfer * STp->block_size; in read_tape()
2049 DEBC_printk(STp, "EOM detected (%d " in read_tape()
2056 DEBC_printk(STp, "Tape error while reading.\n"); in read_tape()
2060 DEBC_printk(STp, "Zero returned for " in read_tape()
2080 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2081 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2085 if (STp->block_size == 0) in read_tape()
2088 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2103 struct scsi_tape *STp = filp->private_data; in st_read() local
2106 struct st_buffer *STbp = STp->buffer; in st_read()
2108 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2111 retval = rw_checks(STp, filp, count); in st_read()
2115 STm = &(STp->modes[STp->current_mode]); in st_read()
2116 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2121 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2124 STps = &(STp->ps[STp->partition]); in st_read()
2126 retval = flush_buffer(STp, 0); in st_read()
2133 st_printk(ST_DEB_MSG, STp, in st_read()
2138 retval = setup_buffering(STp, buf, count, 1); in st_read()
2174 special = read_tape(STp, count - total, &SRpnt); in st_read()
2185 st_printk(ST_DEB_MSG, STp, in st_read()
2203 if (STp->block_size == 0) in st_read()
2233 release_buffering(STp, 1); in st_read()
2236 mutex_unlock(&STp->lock); in st_read()
2245 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm) in DEB() argument
2248 st_printk(KERN_INFO, STp, in DEB()
2251 STp->current_mode, STm->do_buffer_writes, in DEB()
2253 st_printk(KERN_INFO, STp, in DEB()
2256 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2257 STp->do_auto_lock); in DEB()
2258 st_printk(KERN_INFO, STp, in DEB()
2261 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2262 STp->can_partitions, STp->scsi2_logical); in DEB()
2263 st_printk(KERN_INFO, STp, in DEB()
2266 STm->sysv, STp->immediate, STp->sili, in DEB()
2267 STp->immediate_filemark); in DEB()
2268 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging); in DEB()
2274 static int st_set_options(struct scsi_tape *STp, long options)
2282 STm = &(STp->modes[STp->current_mode]);
2288 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2294 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2295 STp->current_mode);
2304 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2305 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2306 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2307 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2308 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2309 if ((STp->device)->scsi_level >= SCSI_2)
2310 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2311 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2312 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2313 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2315 STp->sili = (options & MT_ST_SILI) != 0;
2317 st_log_options(STp, STm); )
2329 STp->two_fm = value;
2331 STp->fast_mteom = value;
2333 STp->do_auto_lock = value;
2335 STp->can_bsr = value;
2337 STp->omit_blklims = value;
2338 if ((STp->device)->scsi_level >= SCSI_2 &&
2340 STp->can_partitions = value;
2342 STp->scsi2_logical = value;
2344 STp->immediate = value;
2346 STp->immediate_filemark = value;
2350 STp->sili = value;
2354 st_log_options(STp, STm); )
2361 DEBC_printk(STp, "Default block size disabled.\n");
2364 DEBC_printk(STp,"Default block size set to "
2366 if (STp->ready == ST_READY) {
2367 STp->blksize_changed = 0;
2368 set_mode_densblk(STp, STm);
2374 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2375 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2378 blk_queue_rq_timeout(STp->device->request_queue,
2380 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2389 STp->cln_mode = value;
2390 STp->cln_sense_mask = (options >> 8) & 0xff;
2391 STp->cln_sense_value = (options >> 16) & 0xff;
2392 st_printk(KERN_INFO, STp,
2394 value, STp->cln_sense_mask, STp->cln_sense_value);
2401 DEBC_printk(STp,
2405 DEBC_printk(STp, "Density default set to %x\n",
2407 if (STp->ready == ST_READY) {
2408 STp->density_changed = 0;
2409 set_mode_densblk(STp, STm);
2414 STp->default_drvbuffer = 0xff;
2415 DEBC_printk(STp,
2418 STp->default_drvbuffer = value & 7;
2419 DEBC_printk(STp,
2421 STp->default_drvbuffer);
2422 if (STp->ready == ST_READY)
2423 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2428 DEBC_printk(STp,
2432 STp->c_algo = (value & 0xff00) >> 8;
2433 DEBC_printk(STp, "Compression "
2435 STp->c_algo);
2439 DEBC_printk(STp, "Compression default "
2442 if (STp->ready == ST_READY) {
2443 STp->compression_changed = 0;
2444 st_compression(STp, (STm->default_compression == ST_YES));
2477 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) in read_mode_page() argument
2489 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE, in read_mode_page()
2490 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2492 return (STp->buffer)->syscall_result; in read_mode_page()
2496 return STp->buffer->syscall_result; in read_mode_page()
2502 static int write_mode_page(struct scsi_tape *STp, int page, int slow) in write_mode_page() argument
2512 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2513 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2516 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2517 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2518 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2519 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2522 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2523 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE, in write_mode_page()
2526 return (STp->buffer)->syscall_result; in write_mode_page()
2530 return STp->buffer->syscall_result; in write_mode_page()
2551 static int st_compression(struct scsi_tape * STp, int state) in st_compression() argument
2555 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2557 if (STp->ready != ST_READY) in st_compression()
2561 retval = read_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2563 DEBC_printk(STp, "Compression mode page not supported.\n"); in st_compression()
2568 DEBC_printk(STp, "Compression state is %d.\n", in st_compression()
2573 DEBC_printk(STp, "Compression not supported.\n"); in st_compression()
2580 if (STp->c_algo != 0) in st_compression()
2581 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2585 if (STp->c_algo != 0) in st_compression()
2589 retval = write_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2591 DEBC_printk(STp, "Compression change failed.\n"); in st_compression()
2594 DEBC_printk(STp, "Compression state changed to %d.\n", state); in st_compression()
2596 STp->compression_changed = 1; in st_compression()
2602 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) in do_load_unload() argument
2609 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2610 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2625 DEBC_printk(STp, " Enhanced %sload slot %2d.\n", in do_load_unload()
2630 if (STp->immediate) { in do_load_unload()
2632 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2635 timeout = STp->long_timeout; in do_load_unload()
2639 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n"); in do_load_unload()
2641 st_printk(ST_DEB_MSG, STp, "Loading tape.\n"); in do_load_unload()
2644 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in do_load_unload()
2647 return (STp->buffer)->syscall_result; in do_load_unload()
2649 retval = (STp->buffer)->syscall_result; in do_load_unload()
2655 STp->rew_at_close = 0; in do_load_unload()
2656 STp->ready = ST_NO_TAPE; in do_load_unload()
2659 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2660 retval = check_tape(STp, filp); in do_load_unload()
2666 STps = &(STp->ps[STp->partition]); in do_load_unload()
2676 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) in deb_space_print() argument
2686 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n", in deb_space_print()
2692 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) … in deb_space_print() argument
2697 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg) in st_int_ioctl() argument
2709 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2710 if (STp->ready != ST_READY) { in st_int_ioctl()
2711 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2716 timeout = STp->long_timeout; in st_int_ioctl()
2717 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2733 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd); in st_int_ioctl()
2749 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd); in st_int_ioctl()
2761 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd); in st_int_ioctl()
2773 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd); in st_int_ioctl()
2784 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd); in st_int_ioctl()
2797 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd); in st_int_ioctl()
2806 if (STp->write_prot) in st_int_ioctl()
2812 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2817 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2820 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2826 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2839 if (STp->immediate) { in st_int_ioctl()
2841 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2843 DEBC_printk(STp, "Rewinding tape.\n"); in st_int_ioctl()
2847 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()
3508 struct scsi_tape *STp = file->private_data; in st_ioctl_common() local
3512 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl_common()
3516 if (debugging && !STp->in_use) { in st_ioctl_common()
3517 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n"); in st_ioctl_common()
3522 STm = &(STp->modes[STp->current_mode]); in st_ioctl_common()
3523 STps = &(STp->ps[STp->partition]); in st_ioctl_common()
3531 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl_common()
3554 st_printk(KERN_WARNING, STp, in st_ioctl_common()
3566 if (!STp->pos_unknown) { in st_ioctl_common()
3584 i = !STp->can_partitions || in st_ioctl_common()
3585 (STp->new_partition != STp->partition); in st_ioctl_common()
3594 i = flush_buffer(STp, i); in st_ioctl_common()
3603 i = st_int_ioctl(STp, MTWEOF, 1); in st_ioctl_common()
3628 reset_state(STp); in st_ioctl_common()
3630 STp->device->was_reset = 0; in st_ioctl_common()
3638 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl_common()
3639 do_door_lock(STp, 0); /* Ignore result! */ in st_ioctl_common()
3643 retval = st_set_options(STp, mtc.mt_count); in st_ioctl_common()
3648 if (!STp->can_partitions || in st_ioctl_common()
3653 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl_common()
3654 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl_common()
3658 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl_common()
3662 STp->new_partition = mtc.mt_count; in st_ioctl_common()
3668 if (!STp->can_partitions) { in st_ioctl_common()
3672 i = do_load_unload(STp, file, 1); in st_ioctl_common()
3677 i = partition_tape(STp, mtc.mt_count); in st_ioctl_common()
3683 STp->ps[i].rw = ST_IDLE; in st_ioctl_common()
3684 STp->ps[i].at_sm = 0; in st_ioctl_common()
3685 STp->ps[i].last_block_valid = 0; in st_ioctl_common()
3687 STp->partition = STp->new_partition = 0; in st_ioctl_common()
3688 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl_common()
3695 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl_common()
3696 if (!STp->can_partitions) in st_ioctl_common()
3697 STp->ps[0].rw = ST_IDLE; in st_ioctl_common()
3703 retval = do_load_unload(STp, file, 0); in st_ioctl_common()
3708 retval = do_load_unload(STp, file, max(1, mtc.mt_count)); in st_ioctl_common()
3713 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK)); in st_ioctl_common()
3717 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl_common()
3718 (i = switch_partition(STp)) < 0) { in st_ioctl_common()
3724 retval = st_compression(STp, (mtc.mt_count & 1)); in st_ioctl_common()
3726 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count); in st_ioctl_common()
3734 if ((i = flush_buffer(STp, 0)) < 0) { in st_ioctl_common()
3738 if (STp->can_partitions && in st_ioctl_common()
3739 (i = switch_partition(STp)) < 0) { in st_ioctl_common()
3752 mt_status.mt_type = STp->tape_type; in st_ioctl_common()
3754 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl_common()
3755 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl_common()
3758 if (STp->block_size != 0) { in st_ioctl_common()
3761 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl_common()
3764 ((STp->buffer)->buffer_bytes + in st_ioctl_common()
3765 STp->block_size - 1) / STp->block_size; in st_ioctl_common()
3769 if (STp->drv_write_prot) in st_ioctl_common()
3777 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl_common()
3778 mt_status.mt_resid = STp->partition; in st_ioctl_common()
3783 if (STp->density == 1) in st_ioctl_common()
3785 else if (STp->density == 2) in st_ioctl_common()
3787 else if (STp->density == 3) in st_ioctl_common()
3789 if (STp->ready == ST_READY) in st_ioctl_common()
3791 if (STp->ready == ST_NO_TAPE) in st_ioctl_common()
3796 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl_common()
3797 STp->drv_buffer != 0) in st_ioctl_common()
3799 if (STp->cleaning_req) in st_ioctl_common()
3806 STp->recover_reg = 0; /* Clear after read */ in st_ioctl_common()
3815 if ((i = get_location(STp, &blk, &bt, 0)) < 0) { in st_ioctl_common()
3823 mutex_unlock(&STp->lock); in st_ioctl_common()
3827 retval = scsi_ioctl(STp->device, cmd_in, p); in st_ioctl_common()
3829 STp->rew_at_close = 0; in st_ioctl_common()
3830 STp->ready = ST_NO_TAPE; in st_ioctl_common()
3845 i = scsi_cmd_ioctl(STp->disk->queue, STp->disk, in st_ioctl_common()
3854 mutex_unlock(&STp->lock); in st_ioctl_common()
3861 struct scsi_tape *STp = file->private_data; in st_ioctl() local
3868 return scsi_ioctl(STp->device, cmd_in, p); in st_ioctl()
3875 struct scsi_tape *STp = file->private_data; in st_compat_ioctl() local
3890 return scsi_compat_ioctl(STp->device, cmd_in, p); in st_compat_ioctl()
4135 char *stp; in st_setup() local
4137 stp = get_options(str, ARRAY_SIZE(ints), ints); in st_setup()
4144 while (stp != NULL) { in st_setup()
4147 if (!strncmp(stp, parms[i].name, len) && in st_setup()
4148 (*(stp + len) == ':' || *(stp + len) == '=')) { in st_setup()
4151 simple_strtoul(stp + len + 1, NULL, 0); in st_setup()
4160 stp); in st_setup()
4161 stp = strchr(stp, ','); in st_setup()
4162 if (stp) in st_setup()
4163 stp++; in st_setup()
4284 char *stp; in st_probe() local
4288 if ((stp = st_incompatible(SDp))) { in st_probe()
4675 struct scsi_tape *STp = STm->tape; in options_show() local
4683 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4684 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4686 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4687 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4688 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4689 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4691 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4692 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4693 options |= STp->sili ? MT_ST_SILI : 0; in options_show()