Lines Matching refs:STp

246 	struct scsi_tape *STp = NULL;  in scsi_tape_get()  local
251 STp = idr_find(&st_index_idr, dev); in scsi_tape_get()
252 if (!STp) goto out; in scsi_tape_get()
254 kref_get(&STp->kref); in scsi_tape_get()
256 if (!STp->device) in scsi_tape_get()
259 if (scsi_device_get(STp->device)) in scsi_tape_get()
265 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_get()
266 STp = NULL; in scsi_tape_get()
270 return STp; in scsi_tape_get()
273 static void scsi_tape_put(struct scsi_tape *STp) in scsi_tape_put() argument
275 struct scsi_device *sdev = STp->device; in scsi_tape_put()
278 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_put()
358 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) in st_chk_result() argument
364 char *name = STp->name; in st_chk_result()
367 ctr = scsi_get_ua_por_ctr(STp->device); in st_chk_result()
368 if (ctr != STp->por_ctr) { in st_chk_result()
369 STp->por_ctr = ctr; in st_chk_result()
370 STp->pos_unknown = 1; /* ASC => power on / reset */ in st_chk_result()
371 st_printk(KERN_WARNING, STp, "Power on/reset recognized."); in st_chk_result()
377 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
381 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
387 st_printk(ST_DEB_MSG, STp, in st_chk_result()
392 __scsi_print_sense(STp->device, name, in st_chk_result()
397 st_printk(KERN_WARNING, STp, in st_chk_result()
409 __scsi_print_sense(STp->device, name, in st_chk_result()
415 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
416 if (STp->cln_sense_value) in st_chk_result()
417 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
418 STp->cln_sense_mask) == STp->cln_sense_value); in st_chk_result()
420 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
421 STp->cln_sense_mask) != 0); in st_chk_result()
425 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
427 cmdstatp->sense_hdr.asc == 0x29 && !STp->pos_unknown) { in st_chk_result()
428 STp->pos_unknown = 1; /* ASC => power on / reset */ in st_chk_result()
429 st_printk(KERN_WARNING, STp, "Power on/reset recognized."); in st_chk_result()
439 STp->recover_count++; in st_chk_result()
440 STp->recover_reg++; in st_chk_result()
450 st_printk(ST_DEB_MSG, STp, in st_chk_result()
452 stp, STp->recover_count); in st_chk_result()
485 static void st_do_stats(struct scsi_tape *STp, struct request *req) in st_do_stats() argument
492 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
493 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
494 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
495 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
497 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
498 - STp->buffer->cmdstat.residual, in st_do_stats()
499 &STp->stats->write_byte_cnt); in st_do_stats()
500 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
501 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
503 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
504 &STp->stats->write_byte_cnt); in st_do_stats()
506 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
507 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time); in st_do_stats()
508 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
509 atomic64_inc(&STp->stats->read_cnt); in st_do_stats()
511 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
512 - STp->buffer->cmdstat.residual, in st_do_stats()
513 &STp->stats->read_byte_cnt); in st_do_stats()
514 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
515 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
517 atomic64_add(atomic_read(&STp->stats->last_read_size), in st_do_stats()
518 &STp->stats->read_byte_cnt); in st_do_stats()
520 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
521 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
522 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
524 atomic64_dec(&STp->stats->in_flight); in st_do_stats()
533 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end() local
536 STp->buffer->cmdstat.midlevel_result = SRpnt->result = scmd->result; in st_scsi_execute_end()
537 STp->buffer->cmdstat.residual = scmd->resid_len; in st_scsi_execute_end()
539 st_do_stats(STp, req); in st_scsi_execute_end()
559 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute() local
581 atomic64_inc(&STp->stats->in_flight); in st_scsi_execute()
583 atomic_set(&STp->stats->last_write_size, bufflen); in st_scsi_execute()
584 STp->stats->write_time = ktime_get(); in st_scsi_execute()
586 atomic_set(&STp->stats->last_read_size, bufflen); in st_scsi_execute()
587 STp->stats->read_time = ktime_get(); in st_scsi_execute()
589 STp->stats->other_time = ktime_get(); in st_scsi_execute()
608 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, in st_do_scsi() argument
612 struct rq_map_data *mdata = &STp->buffer->map_data; in st_do_scsi()
616 if (!do_wait && ((STp->buffer)->last_SRpnt)) { in st_do_scsi()
617 st_printk(KERN_ERR, STp, in st_do_scsi()
620 (STp->buffer)->syscall_result = (-EINTR); in st_do_scsi()
622 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
627 SRpnt = st_allocate_request(STp); in st_do_scsi()
635 (STp->buffer)->last_SRpnt = SRpnt; in st_do_scsi()
637 waiting = &STp->wait; in st_do_scsi()
641 if (STp->buffer->do_dio) { in st_do_scsi()
643 mdata->nr_entries = STp->buffer->sg_segs; in st_do_scsi()
644 mdata->pages = STp->buffer->mapped_pages; in st_do_scsi()
646 mdata->page_order = STp->buffer->reserved_page_order; in st_do_scsi()
649 mdata->pages = STp->buffer->reserved_pages; in st_do_scsi()
654 STp->buffer->cmdstat.have_sense = 0; in st_do_scsi()
655 STp->buffer->syscall_result = 0; in st_do_scsi()
661 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
662 (STp->buffer)->last_SRpnt = NULL; in st_do_scsi()
666 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in st_do_scsi()
677 static int write_behind_check(struct scsi_tape * STp) in write_behind_check() argument
685 STbuffer = STp->buffer; in write_behind_check()
690 if (STp->write_pending) in write_behind_check()
691 STp->nbr_waits++; in write_behind_check()
693 STp->nbr_finished++; in write_behind_check()
696 wait_for_completion(&(STp->wait)); in write_behind_check()
701 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in write_behind_check()
705 STps = &(STp->ps[STp->partition]); in write_behind_check()
707 if (STp->block_size == 0) in write_behind_check()
710 STps->drv_block += STbuffer->writing / STp->block_size; in write_behind_check()
731 st_printk(ST_DEB_MSG, STp, in write_behind_check()
741 static int cross_eof(struct scsi_tape * STp, int forward) in cross_eof() argument
755 DEBC_printk(STp, "Stepping over filemark %s.\n", in cross_eof()
758 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in cross_eof()
759 STp->device->request_queue->rq_timeout, in cross_eof()
762 return (STp->buffer)->syscall_result; in cross_eof()
767 if ((STp->buffer)->cmdstat.midlevel_result != 0) in cross_eof()
768 st_printk(KERN_ERR, STp, in cross_eof()
772 return (STp->buffer)->syscall_result; in cross_eof()
777 static int st_flush_write_buffer(struct scsi_tape * STp) in st_flush_write_buffer() argument
785 result = write_behind_check(STp); in st_flush_write_buffer()
790 if (STp->dirty == 1) { in st_flush_write_buffer()
792 transfer = STp->buffer->buffer_bytes; in st_flush_write_buffer()
793 DEBC_printk(STp, "Flushing %d bytes.\n", transfer); in st_flush_write_buffer()
798 blks = transfer / STp->block_size; in st_flush_write_buffer()
803 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE, in st_flush_write_buffer()
804 STp->device->request_queue->rq_timeout, in st_flush_write_buffer()
807 return (STp->buffer)->syscall_result; in st_flush_write_buffer()
809 STps = &(STp->ps[STp->partition]); in st_flush_write_buffer()
810 if ((STp->buffer)->syscall_result != 0) { in st_flush_write_buffer()
811 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush_write_buffer()
819 STp->dirty = 0; in st_flush_write_buffer()
820 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
825 st_printk(KERN_ERR, STp, "Error on flush.\n"); in st_flush_write_buffer()
832 STp->dirty = 0; in st_flush_write_buffer()
833 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
844 static int flush_buffer(struct scsi_tape *STp, int seek_next) in flush_buffer() argument
849 if (STp->ready != ST_READY) in flush_buffer()
856 if (STp->pos_unknown) in flush_buffer()
859 STps = &(STp->ps[STp->partition]); in flush_buffer()
861 return st_flush_write_buffer(STp); in flush_buffer()
863 if (STp->block_size == 0) in flush_buffer()
866 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
867 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
868 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
869 STp->block_size; in flush_buffer()
870 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
871 (STp->buffer)->read_pointer = 0; in flush_buffer()
875 result = cross_eof(STp, 0); /* Back over the EOF hit */ in flush_buffer()
885 result = st_int_ioctl(STp, MTBSR, backspace); in flush_buffer()
897 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) in set_mode_densblk() argument
902 if (!STp->density_changed && in set_mode_densblk()
904 STm->default_density != STp->density) { in set_mode_densblk()
908 arg = STp->density; in set_mode_densblk()
910 if (!STp->blksize_changed && in set_mode_densblk()
912 STm->default_blksize != STp->block_size) { in set_mode_densblk()
916 arg |= STp->block_size; in set_mode_densblk()
918 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { in set_mode_densblk()
919 st_printk(KERN_WARNING, STp, in set_mode_densblk()
931 static int do_door_lock(struct scsi_tape * STp, int do_lock) in do_door_lock() argument
935 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); in do_door_lock()
937 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
940 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
942 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
948 static void reset_state(struct scsi_tape *STp) in reset_state() argument
953 STp->pos_unknown = 0; in reset_state()
955 STps = &(STp->ps[i]); in reset_state()
963 if (STp->can_partitions) { in reset_state()
964 STp->partition = find_partition(STp); in reset_state()
965 if (STp->partition < 0) in reset_state()
966 STp->partition = 0; in reset_state()
979 static int test_ready(struct scsi_tape *STp, int do_wait) in test_ready() argument
986 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
993 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, in test_ready()
994 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
997 retval = (STp->buffer)->syscall_result; in test_ready()
1008 DEBC_printk(STp, "New tape session."); in test_ready()
1030 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
1040 ctr = scsi_get_ua_new_media_ctr(STp->device); in test_ready()
1041 if (ctr != STp->new_media_ctr) { in test_ready()
1042 STp->new_media_ctr = ctr; in test_ready()
1044 DEBC_printk(STp, "New tape session."); in test_ready()
1047 retval = (STp->buffer)->syscall_result; in test_ready()
1052 if (STp->first_tur) { in test_ready()
1054 STp->pos_unknown = 0; in test_ready()
1055 STp->first_tur = 0; in test_ready()
1069 static int check_tape(struct scsi_tape *STp, struct file *filp) in check_tape() argument
1080 STp->ready = ST_READY; in check_tape()
1082 if (mode != STp->current_mode) { in check_tape()
1083 DEBC_printk(STp, "Mode change from %d to %d.\n", in check_tape()
1084 STp->current_mode, mode); in check_tape()
1086 STp->current_mode = mode; in check_tape()
1088 STm = &(STp->modes[STp->current_mode]); in check_tape()
1090 saved_cleaning = STp->cleaning_req; in check_tape()
1091 STp->cleaning_req = 0; in check_tape()
1094 retval = test_ready(STp, do_wait); in check_tape()
1100 STp->pos_unknown = 0; in check_tape()
1101 STp->partition = STp->new_partition = 0; in check_tape()
1102 if (STp->can_partitions) in check_tape()
1103 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1106 STps = &(STp->ps[i]); in check_tape()
1117 STp->cleaning_req |= saved_cleaning; in check_tape()
1121 STp->ready = ST_NO_TAPE; in check_tape()
1123 STp->ready = ST_NOT_READY; in check_tape()
1125 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1126 STp->write_prot = 0; in check_tape()
1127 STp->block_size = 0; in check_tape()
1128 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1129 STp->partition = STp->new_partition = 0; in check_tape()
1130 STp->door_locked = ST_UNLOCKED; in check_tape()
1135 if (STp->omit_blklims) in check_tape()
1136 STp->min_block = STp->max_block = (-1); in check_tape()
1141 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE, in check_tape()
1142 STp->device->request_queue->rq_timeout, in check_tape()
1145 retval = (STp->buffer)->syscall_result; in check_tape()
1149 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1150 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1151 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1152 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1153 (STp->buffer)->b_data[5]; in check_tape()
1154 if ( DEB( debugging || ) !STp->inited) in check_tape()
1155 st_printk(KERN_INFO, STp, in check_tape()
1157 STp->min_block, STp->max_block); in check_tape()
1159 STp->min_block = STp->max_block = (-1); in check_tape()
1160 DEBC_printk(STp, "Can't read block limits.\n"); in check_tape()
1168 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE, in check_tape()
1169 STp->device->request_queue->rq_timeout, in check_tape()
1172 retval = (STp->buffer)->syscall_result; in check_tape()
1176 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1177 DEBC_printk(STp, "No Mode Sense.\n"); in check_tape()
1178 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1179 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1180 STp->drv_write_prot = 0; in check_tape()
1182 DEBC_printk(STp,"Mode sense. Length %d, " in check_tape()
1184 (STp->buffer)->b_data[0], in check_tape()
1185 (STp->buffer)->b_data[1], in check_tape()
1186 (STp->buffer)->b_data[2], in check_tape()
1187 (STp->buffer)->b_data[3]); in check_tape()
1189 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1190 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1191 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1192 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1193 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1194 DEBC_printk(STp, "Density %x, tape length: %x, " in check_tape()
1196 STp->density, in check_tape()
1197 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1198 (STp->buffer)->b_data[6] * 256 + in check_tape()
1199 (STp->buffer)->b_data[7], in check_tape()
1200 STp->drv_buffer); in check_tape()
1202 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1203 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1204 st_printk(KERN_WARNING, STp, in check_tape()
1207 STp->immediate_filemark = 0; in check_tape()
1212 STp->inited = 1; in check_tape()
1214 if (STp->block_size > 0) in check_tape()
1215 (STp->buffer)->buffer_blocks = in check_tape()
1216 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1218 (STp->buffer)->buffer_blocks = 1; in check_tape()
1219 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1221 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n", in check_tape()
1222 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1223 (STp->buffer)->buffer_blocks); in check_tape()
1225 if (STp->drv_write_prot) { in check_tape()
1226 STp->write_prot = 1; in check_tape()
1228 DEBC_printk(STp, "Write protected\n"); in check_tape()
1238 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1242 DEBC_printk(STp, "Updating partition number in status.\n"); in check_tape()
1243 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1244 retval = STp->partition; in check_tape()
1247 STp->new_partition = STp->partition; in check_tape()
1248 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1252 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1253 STp->compression_changed = 0; in check_tape()
1255 (retval = set_mode_densblk(STp, STm)) < 0) in check_tape()
1258 if (STp->default_drvbuffer != 0xff) { in check_tape()
1259 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1260 st_printk(KERN_WARNING, STp, in check_tape()
1263 STp->default_drvbuffer); in check_tape()
1280 struct scsi_tape *STp; in st_open() local
1291 if (!(STp = scsi_tape_get(dev))) { in st_open()
1295 filp->private_data = STp; in st_open()
1298 if (STp->in_use) { in st_open()
1300 DEBC_printk(STp, "Device already in use.\n"); in st_open()
1301 scsi_tape_put(STp); in st_open()
1305 STp->in_use = 1; in st_open()
1307 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1309 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1314 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1320 if (!enlarge_buffer(STp->buffer, PAGE_SIZE)) { in st_open()
1321 st_printk(KERN_WARNING, STp, in st_open()
1327 (STp->buffer)->cleared = 0; in st_open()
1328 (STp->buffer)->writing = 0; in st_open()
1329 (STp->buffer)->syscall_result = 0; in st_open()
1331 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1333 STp->dirty = 0; in st_open()
1335 STps = &(STp->ps[i]); in st_open()
1338 STp->try_dio_now = STp->try_dio; in st_open()
1339 STp->recover_count = 0; in st_open()
1340 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1341 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1343 retval = check_tape(STp, filp); in st_open()
1348 if (STp->ready == NO_TAPE) in st_open()
1357 normalize_buffer(STp->buffer); in st_open()
1359 STp->in_use = 0; in st_open()
1362 scsi_autopm_put_device(STp->device); in st_open()
1363 scsi_tape_put(STp); in st_open()
1375 struct scsi_tape *STp = filp->private_data; in st_flush() local
1376 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1377 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1382 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1383 result = st_flush_write_buffer(STp); in st_flush()
1388 if (STp->can_partitions && in st_flush()
1389 (result2 = switch_partition(STp)) < 0) { in st_flush()
1390 DEBC_printk(STp, "switch_partition at close failed.\n"); in st_flush()
1396 DEBC( if (STp->nbr_requests) in st_flush()
1397 st_printk(KERN_DEBUG, STp, in st_flush()
1399 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1400 STp->nbr_pages)); in st_flush()
1402 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1403 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1406 DEBC_printk(STp, "Async write waits %d, finished %d.\n", in st_flush()
1407 STp->nbr_waits, STp->nbr_finished); in st_flush()
1411 if (STp->immediate_filemark) in st_flush()
1413 cmd[4] = 1 + STp->two_fm; in st_flush()
1415 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in st_flush()
1416 STp->device->request_queue->rq_timeout, in st_flush()
1419 result = (STp->buffer)->syscall_result; in st_flush()
1423 if (STp->buffer->syscall_result == 0 || in st_flush()
1435 if (STp->two_fm) in st_flush()
1436 cross_eof(STp, 0); in st_flush()
1442 st_printk(KERN_ERR, STp, in st_flush()
1448 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]); in st_flush()
1449 } else if (!STp->rew_at_close) { in st_flush()
1450 STps = &(STp->ps[STp->partition]); in st_flush()
1452 if (STp->can_bsr) in st_flush()
1453 result = flush_buffer(STp, 0); in st_flush()
1455 result = cross_eof(STp, 0); in st_flush()
1465 !(result = cross_eof(STp, 1))) || in st_flush()
1475 if (STp->rew_at_close) { in st_flush()
1476 result2 = st_int_ioctl(STp, MTREW, 1); in st_flush()
1488 struct scsi_tape *STp = filp->private_data; in st_release() local
1490 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1491 do_door_lock(STp, 0); in st_release()
1493 normalize_buffer(STp->buffer); in st_release()
1495 STp->in_use = 0; in st_release()
1497 scsi_autopm_put_device(STp->device); in st_release()
1498 scsi_tape_put(STp); in st_release()
1504 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) in rw_checks() argument
1514 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1519 if (STp->ready != ST_READY) { in rw_checks()
1520 if (STp->ready == ST_NO_TAPE) in rw_checks()
1527 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1537 if (STp->pos_unknown) { in rw_checks()
1546 if (!STp->in_use) { in rw_checks()
1547 st_printk(ST_DEB_MSG, STp, in rw_checks()
1553 if (STp->can_partitions && in rw_checks()
1554 (retval = switch_partition(STp)) < 0) in rw_checks()
1557 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1558 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1563 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1564 !do_door_lock(STp, 1)) in rw_checks()
1565 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1572 static int setup_buffering(struct scsi_tape *STp, const char __user *buf, in setup_buffering() argument
1576 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1579 i = STp->try_dio_now && try_rdio; in setup_buffering()
1581 i = STp->try_dio_now && try_wdio; in setup_buffering()
1584 STp->device->request_queue)) == 0) { in setup_buffering()
1596 STp->nbr_dio++; in setup_buffering()
1597 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1602 DEB( STp->nbr_requests++; ) in setup_buffering()
1605 if (STp->block_size) in setup_buffering()
1606 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1607 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1612 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1618 st_printk(KERN_WARNING, STp, in setup_buffering()
1624 if (STp->block_size) in setup_buffering()
1625 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1634 static void release_buffering(struct scsi_tape *STp, int is_read) in release_buffering() argument
1638 STbp = STp->buffer; in release_buffering()
1659 struct scsi_tape *STp = filp->private_data; in st_write() local
1664 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1667 retval = rw_checks(STp, filp, count); in st_write()
1672 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1673 st_printk(KERN_WARNING, STp, in st_write()
1679 STm = &(STp->modes[STp->current_mode]); in st_write()
1680 STps = &(STp->ps[STp->partition]); in st_write()
1682 if (STp->write_prot) { in st_write()
1689 retval = flush_buffer(STp, 0); in st_write()
1695 if ((retval = set_mode_densblk(STp, STm)) < 0) in st_write()
1698 !(STp->compression_changed)) { in st_write()
1699 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1700 st_printk(KERN_WARNING, STp, in st_write()
1710 STbp = STp->buffer; in st_write()
1711 i = write_behind_check(STp); in st_write()
1731 if (STp->block_size != 0 && in st_write()
1739 retval = setup_buffering(STp, buf, count, 0); in st_write()
1747 cmd[1] = (STp->block_size != 0); in st_write()
1758 if (STp->block_size == 0) in st_write()
1761 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1776 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1779 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1780 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1782 STp->dirty = 1; in st_write()
1789 if (STp->block_size == 0) in st_write()
1796 blks /= STp->block_size; in st_write()
1797 transfer = blks * STp->block_size; in st_write()
1803 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE, in st_write()
1804 STp->device->request_queue->rq_timeout, in st_write()
1812 STp->dirty = !(STbp->writing == in st_write()
1815 DEB( STp->write_pending = 1; ) in st_write()
1820 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1822 DEBC_printk(STp, "Error on write:\n"); in st_write()
1827 else if (STp->block_size == 0 && in st_write()
1832 if (STp->block_size != 0) in st_write()
1833 undone *= STp->block_size; in st_write()
1839 if (STp->block_size) in st_write()
1840 blks = (transfer - undone) / STp->block_size; in st_write()
1846 if (STp->block_size == 0 || in st_write()
1849 DEBC_printk(STp, "EOM with %d " in st_write()
1857 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1861 STp->block_size; in st_write()
1864 DEBC_printk(STp, "Retry " in st_write()
1867 STp->buffer->buffer_bytes); in st_write()
1878 DEBC_printk(STp, "EOM with " in st_write()
1891 if (STp->block_size == 0) in st_write()
1898 STp->dirty = 0; in st_write()
1916 release_buffering(STp, 0); in st_write()
1917 mutex_unlock(&STp->lock); in st_write()
1928 static long read_tape(struct scsi_tape *STp, long count, in read_tape() argument
1942 STm = &(STp->modes[STp->current_mode]); in read_tape()
1943 STps = &(STp->ps[STp->partition]); in read_tape()
1946 STbp = STp->buffer; in read_tape()
1948 if (STp->block_size == 0) in read_tape()
1951 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1952 blks = (STp->buffer)->buffer_blocks; in read_tape()
1953 bytes = blks * STp->block_size; in read_tape()
1956 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1957 bytes = (STp->buffer)->buffer_size; in read_tape()
1958 blks = bytes / STp->block_size; in read_tape()
1959 bytes = blks * STp->block_size; in read_tape()
1965 cmd[1] = (STp->block_size != 0); in read_tape()
1966 if (!cmd[1] && STp->sili) in read_tape()
1973 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, in read_tape()
1974 STp->device->request_queue->rq_timeout, in read_tape()
1976 release_buffering(STp, 1); in read_tape()
1986 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1989 DEBC_printk(STp, in read_tape()
2007 if (STp->block_size == 0) in read_tape()
2014 if (STp->block_size == 0 && in read_tape()
2016 st_printk(KERN_NOTICE, STp, in read_tape()
2026 } else if (STp->block_size == 0) { in read_tape()
2032 st_printk(KERN_NOTICE, STp, in read_tape()
2037 st_int_ioctl(STp, MTBSR, 1); in read_tape()
2042 STp->block_size; in read_tape()
2043 DEBC_printk(STp, "ILI but " in read_tape()
2050 if (st_int_ioctl(STp, MTBSR, 1)) in read_tape()
2058 if (STp->block_size == 0) in read_tape()
2062 bytes - transfer * STp->block_size; in read_tape()
2063 DEBC_printk(STp, "EOF detected (%d " in read_tape()
2071 if (STp->block_size == 0) in read_tape()
2075 bytes - transfer * STp->block_size; in read_tape()
2077 DEBC_printk(STp, "EOM detected (%d " in read_tape()
2084 DEBC_printk(STp, "Tape error while reading.\n"); in read_tape()
2088 DEBC_printk(STp, "Zero returned for " in read_tape()
2108 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2109 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2113 if (STp->block_size == 0) in read_tape()
2116 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2131 struct scsi_tape *STp = filp->private_data; in st_read() local
2134 struct st_buffer *STbp = STp->buffer; in st_read()
2136 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2139 retval = rw_checks(STp, filp, count); in st_read()
2143 STm = &(STp->modes[STp->current_mode]); in st_read()
2144 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2149 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2152 STps = &(STp->ps[STp->partition]); in st_read()
2154 retval = flush_buffer(STp, 0); in st_read()
2161 st_printk(ST_DEB_MSG, STp, in st_read()
2166 retval = setup_buffering(STp, buf, count, 1); in st_read()
2202 special = read_tape(STp, count - total, &SRpnt); in st_read()
2213 st_printk(ST_DEB_MSG, STp, in st_read()
2231 if (STp->block_size == 0) in st_read()
2261 release_buffering(STp, 1); in st_read()
2264 mutex_unlock(&STp->lock); in st_read()
2273 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm) in DEB() argument
2276 st_printk(KERN_INFO, STp, in DEB()
2279 STp->current_mode, STm->do_buffer_writes, in DEB()
2281 st_printk(KERN_INFO, STp, in DEB()
2284 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2285 STp->do_auto_lock); in DEB()
2286 st_printk(KERN_INFO, STp, in DEB()
2289 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2290 STp->can_partitions, STp->scsi2_logical); in DEB()
2291 st_printk(KERN_INFO, STp, in DEB()
2294 STm->sysv, STp->immediate, STp->sili, in DEB()
2295 STp->immediate_filemark); in DEB()
2296 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging); in DEB()
2302 static int st_set_options(struct scsi_tape *STp, long options)
2310 STm = &(STp->modes[STp->current_mode]);
2316 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2322 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2323 STp->current_mode);
2332 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2333 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2334 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2335 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2336 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2337 if ((STp->device)->scsi_level >= SCSI_2)
2338 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2339 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2340 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2341 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2343 STp->sili = (options & MT_ST_SILI) != 0;
2345 st_log_options(STp, STm); )
2357 STp->two_fm = value;
2359 STp->fast_mteom = value;
2361 STp->do_auto_lock = value;
2363 STp->can_bsr = value;
2365 STp->omit_blklims = value;
2366 if ((STp->device)->scsi_level >= SCSI_2 &&
2368 STp->can_partitions = value;
2370 STp->scsi2_logical = value;
2372 STp->immediate = value;
2374 STp->immediate_filemark = value;
2378 STp->sili = value;
2382 st_log_options(STp, STm); )
2389 DEBC_printk(STp, "Default block size disabled.\n");
2392 DEBC_printk(STp,"Default block size set to "
2394 if (STp->ready == ST_READY) {
2395 STp->blksize_changed = 0;
2396 set_mode_densblk(STp, STm);
2402 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2403 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2406 blk_queue_rq_timeout(STp->device->request_queue,
2408 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2417 STp->cln_mode = value;
2418 STp->cln_sense_mask = (options >> 8) & 0xff;
2419 STp->cln_sense_value = (options >> 16) & 0xff;
2420 st_printk(KERN_INFO, STp,
2422 value, STp->cln_sense_mask, STp->cln_sense_value);
2429 DEBC_printk(STp,
2433 DEBC_printk(STp, "Density default set to %x\n",
2435 if (STp->ready == ST_READY) {
2436 STp->density_changed = 0;
2437 set_mode_densblk(STp, STm);
2442 STp->default_drvbuffer = 0xff;
2443 DEBC_printk(STp,
2446 STp->default_drvbuffer = value & 7;
2447 DEBC_printk(STp,
2449 STp->default_drvbuffer);
2450 if (STp->ready == ST_READY)
2451 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2456 DEBC_printk(STp,
2460 STp->c_algo = (value & 0xff00) >> 8;
2461 DEBC_printk(STp, "Compression "
2463 STp->c_algo);
2467 DEBC_printk(STp, "Compression default "
2470 if (STp->ready == ST_READY) {
2471 STp->compression_changed = 0;
2472 st_compression(STp, (STm->default_compression == ST_YES));
2505 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) in read_mode_page() argument
2517 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE, in read_mode_page()
2518 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2520 return (STp->buffer)->syscall_result; in read_mode_page()
2524 return STp->buffer->syscall_result; in read_mode_page()
2530 static int write_mode_page(struct scsi_tape *STp, int page, int slow) in write_mode_page() argument
2540 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2541 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2544 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2545 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2546 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2547 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2550 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2551 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE, in write_mode_page()
2554 return (STp->buffer)->syscall_result; in write_mode_page()
2558 return STp->buffer->syscall_result; in write_mode_page()
2579 static int st_compression(struct scsi_tape * STp, int state) in st_compression() argument
2583 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2585 if (STp->ready != ST_READY) in st_compression()
2589 retval = read_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2591 DEBC_printk(STp, "Compression mode page not supported.\n"); in st_compression()
2596 DEBC_printk(STp, "Compression state is %d.\n", in st_compression()
2601 DEBC_printk(STp, "Compression not supported.\n"); in st_compression()
2608 if (STp->c_algo != 0) in st_compression()
2609 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2613 if (STp->c_algo != 0) in st_compression()
2617 retval = write_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2619 DEBC_printk(STp, "Compression change failed.\n"); in st_compression()
2622 DEBC_printk(STp, "Compression state changed to %d.\n", state); in st_compression()
2624 STp->compression_changed = 1; in st_compression()
2630 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) in do_load_unload() argument
2637 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2638 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2653 DEBC_printk(STp, " Enhanced %sload slot %2d.\n", in do_load_unload()
2658 if (STp->immediate) { in do_load_unload()
2660 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2663 timeout = STp->long_timeout; in do_load_unload()
2667 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n"); in do_load_unload()
2669 st_printk(ST_DEB_MSG, STp, "Loading tape.\n"); in do_load_unload()
2672 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in do_load_unload()
2675 return (STp->buffer)->syscall_result; in do_load_unload()
2677 retval = (STp->buffer)->syscall_result; in do_load_unload()
2683 STp->rew_at_close = 0; in do_load_unload()
2684 STp->ready = ST_NO_TAPE; in do_load_unload()
2687 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2688 retval = check_tape(STp, filp); in do_load_unload()
2694 STps = &(STp->ps[STp->partition]); in do_load_unload()
2704 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) in deb_space_print() argument
2714 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n", in deb_space_print()
2720 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) … in deb_space_print() argument
2725 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg) in st_int_ioctl() argument
2737 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2738 if (STp->ready != ST_READY) { in st_int_ioctl()
2739 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2744 timeout = STp->long_timeout; in st_int_ioctl()
2745 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2761 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd); in st_int_ioctl()
2777 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd); in st_int_ioctl()
2789 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd); in st_int_ioctl()
2801 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd); in st_int_ioctl()
2812 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd); in st_int_ioctl()
2825 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd); in st_int_ioctl()
2834 if (STp->write_prot) in st_int_ioctl()
2840 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2845 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2848 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2854 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2867 if (STp->immediate) { in st_int_ioctl()
2869 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2871 DEBC_printk(STp, "Rewinding tape.\n"); in st_int_ioctl()
2875 DEBC_printk(STp, "No op on tape.\n"); in st_int_ioctl()
2879 if (STp->immediate) { in st_int_ioctl()
2881 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2884 DEBC_printk(STp, "Retensioning tape.\n"); in st_int_ioctl()
2888 if (!STp->fast_mteom) { in st_int_ioctl()
2890 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff); in st_int_ioctl()
2902 DEBC_printk(STp, "Spacing to end of recorded medium.\n"); in st_int_ioctl()
2907 if (STp->write_prot) in st_int_ioctl()
2911 if (STp->immediate) { in st_int_ioctl()
2913 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2916 timeout = STp->long_timeout * 8; in st_int_ioctl()
2918 DEBC_printk(STp, "Erasing tape.\n"); in st_int_ioctl()
2925 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in st_int_ioctl()
2929 STp->max_block > 0 && in st_int_ioctl()
2930 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || in st_int_ioctl()
2931 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { in st_int_ioctl()
2932 st_printk(KERN_WARNING, STp, "Illegal block size.\n"); in st_int_ioctl()
2936 if ((STp->use_pf & USE_PF)) in st_int_ioctl()
2941 memset((STp->buffer)->b_data, 0, 12); in st_int_ioctl()
2943 (STp->buffer)->b_data[2] = (arg & 7) << 4; in st_int_ioctl()
2945 (STp->buffer)->b_data[2] = in st_int_ioctl()
2946 STp->drv_buffer << 4; in st_int_ioctl()
2947 (STp->buffer)->b_data[3] = 8; /* block descriptor length */ in st_int_ioctl()
2949 (STp->buffer)->b_data[4] = arg; in st_int_ioctl()
2950 STp->density_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2951 STp->changed_density = arg; in st_int_ioctl()
2953 (STp->buffer)->b_data[4] = arg >> 24; in st_int_ioctl()
2955 (STp->buffer)->b_data[4] = STp->density; in st_int_ioctl()
2959 STp->blksize_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2960 STp->changed_blksize = arg; in st_int_ioctl()
2963 ltmp = STp->block_size; in st_int_ioctl()
2964 (STp->buffer)->b_data[9] = (ltmp >> 16); in st_int_ioctl()
2965 (STp->buffer)->b_data[10] = (ltmp >> 8); in st_int_ioctl()
2966 (STp->buffer)->b_data[11] = ltmp; in st_int_ioctl()
2967 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2970 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2972 (STp->buffer)->b_data[9] * 65536 + in st_int_ioctl()
2973 (STp->buffer)->b_data[10] * 256 + in st_int_ioctl()
2974 (STp->buffer)->b_data[11]); in st_int_ioctl()
2976 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2978 (STp->buffer)->b_data[4]); in st_int_ioctl()
2980 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2982 ((STp->buffer)->b_data[2] >> 4) & 7); in st_int_ioctl()
2989 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction, in st_int_ioctl()
2992 return (STp->buffer)->syscall_result; in st_int_ioctl()
2994 ioctl_result = (STp->buffer)->syscall_result; in st_int_ioctl()
3004 ioctl_result = st_int_ioctl(STp, MTFSF, 1); in st_int_ioctl()
3006 ioctl_result = st_int_ioctl(STp, MTBSF, 1); in st_int_ioctl()
3009 STp->block_size = arg & MT_ST_BLKSIZE_MASK; in st_int_ioctl()
3010 if (STp->block_size != 0) { in st_int_ioctl()
3011 (STp->buffer)->buffer_blocks = in st_int_ioctl()
3012 (STp->buffer)->buffer_size / STp->block_size; in st_int_ioctl()
3014 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in st_int_ioctl()
3016 STp->density = arg >> MT_ST_DENSITY_SHIFT; in st_int_ioctl()
3018 STp->drv_buffer = (arg & 7); in st_int_ioctl()
3020 STp->density = arg; in st_int_ioctl()
3033 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_int_ioctl()
3109 (STp->device)->scsi_level <= SCSI_2 && in st_int_ioctl()
3110 !(STp->use_pf & PF_TESTED)) { in st_int_ioctl()
3113 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED; in st_int_ioctl()
3116 return st_int_ioctl(STp, cmd_in, arg); in st_int_ioctl()
3135 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition, in get_location() argument
3142 if (STp->ready != ST_READY) in get_location()
3146 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3151 if (!logical && !STp->scsi2_logical) in get_location()
3154 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE, in get_location()
3155 STp->device->request_queue->rq_timeout, in get_location()
3158 return (STp->buffer)->syscall_result; in get_location()
3160 if ((STp->buffer)->syscall_result != 0 || in get_location()
3161 (STp->device->scsi_level >= SCSI_2 && in get_location()
3162 ((STp->buffer)->b_data[0] & 4) != 0)) { in get_location()
3164 DEBC_printk(STp, " Can't read tape position.\n"); in get_location()
3168 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3169 *block = ((STp->buffer)->b_data[0] << 16) in get_location()
3170 + ((STp->buffer)->b_data[1] << 8) in get_location()
3171 + (STp->buffer)->b_data[2]; in get_location()
3174 *block = ((STp->buffer)->b_data[4] << 24) in get_location()
3175 + ((STp->buffer)->b_data[5] << 16) in get_location()
3176 + ((STp->buffer)->b_data[6] << 8) in get_location()
3177 + (STp->buffer)->b_data[7]; in get_location()
3178 *partition = (STp->buffer)->b_data[1]; in get_location()
3179 if (((STp->buffer)->b_data[0] & 0x80) && in get_location()
3180 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ in get_location()
3181 STp->ps[0].drv_block = STp->ps[0].drv_file = 0; in get_location()
3183 DEBC_printk(STp, "Got tape pos. blk %d part %d.\n", in get_location()
3195 static int set_location(struct scsi_tape *STp, unsigned int block, int partition, in set_location() argument
3205 if (STp->ready != ST_READY) in set_location()
3207 timeout = STp->long_timeout; in set_location()
3208 STps = &(STp->ps[STp->partition]); in set_location()
3210 DEBC_printk(STp, "Setting block to %d and partition to %d.\n", in set_location()
3216 if ((!STp->can_partitions && partition != 0) || in set_location()
3219 if (partition != STp->partition) { in set_location()
3220 if (get_location(STp, &blk, &p, 1)) in set_location()
3225 DEBC_printk(STp, "Visited block %d for " in set_location()
3227 blk, STp->partition); in set_location()
3232 if ((STp->device)->scsi_level < SCSI_2) { in set_location()
3244 if (!logical && !STp->scsi2_logical) in set_location()
3246 if (STp->partition != partition) { in set_location()
3249 DEBC_printk(STp, "Trying to change partition " in set_location()
3250 "from %d to %d\n", STp->partition, in set_location()
3254 if (STp->immediate) { in set_location()
3256 timeout = STp->device->request_queue->rq_timeout; in set_location()
3259 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in set_location()
3262 return (STp->buffer)->syscall_result; in set_location()
3266 if ((STp->buffer)->syscall_result != 0) { in set_location()
3268 if (STp->can_partitions && in set_location()
3269 (STp->device)->scsi_level >= SCSI_2 && in set_location()
3270 (p = find_partition(STp)) >= 0) in set_location()
3271 STp->partition = p; in set_location()
3273 if (STp->can_partitions) { in set_location()
3274 STp->partition = partition; in set_location()
3275 STps = &(STp->ps[partition]); in set_location()
3297 static int find_partition(struct scsi_tape *STp) in find_partition() argument
3302 if ((i = get_location(STp, &block, &partition, 1)) < 0) in find_partition()
3311 static int switch_partition(struct scsi_tape *STp) in switch_partition() argument
3315 if (STp->partition == STp->new_partition) in switch_partition()
3317 STps = &(STp->ps[STp->new_partition]); in switch_partition()
3320 return set_location(STp, STps->last_block_visited, STp->new_partition, 1); in switch_partition()
3342 static int nbr_partitions(struct scsi_tape *STp) in nbr_partitions() argument
3346 if (STp->ready != ST_READY) in nbr_partitions()
3349 result = read_mode_page(STp, PART_PAGE, 1); in nbr_partitions()
3352 DEBC_printk(STp, "Can't read medium partition page.\n"); in nbr_partitions()
3355 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + in nbr_partitions()
3357 DEBC_printk(STp, "Number of partitions %d.\n", result); in nbr_partitions()
3364 static int format_medium(struct scsi_tape *STp, int format) in format_medium() argument
3367 int timeout = STp->long_timeout; in format_medium()
3374 if (STp->immediate) { in format_medium()
3376 timeout = STp->device->request_queue->rq_timeout; in format_medium()
3378 DEBC_printk(STp, "Sending FORMAT MEDIUM\n"); in format_medium()
3379 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in format_medium()
3382 result = STp->buffer->syscall_result; in format_medium()
3408 static int partition_tape(struct scsi_tape *STp, int size) in partition_tape() argument
3412 bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false; in partition_tape()
3417 result = read_mode_page(STp, PART_PAGE, 0); in partition_tape()
3419 DEBC_printk(STp, "Can't read partition mode page.\n"); in partition_tape()
3429 bp = (STp->buffer)->b_data; in partition_tape()
3431 DEBC_printk(STp, "Partition page length is %d bytes.\n", in partition_tape()
3442 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3443 result = format_medium(STp, 0); in partition_tape()
3485 DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n", in partition_tape()
3493 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3502 DEBC_printk(STp, in partition_tape()
3517 result = write_mode_page(STp, PART_PAGE, 1); in partition_tape()
3520 result = format_medium(STp, 1); in partition_tape()
3523 st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n"); in partition_tape()
3535 static long st_common_ioctl(struct scsi_tape *STp, struct st_modedef *STm, in st_common_ioctl() argument
3560 if ((i = flush_buffer(STp, 0)) < 0) { in st_common_ioctl()
3564 if (STp->can_partitions) { in st_common_ioctl()
3565 i = switch_partition(STp); in st_common_ioctl()
3573 mutex_unlock(&STp->lock); in st_common_ioctl()
3575 retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, in st_common_ioctl()
3579 STp->rew_at_close = 0; in st_common_ioctl()
3580 STp->ready = ST_NO_TAPE; in st_common_ioctl()
3585 mutex_unlock(&STp->lock); in st_common_ioctl()
3597 struct scsi_tape *STp = file->private_data; in st_ioctl() local
3601 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl()
3605 if (debugging && !STp->in_use) { in st_ioctl()
3606 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n"); in st_ioctl()
3611 STm = &(STp->modes[STp->current_mode]); in st_ioctl()
3612 STps = &(STp->ps[STp->partition]); in st_ioctl()
3620 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl()
3631 return st_common_ioctl(STp, STm, file, cmd_in, arg); in st_ioctl()
3652 st_printk(KERN_WARNING, STp, in st_ioctl()
3664 if (!STp->pos_unknown) { in st_ioctl()
3682 i = !STp->can_partitions || in st_ioctl()
3683 (STp->new_partition != STp->partition); in st_ioctl()
3692 i = flush_buffer(STp, i); in st_ioctl()
3701 i = st_int_ioctl(STp, MTWEOF, 1); in st_ioctl()
3727 reset_state(STp); /* Clears pos_unknown */ in st_ioctl()
3732 if (STp->can_partitions) { in st_ioctl()
3736 STp->partition = 0; in st_ioctl()
3737 switch_partition(STp); in st_ioctl()
3739 if (STp->density_changed) in st_ioctl()
3740 st_int_ioctl(STp, MTSETDENSITY, STp->changed_density); in st_ioctl()
3741 if (STp->blksize_changed) in st_ioctl()
3742 st_int_ioctl(STp, MTSETBLK, STp->changed_blksize); in st_ioctl()
3751 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl()
3752 do_door_lock(STp, 0); /* Ignore result! */ in st_ioctl()
3756 retval = st_set_options(STp, mtc.mt_count); in st_ioctl()
3761 if (!STp->can_partitions || in st_ioctl()
3766 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl()
3767 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl()
3771 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl()
3775 STp->new_partition = mtc.mt_count; in st_ioctl()
3781 if (!STp->can_partitions) { in st_ioctl()
3785 i = do_load_unload(STp, file, 1); in st_ioctl()
3790 i = partition_tape(STp, mtc.mt_count); in st_ioctl()
3796 STp->ps[i].rw = ST_IDLE; in st_ioctl()
3797 STp->ps[i].at_sm = 0; in st_ioctl()
3798 STp->ps[i].last_block_valid = 0; in st_ioctl()
3800 STp->partition = STp->new_partition = 0; in st_ioctl()
3801 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl()
3808 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl()
3809 if (!STp->can_partitions) in st_ioctl()
3810 STp->ps[0].rw = ST_IDLE; in st_ioctl()
3816 retval = do_load_unload(STp, file, 0); in st_ioctl()
3821 retval = do_load_unload(STp, file, max(1, mtc.mt_count)); in st_ioctl()
3826 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK)); in st_ioctl()
3830 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl()
3831 (i = switch_partition(STp)) < 0) { in st_ioctl()
3837 retval = st_compression(STp, (mtc.mt_count & 1)); in st_ioctl()
3839 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count); in st_ioctl()
3849 if ((i = flush_buffer(STp, 0)) < 0) { in st_ioctl()
3850 if (cmd_mtiocget && STp->pos_unknown) { in st_ioctl()
3852 reset_state(STp); in st_ioctl()
3853 STp->pos_unknown = 1; in st_ioctl()
3859 if (STp->can_partitions) { in st_ioctl()
3860 i = switch_partition(STp); in st_ioctl()
3876 mt_status.mt_type = STp->tape_type; in st_ioctl()
3878 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl()
3879 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl()
3882 if (STp->block_size != 0 && mt_status.mt_blkno >= 0) { in st_ioctl()
3885 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl()
3888 ((STp->buffer)->buffer_bytes + in st_ioctl()
3889 STp->block_size - 1) / STp->block_size; in st_ioctl()
3893 if (STp->drv_write_prot) in st_ioctl()
3901 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl()
3902 mt_status.mt_resid = STp->partition; in st_ioctl()
3907 if (STp->density == 1) in st_ioctl()
3909 else if (STp->density == 2) in st_ioctl()
3911 else if (STp->density == 3) in st_ioctl()
3913 if (STp->ready == ST_READY) in st_ioctl()
3915 if (STp->ready == ST_NO_TAPE) in st_ioctl()
3920 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl()
3921 STp->drv_buffer != 0) in st_ioctl()
3923 if (STp->cleaning_req) in st_ioctl()
3930 STp->recover_reg = 0; /* Clear after read */ in st_ioctl()
3939 if ((i = get_location(STp, &blk, &bt, 0)) < 0) { in st_ioctl()
3947 mutex_unlock(&STp->lock); in st_ioctl()
4725 struct scsi_tape *STp = STm->tape; in options_show() local
4733 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4734 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4736 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4737 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4738 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4739 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4741 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4742 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4743 options |= STp->sili ? MT_ST_SILI : 0; in options_show()
4762 struct scsi_tape *STp = STm->tape; in position_lost_in_reset_show() local
4764 return sprintf(buf, "%d", STp->pos_unknown); in position_lost_in_reset_show()