Lines Matching full:stp
244 struct scsi_tape *STp = NULL; in scsi_tape_get() local
249 STp = idr_find(&st_index_idr, dev); in scsi_tape_get()
250 if (!STp) goto out; in scsi_tape_get()
252 kref_get(&STp->kref); in scsi_tape_get()
254 if (!STp->device) in scsi_tape_get()
257 if (scsi_device_get(STp->device)) in scsi_tape_get()
263 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_get()
264 STp = NULL; in scsi_tape_get()
268 return STp; in scsi_tape_get()
271 static void scsi_tape_put(struct scsi_tape *STp) in scsi_tape_put() argument
273 struct scsi_device *sdev = STp->device; in scsi_tape_put()
276 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_put()
356 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) in st_chk_result() argument
360 DEB(const char *stp;) in st_chk_result()
361 char *name = STp->name; in st_chk_result()
367 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
371 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
377 st_printk(ST_DEB_MSG, STp, in st_chk_result()
382 __scsi_print_sense(STp->device, name, in st_chk_result()
387 st_printk(KERN_WARNING, STp, in st_chk_result()
399 __scsi_print_sense(STp->device, name, in st_chk_result()
405 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
406 if (STp->cln_sense_value) in st_chk_result()
407 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
408 STp->cln_sense_mask) == STp->cln_sense_value); in st_chk_result()
410 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
411 STp->cln_sense_mask) != 0); in st_chk_result()
415 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
417 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
426 STp->recover_count++; in st_chk_result()
427 STp->recover_reg++; in st_chk_result()
432 stp = "read"; in st_chk_result()
434 stp = "write"; in st_chk_result()
436 stp = "ioctl"; in st_chk_result()
437 st_printk(ST_DEB_MSG, STp, in st_chk_result()
439 stp, STp->recover_count); in st_chk_result()
448 static struct st_request *st_allocate_request(struct scsi_tape *stp) in st_allocate_request() argument
454 streq->stp = stp; in st_allocate_request()
456 st_printk(KERN_ERR, stp, in st_allocate_request()
459 stp->buffer->syscall_result = -EINTR; in st_allocate_request()
461 stp->buffer->syscall_result = -EBUSY; in st_allocate_request()
472 static void st_do_stats(struct scsi_tape *STp, struct request *req) in st_do_stats() argument
478 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
479 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
480 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
481 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
483 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
484 - STp->buffer->cmdstat.residual, in st_do_stats()
485 &STp->stats->write_byte_cnt); in st_do_stats()
486 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
487 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
489 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
490 &STp->stats->write_byte_cnt); in st_do_stats()
492 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
493 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_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->read_cnt); in st_do_stats()
497 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
498 - STp->buffer->cmdstat.residual, in st_do_stats()
499 &STp->stats->read_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_read_size), in st_do_stats()
504 &STp->stats->read_byte_cnt); in st_do_stats()
506 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
507 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
508 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
510 atomic64_dec(&STp->stats->in_flight); in st_do_stats()
517 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end() local
520 STp->buffer->cmdstat.midlevel_result = SRpnt->result = rq->result; in st_scsi_execute_end()
521 STp->buffer->cmdstat.residual = rq->resid_len; in st_scsi_execute_end()
523 st_do_stats(STp, req); in st_scsi_execute_end()
541 struct rq_map_data *mdata = &SRpnt->stp->buffer->map_data; in st_scsi_execute()
543 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute() local
545 req = blk_get_request(SRpnt->stp->device->request_queue, in st_scsi_execute()
564 atomic64_inc(&STp->stats->in_flight); in st_scsi_execute()
566 atomic_set(&STp->stats->last_write_size, bufflen); in st_scsi_execute()
567 STp->stats->write_time = ktime_get(); in st_scsi_execute()
569 atomic_set(&STp->stats->last_read_size, bufflen); in st_scsi_execute()
570 STp->stats->read_time = ktime_get(); in st_scsi_execute()
572 STp->stats->other_time = ktime_get(); in st_scsi_execute()
591 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, in st_do_scsi() argument
595 struct rq_map_data *mdata = &STp->buffer->map_data; in st_do_scsi()
599 if (!do_wait && ((STp->buffer)->last_SRpnt)) { in st_do_scsi()
600 st_printk(KERN_ERR, STp, in st_do_scsi()
603 (STp->buffer)->syscall_result = (-EINTR); in st_do_scsi()
605 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
610 SRpnt = st_allocate_request(STp); in st_do_scsi()
618 (STp->buffer)->last_SRpnt = SRpnt; in st_do_scsi()
620 waiting = &STp->wait; in st_do_scsi()
624 if (STp->buffer->do_dio) { in st_do_scsi()
626 mdata->nr_entries = STp->buffer->sg_segs; in st_do_scsi()
627 mdata->pages = STp->buffer->mapped_pages; in st_do_scsi()
629 mdata->page_order = STp->buffer->reserved_page_order; in st_do_scsi()
632 mdata->pages = STp->buffer->reserved_pages; in st_do_scsi()
637 STp->buffer->cmdstat.have_sense = 0; in st_do_scsi()
638 STp->buffer->syscall_result = 0; in st_do_scsi()
644 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
645 (STp->buffer)->last_SRpnt = NULL; in st_do_scsi()
649 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in st_do_scsi()
660 static int write_behind_check(struct scsi_tape * STp) in write_behind_check() argument
668 STbuffer = STp->buffer; in write_behind_check()
673 if (STp->write_pending) in write_behind_check()
674 STp->nbr_waits++; in write_behind_check()
676 STp->nbr_finished++; in write_behind_check()
679 wait_for_completion(&(STp->wait)); in write_behind_check()
684 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in write_behind_check()
688 STps = &(STp->ps[STp->partition]); in write_behind_check()
690 if (STp->block_size == 0) in write_behind_check()
693 STps->drv_block += STbuffer->writing / STp->block_size; in write_behind_check()
714 st_printk(ST_DEB_MSG, STp, in write_behind_check()
724 static int cross_eof(struct scsi_tape * STp, int forward) in cross_eof() argument
738 DEBC_printk(STp, "Stepping over filemark %s.\n", in cross_eof()
741 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in cross_eof()
742 STp->device->request_queue->rq_timeout, in cross_eof()
745 return (STp->buffer)->syscall_result; in cross_eof()
750 if ((STp->buffer)->cmdstat.midlevel_result != 0) in cross_eof()
751 st_printk(KERN_ERR, STp, in cross_eof()
755 return (STp->buffer)->syscall_result; in cross_eof()
760 static int st_flush_write_buffer(struct scsi_tape * STp) in st_flush_write_buffer() argument
768 result = write_behind_check(STp); in st_flush_write_buffer()
773 if (STp->dirty == 1) { in st_flush_write_buffer()
775 transfer = STp->buffer->buffer_bytes; in st_flush_write_buffer()
776 DEBC_printk(STp, "Flushing %d bytes.\n", transfer); in st_flush_write_buffer()
781 blks = transfer / STp->block_size; in st_flush_write_buffer()
786 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE, in st_flush_write_buffer()
787 STp->device->request_queue->rq_timeout, in st_flush_write_buffer()
790 return (STp->buffer)->syscall_result; in st_flush_write_buffer()
792 STps = &(STp->ps[STp->partition]); in st_flush_write_buffer()
793 if ((STp->buffer)->syscall_result != 0) { in st_flush_write_buffer()
794 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush_write_buffer()
802 STp->dirty = 0; in st_flush_write_buffer()
803 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
808 st_printk(KERN_ERR, STp, "Error on flush.\n"); in st_flush_write_buffer()
815 STp->dirty = 0; in st_flush_write_buffer()
816 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
827 static int flush_buffer(struct scsi_tape *STp, int seek_next) in flush_buffer() argument
836 if (STp->pos_unknown) in flush_buffer()
839 if (STp->ready != ST_READY) in flush_buffer()
841 STps = &(STp->ps[STp->partition]); in flush_buffer()
843 return st_flush_write_buffer(STp); in flush_buffer()
845 if (STp->block_size == 0) in flush_buffer()
848 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
849 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
850 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
851 STp->block_size; in flush_buffer()
852 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
853 (STp->buffer)->read_pointer = 0; in flush_buffer()
857 result = cross_eof(STp, 0); /* Back over the EOF hit */ in flush_buffer()
867 result = st_int_ioctl(STp, MTBSR, backspace); in flush_buffer()
879 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) in set_mode_densblk() argument
884 if (!STp->density_changed && in set_mode_densblk()
886 STm->default_density != STp->density) { in set_mode_densblk()
890 arg = STp->density; in set_mode_densblk()
892 if (!STp->blksize_changed && in set_mode_densblk()
894 STm->default_blksize != STp->block_size) { in set_mode_densblk()
898 arg |= STp->block_size; in set_mode_densblk()
900 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { in set_mode_densblk()
901 st_printk(KERN_WARNING, STp, in set_mode_densblk()
913 static int do_door_lock(struct scsi_tape * STp, int do_lock) in do_door_lock() argument
917 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); in do_door_lock()
919 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
922 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
924 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
930 static void reset_state(struct scsi_tape *STp) in reset_state() argument
935 STp->pos_unknown = 0; in reset_state()
937 STps = &(STp->ps[i]); in reset_state()
945 if (STp->can_partitions) { in reset_state()
946 STp->partition = find_partition(STp); in reset_state()
947 if (STp->partition < 0) in reset_state()
948 STp->partition = 0; in reset_state()
949 STp->new_partition = STp->partition; in reset_state()
962 static int test_ready(struct scsi_tape *STp, int do_wait) in test_ready() argument
968 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
975 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, in test_ready()
976 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
979 retval = (STp->buffer)->syscall_result; in test_ready()
1009 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
1019 retval = (STp->buffer)->syscall_result; in test_ready()
1036 static int check_tape(struct scsi_tape *STp, struct file *filp) in check_tape() argument
1047 STp->ready = ST_READY; in check_tape()
1049 if (mode != STp->current_mode) { in check_tape()
1050 DEBC_printk(STp, "Mode change from %d to %d.\n", in check_tape()
1051 STp->current_mode, mode); in check_tape()
1053 STp->current_mode = mode; in check_tape()
1055 STm = &(STp->modes[STp->current_mode]); in check_tape()
1057 saved_cleaning = STp->cleaning_req; in check_tape()
1058 STp->cleaning_req = 0; in check_tape()
1061 retval = test_ready(STp, do_wait); in check_tape()
1067 STp->pos_unknown = 0; in check_tape()
1068 STp->partition = STp->new_partition = 0; in check_tape()
1069 if (STp->can_partitions) in check_tape()
1070 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1073 STps = &(STp->ps[i]); in check_tape()
1084 STp->cleaning_req |= saved_cleaning; in check_tape()
1088 STp->ready = ST_NO_TAPE; in check_tape()
1090 STp->ready = ST_NOT_READY; in check_tape()
1092 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1093 STp->write_prot = 0; in check_tape()
1094 STp->block_size = 0; in check_tape()
1095 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1096 STp->partition = STp->new_partition = 0; in check_tape()
1097 STp->door_locked = ST_UNLOCKED; in check_tape()
1102 if (STp->omit_blklims) in check_tape()
1103 STp->min_block = STp->max_block = (-1); in check_tape()
1108 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE, in check_tape()
1109 STp->device->request_queue->rq_timeout, in check_tape()
1112 retval = (STp->buffer)->syscall_result; in check_tape()
1116 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1117 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1118 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1119 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1120 (STp->buffer)->b_data[5]; in check_tape()
1121 if ( DEB( debugging || ) !STp->inited) in check_tape()
1122 st_printk(KERN_INFO, STp, in check_tape()
1124 STp->min_block, STp->max_block); in check_tape()
1126 STp->min_block = STp->max_block = (-1); in check_tape()
1127 DEBC_printk(STp, "Can't read block limits.\n"); in check_tape()
1135 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE, in check_tape()
1136 STp->device->request_queue->rq_timeout, in check_tape()
1139 retval = (STp->buffer)->syscall_result; in check_tape()
1143 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1144 DEBC_printk(STp, "No Mode Sense.\n"); in check_tape()
1145 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1146 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1147 STp->drv_write_prot = 0; in check_tape()
1149 DEBC_printk(STp,"Mode sense. Length %d, " in check_tape()
1151 (STp->buffer)->b_data[0], in check_tape()
1152 (STp->buffer)->b_data[1], in check_tape()
1153 (STp->buffer)->b_data[2], in check_tape()
1154 (STp->buffer)->b_data[3]); in check_tape()
1156 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1157 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1158 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1159 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1160 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1161 DEBC_printk(STp, "Density %x, tape length: %x, " in check_tape()
1163 STp->density, in check_tape()
1164 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1165 (STp->buffer)->b_data[6] * 256 + in check_tape()
1166 (STp->buffer)->b_data[7], in check_tape()
1167 STp->drv_buffer); in check_tape()
1169 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1170 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1171 st_printk(KERN_WARNING, STp, in check_tape()
1174 STp->immediate_filemark = 0; in check_tape()
1179 STp->inited = 1; in check_tape()
1181 if (STp->block_size > 0) in check_tape()
1182 (STp->buffer)->buffer_blocks = in check_tape()
1183 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1185 (STp->buffer)->buffer_blocks = 1; in check_tape()
1186 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1188 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n", in check_tape()
1189 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1190 (STp->buffer)->buffer_blocks); in check_tape()
1192 if (STp->drv_write_prot) { in check_tape()
1193 STp->write_prot = 1; in check_tape()
1195 DEBC_printk(STp, "Write protected\n"); in check_tape()
1205 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1209 DEBC_printk(STp, "Updating partition number in status.\n"); in check_tape()
1210 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1211 retval = STp->partition; in check_tape()
1214 STp->new_partition = STp->partition; in check_tape()
1215 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1219 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1220 STp->compression_changed = 0; in check_tape()
1222 (retval = set_mode_densblk(STp, STm)) < 0) in check_tape()
1225 if (STp->default_drvbuffer != 0xff) { in check_tape()
1226 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1227 st_printk(KERN_WARNING, STp, in check_tape()
1230 STp->default_drvbuffer); in check_tape()
1247 struct scsi_tape *STp; in st_open() local
1258 if (!(STp = scsi_tape_get(dev))) { in st_open()
1262 filp->private_data = STp; in st_open()
1265 if (STp->in_use) { in st_open()
1267 DEBC_printk(STp, "Device already in use.\n"); in st_open()
1268 scsi_tape_put(STp); in st_open()
1272 STp->in_use = 1; in st_open()
1274 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1276 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1281 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1287 if (!enlarge_buffer(STp->buffer, PAGE_SIZE)) { in st_open()
1288 st_printk(KERN_WARNING, STp, in st_open()
1294 (STp->buffer)->cleared = 0; in st_open()
1295 (STp->buffer)->writing = 0; in st_open()
1296 (STp->buffer)->syscall_result = 0; in st_open()
1298 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1300 STp->dirty = 0; in st_open()
1302 STps = &(STp->ps[i]); in st_open()
1305 STp->try_dio_now = STp->try_dio; in st_open()
1306 STp->recover_count = 0; in st_open()
1307 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1308 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1310 retval = check_tape(STp, filp); in st_open()
1315 if (STp->ready == NO_TAPE) in st_open()
1324 normalize_buffer(STp->buffer); in st_open()
1326 STp->in_use = 0; in st_open()
1329 scsi_autopm_put_device(STp->device); in st_open()
1330 scsi_tape_put(STp); in st_open()
1342 struct scsi_tape *STp = filp->private_data; in st_flush() local
1343 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1344 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1349 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1350 result = st_flush_write_buffer(STp); in st_flush()
1355 if (STp->can_partitions && in st_flush()
1356 (result2 = switch_partition(STp)) < 0) { in st_flush()
1357 DEBC_printk(STp, "switch_partition at close failed.\n"); in st_flush()
1363 DEBC( if (STp->nbr_requests) in st_flush()
1364 st_printk(KERN_DEBUG, STp, in st_flush()
1366 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1367 STp->nbr_pages)); in st_flush()
1369 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1370 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1373 DEBC_printk(STp, "Async write waits %d, finished %d.\n", in st_flush()
1374 STp->nbr_waits, STp->nbr_finished); in st_flush()
1378 if (STp->immediate_filemark) in st_flush()
1380 cmd[4] = 1 + STp->two_fm; in st_flush()
1382 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in st_flush()
1383 STp->device->request_queue->rq_timeout, in st_flush()
1386 result = (STp->buffer)->syscall_result; in st_flush()
1390 if (STp->buffer->syscall_result == 0 || in st_flush()
1402 if (STp->two_fm) in st_flush()
1403 cross_eof(STp, 0); in st_flush()
1409 st_printk(KERN_ERR, STp, in st_flush()
1415 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]); in st_flush()
1416 } else if (!STp->rew_at_close) { in st_flush()
1417 STps = &(STp->ps[STp->partition]); in st_flush()
1419 if (STp->can_bsr) in st_flush()
1420 result = flush_buffer(STp, 0); in st_flush()
1422 result = cross_eof(STp, 0); in st_flush()
1432 !(result = cross_eof(STp, 1))) || in st_flush()
1442 if (STp->rew_at_close) { in st_flush()
1443 result2 = st_int_ioctl(STp, MTREW, 1); in st_flush()
1455 struct scsi_tape *STp = filp->private_data; in st_release() local
1457 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1458 do_door_lock(STp, 0); in st_release()
1460 normalize_buffer(STp->buffer); in st_release()
1462 STp->in_use = 0; in st_release()
1464 scsi_autopm_put_device(STp->device); in st_release()
1465 scsi_tape_put(STp); in st_release()
1471 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) in rw_checks() argument
1481 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1486 if (STp->ready != ST_READY) { in rw_checks()
1487 if (STp->ready == ST_NO_TAPE) in rw_checks()
1494 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1504 if (STp->pos_unknown) { in rw_checks()
1513 if (!STp->in_use) { in rw_checks()
1514 st_printk(ST_DEB_MSG, STp, in rw_checks()
1520 if (STp->can_partitions && in rw_checks()
1521 (retval = switch_partition(STp)) < 0) in rw_checks()
1524 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1525 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1530 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1531 !do_door_lock(STp, 1)) in rw_checks()
1532 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1539 static int setup_buffering(struct scsi_tape *STp, const char __user *buf, in setup_buffering() argument
1543 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1546 i = STp->try_dio_now && try_rdio; in setup_buffering()
1548 i = STp->try_dio_now && try_wdio; in setup_buffering()
1551 STp->device->request_queue)) == 0) { in setup_buffering()
1563 STp->nbr_dio++; in setup_buffering()
1564 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1569 DEB( STp->nbr_requests++; ) in setup_buffering()
1572 if (STp->block_size) in setup_buffering()
1573 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1574 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1579 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1585 st_printk(KERN_WARNING, STp, in setup_buffering()
1591 if (STp->block_size) in setup_buffering()
1592 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1601 static void release_buffering(struct scsi_tape *STp, int is_read) in release_buffering() argument
1605 STbp = STp->buffer; in release_buffering()
1626 struct scsi_tape *STp = filp->private_data; in st_write() local
1631 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1634 retval = rw_checks(STp, filp, count); in st_write()
1639 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1640 st_printk(KERN_WARNING, STp, in st_write()
1646 STm = &(STp->modes[STp->current_mode]); in st_write()
1647 STps = &(STp->ps[STp->partition]); in st_write()
1649 if (STp->write_prot) { in st_write()
1656 retval = flush_buffer(STp, 0); in st_write()
1662 if ((retval = set_mode_densblk(STp, STm)) < 0) in st_write()
1665 !(STp->compression_changed)) { in st_write()
1666 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1667 st_printk(KERN_WARNING, STp, in st_write()
1677 STbp = STp->buffer; in st_write()
1678 i = write_behind_check(STp); in st_write()
1698 if (STp->block_size != 0 && in st_write()
1706 retval = setup_buffering(STp, buf, count, 0); in st_write()
1714 cmd[1] = (STp->block_size != 0); in st_write()
1725 if (STp->block_size == 0) in st_write()
1728 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1743 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1746 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1747 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1749 STp->dirty = 1; in st_write()
1756 if (STp->block_size == 0) in st_write()
1763 blks /= STp->block_size; in st_write()
1764 transfer = blks * STp->block_size; in st_write()
1770 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE, in st_write()
1771 STp->device->request_queue->rq_timeout, in st_write()
1779 STp->dirty = !(STbp->writing == in st_write()
1782 DEB( STp->write_pending = 1; ) in st_write()
1787 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1789 DEBC_printk(STp, "Error on write:\n"); in st_write()
1794 else if (STp->block_size == 0 && in st_write()
1799 if (STp->block_size != 0) in st_write()
1800 undone *= STp->block_size; in st_write()
1806 if (STp->block_size) in st_write()
1807 blks = (transfer - undone) / STp->block_size; in st_write()
1813 if (STp->block_size == 0 || in st_write()
1816 DEBC_printk(STp, "EOM with %d " in st_write()
1824 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1828 STp->block_size; in st_write()
1831 DEBC_printk(STp, "Retry " in st_write()
1834 STp->buffer->buffer_bytes); in st_write()
1845 DEBC_printk(STp, "EOM with " in st_write()
1858 if (STp->block_size == 0) in st_write()
1865 STp->dirty = 0; in st_write()
1883 release_buffering(STp, 0); in st_write()
1884 mutex_unlock(&STp->lock); in st_write()
1895 static long read_tape(struct scsi_tape *STp, long count, in read_tape() argument
1909 STm = &(STp->modes[STp->current_mode]); in read_tape()
1910 STps = &(STp->ps[STp->partition]); in read_tape()
1913 STbp = STp->buffer; in read_tape()
1915 if (STp->block_size == 0) in read_tape()
1918 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1919 blks = (STp->buffer)->buffer_blocks; in read_tape()
1920 bytes = blks * STp->block_size; in read_tape()
1923 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1924 bytes = (STp->buffer)->buffer_size; in read_tape()
1925 blks = bytes / STp->block_size; in read_tape()
1926 bytes = blks * STp->block_size; in read_tape()
1932 cmd[1] = (STp->block_size != 0); in read_tape()
1933 if (!cmd[1] && STp->sili) in read_tape()
1940 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, in read_tape()
1941 STp->device->request_queue->rq_timeout, in read_tape()
1943 release_buffering(STp, 1); in read_tape()
1953 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1956 DEBC_printk(STp, in read_tape()
1974 if (STp->block_size == 0) in read_tape()
1981 if (STp->block_size == 0 && in read_tape()
1983 st_printk(KERN_NOTICE, STp, in read_tape()
1993 } else if (STp->block_size == 0) { in read_tape()
1999 st_printk(KERN_NOTICE, STp, in read_tape()
2004 st_int_ioctl(STp, MTBSR, 1); in read_tape()
2009 STp->block_size; in read_tape()
2010 DEBC_printk(STp, "ILI but " in read_tape()
2017 if (st_int_ioctl(STp, MTBSR, 1)) in read_tape()
2025 if (STp->block_size == 0) in read_tape()
2029 bytes - transfer * STp->block_size; in read_tape()
2030 DEBC_printk(STp, "EOF detected (%d " in read_tape()
2038 if (STp->block_size == 0) in read_tape()
2042 bytes - transfer * STp->block_size; in read_tape()
2044 DEBC_printk(STp, "EOM detected (%d " in read_tape()
2051 DEBC_printk(STp, "Tape error while reading.\n"); in read_tape()
2055 DEBC_printk(STp, "Zero returned for " in read_tape()
2075 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2076 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2080 if (STp->block_size == 0) in read_tape()
2083 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2098 struct scsi_tape *STp = filp->private_data; in st_read() local
2101 struct st_buffer *STbp = STp->buffer; in st_read()
2103 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2106 retval = rw_checks(STp, filp, count); in st_read()
2110 STm = &(STp->modes[STp->current_mode]); in st_read()
2111 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2116 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2119 STps = &(STp->ps[STp->partition]); in st_read()
2121 retval = flush_buffer(STp, 0); in st_read()
2128 st_printk(ST_DEB_MSG, STp, in st_read()
2133 retval = setup_buffering(STp, buf, count, 1); in st_read()
2169 special = read_tape(STp, count - total, &SRpnt); in st_read()
2180 st_printk(ST_DEB_MSG, STp, in st_read()
2198 if (STp->block_size == 0) in st_read()
2228 release_buffering(STp, 1); in st_read()
2231 mutex_unlock(&STp->lock); in st_read()
2240 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm) in DEB() argument
2243 st_printk(KERN_INFO, STp, in DEB()
2246 STp->current_mode, STm->do_buffer_writes, in DEB()
2248 st_printk(KERN_INFO, STp, in DEB()
2251 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2252 STp->do_auto_lock); in DEB()
2253 st_printk(KERN_INFO, STp, in DEB()
2256 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2257 STp->can_partitions, STp->scsi2_logical); in DEB()
2258 st_printk(KERN_INFO, STp, in DEB()
2261 STm->sysv, STp->immediate, STp->sili, in DEB()
2262 STp->immediate_filemark); in DEB()
2263 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging); in DEB()
2269 static int st_set_options(struct scsi_tape *STp, long options)
2277 STm = &(STp->modes[STp->current_mode]);
2283 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2289 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2290 STp->current_mode);
2299 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2300 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2301 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2302 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2303 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2304 if ((STp->device)->scsi_level >= SCSI_2)
2305 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2306 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2307 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2308 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2310 STp->sili = (options & MT_ST_SILI) != 0;
2312 st_log_options(STp, STm); )
2324 STp->two_fm = value;
2326 STp->fast_mteom = value;
2328 STp->do_auto_lock = value;
2330 STp->can_bsr = value;
2332 STp->omit_blklims = value;
2333 if ((STp->device)->scsi_level >= SCSI_2 &&
2335 STp->can_partitions = value;
2337 STp->scsi2_logical = value;
2339 STp->immediate = value;
2341 STp->immediate_filemark = value;
2345 STp->sili = value;
2349 st_log_options(STp, STm); )
2356 DEBC_printk(STp, "Default block size disabled.\n");
2359 DEBC_printk(STp,"Default block size set to "
2361 if (STp->ready == ST_READY) {
2362 STp->blksize_changed = 0;
2363 set_mode_densblk(STp, STm);
2369 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2370 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2373 blk_queue_rq_timeout(STp->device->request_queue,
2375 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2384 STp->cln_mode = value;
2385 STp->cln_sense_mask = (options >> 8) & 0xff;
2386 STp->cln_sense_value = (options >> 16) & 0xff;
2387 st_printk(KERN_INFO, STp,
2389 value, STp->cln_sense_mask, STp->cln_sense_value);
2396 DEBC_printk(STp,
2400 DEBC_printk(STp, "Density default set to %x\n",
2402 if (STp->ready == ST_READY) {
2403 STp->density_changed = 0;
2404 set_mode_densblk(STp, STm);
2409 STp->default_drvbuffer = 0xff;
2410 DEBC_printk(STp,
2413 STp->default_drvbuffer = value & 7;
2414 DEBC_printk(STp,
2416 STp->default_drvbuffer);
2417 if (STp->ready == ST_READY)
2418 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2423 DEBC_printk(STp,
2427 STp->c_algo = (value & 0xff00) >> 8;
2428 DEBC_printk(STp, "Compression "
2430 STp->c_algo);
2434 DEBC_printk(STp, "Compression default "
2437 if (STp->ready == ST_READY) {
2438 STp->compression_changed = 0;
2439 st_compression(STp, (STm->default_compression == ST_YES));
2472 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) in read_mode_page() argument
2484 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE, in read_mode_page()
2485 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2487 return (STp->buffer)->syscall_result; in read_mode_page()
2491 return STp->buffer->syscall_result; in read_mode_page()
2497 static int write_mode_page(struct scsi_tape *STp, int page, int slow) in write_mode_page() argument
2507 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2508 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2511 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2512 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2513 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2514 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2517 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2518 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE, in write_mode_page()
2521 return (STp->buffer)->syscall_result; in write_mode_page()
2525 return STp->buffer->syscall_result; in write_mode_page()
2546 static int st_compression(struct scsi_tape * STp, int state) in st_compression() argument
2550 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2552 if (STp->ready != ST_READY) in st_compression()
2556 retval = read_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2558 DEBC_printk(STp, "Compression mode page not supported.\n"); in st_compression()
2563 DEBC_printk(STp, "Compression state is %d.\n", in st_compression()
2568 DEBC_printk(STp, "Compression not supported.\n"); in st_compression()
2575 if (STp->c_algo != 0) in st_compression()
2576 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2580 if (STp->c_algo != 0) in st_compression()
2584 retval = write_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2586 DEBC_printk(STp, "Compression change failed.\n"); in st_compression()
2589 DEBC_printk(STp, "Compression state changed to %d.\n", state); in st_compression()
2591 STp->compression_changed = 1; in st_compression()
2597 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) in do_load_unload() argument
2604 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2605 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2620 DEBC_printk(STp, " Enhanced %sload slot %2d.\n", in do_load_unload()
2625 if (STp->immediate) { in do_load_unload()
2627 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2630 timeout = STp->long_timeout; in do_load_unload()
2634 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n"); in do_load_unload()
2636 st_printk(ST_DEB_MSG, STp, "Loading tape.\n"); in do_load_unload()
2639 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in do_load_unload()
2642 return (STp->buffer)->syscall_result; in do_load_unload()
2644 retval = (STp->buffer)->syscall_result; in do_load_unload()
2650 STp->rew_at_close = 0; in do_load_unload()
2651 STp->ready = ST_NO_TAPE; in do_load_unload()
2654 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2655 retval = check_tape(STp, filp); in do_load_unload()
2661 STps = &(STp->ps[STp->partition]); in do_load_unload()
2671 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) in deb_space_print() argument
2681 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n", in deb_space_print()
2687 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) … in deb_space_print() argument
2692 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg) in st_int_ioctl() argument
2704 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2705 if (STp->ready != ST_READY) { in st_int_ioctl()
2706 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2711 timeout = STp->long_timeout; in st_int_ioctl()
2712 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2728 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd); in st_int_ioctl()
2744 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd); in st_int_ioctl()
2756 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd); in st_int_ioctl()
2768 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd); in st_int_ioctl()
2779 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd); in st_int_ioctl()
2792 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd); in st_int_ioctl()
2801 if (STp->write_prot) in st_int_ioctl()
2807 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2812 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2815 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2821 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2834 if (STp->immediate) { in st_int_ioctl()
2836 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2838 DEBC_printk(STp, "Rewinding tape.\n"); in st_int_ioctl()
2842 DEBC_printk(STp, "No op on tape.\n"); in st_int_ioctl()
2846 if (STp->immediate) { in st_int_ioctl()
2848 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2851 DEBC_printk(STp, "Retensioning tape.\n"); in st_int_ioctl()
2855 if (!STp->fast_mteom) { in st_int_ioctl()
2857 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff); in st_int_ioctl()
2869 DEBC_printk(STp, "Spacing to end of recorded medium.\n"); in st_int_ioctl()
2874 if (STp->write_prot) in st_int_ioctl()
2878 if (STp->immediate) { in st_int_ioctl()
2880 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2883 timeout = STp->long_timeout * 8; in st_int_ioctl()
2885 DEBC_printk(STp, "Erasing tape.\n"); in st_int_ioctl()
2893 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in st_int_ioctl()
2897 STp->max_block > 0 && in st_int_ioctl()
2898 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || in st_int_ioctl()
2899 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { in st_int_ioctl()
2900 st_printk(KERN_WARNING, STp, "Illegal block size.\n"); in st_int_ioctl()
2904 if ((STp->use_pf & USE_PF)) in st_int_ioctl()
2909 memset((STp->buffer)->b_data, 0, 12); in st_int_ioctl()
2911 (STp->buffer)->b_data[2] = (arg & 7) << 4; in st_int_ioctl()
2913 (STp->buffer)->b_data[2] = in st_int_ioctl()
2914 STp->drv_buffer << 4; in st_int_ioctl()
2915 (STp->buffer)->b_data[3] = 8; /* block descriptor length */ in st_int_ioctl()
2917 (STp->buffer)->b_data[4] = arg; in st_int_ioctl()
2918 STp->density_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2920 (STp->buffer)->b_data[4] = arg >> 24; in st_int_ioctl()
2922 (STp->buffer)->b_data[4] = STp->density; in st_int_ioctl()
2926 STp->blksize_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2928 ltmp = STp->block_size; in st_int_ioctl()
2929 (STp->buffer)->b_data[9] = (ltmp >> 16); in st_int_ioctl()
2930 (STp->buffer)->b_data[10] = (ltmp >> 8); in st_int_ioctl()
2931 (STp->buffer)->b_data[11] = ltmp; in st_int_ioctl()
2932 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2935 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2937 (STp->buffer)->b_data[9] * 65536 + in st_int_ioctl()
2938 (STp->buffer)->b_data[10] * 256 + in st_int_ioctl()
2939 (STp->buffer)->b_data[11]); in st_int_ioctl()
2941 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2943 (STp->buffer)->b_data[4]); in st_int_ioctl()
2945 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2947 ((STp->buffer)->b_data[2] >> 4) & 7); in st_int_ioctl()
2954 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction, in st_int_ioctl()
2957 return (STp->buffer)->syscall_result; in st_int_ioctl()
2959 ioctl_result = (STp->buffer)->syscall_result; in st_int_ioctl()
2969 ioctl_result = st_int_ioctl(STp, MTFSF, 1); in st_int_ioctl()
2971 ioctl_result = st_int_ioctl(STp, MTBSF, 1); in st_int_ioctl()
2974 STp->block_size = arg & MT_ST_BLKSIZE_MASK; in st_int_ioctl()
2975 if (STp->block_size != 0) { in st_int_ioctl()
2976 (STp->buffer)->buffer_blocks = in st_int_ioctl()
2977 (STp->buffer)->buffer_size / STp->block_size; in st_int_ioctl()
2979 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in st_int_ioctl()
2981 STp->density = arg >> MT_ST_DENSITY_SHIFT; in st_int_ioctl()
2983 STp->drv_buffer = (arg & 7); in st_int_ioctl()
2985 STp->density = arg; in st_int_ioctl()
2998 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_int_ioctl()
3073 !(STp->use_pf & PF_TESTED)) { in st_int_ioctl()
3076 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED; in st_int_ioctl()
3079 return st_int_ioctl(STp, cmd_in, arg); in st_int_ioctl()
3098 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition, in get_location() argument
3105 if (STp->ready != ST_READY) in get_location()
3109 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3114 if (!logical && !STp->scsi2_logical) in get_location()
3117 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE, in get_location()
3118 STp->device->request_queue->rq_timeout, in get_location()
3121 return (STp->buffer)->syscall_result; in get_location()
3123 if ((STp->buffer)->syscall_result != 0 || in get_location()
3124 (STp->device->scsi_level >= SCSI_2 && in get_location()
3125 ((STp->buffer)->b_data[0] & 4) != 0)) { in get_location()
3127 DEBC_printk(STp, " Can't read tape position.\n"); in get_location()
3131 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3132 *block = ((STp->buffer)->b_data[0] << 16) in get_location()
3133 + ((STp->buffer)->b_data[1] << 8) in get_location()
3134 + (STp->buffer)->b_data[2]; in get_location()
3137 *block = ((STp->buffer)->b_data[4] << 24) in get_location()
3138 + ((STp->buffer)->b_data[5] << 16) in get_location()
3139 + ((STp->buffer)->b_data[6] << 8) in get_location()
3140 + (STp->buffer)->b_data[7]; in get_location()
3141 *partition = (STp->buffer)->b_data[1]; in get_location()
3142 if (((STp->buffer)->b_data[0] & 0x80) && in get_location()
3143 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ in get_location()
3144 STp->ps[0].drv_block = STp->ps[0].drv_file = 0; in get_location()
3146 DEBC_printk(STp, "Got tape pos. blk %d part %d.\n", in get_location()
3158 static int set_location(struct scsi_tape *STp, unsigned int block, int partition, in set_location() argument
3168 if (STp->ready != ST_READY) in set_location()
3170 timeout = STp->long_timeout; in set_location()
3171 STps = &(STp->ps[STp->partition]); in set_location()
3173 DEBC_printk(STp, "Setting block to %d and partition to %d.\n", in set_location()
3179 if ((!STp->can_partitions && partition != 0) || in set_location()
3182 if (partition != STp->partition) { in set_location()
3183 if (get_location(STp, &blk, &p, 1)) in set_location()
3188 DEBC_printk(STp, "Visited block %d for " in set_location()
3190 blk, STp->partition); in set_location()
3195 if ((STp->device)->scsi_level < SCSI_2) { in set_location()
3207 if (!logical && !STp->scsi2_logical) in set_location()
3209 if (STp->partition != partition) { in set_location()
3212 DEBC_printk(STp, "Trying to change partition " in set_location()
3213 "from %d to %d\n", STp->partition, in set_location()
3217 if (STp->immediate) { in set_location()
3219 timeout = STp->device->request_queue->rq_timeout; in set_location()
3222 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in set_location()
3225 return (STp->buffer)->syscall_result; in set_location()
3229 if ((STp->buffer)->syscall_result != 0) { in set_location()
3231 if (STp->can_partitions && in set_location()
3232 (STp->device)->scsi_level >= SCSI_2 && in set_location()
3233 (p = find_partition(STp)) >= 0) in set_location()
3234 STp->partition = p; in set_location()
3236 if (STp->can_partitions) { in set_location()
3237 STp->partition = partition; in set_location()
3238 STps = &(STp->ps[partition]); in set_location()
3260 static int find_partition(struct scsi_tape *STp) in find_partition() argument
3265 if ((i = get_location(STp, &block, &partition, 1)) < 0) in find_partition()
3274 static int switch_partition(struct scsi_tape *STp) in switch_partition() argument
3278 if (STp->partition == STp->new_partition) in switch_partition()
3280 STps = &(STp->ps[STp->new_partition]); in switch_partition()
3283 return set_location(STp, STps->last_block_visited, STp->new_partition, 1); in switch_partition()
3305 static int nbr_partitions(struct scsi_tape *STp) in nbr_partitions() argument
3309 if (STp->ready != ST_READY) in nbr_partitions()
3312 result = read_mode_page(STp, PART_PAGE, 1); in nbr_partitions()
3315 DEBC_printk(STp, "Can't read medium partition page.\n"); in nbr_partitions()
3318 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + in nbr_partitions()
3320 DEBC_printk(STp, "Number of partitions %d.\n", result); in nbr_partitions()
3327 static int format_medium(struct scsi_tape *STp, int format) in format_medium() argument
3330 int timeout = STp->long_timeout; in format_medium()
3337 if (STp->immediate) { in format_medium()
3339 timeout = STp->device->request_queue->rq_timeout; in format_medium()
3341 DEBC_printk(STp, "Sending FORMAT MEDIUM\n"); in format_medium()
3342 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in format_medium()
3345 result = STp->buffer->syscall_result; in format_medium()
3371 static int partition_tape(struct scsi_tape *STp, int size) in partition_tape() argument
3375 bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false; in partition_tape()
3380 result = read_mode_page(STp, PART_PAGE, 0); in partition_tape()
3382 DEBC_printk(STp, "Can't read partition mode page.\n"); in partition_tape()
3392 bp = (STp->buffer)->b_data; in partition_tape()
3394 DEBC_printk(STp, "Partition page length is %d bytes.\n", in partition_tape()
3405 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3406 result = format_medium(STp, 0); in partition_tape()
3448 DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n", in partition_tape()
3456 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3465 DEBC_printk(STp, in partition_tape()
3480 result = write_mode_page(STp, PART_PAGE, 1); in partition_tape()
3483 result = format_medium(STp, 1); in partition_tape()
3486 st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n"); in partition_tape()
3503 struct scsi_tape *STp = file->private_data; in st_ioctl() local
3507 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl()
3511 if (debugging && !STp->in_use) { in st_ioctl()
3512 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n"); in st_ioctl()
3517 STm = &(STp->modes[STp->current_mode]); in st_ioctl()
3518 STps = &(STp->ps[STp->partition]); in st_ioctl()
3526 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl()
3549 st_printk(KERN_WARNING, STp, in st_ioctl()
3561 if (!STp->pos_unknown) { in st_ioctl()
3579 i = !STp->can_partitions || in st_ioctl()
3580 (STp->new_partition != STp->partition); in st_ioctl()
3589 i = flush_buffer(STp, i); in st_ioctl()
3598 i = st_int_ioctl(STp, MTWEOF, 1); in st_ioctl()
3623 reset_state(STp); in st_ioctl()
3625 STp->device->was_reset = 0; in st_ioctl()
3633 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl()
3634 do_door_lock(STp, 0); /* Ignore result! */ in st_ioctl()
3638 retval = st_set_options(STp, mtc.mt_count); in st_ioctl()
3643 if (!STp->can_partitions || in st_ioctl()
3648 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl()
3649 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl()
3653 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl()
3657 STp->new_partition = mtc.mt_count; in st_ioctl()
3663 if (!STp->can_partitions) { in st_ioctl()
3667 i = do_load_unload(STp, file, 1); in st_ioctl()
3672 i = partition_tape(STp, mtc.mt_count); in st_ioctl()
3678 STp->ps[i].rw = ST_IDLE; in st_ioctl()
3679 STp->ps[i].at_sm = 0; in st_ioctl()
3680 STp->ps[i].last_block_valid = 0; in st_ioctl()
3682 STp->partition = STp->new_partition = 0; in st_ioctl()
3683 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl()
3690 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl()
3691 if (!STp->can_partitions) in st_ioctl()
3692 STp->ps[0].rw = ST_IDLE; in st_ioctl()
3698 retval = do_load_unload(STp, file, 0); in st_ioctl()
3703 retval = do_load_unload(STp, file, max(1, mtc.mt_count)); in st_ioctl()
3708 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK)); in st_ioctl()
3712 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl()
3713 (i = switch_partition(STp)) < 0) { in st_ioctl()
3719 retval = st_compression(STp, (mtc.mt_count & 1)); in st_ioctl()
3721 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count); in st_ioctl()
3729 if ((i = flush_buffer(STp, 0)) < 0) { in st_ioctl()
3733 if (STp->can_partitions && in st_ioctl()
3734 (i = switch_partition(STp)) < 0) { in st_ioctl()
3747 mt_status.mt_type = STp->tape_type; in st_ioctl()
3749 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl()
3750 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl()
3753 if (STp->block_size != 0) { in st_ioctl()
3756 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl()
3759 ((STp->buffer)->buffer_bytes + in st_ioctl()
3760 STp->block_size - 1) / STp->block_size; in st_ioctl()
3764 if (STp->drv_write_prot) in st_ioctl()
3772 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl()
3773 mt_status.mt_resid = STp->partition; in st_ioctl()
3778 if (STp->density == 1) in st_ioctl()
3780 else if (STp->density == 2) in st_ioctl()
3782 else if (STp->density == 3) in st_ioctl()
3784 if (STp->ready == ST_READY) in st_ioctl()
3786 if (STp->ready == ST_NO_TAPE) in st_ioctl()
3791 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl()
3792 STp->drv_buffer != 0) in st_ioctl()
3794 if (STp->cleaning_req) in st_ioctl()
3801 STp->recover_reg = 0; /* Clear after read */ in st_ioctl()
3810 if ((i = get_location(STp, &blk, &bt, 0)) < 0) { in st_ioctl()
3818 mutex_unlock(&STp->lock); in st_ioctl()
3831 retval = scsi_ioctl(STp->device, NULL, file->f_mode, cmd_in, p); in st_ioctl()
3834 STp->rew_at_close = 0; in st_ioctl()
3835 STp->ready = ST_NO_TAPE; in st_ioctl()
3840 mutex_unlock(&STp->lock); in st_ioctl()
4099 char *stp; in st_setup() local
4101 stp = get_options(str, ARRAY_SIZE(ints), ints); in st_setup()
4108 while (stp != NULL) { in st_setup()
4111 if (!strncmp(stp, parms[i].name, len) && in st_setup()
4112 (*(stp + len) == ':' || *(stp + len) == '=')) { in st_setup()
4115 simple_strtoul(stp + len + 1, NULL, 0); in st_setup()
4124 stp); in st_setup()
4125 stp = strchr(stp, ','); in st_setup()
4126 if (stp) in st_setup()
4127 stp++; in st_setup()
4247 char *stp; in st_probe() local
4251 if ((stp = st_incompatible(SDp))) { in st_probe()
4617 struct scsi_tape *STp = STm->tape; in options_show() local
4625 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4626 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4628 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4629 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4630 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4631 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4633 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4634 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4635 options |= STp->sili ? MT_ST_SILI : 0; in options_show()