• Home
  • Raw
  • Download

Lines Matching full:stp

245 	struct scsi_tape *STp = NULL;  in scsi_tape_get()  local
250 STp = idr_find(&st_index_idr, dev); in scsi_tape_get()
251 if (!STp) goto out; in scsi_tape_get()
253 kref_get(&STp->kref); in scsi_tape_get()
255 if (!STp->device) in scsi_tape_get()
258 if (scsi_device_get(STp->device)) in scsi_tape_get()
264 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_get()
265 STp = NULL; in scsi_tape_get()
269 return STp; in scsi_tape_get()
272 static void scsi_tape_put(struct scsi_tape *STp) in scsi_tape_put() argument
274 struct scsi_device *sdev = STp->device; in scsi_tape_put()
277 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_put()
357 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) in st_chk_result() argument
361 DEB(const char *stp;) in st_chk_result()
362 char *name = STp->name; in st_chk_result()
368 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
372 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
378 st_printk(ST_DEB_MSG, STp, in st_chk_result()
383 __scsi_print_sense(STp->device, name, in st_chk_result()
388 st_printk(KERN_WARNING, STp, in st_chk_result()
400 __scsi_print_sense(STp->device, name, in st_chk_result()
406 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
407 if (STp->cln_sense_value) in st_chk_result()
408 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
409 STp->cln_sense_mask) == STp->cln_sense_value); in st_chk_result()
411 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
412 STp->cln_sense_mask) != 0); in st_chk_result()
416 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
418 STp->pos_unknown = 1; /* ASC => power on / reset */ in st_chk_result()
420 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
429 STp->recover_count++; in st_chk_result()
430 STp->recover_reg++; in st_chk_result()
435 stp = "read"; in st_chk_result()
437 stp = "write"; in st_chk_result()
439 stp = "ioctl"; in st_chk_result()
440 st_printk(ST_DEB_MSG, STp, in st_chk_result()
442 stp, STp->recover_count); in st_chk_result()
451 static struct st_request *st_allocate_request(struct scsi_tape *stp) in st_allocate_request() argument
457 streq->stp = stp; in st_allocate_request()
459 st_printk(KERN_ERR, stp, in st_allocate_request()
462 stp->buffer->syscall_result = -EINTR; in st_allocate_request()
464 stp->buffer->syscall_result = -EBUSY; in st_allocate_request()
475 static void st_do_stats(struct scsi_tape *STp, struct request *req) in st_do_stats() argument
482 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
483 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
484 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
485 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
487 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
488 - STp->buffer->cmdstat.residual, in st_do_stats()
489 &STp->stats->write_byte_cnt); in st_do_stats()
490 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
491 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
493 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
494 &STp->stats->write_byte_cnt); in st_do_stats()
496 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
497 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time); in st_do_stats()
498 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
499 atomic64_inc(&STp->stats->read_cnt); in st_do_stats()
501 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
502 - STp->buffer->cmdstat.residual, in st_do_stats()
503 &STp->stats->read_byte_cnt); in st_do_stats()
504 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
505 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
507 atomic64_add(atomic_read(&STp->stats->last_read_size), in st_do_stats()
508 &STp->stats->read_byte_cnt); in st_do_stats()
510 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
511 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
512 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
514 atomic64_dec(&STp->stats->in_flight); in st_do_stats()
522 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end() local
525 STp->buffer->cmdstat.midlevel_result = SRpnt->result = scmd->result; in st_scsi_execute_end()
526 STp->buffer->cmdstat.residual = scmd->resid_len; in st_scsi_execute_end()
528 st_do_stats(STp, req); in st_scsi_execute_end()
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
551 req = scsi_alloc_request(SRpnt->stp->device->request_queue, in st_scsi_execute()
570 atomic64_inc(&STp->stats->in_flight); in st_scsi_execute()
572 atomic_set(&STp->stats->last_write_size, bufflen); in st_scsi_execute()
573 STp->stats->write_time = ktime_get(); in st_scsi_execute()
575 atomic_set(&STp->stats->last_read_size, bufflen); in st_scsi_execute()
576 STp->stats->read_time = ktime_get(); in st_scsi_execute()
578 STp->stats->other_time = ktime_get(); in st_scsi_execute()
597 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, in st_do_scsi() argument
601 struct rq_map_data *mdata = &STp->buffer->map_data; in st_do_scsi()
605 if (!do_wait && ((STp->buffer)->last_SRpnt)) { in st_do_scsi()
606 st_printk(KERN_ERR, STp, in st_do_scsi()
609 (STp->buffer)->syscall_result = (-EINTR); in st_do_scsi()
611 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
616 SRpnt = st_allocate_request(STp); in st_do_scsi()
624 (STp->buffer)->last_SRpnt = SRpnt; in st_do_scsi()
626 waiting = &STp->wait; in st_do_scsi()
630 if (STp->buffer->do_dio) { in st_do_scsi()
632 mdata->nr_entries = STp->buffer->sg_segs; in st_do_scsi()
633 mdata->pages = STp->buffer->mapped_pages; in st_do_scsi()
635 mdata->page_order = STp->buffer->reserved_page_order; in st_do_scsi()
638 mdata->pages = STp->buffer->reserved_pages; in st_do_scsi()
643 STp->buffer->cmdstat.have_sense = 0; in st_do_scsi()
644 STp->buffer->syscall_result = 0; in st_do_scsi()
650 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
651 (STp->buffer)->last_SRpnt = NULL; in st_do_scsi()
655 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in st_do_scsi()
666 static int write_behind_check(struct scsi_tape * STp) in write_behind_check() argument
674 STbuffer = STp->buffer; in write_behind_check()
679 if (STp->write_pending) in write_behind_check()
680 STp->nbr_waits++; in write_behind_check()
682 STp->nbr_finished++; in write_behind_check()
685 wait_for_completion(&(STp->wait)); in write_behind_check()
690 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in write_behind_check()
694 STps = &(STp->ps[STp->partition]); in write_behind_check()
696 if (STp->block_size == 0) in write_behind_check()
699 STps->drv_block += STbuffer->writing / STp->block_size; in write_behind_check()
720 st_printk(ST_DEB_MSG, STp, in write_behind_check()
730 static int cross_eof(struct scsi_tape * STp, int forward) in cross_eof() argument
744 DEBC_printk(STp, "Stepping over filemark %s.\n", in cross_eof()
747 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in cross_eof()
748 STp->device->request_queue->rq_timeout, in cross_eof()
751 return (STp->buffer)->syscall_result; in cross_eof()
756 if ((STp->buffer)->cmdstat.midlevel_result != 0) in cross_eof()
757 st_printk(KERN_ERR, STp, in cross_eof()
761 return (STp->buffer)->syscall_result; in cross_eof()
766 static int st_flush_write_buffer(struct scsi_tape * STp) in st_flush_write_buffer() argument
774 result = write_behind_check(STp); in st_flush_write_buffer()
779 if (STp->dirty == 1) { in st_flush_write_buffer()
781 transfer = STp->buffer->buffer_bytes; in st_flush_write_buffer()
782 DEBC_printk(STp, "Flushing %d bytes.\n", transfer); in st_flush_write_buffer()
787 blks = transfer / STp->block_size; in st_flush_write_buffer()
792 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE, in st_flush_write_buffer()
793 STp->device->request_queue->rq_timeout, in st_flush_write_buffer()
796 return (STp->buffer)->syscall_result; in st_flush_write_buffer()
798 STps = &(STp->ps[STp->partition]); in st_flush_write_buffer()
799 if ((STp->buffer)->syscall_result != 0) { in st_flush_write_buffer()
800 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush_write_buffer()
808 STp->dirty = 0; in st_flush_write_buffer()
809 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
814 st_printk(KERN_ERR, STp, "Error on flush.\n"); in st_flush_write_buffer()
821 STp->dirty = 0; in st_flush_write_buffer()
822 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
833 static int flush_buffer(struct scsi_tape *STp, int seek_next) in flush_buffer() argument
838 if (STp->ready != ST_READY) in flush_buffer()
845 if (STp->pos_unknown) in flush_buffer()
848 STps = &(STp->ps[STp->partition]); in flush_buffer()
850 return st_flush_write_buffer(STp); in flush_buffer()
852 if (STp->block_size == 0) in flush_buffer()
855 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
856 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
857 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
858 STp->block_size; in flush_buffer()
859 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
860 (STp->buffer)->read_pointer = 0; in flush_buffer()
864 result = cross_eof(STp, 0); /* Back over the EOF hit */ in flush_buffer()
874 result = st_int_ioctl(STp, MTBSR, backspace); in flush_buffer()
886 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) in set_mode_densblk() argument
891 if (!STp->density_changed && in set_mode_densblk()
893 STm->default_density != STp->density) { in set_mode_densblk()
897 arg = STp->density; in set_mode_densblk()
899 if (!STp->blksize_changed && in set_mode_densblk()
901 STm->default_blksize != STp->block_size) { in set_mode_densblk()
905 arg |= STp->block_size; in set_mode_densblk()
907 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { in set_mode_densblk()
908 st_printk(KERN_WARNING, STp, in set_mode_densblk()
920 static int do_door_lock(struct scsi_tape * STp, int do_lock) in do_door_lock() argument
924 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); in do_door_lock()
926 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
929 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
931 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
937 static void reset_state(struct scsi_tape *STp) in reset_state() argument
942 STp->pos_unknown = 0; in reset_state()
944 STps = &(STp->ps[i]); in reset_state()
952 if (STp->can_partitions) { in reset_state()
953 STp->partition = find_partition(STp); in reset_state()
954 if (STp->partition < 0) in reset_state()
955 STp->partition = 0; in reset_state()
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()
1030 if (STp->first_tur) { in test_ready()
1032 STp->pos_unknown = 0; in test_ready()
1033 STp->first_tur = 0; in test_ready()
1047 static int check_tape(struct scsi_tape *STp, struct file *filp) in check_tape() argument
1058 STp->ready = ST_READY; in check_tape()
1060 if (mode != STp->current_mode) { in check_tape()
1061 DEBC_printk(STp, "Mode change from %d to %d.\n", in check_tape()
1062 STp->current_mode, mode); in check_tape()
1064 STp->current_mode = mode; in check_tape()
1066 STm = &(STp->modes[STp->current_mode]); in check_tape()
1068 saved_cleaning = STp->cleaning_req; in check_tape()
1069 STp->cleaning_req = 0; in check_tape()
1072 retval = test_ready(STp, do_wait); in check_tape()
1078 STp->pos_unknown = 0; in check_tape()
1079 STp->partition = STp->new_partition = 0; in check_tape()
1080 if (STp->can_partitions) in check_tape()
1081 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1084 STps = &(STp->ps[i]); in check_tape()
1095 STp->cleaning_req |= saved_cleaning; in check_tape()
1099 STp->ready = ST_NO_TAPE; in check_tape()
1101 STp->ready = ST_NOT_READY; in check_tape()
1103 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1104 STp->write_prot = 0; in check_tape()
1105 STp->block_size = 0; in check_tape()
1106 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1107 STp->partition = STp->new_partition = 0; in check_tape()
1108 STp->door_locked = ST_UNLOCKED; in check_tape()
1113 if (STp->omit_blklims) in check_tape()
1114 STp->min_block = STp->max_block = (-1); in check_tape()
1119 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE, in check_tape()
1120 STp->device->request_queue->rq_timeout, in check_tape()
1123 retval = (STp->buffer)->syscall_result; in check_tape()
1127 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1128 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1129 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1130 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1131 (STp->buffer)->b_data[5]; in check_tape()
1132 if ( DEB( debugging || ) !STp->inited) in check_tape()
1133 st_printk(KERN_INFO, STp, in check_tape()
1135 STp->min_block, STp->max_block); in check_tape()
1137 STp->min_block = STp->max_block = (-1); in check_tape()
1138 DEBC_printk(STp, "Can't read block limits.\n"); in check_tape()
1146 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE, in check_tape()
1147 STp->device->request_queue->rq_timeout, in check_tape()
1150 retval = (STp->buffer)->syscall_result; in check_tape()
1154 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1155 DEBC_printk(STp, "No Mode Sense.\n"); in check_tape()
1156 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1157 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1158 STp->drv_write_prot = 0; in check_tape()
1160 DEBC_printk(STp,"Mode sense. Length %d, " in check_tape()
1162 (STp->buffer)->b_data[0], in check_tape()
1163 (STp->buffer)->b_data[1], in check_tape()
1164 (STp->buffer)->b_data[2], in check_tape()
1165 (STp->buffer)->b_data[3]); in check_tape()
1167 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1168 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1169 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1170 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1171 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1172 DEBC_printk(STp, "Density %x, tape length: %x, " in check_tape()
1174 STp->density, in check_tape()
1175 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1176 (STp->buffer)->b_data[6] * 256 + in check_tape()
1177 (STp->buffer)->b_data[7], in check_tape()
1178 STp->drv_buffer); in check_tape()
1180 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1181 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1182 st_printk(KERN_WARNING, STp, in check_tape()
1185 STp->immediate_filemark = 0; in check_tape()
1190 STp->inited = 1; in check_tape()
1192 if (STp->block_size > 0) in check_tape()
1193 (STp->buffer)->buffer_blocks = in check_tape()
1194 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1196 (STp->buffer)->buffer_blocks = 1; in check_tape()
1197 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1199 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n", in check_tape()
1200 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1201 (STp->buffer)->buffer_blocks); in check_tape()
1203 if (STp->drv_write_prot) { in check_tape()
1204 STp->write_prot = 1; in check_tape()
1206 DEBC_printk(STp, "Write protected\n"); in check_tape()
1216 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1220 DEBC_printk(STp, "Updating partition number in status.\n"); in check_tape()
1221 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1222 retval = STp->partition; in check_tape()
1225 STp->new_partition = STp->partition; in check_tape()
1226 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1230 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1231 STp->compression_changed = 0; in check_tape()
1233 (retval = set_mode_densblk(STp, STm)) < 0) in check_tape()
1236 if (STp->default_drvbuffer != 0xff) { in check_tape()
1237 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1238 st_printk(KERN_WARNING, STp, in check_tape()
1241 STp->default_drvbuffer); in check_tape()
1258 struct scsi_tape *STp; in st_open() local
1269 if (!(STp = scsi_tape_get(dev))) { in st_open()
1273 filp->private_data = STp; in st_open()
1276 if (STp->in_use) { in st_open()
1278 DEBC_printk(STp, "Device already in use.\n"); in st_open()
1279 scsi_tape_put(STp); in st_open()
1283 STp->in_use = 1; in st_open()
1285 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1287 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1292 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1298 if (!enlarge_buffer(STp->buffer, PAGE_SIZE)) { in st_open()
1299 st_printk(KERN_WARNING, STp, in st_open()
1305 (STp->buffer)->cleared = 0; in st_open()
1306 (STp->buffer)->writing = 0; in st_open()
1307 (STp->buffer)->syscall_result = 0; in st_open()
1309 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1311 STp->dirty = 0; in st_open()
1313 STps = &(STp->ps[i]); in st_open()
1316 STp->try_dio_now = STp->try_dio; in st_open()
1317 STp->recover_count = 0; in st_open()
1318 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1319 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1321 retval = check_tape(STp, filp); in st_open()
1326 if (STp->ready == NO_TAPE) in st_open()
1335 normalize_buffer(STp->buffer); in st_open()
1337 STp->in_use = 0; in st_open()
1340 scsi_autopm_put_device(STp->device); in st_open()
1341 scsi_tape_put(STp); in st_open()
1353 struct scsi_tape *STp = filp->private_data; in st_flush() local
1354 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1355 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1360 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1361 result = st_flush_write_buffer(STp); in st_flush()
1366 if (STp->can_partitions && in st_flush()
1367 (result2 = switch_partition(STp)) < 0) { in st_flush()
1368 DEBC_printk(STp, "switch_partition at close failed.\n"); in st_flush()
1374 DEBC( if (STp->nbr_requests) in st_flush()
1375 st_printk(KERN_DEBUG, STp, in st_flush()
1377 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1378 STp->nbr_pages)); in st_flush()
1380 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1381 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1384 DEBC_printk(STp, "Async write waits %d, finished %d.\n", in st_flush()
1385 STp->nbr_waits, STp->nbr_finished); in st_flush()
1389 if (STp->immediate_filemark) in st_flush()
1391 cmd[4] = 1 + STp->two_fm; in st_flush()
1393 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in st_flush()
1394 STp->device->request_queue->rq_timeout, in st_flush()
1397 result = (STp->buffer)->syscall_result; in st_flush()
1401 if (STp->buffer->syscall_result == 0 || in st_flush()
1413 if (STp->two_fm) in st_flush()
1414 cross_eof(STp, 0); in st_flush()
1420 st_printk(KERN_ERR, STp, in st_flush()
1426 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]); in st_flush()
1427 } else if (!STp->rew_at_close) { in st_flush()
1428 STps = &(STp->ps[STp->partition]); in st_flush()
1430 if (STp->can_bsr) in st_flush()
1431 result = flush_buffer(STp, 0); in st_flush()
1433 result = cross_eof(STp, 0); in st_flush()
1443 !(result = cross_eof(STp, 1))) || in st_flush()
1453 if (STp->rew_at_close) { in st_flush()
1454 result2 = st_int_ioctl(STp, MTREW, 1); in st_flush()
1466 struct scsi_tape *STp = filp->private_data; in st_release() local
1468 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1469 do_door_lock(STp, 0); in st_release()
1471 normalize_buffer(STp->buffer); in st_release()
1473 STp->in_use = 0; in st_release()
1475 scsi_autopm_put_device(STp->device); in st_release()
1476 scsi_tape_put(STp); in st_release()
1482 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) in rw_checks() argument
1492 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1497 if (STp->ready != ST_READY) { in rw_checks()
1498 if (STp->ready == ST_NO_TAPE) in rw_checks()
1505 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1515 if (STp->pos_unknown) { in rw_checks()
1524 if (!STp->in_use) { in rw_checks()
1525 st_printk(ST_DEB_MSG, STp, in rw_checks()
1531 if (STp->can_partitions && in rw_checks()
1532 (retval = switch_partition(STp)) < 0) in rw_checks()
1535 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1536 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1541 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1542 !do_door_lock(STp, 1)) in rw_checks()
1543 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1550 static int setup_buffering(struct scsi_tape *STp, const char __user *buf, in setup_buffering() argument
1554 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1557 i = STp->try_dio_now && try_rdio; in setup_buffering()
1559 i = STp->try_dio_now && try_wdio; in setup_buffering()
1562 STp->device->request_queue)) == 0) { in setup_buffering()
1574 STp->nbr_dio++; in setup_buffering()
1575 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1580 DEB( STp->nbr_requests++; ) in setup_buffering()
1583 if (STp->block_size) in setup_buffering()
1584 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1585 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1590 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1596 st_printk(KERN_WARNING, STp, in setup_buffering()
1602 if (STp->block_size) in setup_buffering()
1603 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1612 static void release_buffering(struct scsi_tape *STp, int is_read) in release_buffering() argument
1616 STbp = STp->buffer; in release_buffering()
1637 struct scsi_tape *STp = filp->private_data; in st_write() local
1642 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1645 retval = rw_checks(STp, filp, count); in st_write()
1650 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1651 st_printk(KERN_WARNING, STp, in st_write()
1657 STm = &(STp->modes[STp->current_mode]); in st_write()
1658 STps = &(STp->ps[STp->partition]); in st_write()
1660 if (STp->write_prot) { in st_write()
1667 retval = flush_buffer(STp, 0); in st_write()
1673 if ((retval = set_mode_densblk(STp, STm)) < 0) in st_write()
1676 !(STp->compression_changed)) { in st_write()
1677 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1678 st_printk(KERN_WARNING, STp, in st_write()
1688 STbp = STp->buffer; in st_write()
1689 i = write_behind_check(STp); in st_write()
1709 if (STp->block_size != 0 && in st_write()
1717 retval = setup_buffering(STp, buf, count, 0); in st_write()
1725 cmd[1] = (STp->block_size != 0); in st_write()
1736 if (STp->block_size == 0) in st_write()
1739 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1754 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1757 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1758 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1760 STp->dirty = 1; in st_write()
1767 if (STp->block_size == 0) in st_write()
1774 blks /= STp->block_size; in st_write()
1775 transfer = blks * STp->block_size; in st_write()
1781 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE, in st_write()
1782 STp->device->request_queue->rq_timeout, in st_write()
1790 STp->dirty = !(STbp->writing == in st_write()
1793 DEB( STp->write_pending = 1; ) in st_write()
1798 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1800 DEBC_printk(STp, "Error on write:\n"); in st_write()
1805 else if (STp->block_size == 0 && in st_write()
1810 if (STp->block_size != 0) in st_write()
1811 undone *= STp->block_size; in st_write()
1817 if (STp->block_size) in st_write()
1818 blks = (transfer - undone) / STp->block_size; in st_write()
1824 if (STp->block_size == 0 || in st_write()
1827 DEBC_printk(STp, "EOM with %d " in st_write()
1835 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1839 STp->block_size; in st_write()
1842 DEBC_printk(STp, "Retry " in st_write()
1845 STp->buffer->buffer_bytes); in st_write()
1856 DEBC_printk(STp, "EOM with " in st_write()
1869 if (STp->block_size == 0) in st_write()
1876 STp->dirty = 0; in st_write()
1894 release_buffering(STp, 0); in st_write()
1895 mutex_unlock(&STp->lock); in st_write()
1906 static long read_tape(struct scsi_tape *STp, long count, in read_tape() argument
1920 STm = &(STp->modes[STp->current_mode]); in read_tape()
1921 STps = &(STp->ps[STp->partition]); in read_tape()
1924 STbp = STp->buffer; in read_tape()
1926 if (STp->block_size == 0) in read_tape()
1929 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1930 blks = (STp->buffer)->buffer_blocks; in read_tape()
1931 bytes = blks * STp->block_size; in read_tape()
1934 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1935 bytes = (STp->buffer)->buffer_size; in read_tape()
1936 blks = bytes / STp->block_size; in read_tape()
1937 bytes = blks * STp->block_size; in read_tape()
1943 cmd[1] = (STp->block_size != 0); in read_tape()
1944 if (!cmd[1] && STp->sili) in read_tape()
1951 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, in read_tape()
1952 STp->device->request_queue->rq_timeout, in read_tape()
1954 release_buffering(STp, 1); in read_tape()
1964 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1967 DEBC_printk(STp, in read_tape()
1985 if (STp->block_size == 0) in read_tape()
1992 if (STp->block_size == 0 && in read_tape()
1994 st_printk(KERN_NOTICE, STp, in read_tape()
2004 } else if (STp->block_size == 0) { in read_tape()
2010 st_printk(KERN_NOTICE, STp, in read_tape()
2015 st_int_ioctl(STp, MTBSR, 1); in read_tape()
2020 STp->block_size; in read_tape()
2021 DEBC_printk(STp, "ILI but " in read_tape()
2028 if (st_int_ioctl(STp, MTBSR, 1)) in read_tape()
2036 if (STp->block_size == 0) in read_tape()
2040 bytes - transfer * STp->block_size; in read_tape()
2041 DEBC_printk(STp, "EOF detected (%d " in read_tape()
2049 if (STp->block_size == 0) in read_tape()
2053 bytes - transfer * STp->block_size; in read_tape()
2055 DEBC_printk(STp, "EOM detected (%d " in read_tape()
2062 DEBC_printk(STp, "Tape error while reading.\n"); in read_tape()
2066 DEBC_printk(STp, "Zero returned for " in read_tape()
2086 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2087 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2091 if (STp->block_size == 0) in read_tape()
2094 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2109 struct scsi_tape *STp = filp->private_data; in st_read() local
2112 struct st_buffer *STbp = STp->buffer; in st_read()
2114 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2117 retval = rw_checks(STp, filp, count); in st_read()
2121 STm = &(STp->modes[STp->current_mode]); in st_read()
2122 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2127 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2130 STps = &(STp->ps[STp->partition]); in st_read()
2132 retval = flush_buffer(STp, 0); in st_read()
2139 st_printk(ST_DEB_MSG, STp, in st_read()
2144 retval = setup_buffering(STp, buf, count, 1); in st_read()
2180 special = read_tape(STp, count - total, &SRpnt); in st_read()
2191 st_printk(ST_DEB_MSG, STp, in st_read()
2209 if (STp->block_size == 0) in st_read()
2239 release_buffering(STp, 1); in st_read()
2242 mutex_unlock(&STp->lock); in st_read()
2251 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm) in DEB() argument
2254 st_printk(KERN_INFO, STp, in DEB()
2257 STp->current_mode, STm->do_buffer_writes, in DEB()
2259 st_printk(KERN_INFO, STp, in DEB()
2262 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2263 STp->do_auto_lock); in DEB()
2264 st_printk(KERN_INFO, STp, in DEB()
2267 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2268 STp->can_partitions, STp->scsi2_logical); in DEB()
2269 st_printk(KERN_INFO, STp, in DEB()
2272 STm->sysv, STp->immediate, STp->sili, in DEB()
2273 STp->immediate_filemark); in DEB()
2274 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging); in DEB()
2280 static int st_set_options(struct scsi_tape *STp, long options)
2288 STm = &(STp->modes[STp->current_mode]);
2294 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2300 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2301 STp->current_mode);
2310 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2311 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2312 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2313 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2314 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2315 if ((STp->device)->scsi_level >= SCSI_2)
2316 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2317 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2318 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2319 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2321 STp->sili = (options & MT_ST_SILI) != 0;
2323 st_log_options(STp, STm); )
2335 STp->two_fm = value;
2337 STp->fast_mteom = value;
2339 STp->do_auto_lock = value;
2341 STp->can_bsr = value;
2343 STp->omit_blklims = value;
2344 if ((STp->device)->scsi_level >= SCSI_2 &&
2346 STp->can_partitions = value;
2348 STp->scsi2_logical = value;
2350 STp->immediate = value;
2352 STp->immediate_filemark = value;
2356 STp->sili = value;
2360 st_log_options(STp, STm); )
2367 DEBC_printk(STp, "Default block size disabled.\n");
2370 DEBC_printk(STp,"Default block size set to "
2372 if (STp->ready == ST_READY) {
2373 STp->blksize_changed = 0;
2374 set_mode_densblk(STp, STm);
2380 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2381 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2384 blk_queue_rq_timeout(STp->device->request_queue,
2386 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2395 STp->cln_mode = value;
2396 STp->cln_sense_mask = (options >> 8) & 0xff;
2397 STp->cln_sense_value = (options >> 16) & 0xff;
2398 st_printk(KERN_INFO, STp,
2400 value, STp->cln_sense_mask, STp->cln_sense_value);
2407 DEBC_printk(STp,
2411 DEBC_printk(STp, "Density default set to %x\n",
2413 if (STp->ready == ST_READY) {
2414 STp->density_changed = 0;
2415 set_mode_densblk(STp, STm);
2420 STp->default_drvbuffer = 0xff;
2421 DEBC_printk(STp,
2424 STp->default_drvbuffer = value & 7;
2425 DEBC_printk(STp,
2427 STp->default_drvbuffer);
2428 if (STp->ready == ST_READY)
2429 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2434 DEBC_printk(STp,
2438 STp->c_algo = (value & 0xff00) >> 8;
2439 DEBC_printk(STp, "Compression "
2441 STp->c_algo);
2445 DEBC_printk(STp, "Compression default "
2448 if (STp->ready == ST_READY) {
2449 STp->compression_changed = 0;
2450 st_compression(STp, (STm->default_compression == ST_YES));
2483 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) in read_mode_page() argument
2495 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE, in read_mode_page()
2496 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2498 return (STp->buffer)->syscall_result; in read_mode_page()
2502 return STp->buffer->syscall_result; in read_mode_page()
2508 static int write_mode_page(struct scsi_tape *STp, int page, int slow) in write_mode_page() argument
2518 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2519 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2522 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2523 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2524 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2525 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2528 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2529 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE, in write_mode_page()
2532 return (STp->buffer)->syscall_result; in write_mode_page()
2536 return STp->buffer->syscall_result; in write_mode_page()
2557 static int st_compression(struct scsi_tape * STp, int state) in st_compression() argument
2561 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2563 if (STp->ready != ST_READY) in st_compression()
2567 retval = read_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2569 DEBC_printk(STp, "Compression mode page not supported.\n"); in st_compression()
2574 DEBC_printk(STp, "Compression state is %d.\n", in st_compression()
2579 DEBC_printk(STp, "Compression not supported.\n"); in st_compression()
2586 if (STp->c_algo != 0) in st_compression()
2587 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2591 if (STp->c_algo != 0) in st_compression()
2595 retval = write_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2597 DEBC_printk(STp, "Compression change failed.\n"); in st_compression()
2600 DEBC_printk(STp, "Compression state changed to %d.\n", state); in st_compression()
2602 STp->compression_changed = 1; in st_compression()
2608 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) in do_load_unload() argument
2615 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2616 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2631 DEBC_printk(STp, " Enhanced %sload slot %2d.\n", in do_load_unload()
2636 if (STp->immediate) { in do_load_unload()
2638 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2641 timeout = STp->long_timeout; in do_load_unload()
2645 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n"); in do_load_unload()
2647 st_printk(ST_DEB_MSG, STp, "Loading tape.\n"); in do_load_unload()
2650 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in do_load_unload()
2653 return (STp->buffer)->syscall_result; in do_load_unload()
2655 retval = (STp->buffer)->syscall_result; in do_load_unload()
2661 STp->rew_at_close = 0; in do_load_unload()
2662 STp->ready = ST_NO_TAPE; in do_load_unload()
2665 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2666 retval = check_tape(STp, filp); in do_load_unload()
2672 STps = &(STp->ps[STp->partition]); in do_load_unload()
2682 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) in deb_space_print() argument
2692 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n", in deb_space_print()
2698 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) … in deb_space_print() argument
2703 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg) in st_int_ioctl() argument
2715 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2716 if (STp->ready != ST_READY) { in st_int_ioctl()
2717 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2722 timeout = STp->long_timeout; in st_int_ioctl()
2723 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2739 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd); in st_int_ioctl()
2755 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd); in st_int_ioctl()
2767 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd); in st_int_ioctl()
2779 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd); in st_int_ioctl()
2790 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd); in st_int_ioctl()
2803 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd); in st_int_ioctl()
2812 if (STp->write_prot) in st_int_ioctl()
2818 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2823 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2826 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2832 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2845 if (STp->immediate) { in st_int_ioctl()
2847 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2849 DEBC_printk(STp, "Rewinding tape.\n"); in st_int_ioctl()
2853 DEBC_printk(STp, "No op on tape.\n"); in st_int_ioctl()
2857 if (STp->immediate) { in st_int_ioctl()
2859 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2862 DEBC_printk(STp, "Retensioning tape.\n"); in st_int_ioctl()
2866 if (!STp->fast_mteom) { in st_int_ioctl()
2868 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff); in st_int_ioctl()
2880 DEBC_printk(STp, "Spacing to end of recorded medium.\n"); in st_int_ioctl()
2885 if (STp->write_prot) in st_int_ioctl()
2889 if (STp->immediate) { in st_int_ioctl()
2891 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2894 timeout = STp->long_timeout * 8; in st_int_ioctl()
2896 DEBC_printk(STp, "Erasing tape.\n"); in st_int_ioctl()
2903 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in st_int_ioctl()
2907 STp->max_block > 0 && in st_int_ioctl()
2908 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || in st_int_ioctl()
2909 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { in st_int_ioctl()
2910 st_printk(KERN_WARNING, STp, "Illegal block size.\n"); in st_int_ioctl()
2914 if ((STp->use_pf & USE_PF)) in st_int_ioctl()
2919 memset((STp->buffer)->b_data, 0, 12); in st_int_ioctl()
2921 (STp->buffer)->b_data[2] = (arg & 7) << 4; in st_int_ioctl()
2923 (STp->buffer)->b_data[2] = in st_int_ioctl()
2924 STp->drv_buffer << 4; in st_int_ioctl()
2925 (STp->buffer)->b_data[3] = 8; /* block descriptor length */ in st_int_ioctl()
2927 (STp->buffer)->b_data[4] = arg; in st_int_ioctl()
2928 STp->density_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2929 STp->changed_density = arg; in st_int_ioctl()
2931 (STp->buffer)->b_data[4] = arg >> 24; in st_int_ioctl()
2933 (STp->buffer)->b_data[4] = STp->density; in st_int_ioctl()
2937 STp->blksize_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2938 STp->changed_blksize = arg; in st_int_ioctl()
2941 ltmp = STp->block_size; in st_int_ioctl()
2942 (STp->buffer)->b_data[9] = (ltmp >> 16); in st_int_ioctl()
2943 (STp->buffer)->b_data[10] = (ltmp >> 8); in st_int_ioctl()
2944 (STp->buffer)->b_data[11] = ltmp; in st_int_ioctl()
2945 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2948 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2950 (STp->buffer)->b_data[9] * 65536 + in st_int_ioctl()
2951 (STp->buffer)->b_data[10] * 256 + in st_int_ioctl()
2952 (STp->buffer)->b_data[11]); in st_int_ioctl()
2954 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2956 (STp->buffer)->b_data[4]); in st_int_ioctl()
2958 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2960 ((STp->buffer)->b_data[2] >> 4) & 7); in st_int_ioctl()
2967 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction, in st_int_ioctl()
2970 return (STp->buffer)->syscall_result; in st_int_ioctl()
2972 ioctl_result = (STp->buffer)->syscall_result; in st_int_ioctl()
2982 ioctl_result = st_int_ioctl(STp, MTFSF, 1); in st_int_ioctl()
2984 ioctl_result = st_int_ioctl(STp, MTBSF, 1); in st_int_ioctl()
2987 STp->block_size = arg & MT_ST_BLKSIZE_MASK; in st_int_ioctl()
2988 if (STp->block_size != 0) { in st_int_ioctl()
2989 (STp->buffer)->buffer_blocks = in st_int_ioctl()
2990 (STp->buffer)->buffer_size / STp->block_size; in st_int_ioctl()
2992 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in st_int_ioctl()
2994 STp->density = arg >> MT_ST_DENSITY_SHIFT; in st_int_ioctl()
2996 STp->drv_buffer = (arg & 7); in st_int_ioctl()
2998 STp->density = arg; in st_int_ioctl()
3011 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_int_ioctl()
3087 (STp->device)->scsi_level <= SCSI_2 && in st_int_ioctl()
3088 !(STp->use_pf & PF_TESTED)) { in st_int_ioctl()
3091 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED; in st_int_ioctl()
3094 return st_int_ioctl(STp, cmd_in, arg); in st_int_ioctl()
3113 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition, in get_location() argument
3120 if (STp->ready != ST_READY) in get_location()
3124 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3129 if (!logical && !STp->scsi2_logical) in get_location()
3132 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE, in get_location()
3133 STp->device->request_queue->rq_timeout, in get_location()
3136 return (STp->buffer)->syscall_result; in get_location()
3138 if ((STp->buffer)->syscall_result != 0 || in get_location()
3139 (STp->device->scsi_level >= SCSI_2 && in get_location()
3140 ((STp->buffer)->b_data[0] & 4) != 0)) { in get_location()
3142 DEBC_printk(STp, " Can't read tape position.\n"); in get_location()
3146 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3147 *block = ((STp->buffer)->b_data[0] << 16) in get_location()
3148 + ((STp->buffer)->b_data[1] << 8) in get_location()
3149 + (STp->buffer)->b_data[2]; in get_location()
3152 *block = ((STp->buffer)->b_data[4] << 24) in get_location()
3153 + ((STp->buffer)->b_data[5] << 16) in get_location()
3154 + ((STp->buffer)->b_data[6] << 8) in get_location()
3155 + (STp->buffer)->b_data[7]; in get_location()
3156 *partition = (STp->buffer)->b_data[1]; in get_location()
3157 if (((STp->buffer)->b_data[0] & 0x80) && in get_location()
3158 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ in get_location()
3159 STp->ps[0].drv_block = STp->ps[0].drv_file = 0; in get_location()
3161 DEBC_printk(STp, "Got tape pos. blk %d part %d.\n", in get_location()
3173 static int set_location(struct scsi_tape *STp, unsigned int block, int partition, in set_location() argument
3183 if (STp->ready != ST_READY) in set_location()
3185 timeout = STp->long_timeout; in set_location()
3186 STps = &(STp->ps[STp->partition]); in set_location()
3188 DEBC_printk(STp, "Setting block to %d and partition to %d.\n", in set_location()
3194 if ((!STp->can_partitions && partition != 0) || in set_location()
3197 if (partition != STp->partition) { in set_location()
3198 if (get_location(STp, &blk, &p, 1)) in set_location()
3203 DEBC_printk(STp, "Visited block %d for " in set_location()
3205 blk, STp->partition); in set_location()
3210 if ((STp->device)->scsi_level < SCSI_2) { in set_location()
3222 if (!logical && !STp->scsi2_logical) in set_location()
3224 if (STp->partition != partition) { in set_location()
3227 DEBC_printk(STp, "Trying to change partition " in set_location()
3228 "from %d to %d\n", STp->partition, in set_location()
3232 if (STp->immediate) { in set_location()
3234 timeout = STp->device->request_queue->rq_timeout; in set_location()
3237 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in set_location()
3240 return (STp->buffer)->syscall_result; in set_location()
3244 if ((STp->buffer)->syscall_result != 0) { in set_location()
3246 if (STp->can_partitions && in set_location()
3247 (STp->device)->scsi_level >= SCSI_2 && in set_location()
3248 (p = find_partition(STp)) >= 0) in set_location()
3249 STp->partition = p; in set_location()
3251 if (STp->can_partitions) { in set_location()
3252 STp->partition = partition; in set_location()
3253 STps = &(STp->ps[partition]); in set_location()
3275 static int find_partition(struct scsi_tape *STp) in find_partition() argument
3280 if ((i = get_location(STp, &block, &partition, 1)) < 0) in find_partition()
3289 static int switch_partition(struct scsi_tape *STp) in switch_partition() argument
3293 if (STp->partition == STp->new_partition) in switch_partition()
3295 STps = &(STp->ps[STp->new_partition]); in switch_partition()
3298 return set_location(STp, STps->last_block_visited, STp->new_partition, 1); in switch_partition()
3320 static int nbr_partitions(struct scsi_tape *STp) in nbr_partitions() argument
3324 if (STp->ready != ST_READY) in nbr_partitions()
3327 result = read_mode_page(STp, PART_PAGE, 1); in nbr_partitions()
3330 DEBC_printk(STp, "Can't read medium partition page.\n"); in nbr_partitions()
3333 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + in nbr_partitions()
3335 DEBC_printk(STp, "Number of partitions %d.\n", result); in nbr_partitions()
3342 static int format_medium(struct scsi_tape *STp, int format) in format_medium() argument
3345 int timeout = STp->long_timeout; in format_medium()
3352 if (STp->immediate) { in format_medium()
3354 timeout = STp->device->request_queue->rq_timeout; in format_medium()
3356 DEBC_printk(STp, "Sending FORMAT MEDIUM\n"); in format_medium()
3357 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in format_medium()
3360 result = STp->buffer->syscall_result; in format_medium()
3386 static int partition_tape(struct scsi_tape *STp, int size) in partition_tape() argument
3390 bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false; in partition_tape()
3395 result = read_mode_page(STp, PART_PAGE, 0); in partition_tape()
3397 DEBC_printk(STp, "Can't read partition mode page.\n"); in partition_tape()
3407 bp = (STp->buffer)->b_data; in partition_tape()
3409 DEBC_printk(STp, "Partition page length is %d bytes.\n", in partition_tape()
3420 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3421 result = format_medium(STp, 0); in partition_tape()
3463 DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n", in partition_tape()
3471 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3480 DEBC_printk(STp, in partition_tape()
3495 result = write_mode_page(STp, PART_PAGE, 1); in partition_tape()
3498 result = format_medium(STp, 1); in partition_tape()
3501 st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n"); in partition_tape()
3519 struct scsi_tape *STp = file->private_data; in st_ioctl() local
3523 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl()
3527 if (debugging && !STp->in_use) { in st_ioctl()
3528 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n"); in st_ioctl()
3533 STm = &(STp->modes[STp->current_mode]); in st_ioctl()
3534 STps = &(STp->ps[STp->partition]); in st_ioctl()
3542 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl()
3565 st_printk(KERN_WARNING, STp, in st_ioctl()
3577 if (!STp->pos_unknown) { in st_ioctl()
3595 i = !STp->can_partitions || in st_ioctl()
3596 (STp->new_partition != STp->partition); in st_ioctl()
3605 i = flush_buffer(STp, i); in st_ioctl()
3614 i = st_int_ioctl(STp, MTWEOF, 1); in st_ioctl()
3640 reset_state(STp); /* Clears pos_unknown */ in st_ioctl()
3642 STp->device->was_reset = 0; in st_ioctl()
3647 if (STp->can_partitions) { in st_ioctl()
3648 /* STp->new_partition contains the in st_ioctl()
3651 STp->partition = 0; in st_ioctl()
3652 switch_partition(STp); in st_ioctl()
3654 if (STp->density_changed) in st_ioctl()
3655 st_int_ioctl(STp, MTSETDENSITY, STp->changed_density); in st_ioctl()
3656 if (STp->blksize_changed) in st_ioctl()
3657 st_int_ioctl(STp, MTSETBLK, STp->changed_blksize); in st_ioctl()
3666 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl()
3667 do_door_lock(STp, 0); /* Ignore result! */ in st_ioctl()
3671 retval = st_set_options(STp, mtc.mt_count); in st_ioctl()
3676 if (!STp->can_partitions || in st_ioctl()
3681 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl()
3682 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl()
3686 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl()
3690 STp->new_partition = mtc.mt_count; in st_ioctl()
3696 if (!STp->can_partitions) { in st_ioctl()
3700 i = do_load_unload(STp, file, 1); in st_ioctl()
3705 i = partition_tape(STp, mtc.mt_count); in st_ioctl()
3711 STp->ps[i].rw = ST_IDLE; in st_ioctl()
3712 STp->ps[i].at_sm = 0; in st_ioctl()
3713 STp->ps[i].last_block_valid = 0; in st_ioctl()
3715 STp->partition = STp->new_partition = 0; in st_ioctl()
3716 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl()
3723 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl()
3724 if (!STp->can_partitions) in st_ioctl()
3725 STp->ps[0].rw = ST_IDLE; in st_ioctl()
3731 retval = do_load_unload(STp, file, 0); in st_ioctl()
3736 retval = do_load_unload(STp, file, max(1, mtc.mt_count)); in st_ioctl()
3741 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK)); in st_ioctl()
3745 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl()
3746 (i = switch_partition(STp)) < 0) { in st_ioctl()
3752 retval = st_compression(STp, (mtc.mt_count & 1)); in st_ioctl()
3754 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count); in st_ioctl()
3764 if ((i = flush_buffer(STp, 0)) < 0) { in st_ioctl()
3765 if (cmd_mtiocget && STp->pos_unknown) { in st_ioctl()
3767 reset_state(STp); in st_ioctl()
3768 STp->pos_unknown = 1; in st_ioctl()
3774 if (STp->can_partitions) { in st_ioctl()
3775 i = switch_partition(STp); in st_ioctl()
3791 mt_status.mt_type = STp->tape_type; in st_ioctl()
3793 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl()
3794 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl()
3797 if (STp->block_size != 0 && mt_status.mt_blkno >= 0) { in st_ioctl()
3800 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl()
3803 ((STp->buffer)->buffer_bytes + in st_ioctl()
3804 STp->block_size - 1) / STp->block_size; in st_ioctl()
3808 if (STp->drv_write_prot) in st_ioctl()
3816 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl()
3817 mt_status.mt_resid = STp->partition; in st_ioctl()
3822 if (STp->density == 1) in st_ioctl()
3824 else if (STp->density == 2) in st_ioctl()
3826 else if (STp->density == 3) in st_ioctl()
3828 if (STp->ready == ST_READY) in st_ioctl()
3830 if (STp->ready == ST_NO_TAPE) in st_ioctl()
3835 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl()
3836 STp->drv_buffer != 0) in st_ioctl()
3838 if (STp->cleaning_req) in st_ioctl()
3845 STp->recover_reg = 0; /* Clear after read */ in st_ioctl()
3854 if ((i = get_location(STp, &blk, &bt, 0)) < 0) { in st_ioctl()
3862 mutex_unlock(&STp->lock); in st_ioctl()
3875 retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, cmd_in, p); in st_ioctl()
3878 STp->rew_at_close = 0; in st_ioctl()
3879 STp->ready = ST_NO_TAPE; in st_ioctl()
3884 mutex_unlock(&STp->lock); in st_ioctl()
4143 char *stp; in st_setup() local
4145 stp = get_options(str, ARRAY_SIZE(ints), ints); in st_setup()
4152 while (stp != NULL) { in st_setup()
4155 if (!strncmp(stp, parms[i].name, len) && in st_setup()
4156 (*(stp + len) == ':' || *(stp + len) == '=')) { in st_setup()
4159 simple_strtoul(stp + len + 1, NULL, 0); in st_setup()
4168 stp); in st_setup()
4169 stp = strchr(stp, ','); in st_setup()
4170 if (stp) in st_setup()
4171 stp++; in st_setup()
4660 struct scsi_tape *STp = STm->tape; in options_show() local
4668 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4669 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4671 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4672 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4673 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4674 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4676 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4677 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4678 options |= STp->sili ? MT_ST_SILI : 0; in options_show()