Lines Matching refs:STp
243 struct scsi_tape *STp = NULL; in scsi_tape_get() local
248 STp = idr_find(&st_index_idr, dev); in scsi_tape_get()
249 if (!STp) goto out; in scsi_tape_get()
251 kref_get(&STp->kref); in scsi_tape_get()
253 if (!STp->device) in scsi_tape_get()
256 if (scsi_device_get(STp->device)) in scsi_tape_get()
262 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_get()
263 STp = NULL; in scsi_tape_get()
267 return STp; in scsi_tape_get()
270 static void scsi_tape_put(struct scsi_tape *STp) in scsi_tape_put() argument
272 struct scsi_device *sdev = STp->device; in scsi_tape_put()
275 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
363 char *name = tape_name(STp); in st_chk_result()
369 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
373 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
379 st_printk(ST_DEB_MSG, STp, in st_chk_result()
384 __scsi_print_sense(STp->device, name, in st_chk_result()
389 st_printk(KERN_WARNING, STp, in st_chk_result()
401 __scsi_print_sense(STp->device, name, in st_chk_result()
407 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
408 if (STp->cln_sense_value) in st_chk_result()
409 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
410 STp->cln_sense_mask) == STp->cln_sense_value); in st_chk_result()
412 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
413 STp->cln_sense_mask) != 0); in st_chk_result()
417 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
419 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
428 STp->recover_count++; in st_chk_result()
429 STp->recover_reg++; in st_chk_result()
439 st_printk(ST_DEB_MSG, STp, in st_chk_result()
441 stp, STp->recover_count); in st_chk_result()
477 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end() local
480 STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors; in st_scsi_execute_end()
481 STp->buffer->cmdstat.residual = req->resid_len; in st_scsi_execute_end()
537 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, in st_do_scsi() argument
541 struct rq_map_data *mdata = &STp->buffer->map_data; in st_do_scsi()
545 if (!do_wait && ((STp->buffer)->last_SRpnt)) { in st_do_scsi()
546 st_printk(KERN_ERR, STp, in st_do_scsi()
549 (STp->buffer)->syscall_result = (-EINTR); in st_do_scsi()
551 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
556 SRpnt = st_allocate_request(STp); in st_do_scsi()
564 (STp->buffer)->last_SRpnt = SRpnt; in st_do_scsi()
566 waiting = &STp->wait; in st_do_scsi()
570 if (STp->buffer->do_dio) { in st_do_scsi()
572 mdata->nr_entries = STp->buffer->sg_segs; in st_do_scsi()
573 mdata->pages = STp->buffer->mapped_pages; in st_do_scsi()
575 mdata->page_order = STp->buffer->reserved_page_order; in st_do_scsi()
578 mdata->pages = STp->buffer->reserved_pages; in st_do_scsi()
583 STp->buffer->cmdstat.have_sense = 0; in st_do_scsi()
584 STp->buffer->syscall_result = 0; in st_do_scsi()
590 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
591 (STp->buffer)->last_SRpnt = NULL; in st_do_scsi()
595 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in st_do_scsi()
606 static int write_behind_check(struct scsi_tape * STp) in write_behind_check() argument
614 STbuffer = STp->buffer; in write_behind_check()
619 if (STp->write_pending) in write_behind_check()
620 STp->nbr_waits++; in write_behind_check()
622 STp->nbr_finished++; in write_behind_check()
625 wait_for_completion(&(STp->wait)); in write_behind_check()
630 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in write_behind_check()
634 STps = &(STp->ps[STp->partition]); in write_behind_check()
636 if (STp->block_size == 0) in write_behind_check()
639 STps->drv_block += STbuffer->writing / STp->block_size; in write_behind_check()
660 st_printk(ST_DEB_MSG, STp, in write_behind_check()
670 static int cross_eof(struct scsi_tape * STp, int forward) in cross_eof() argument
684 DEBC_printk(STp, "Stepping over filemark %s.\n", in cross_eof()
687 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in cross_eof()
688 STp->device->request_queue->rq_timeout, in cross_eof()
691 return (STp->buffer)->syscall_result; in cross_eof()
696 if ((STp->buffer)->cmdstat.midlevel_result != 0) in cross_eof()
697 st_printk(KERN_ERR, STp, in cross_eof()
701 return (STp->buffer)->syscall_result; in cross_eof()
706 static int st_flush_write_buffer(struct scsi_tape * STp) in st_flush_write_buffer() argument
714 result = write_behind_check(STp); in st_flush_write_buffer()
719 if (STp->dirty == 1) { in st_flush_write_buffer()
721 transfer = STp->buffer->buffer_bytes; in st_flush_write_buffer()
722 DEBC_printk(STp, "Flushing %d bytes.\n", transfer); in st_flush_write_buffer()
727 blks = transfer / STp->block_size; in st_flush_write_buffer()
732 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE, in st_flush_write_buffer()
733 STp->device->request_queue->rq_timeout, in st_flush_write_buffer()
736 return (STp->buffer)->syscall_result; in st_flush_write_buffer()
738 STps = &(STp->ps[STp->partition]); in st_flush_write_buffer()
739 if ((STp->buffer)->syscall_result != 0) { in st_flush_write_buffer()
740 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush_write_buffer()
748 STp->dirty = 0; in st_flush_write_buffer()
749 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
754 st_printk(KERN_ERR, STp, "Error on flush.\n"); in st_flush_write_buffer()
761 STp->dirty = 0; in st_flush_write_buffer()
762 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
773 static int flush_buffer(struct scsi_tape *STp, int seek_next) in flush_buffer() argument
779 STbuffer = STp->buffer; in flush_buffer()
785 if (STp->pos_unknown) in flush_buffer()
788 if (STp->ready != ST_READY) in flush_buffer()
790 STps = &(STp->ps[STp->partition]); in flush_buffer()
792 return st_flush_write_buffer(STp); in flush_buffer()
794 if (STp->block_size == 0) in flush_buffer()
797 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
798 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
799 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
800 STp->block_size; in flush_buffer()
801 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
802 (STp->buffer)->read_pointer = 0; in flush_buffer()
806 result = cross_eof(STp, 0); /* Back over the EOF hit */ in flush_buffer()
816 result = st_int_ioctl(STp, MTBSR, backspace); in flush_buffer()
828 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm) in set_mode_densblk() argument
833 if (!STp->density_changed && in set_mode_densblk()
835 STm->default_density != STp->density) { in set_mode_densblk()
839 arg = STp->density; in set_mode_densblk()
841 if (!STp->blksize_changed && in set_mode_densblk()
843 STm->default_blksize != STp->block_size) { in set_mode_densblk()
847 arg |= STp->block_size; in set_mode_densblk()
849 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) { in set_mode_densblk()
850 st_printk(KERN_WARNING, STp, in set_mode_densblk()
862 static int do_door_lock(struct scsi_tape * STp, int do_lock) in do_door_lock() argument
866 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); in do_door_lock()
868 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
871 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
873 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
879 static void reset_state(struct scsi_tape *STp) in reset_state() argument
884 STp->pos_unknown = 0; in reset_state()
886 STps = &(STp->ps[i]); in reset_state()
894 if (STp->can_partitions) { in reset_state()
895 STp->partition = find_partition(STp); in reset_state()
896 if (STp->partition < 0) in reset_state()
897 STp->partition = 0; in reset_state()
898 STp->new_partition = STp->partition; in reset_state()
911 static int test_ready(struct scsi_tape *STp, int do_wait) in test_ready() argument
917 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
924 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, in test_ready()
925 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
928 retval = (STp->buffer)->syscall_result; in test_ready()
958 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
968 retval = (STp->buffer)->syscall_result; in test_ready()
985 static int check_tape(struct scsi_tape *STp, struct file *filp) in check_tape() argument
996 STp->ready = ST_READY; in check_tape()
998 if (mode != STp->current_mode) { in check_tape()
999 DEBC_printk(STp, "Mode change from %d to %d.\n", in check_tape()
1000 STp->current_mode, mode); in check_tape()
1002 STp->current_mode = mode; in check_tape()
1004 STm = &(STp->modes[STp->current_mode]); in check_tape()
1006 saved_cleaning = STp->cleaning_req; in check_tape()
1007 STp->cleaning_req = 0; in check_tape()
1010 retval = test_ready(STp, do_wait); in check_tape()
1016 STp->pos_unknown = 0; in check_tape()
1017 STp->partition = STp->new_partition = 0; in check_tape()
1018 if (STp->can_partitions) in check_tape()
1019 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1022 STps = &(STp->ps[i]); in check_tape()
1033 STp->cleaning_req |= saved_cleaning; in check_tape()
1037 STp->ready = ST_NO_TAPE; in check_tape()
1039 STp->ready = ST_NOT_READY; in check_tape()
1041 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1042 STp->write_prot = 0; in check_tape()
1043 STp->block_size = 0; in check_tape()
1044 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1045 STp->partition = STp->new_partition = 0; in check_tape()
1046 STp->door_locked = ST_UNLOCKED; in check_tape()
1051 if (STp->omit_blklims) in check_tape()
1052 STp->min_block = STp->max_block = (-1); in check_tape()
1057 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE, in check_tape()
1058 STp->device->request_queue->rq_timeout, in check_tape()
1061 retval = (STp->buffer)->syscall_result; in check_tape()
1065 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1066 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1067 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1068 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1069 (STp->buffer)->b_data[5]; in check_tape()
1070 if ( DEB( debugging || ) !STp->inited) in check_tape()
1071 st_printk(KERN_INFO, STp, in check_tape()
1073 STp->min_block, STp->max_block); in check_tape()
1075 STp->min_block = STp->max_block = (-1); in check_tape()
1076 DEBC_printk(STp, "Can't read block limits.\n"); in check_tape()
1084 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE, in check_tape()
1085 STp->device->request_queue->rq_timeout, in check_tape()
1088 retval = (STp->buffer)->syscall_result; in check_tape()
1092 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1093 DEBC_printk(STp, "No Mode Sense.\n"); in check_tape()
1094 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1095 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1096 STp->drv_write_prot = 0; in check_tape()
1098 DEBC_printk(STp,"Mode sense. Length %d, " in check_tape()
1100 (STp->buffer)->b_data[0], in check_tape()
1101 (STp->buffer)->b_data[1], in check_tape()
1102 (STp->buffer)->b_data[2], in check_tape()
1103 (STp->buffer)->b_data[3]); in check_tape()
1105 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1106 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1107 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1108 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1109 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1110 DEBC_printk(STp, "Density %x, tape length: %x, " in check_tape()
1112 STp->density, in check_tape()
1113 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1114 (STp->buffer)->b_data[6] * 256 + in check_tape()
1115 (STp->buffer)->b_data[7], in check_tape()
1116 STp->drv_buffer); in check_tape()
1118 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1119 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1120 st_printk(KERN_WARNING, STp, in check_tape()
1123 STp->immediate_filemark = 0; in check_tape()
1128 STp->inited = 1; in check_tape()
1130 if (STp->block_size > 0) in check_tape()
1131 (STp->buffer)->buffer_blocks = in check_tape()
1132 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1134 (STp->buffer)->buffer_blocks = 1; in check_tape()
1135 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1137 DEBC_printk(STp, "Block size: %d, buffer size: %d (%d blocks).\n", in check_tape()
1138 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1139 (STp->buffer)->buffer_blocks); in check_tape()
1141 if (STp->drv_write_prot) { in check_tape()
1142 STp->write_prot = 1; in check_tape()
1144 DEBC_printk(STp, "Write protected\n"); in check_tape()
1154 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1158 DEBC_printk(STp, "Updating partition number in status.\n"); in check_tape()
1159 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1160 retval = STp->partition; in check_tape()
1163 STp->new_partition = STp->partition; in check_tape()
1164 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1168 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1169 STp->compression_changed = 0; in check_tape()
1171 (retval = set_mode_densblk(STp, STm)) < 0) in check_tape()
1174 if (STp->default_drvbuffer != 0xff) { in check_tape()
1175 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1176 st_printk(KERN_WARNING, STp, in check_tape()
1179 STp->default_drvbuffer); in check_tape()
1196 struct scsi_tape *STp; in st_open() local
1207 if (!(STp = scsi_tape_get(dev))) { in st_open()
1211 filp->private_data = STp; in st_open()
1214 if (STp->in_use) { in st_open()
1216 scsi_tape_put(STp); in st_open()
1217 DEBC_printk(STp, "Device already in use.\n"); in st_open()
1221 STp->in_use = 1; in st_open()
1223 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1225 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1230 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1236 if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) { in st_open()
1237 st_printk(KERN_WARNING, STp, in st_open()
1243 (STp->buffer)->cleared = 0; in st_open()
1244 (STp->buffer)->writing = 0; in st_open()
1245 (STp->buffer)->syscall_result = 0; in st_open()
1247 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1249 STp->dirty = 0; in st_open()
1251 STps = &(STp->ps[i]); in st_open()
1254 STp->try_dio_now = STp->try_dio; in st_open()
1255 STp->recover_count = 0; in st_open()
1256 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1257 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1259 retval = check_tape(STp, filp); in st_open()
1264 if (STp->ready == NO_TAPE) in st_open()
1273 normalize_buffer(STp->buffer); in st_open()
1275 STp->in_use = 0; in st_open()
1278 scsi_autopm_put_device(STp->device); in st_open()
1279 scsi_tape_put(STp); in st_open()
1291 struct scsi_tape *STp = filp->private_data; in st_flush() local
1292 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1293 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1298 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1299 result = st_flush_write_buffer(STp); in st_flush()
1304 if (STp->can_partitions && in st_flush()
1305 (result2 = switch_partition(STp)) < 0) { in st_flush()
1306 DEBC_printk(STp, "switch_partition at close failed.\n"); in st_flush()
1312 DEBC( if (STp->nbr_requests) in st_flush()
1313 st_printk(KERN_DEBUG, STp, in st_flush()
1315 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1316 STp->nbr_pages)); in st_flush()
1318 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1319 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1322 DEBC_printk(STp, "Async write waits %d, finished %d.\n", in st_flush()
1323 STp->nbr_waits, STp->nbr_finished); in st_flush()
1327 if (STp->immediate_filemark) in st_flush()
1329 cmd[4] = 1 + STp->two_fm; in st_flush()
1331 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in st_flush()
1332 STp->device->request_queue->rq_timeout, in st_flush()
1335 result = (STp->buffer)->syscall_result; in st_flush()
1339 if (STp->buffer->syscall_result == 0 || in st_flush()
1351 if (STp->two_fm) in st_flush()
1352 cross_eof(STp, 0); in st_flush()
1358 st_printk(KERN_ERR, STp, in st_flush()
1364 DEBC_printk(STp, "Buffer flushed, %d EOF(s) written\n", cmd[4]); in st_flush()
1365 } else if (!STp->rew_at_close) { in st_flush()
1366 STps = &(STp->ps[STp->partition]); in st_flush()
1368 if (STp->can_bsr) in st_flush()
1369 result = flush_buffer(STp, 0); in st_flush()
1371 result = cross_eof(STp, 0); in st_flush()
1381 !(result = cross_eof(STp, 1))) || in st_flush()
1391 if (STp->rew_at_close) { in st_flush()
1392 result2 = st_int_ioctl(STp, MTREW, 1); in st_flush()
1405 struct scsi_tape *STp = filp->private_data; in st_release() local
1407 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1408 do_door_lock(STp, 0); in st_release()
1410 normalize_buffer(STp->buffer); in st_release()
1412 STp->in_use = 0; in st_release()
1414 scsi_autopm_put_device(STp->device); in st_release()
1415 scsi_tape_put(STp); in st_release()
1421 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count) in rw_checks() argument
1431 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1436 if (STp->ready != ST_READY) { in rw_checks()
1437 if (STp->ready == ST_NO_TAPE) in rw_checks()
1444 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1454 if (STp->pos_unknown) { in rw_checks()
1463 if (!STp->in_use) { in rw_checks()
1464 st_printk(ST_DEB_MSG, STp, in rw_checks()
1470 if (STp->can_partitions && in rw_checks()
1471 (retval = switch_partition(STp)) < 0) in rw_checks()
1474 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1475 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1480 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1481 !do_door_lock(STp, 1)) in rw_checks()
1482 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1489 static int setup_buffering(struct scsi_tape *STp, const char __user *buf, in setup_buffering() argument
1493 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1496 i = STp->try_dio_now && try_rdio; in setup_buffering()
1498 i = STp->try_dio_now && try_wdio; in setup_buffering()
1501 STp->device->request_queue)) == 0) { in setup_buffering()
1513 STp->nbr_dio++; in setup_buffering()
1514 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1519 DEB( STp->nbr_requests++; ) in setup_buffering()
1522 if (STp->block_size) in setup_buffering()
1523 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1524 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1529 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1534 !enlarge_buffer(STbp, bufsize, STp->restr_dma)) { in setup_buffering()
1535 st_printk(KERN_WARNING, STp, in setup_buffering()
1541 if (STp->block_size) in setup_buffering()
1542 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1551 static void release_buffering(struct scsi_tape *STp, int is_read) in release_buffering() argument
1555 STbp = STp->buffer; in release_buffering()
1576 struct scsi_tape *STp = filp->private_data; in st_write() local
1581 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1584 retval = rw_checks(STp, filp, count); in st_write()
1589 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1590 st_printk(KERN_WARNING, STp, in st_write()
1596 STm = &(STp->modes[STp->current_mode]); in st_write()
1597 STps = &(STp->ps[STp->partition]); in st_write()
1599 if (STp->write_prot) { in st_write()
1606 retval = flush_buffer(STp, 0); in st_write()
1612 if ((retval = set_mode_densblk(STp, STm)) < 0) in st_write()
1615 !(STp->compression_changed)) { in st_write()
1616 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1617 st_printk(KERN_WARNING, STp, in st_write()
1627 STbp = STp->buffer; in st_write()
1628 i = write_behind_check(STp); in st_write()
1648 if (STp->block_size != 0 && in st_write()
1656 retval = setup_buffering(STp, buf, count, 0); in st_write()
1664 cmd[1] = (STp->block_size != 0); in st_write()
1675 if (STp->block_size == 0) in st_write()
1678 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1693 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1696 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1697 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1699 STp->dirty = 1; in st_write()
1706 if (STp->block_size == 0) in st_write()
1713 blks /= STp->block_size; in st_write()
1714 transfer = blks * STp->block_size; in st_write()
1720 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE, in st_write()
1721 STp->device->request_queue->rq_timeout, in st_write()
1729 STp->dirty = !(STbp->writing == in st_write()
1732 DEB( STp->write_pending = 1; ) in st_write()
1737 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1739 DEBC_printk(STp, "Error on write:\n"); in st_write()
1744 else if (STp->block_size == 0 && in st_write()
1749 if (STp->block_size != 0) in st_write()
1750 undone *= STp->block_size; in st_write()
1756 if (STp->block_size) in st_write()
1757 blks = (transfer - undone) / STp->block_size; in st_write()
1763 if (STp->block_size == 0 || in st_write()
1766 DEBC_printk(STp, "EOM with %d " in st_write()
1774 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1778 STp->block_size; in st_write()
1781 DEBC_printk(STp, "Retry " in st_write()
1784 STp->buffer->buffer_bytes); in st_write()
1795 DEBC_printk(STp, "EOM with " in st_write()
1808 if (STp->block_size == 0) in st_write()
1815 STp->dirty = 0; in st_write()
1833 release_buffering(STp, 0); in st_write()
1834 mutex_unlock(&STp->lock); in st_write()
1845 static long read_tape(struct scsi_tape *STp, long count, in read_tape() argument
1859 STm = &(STp->modes[STp->current_mode]); in read_tape()
1860 STps = &(STp->ps[STp->partition]); in read_tape()
1863 STbp = STp->buffer; in read_tape()
1865 if (STp->block_size == 0) in read_tape()
1868 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1869 blks = (STp->buffer)->buffer_blocks; in read_tape()
1870 bytes = blks * STp->block_size; in read_tape()
1873 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1874 bytes = (STp->buffer)->buffer_size; in read_tape()
1875 blks = bytes / STp->block_size; in read_tape()
1876 bytes = blks * STp->block_size; in read_tape()
1882 cmd[1] = (STp->block_size != 0); in read_tape()
1883 if (!cmd[1] && STp->sili) in read_tape()
1890 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, in read_tape()
1891 STp->device->request_queue->rq_timeout, in read_tape()
1893 release_buffering(STp, 1); in read_tape()
1903 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1906 DEBC_printk(STp, in read_tape()
1923 if (STp->block_size == 0 && in read_tape()
1928 if (STp->block_size == 0 && in read_tape()
1930 st_printk(KERN_NOTICE, STp, in read_tape()
1940 } else if (STp->block_size == 0) { in read_tape()
1946 st_printk(KERN_NOTICE, STp, in read_tape()
1951 st_int_ioctl(STp, MTBSR, 1); in read_tape()
1956 STp->block_size; in read_tape()
1957 DEBC_printk(STp, "ILI but " in read_tape()
1964 if (st_int_ioctl(STp, MTBSR, 1)) in read_tape()
1972 if (STp->block_size == 0) in read_tape()
1976 bytes - transfer * STp->block_size; in read_tape()
1977 DEBC_printk(STp, "EOF detected (%d " in read_tape()
1985 if (STp->block_size == 0) in read_tape()
1989 bytes - transfer * STp->block_size; in read_tape()
1991 DEBC_printk(STp, "EOM detected (%d " in read_tape()
1998 DEBC_printk(STp, "Tape error while reading.\n"); in read_tape()
2002 DEBC_printk(STp, "Zero returned for " in read_tape()
2022 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2023 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2027 if (STp->block_size == 0) in read_tape()
2030 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2045 struct scsi_tape *STp = filp->private_data; in st_read() local
2048 struct st_buffer *STbp = STp->buffer; in st_read()
2050 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2053 retval = rw_checks(STp, filp, count); in st_read()
2057 STm = &(STp->modes[STp->current_mode]); in st_read()
2058 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2063 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2066 STps = &(STp->ps[STp->partition]); in st_read()
2068 retval = flush_buffer(STp, 0); in st_read()
2075 st_printk(ST_DEB_MSG, STp, in st_read()
2080 retval = setup_buffering(STp, buf, count, 1); in st_read()
2116 special = read_tape(STp, count - total, &SRpnt); in st_read()
2127 st_printk(ST_DEB_MSG, STp, in st_read()
2145 if (STp->block_size == 0) in st_read()
2175 release_buffering(STp, 1); in st_read()
2178 mutex_unlock(&STp->lock); in st_read()
2187 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm) in DEB() argument
2190 st_printk(KERN_INFO, STp, in DEB()
2193 STp->current_mode, STm->do_buffer_writes, in DEB()
2195 st_printk(KERN_INFO, STp, in DEB()
2198 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2199 STp->do_auto_lock); in DEB()
2200 st_printk(KERN_INFO, STp, in DEB()
2203 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2204 STp->can_partitions, STp->scsi2_logical); in DEB()
2205 st_printk(KERN_INFO, STp, in DEB()
2208 STm->sysv, STp->immediate, STp->sili, in DEB()
2209 STp->immediate_filemark); in DEB()
2210 st_printk(KERN_INFO, STp, " debugging: %d\n", debugging); in DEB()
2216 static int st_set_options(struct scsi_tape *STp, long options)
2224 STm = &(STp->modes[STp->current_mode]);
2230 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2236 DEBC_printk(STp, "Initialized mode %d definition from mode 0\n",
2237 STp->current_mode);
2246 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2247 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2248 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2249 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2250 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2251 if ((STp->device)->scsi_level >= SCSI_2)
2252 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2253 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2254 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2255 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2257 STp->sili = (options & MT_ST_SILI) != 0;
2259 st_log_options(STp, STm); )
2271 STp->two_fm = value;
2273 STp->fast_mteom = value;
2275 STp->do_auto_lock = value;
2277 STp->can_bsr = value;
2279 STp->omit_blklims = value;
2280 if ((STp->device)->scsi_level >= SCSI_2 &&
2282 STp->can_partitions = value;
2284 STp->scsi2_logical = value;
2286 STp->immediate = value;
2288 STp->immediate_filemark = value;
2292 STp->sili = value;
2296 st_log_options(STp, STm); )
2303 DEBC_printk(STp, "Default block size disabled.\n");
2306 DEBC_printk(STp,"Default block size set to "
2308 if (STp->ready == ST_READY) {
2309 STp->blksize_changed = 0;
2310 set_mode_densblk(STp, STm);
2316 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2317 DEBC_printk(STp, "Long timeout set to %d seconds.\n",
2320 blk_queue_rq_timeout(STp->device->request_queue,
2322 DEBC_printk(STp, "Normal timeout set to %d seconds.\n",
2331 STp->cln_mode = value;
2332 STp->cln_sense_mask = (options >> 8) & 0xff;
2333 STp->cln_sense_value = (options >> 16) & 0xff;
2334 st_printk(KERN_INFO, STp,
2336 value, STp->cln_sense_mask, STp->cln_sense_value);
2343 DEBC_printk(STp,
2347 DEBC_printk(STp, "Density default set to %x\n",
2349 if (STp->ready == ST_READY) {
2350 STp->density_changed = 0;
2351 set_mode_densblk(STp, STm);
2356 STp->default_drvbuffer = 0xff;
2357 DEBC_printk(STp,
2360 STp->default_drvbuffer = value & 7;
2361 DEBC_printk(STp,
2363 STp->default_drvbuffer);
2364 if (STp->ready == ST_READY)
2365 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2370 DEBC_printk(STp,
2374 STp->c_algo = (value & 0xff00) >> 8;
2375 DEBC_printk(STp, "Compression "
2377 STp->c_algo);
2381 DEBC_printk(STp, "Compression default "
2384 if (STp->ready == ST_READY) {
2385 STp->compression_changed = 0;
2386 st_compression(STp, (STm->default_compression == ST_YES));
2419 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) in read_mode_page() argument
2431 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE, in read_mode_page()
2432 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2434 return (STp->buffer)->syscall_result; in read_mode_page()
2438 return STp->buffer->syscall_result; in read_mode_page()
2444 static int write_mode_page(struct scsi_tape *STp, int page, int slow) in write_mode_page() argument
2454 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2455 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2458 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2459 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2460 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2461 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2464 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2465 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE, in write_mode_page()
2468 return (STp->buffer)->syscall_result; in write_mode_page()
2472 return STp->buffer->syscall_result; in write_mode_page()
2493 static int st_compression(struct scsi_tape * STp, int state) in st_compression() argument
2497 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2499 if (STp->ready != ST_READY) in st_compression()
2503 retval = read_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2505 DEBC_printk(STp, "Compression mode page not supported.\n"); in st_compression()
2510 DEBC_printk(STp, "Compression state is %d.\n", in st_compression()
2515 DEBC_printk(STp, "Compression not supported.\n"); in st_compression()
2522 if (STp->c_algo != 0) in st_compression()
2523 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2527 if (STp->c_algo != 0) in st_compression()
2531 retval = write_mode_page(STp, COMPRESSION_PAGE, 0); in st_compression()
2533 DEBC_printk(STp, "Compression change failed.\n"); in st_compression()
2536 DEBC_printk(STp, "Compression state changed to %d.\n", state); in st_compression()
2538 STp->compression_changed = 1; in st_compression()
2544 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code) in do_load_unload() argument
2551 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2552 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2567 DEBC_printk(STp, " Enhanced %sload slot %2d.\n", in do_load_unload()
2572 if (STp->immediate) { in do_load_unload()
2574 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2577 timeout = STp->long_timeout; in do_load_unload()
2581 st_printk(ST_DEB_MSG, STp, "Unloading tape.\n"); in do_load_unload()
2583 st_printk(ST_DEB_MSG, STp, "Loading tape.\n"); in do_load_unload()
2586 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE, in do_load_unload()
2589 return (STp->buffer)->syscall_result; in do_load_unload()
2591 retval = (STp->buffer)->syscall_result; in do_load_unload()
2597 STp->rew_at_close = 0; in do_load_unload()
2598 STp->ready = ST_NO_TAPE; in do_load_unload()
2601 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2602 retval = check_tape(STp, filp); in do_load_unload()
2608 STps = &(STp->ps[STp->partition]); in do_load_unload()
2618 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) in deb_space_print() argument
2629 st_printk(ST_DEB_MSG, STp, "Spacing tape %s over %d %s.\n", in deb_space_print()
2635 static void deb_space_print(struct scsi_tape *STp, int direction, char *units, unsigned char *cmd) … in deb_space_print() argument
2640 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg) in st_int_ioctl() argument
2652 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2653 if (STp->ready != ST_READY) { in st_int_ioctl()
2654 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2659 timeout = STp->long_timeout; in st_int_ioctl()
2660 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2675 deb_space_print(STp, ST_DEB_FORWARD, "filemarks", cmd); in st_int_ioctl()
2690 deb_space_print(STp, ST_DEB_BACKWARD, "filemarks", cmd); in st_int_ioctl()
2702 deb_space_print(STp, ST_DEB_FORWARD, "blocks", cmd); in st_int_ioctl()
2714 deb_space_print(STp, ST_DEB_BACKWARD, "blocks", cmd); in st_int_ioctl()
2725 deb_space_print(STp, ST_DEB_FORWARD, "setmarks", cmd); in st_int_ioctl()
2738 deb_space_print(STp, ST_DEB_BACKWARD, "setmarks", cmd); in st_int_ioctl()
2747 if (STp->write_prot) in st_int_ioctl()
2753 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2758 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2761 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2767 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2780 if (STp->immediate) { in st_int_ioctl()
2782 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2784 DEBC_printk(STp, "Rewinding tape.\n"); in st_int_ioctl()
2788 DEBC_printk(STp, "No op on tape.\n"); in st_int_ioctl()
2793 if (STp->immediate) { in st_int_ioctl()
2795 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2798 DEBC_printk(STp, "Retensioning tape.\n"); in st_int_ioctl()
2802 if (!STp->fast_mteom) { in st_int_ioctl()
2804 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff); in st_int_ioctl()
2816 DEBC_printk(STp, "Spacing to end of recorded medium.\n"); in st_int_ioctl()
2821 if (STp->write_prot) in st_int_ioctl()
2825 if (STp->immediate) { in st_int_ioctl()
2827 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2830 timeout = STp->long_timeout * 8; in st_int_ioctl()
2832 DEBC_printk(STp, "Erasing tape.\n"); in st_int_ioctl()
2840 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in st_int_ioctl()
2844 STp->max_block > 0 && in st_int_ioctl()
2845 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || in st_int_ioctl()
2846 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { in st_int_ioctl()
2847 st_printk(KERN_WARNING, STp, "Illegal block size.\n"); in st_int_ioctl()
2851 if ((STp->use_pf & USE_PF)) in st_int_ioctl()
2856 memset((STp->buffer)->b_data, 0, 12); in st_int_ioctl()
2858 (STp->buffer)->b_data[2] = (arg & 7) << 4; in st_int_ioctl()
2860 (STp->buffer)->b_data[2] = in st_int_ioctl()
2861 STp->drv_buffer << 4; in st_int_ioctl()
2862 (STp->buffer)->b_data[3] = 8; /* block descriptor length */ in st_int_ioctl()
2864 (STp->buffer)->b_data[4] = arg; in st_int_ioctl()
2865 STp->density_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2867 (STp->buffer)->b_data[4] = arg >> 24; in st_int_ioctl()
2869 (STp->buffer)->b_data[4] = STp->density; in st_int_ioctl()
2873 STp->blksize_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2875 ltmp = STp->block_size; in st_int_ioctl()
2876 (STp->buffer)->b_data[9] = (ltmp >> 16); in st_int_ioctl()
2877 (STp->buffer)->b_data[10] = (ltmp >> 8); in st_int_ioctl()
2878 (STp->buffer)->b_data[11] = ltmp; in st_int_ioctl()
2879 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2882 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2884 (STp->buffer)->b_data[9] * 65536 + in st_int_ioctl()
2885 (STp->buffer)->b_data[10] * 256 + in st_int_ioctl()
2886 (STp->buffer)->b_data[11]); in st_int_ioctl()
2888 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2890 (STp->buffer)->b_data[4]); in st_int_ioctl()
2892 st_printk(ST_DEB_MSG, STp, in st_int_ioctl()
2894 ((STp->buffer)->b_data[2] >> 4) & 7); in st_int_ioctl()
2901 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction, in st_int_ioctl()
2904 return (STp->buffer)->syscall_result; in st_int_ioctl()
2906 ioctl_result = (STp->buffer)->syscall_result; in st_int_ioctl()
2916 ioctl_result = st_int_ioctl(STp, MTFSF, 1); in st_int_ioctl()
2918 ioctl_result = st_int_ioctl(STp, MTBSF, 1); in st_int_ioctl()
2921 STp->block_size = arg & MT_ST_BLKSIZE_MASK; in st_int_ioctl()
2922 if (STp->block_size != 0) { in st_int_ioctl()
2923 (STp->buffer)->buffer_blocks = in st_int_ioctl()
2924 (STp->buffer)->buffer_size / STp->block_size; in st_int_ioctl()
2926 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in st_int_ioctl()
2928 STp->density = arg >> MT_ST_DENSITY_SHIFT; in st_int_ioctl()
2930 STp->drv_buffer = (arg & 7); in st_int_ioctl()
2932 STp->density = arg; in st_int_ioctl()
2945 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_int_ioctl()
3020 !(STp->use_pf & PF_TESTED)) { in st_int_ioctl()
3023 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED; in st_int_ioctl()
3026 return st_int_ioctl(STp, cmd_in, arg); in st_int_ioctl()
3045 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition, in get_location() argument
3052 if (STp->ready != ST_READY) in get_location()
3056 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3061 if (!logical && !STp->scsi2_logical) in get_location()
3064 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE, in get_location()
3065 STp->device->request_queue->rq_timeout, in get_location()
3068 return (STp->buffer)->syscall_result; in get_location()
3070 if ((STp->buffer)->syscall_result != 0 || in get_location()
3071 (STp->device->scsi_level >= SCSI_2 && in get_location()
3072 ((STp->buffer)->b_data[0] & 4) != 0)) { in get_location()
3074 DEBC_printk(STp, " Can't read tape position.\n"); in get_location()
3078 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3079 *block = ((STp->buffer)->b_data[0] << 16) in get_location()
3080 + ((STp->buffer)->b_data[1] << 8) in get_location()
3081 + (STp->buffer)->b_data[2]; in get_location()
3084 *block = ((STp->buffer)->b_data[4] << 24) in get_location()
3085 + ((STp->buffer)->b_data[5] << 16) in get_location()
3086 + ((STp->buffer)->b_data[6] << 8) in get_location()
3087 + (STp->buffer)->b_data[7]; in get_location()
3088 *partition = (STp->buffer)->b_data[1]; in get_location()
3089 if (((STp->buffer)->b_data[0] & 0x80) && in get_location()
3090 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ in get_location()
3091 STp->ps[0].drv_block = STp->ps[0].drv_file = 0; in get_location()
3093 DEBC_printk(STp, "Got tape pos. blk %d part %d.\n", in get_location()
3105 static int set_location(struct scsi_tape *STp, unsigned int block, int partition, in set_location() argument
3115 if (STp->ready != ST_READY) in set_location()
3117 timeout = STp->long_timeout; in set_location()
3118 STps = &(STp->ps[STp->partition]); in set_location()
3120 DEBC_printk(STp, "Setting block to %d and partition to %d.\n", in set_location()
3126 if ((!STp->can_partitions && partition != 0) || in set_location()
3129 if (partition != STp->partition) { in set_location()
3130 if (get_location(STp, &blk, &p, 1)) in set_location()
3135 DEBC_printk(STp, "Visited block %d for " in set_location()
3137 blk, STp->partition); in set_location()
3142 if ((STp->device)->scsi_level < SCSI_2) { in set_location()
3154 if (!logical && !STp->scsi2_logical) in set_location()
3156 if (STp->partition != partition) { in set_location()
3159 DEBC_printk(STp, "Trying to change partition " in set_location()
3160 "from %d to %d\n", STp->partition, in set_location()
3164 if (STp->immediate) { in set_location()
3166 timeout = STp->device->request_queue->rq_timeout; in set_location()
3169 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE, in set_location()
3172 return (STp->buffer)->syscall_result; in set_location()
3176 if ((STp->buffer)->syscall_result != 0) { in set_location()
3178 if (STp->can_partitions && in set_location()
3179 (STp->device)->scsi_level >= SCSI_2 && in set_location()
3180 (p = find_partition(STp)) >= 0) in set_location()
3181 STp->partition = p; in set_location()
3183 if (STp->can_partitions) { in set_location()
3184 STp->partition = partition; in set_location()
3185 STps = &(STp->ps[partition]); in set_location()
3207 static int find_partition(struct scsi_tape *STp) in find_partition() argument
3212 if ((i = get_location(STp, &block, &partition, 1)) < 0) in find_partition()
3221 static int switch_partition(struct scsi_tape *STp) in switch_partition() argument
3225 if (STp->partition == STp->new_partition) in switch_partition()
3227 STps = &(STp->ps[STp->new_partition]); in switch_partition()
3230 return set_location(STp, STps->last_block_visited, STp->new_partition, 1); in switch_partition()
3249 static int nbr_partitions(struct scsi_tape *STp) in nbr_partitions() argument
3253 if (STp->ready != ST_READY) in nbr_partitions()
3256 result = read_mode_page(STp, PART_PAGE, 1); in nbr_partitions()
3259 DEBC_printk(STp, "Can't read medium partition page.\n"); in nbr_partitions()
3262 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + in nbr_partitions()
3264 DEBC_printk(STp, "Number of partitions %d.\n", result); in nbr_partitions()
3290 static int partition_tape(struct scsi_tape *STp, int size) in partition_tape() argument
3296 result = read_mode_page(STp, PART_PAGE, 0); in partition_tape()
3298 DEBC_printk(STp, "Can't read partition mode page.\n"); in partition_tape()
3302 bp = (STp->buffer)->b_data; in partition_tape()
3304 DEBC_printk(STp, "Partition page length is %d bytes.\n", in partition_tape()
3315 DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n", in partition_tape()
3323 DEBC_printk(STp, "Formatting tape with one partition.\n"); in partition_tape()
3330 DEBC_printk(STp, "Formatting tape with two partitions " in partition_tape()
3337 result = write_mode_page(STp, PART_PAGE, 1); in partition_tape()
3339 st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n"); in partition_tape()
3354 struct scsi_tape *STp = file->private_data; in st_ioctl() local
3359 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl()
3363 if (debugging && !STp->in_use) { in st_ioctl()
3364 st_printk(ST_DEB_MSG, STp, "Incorrect device.\n"); in st_ioctl()
3369 STm = &(STp->modes[STp->current_mode]); in st_ioctl()
3370 STps = &(STp->ps[STp->partition]); in st_ioctl()
3378 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl()
3401 st_printk(KERN_WARNING, STp, in st_ioctl()
3413 if (!STp->pos_unknown) { in st_ioctl()
3431 i = !STp->can_partitions || in st_ioctl()
3432 (STp->new_partition != STp->partition); in st_ioctl()
3441 i = flush_buffer(STp, i); in st_ioctl()
3450 i = st_int_ioctl(STp, MTWEOF, 1); in st_ioctl()
3475 reset_state(STp); in st_ioctl()
3477 STp->device->was_reset = 0; in st_ioctl()
3485 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl()
3486 do_door_lock(STp, 0); /* Ignore result! */ in st_ioctl()
3490 retval = st_set_options(STp, mtc.mt_count); in st_ioctl()
3495 if (!STp->can_partitions || in st_ioctl()
3500 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl()
3501 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl()
3505 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl()
3509 STp->new_partition = mtc.mt_count; in st_ioctl()
3515 if (!STp->can_partitions) { in st_ioctl()
3519 if ((i = st_int_ioctl(STp, MTREW, 0)) < 0 || in st_ioctl()
3520 (i = partition_tape(STp, mtc.mt_count)) < 0) { in st_ioctl()
3525 STp->ps[i].rw = ST_IDLE; in st_ioctl()
3526 STp->ps[i].at_sm = 0; in st_ioctl()
3527 STp->ps[i].last_block_valid = 0; in st_ioctl()
3529 STp->partition = STp->new_partition = 0; in st_ioctl()
3530 STp->nbr_partitions = 1; /* Bad guess ?-) */ in st_ioctl()
3537 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl()
3538 if (!STp->can_partitions) in st_ioctl()
3539 STp->ps[0].rw = ST_IDLE; in st_ioctl()
3545 retval = do_load_unload(STp, file, 0); in st_ioctl()
3550 retval = do_load_unload(STp, file, max(1, mtc.mt_count)); in st_ioctl()
3555 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK)); in st_ioctl()
3559 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl()
3560 (i = switch_partition(STp)) < 0) { in st_ioctl()
3566 retval = st_compression(STp, (mtc.mt_count & 1)); in st_ioctl()
3568 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count); in st_ioctl()
3576 if ((i = flush_buffer(STp, 0)) < 0) { in st_ioctl()
3580 if (STp->can_partitions && in st_ioctl()
3581 (i = switch_partition(STp)) < 0) { in st_ioctl()
3594 mt_status.mt_type = STp->tape_type; in st_ioctl()
3596 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl()
3597 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl()
3600 if (STp->block_size != 0) { in st_ioctl()
3603 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl()
3606 ((STp->buffer)->buffer_bytes + in st_ioctl()
3607 STp->block_size - 1) / STp->block_size; in st_ioctl()
3611 if (STp->drv_write_prot) in st_ioctl()
3619 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl()
3620 mt_status.mt_resid = STp->partition; in st_ioctl()
3625 if (STp->density == 1) in st_ioctl()
3627 else if (STp->density == 2) in st_ioctl()
3629 else if (STp->density == 3) in st_ioctl()
3631 if (STp->ready == ST_READY) in st_ioctl()
3633 if (STp->ready == ST_NO_TAPE) in st_ioctl()
3638 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl()
3639 STp->drv_buffer != 0) in st_ioctl()
3641 if (STp->cleaning_req) in st_ioctl()
3650 STp->recover_reg = 0; /* Clear after read */ in st_ioctl()
3660 if ((i = get_location(STp, &blk, &bt, 0)) < 0) { in st_ioctl()
3670 mutex_unlock(&STp->lock); in st_ioctl()
3682 i = scsi_cmd_ioctl(STp->disk->queue, STp->disk, in st_ioctl()
3688 retval = scsi_ioctl(STp->device, cmd_in, p); in st_ioctl()
3690 STp->rew_at_close = 0; in st_ioctl()
3691 STp->ready = ST_NO_TAPE; in st_ioctl()
3696 mutex_unlock(&STp->lock); in st_ioctl()
3703 struct scsi_tape *STp = file->private_data; in st_compat_ioctl() local
3704 struct scsi_device *sdev = STp->device; in st_compat_ioctl()
4491 struct scsi_tape *STp = STm->tape; in options_show() local
4499 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4500 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4502 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4503 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4504 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4505 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4507 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4508 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4509 options |= STp->sili ? MT_ST_SILI : 0; in options_show()