Lines Matching +full:sc +full:- +full:partitions
1 // SPDX-License-Identifier: GPL-2.0-only
13 Copyright 1992 - 2016 Kai Makisara
16 Some small formal changes - aeb, 950809
18 Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
62 is defined and non-zero. */
159 6-byte SCSI read and write commands. */
160 #if ST_FIXED_BUFFER_SIZE >= (2 << 24 - 1)
161 #error "Buffer size should not exceed (2 << 24 - 1) bytes!"
174 /* Remove mode bits and auto-rewind bit (7) */
176 (iminor(x) & ((1 << ST_MODE_SHIFT)-1)))
179 /* Construct the minor number from the device (d), mode (m), and non-rewind (n) data */
235 {"OnStream", "SC-", "", "osst"}, \
236 {"OnStream", "DI-", "", "osst"}, \
237 {"OnStream", "DP-", "", "osst"}, \
239 {"OnStream", "FW-", "", "osst"}
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()
273 struct scsi_device *sdev = STp->device; in scsi_tape_put()
276 kref_put(&STp->kref, scsi_tape_release); in scsi_tape_put()
289 /* {"XXX", "Yy-", "", NULL}, example */
299 for (rp=&(reject_list[0]); rp->vendor != NULL; rp++) in st_incompatible()
300 if (!strncmp(rp->vendor, SDp->vendor, strlen(rp->vendor)) && in st_incompatible()
301 !strncmp(rp->model, SDp->model, strlen(rp->model)) && in st_incompatible()
302 !strncmp(rp->rev, SDp->rev, strlen(rp->rev))) { in st_incompatible()
303 if (rp->driver_hint) in st_incompatible()
304 return rp->driver_hint; in st_incompatible()
313 sdev_prefix_printk(prefix, (t)->device, (t)->name, fmt, ##a)
324 const u8 *sense = SRpnt->sense; in st_analyze_sense()
326 s->have_sense = scsi_normalize_sense(SRpnt->sense, in st_analyze_sense()
327 SCSI_SENSE_BUFFERSIZE, &s->sense_hdr); in st_analyze_sense()
328 s->flags = 0; in st_analyze_sense()
330 if (s->have_sense) { in st_analyze_sense()
331 s->deferred = 0; in st_analyze_sense()
332 s->remainder_valid = in st_analyze_sense()
333 scsi_get_sense_info_fld(sense, SCSI_SENSE_BUFFERSIZE, &s->uremainder64); in st_analyze_sense()
336 s->deferred = 1; in st_analyze_sense()
339 s->fixed_format = 1; in st_analyze_sense()
340 s->flags = sense[2] & 0xe0; in st_analyze_sense()
343 s->deferred = 1; in st_analyze_sense()
346 s->fixed_format = 0; in st_analyze_sense()
348 s->flags = ucp ? (ucp[3] & 0xe0) : 0; in st_analyze_sense()
358 int result = SRpnt->result; in st_chk_result()
361 char *name = STp->name; in st_chk_result()
367 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
370 if (cmdstatp->have_sense) in st_chk_result()
371 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
379 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], in st_chk_result()
380 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); in st_chk_result()
381 if (cmdstatp->have_sense) in st_chk_result()
382 __scsi_print_sense(STp->device, name, in st_chk_result()
383 SRpnt->sense, SCSI_SENSE_BUFFERSIZE); in st_chk_result()
386 if (!cmdstatp->have_sense) in st_chk_result()
390 else if (cmdstatp->have_sense && in st_chk_result()
396 SRpnt->cmd[0] != MODE_SENSE && in st_chk_result()
397 SRpnt->cmd[0] != TEST_UNIT_READY) { in st_chk_result()
399 __scsi_print_sense(STp->device, name, in st_chk_result()
400 SRpnt->sense, SCSI_SENSE_BUFFERSIZE); in st_chk_result()
404 if (cmdstatp->fixed_format && 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()
413 if (cmdstatp->have_sense && in st_chk_result()
414 cmdstatp->sense_hdr.asc == 0 && cmdstatp->sense_hdr.ascq == 0x17) in st_chk_result()
415 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
416 if (cmdstatp->have_sense && scode == UNIT_ATTENTION && cmdstatp->sense_hdr.asc == 0x29) in st_chk_result()
417 STp->pos_unknown = 1; /* ASC => power on / reset */ in st_chk_result()
419 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
421 if (cmdstatp->have_sense && in st_chk_result()
424 && SRpnt->cmd[0] != WRITE_6 in st_chk_result()
425 && SRpnt->cmd[0] != WRITE_FILEMARKS in st_chk_result()
428 STp->recover_count++; in st_chk_result()
429 STp->recover_reg++; in st_chk_result()
433 if (SRpnt->cmd[0] == READ_6) in st_chk_result()
435 else if (SRpnt->cmd[0] == WRITE_6) in st_chk_result()
441 stp, STp->recover_count); in st_chk_result()
444 if (cmdstatp->flags == 0) in st_chk_result()
447 return (-EIO); in st_chk_result()
456 streq->stp = stp; in st_allocate_request()
461 stp->buffer->syscall_result = -EINTR; in st_allocate_request()
463 stp->buffer->syscall_result = -EBUSY; in st_allocate_request()
480 if (scmd->cmnd[0] == WRITE_6) { in st_do_stats()
481 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
482 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
483 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
484 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
485 if (scmd->result) { in st_do_stats()
486 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
487 - STp->buffer->cmdstat.residual, in st_do_stats()
488 &STp->stats->write_byte_cnt); in st_do_stats()
489 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
490 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
492 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
493 &STp->stats->write_byte_cnt); in st_do_stats()
494 } else if (scmd->cmnd[0] == READ_6) { in st_do_stats()
495 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
496 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time); in st_do_stats()
497 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
498 atomic64_inc(&STp->stats->read_cnt); in st_do_stats()
499 if (scmd->result) { in st_do_stats()
500 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
501 - STp->buffer->cmdstat.residual, in st_do_stats()
502 &STp->stats->read_byte_cnt); in st_do_stats()
503 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
504 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
506 atomic64_add(atomic_read(&STp->stats->last_read_size), in st_do_stats()
507 &STp->stats->read_byte_cnt); in st_do_stats()
509 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
510 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
511 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
513 atomic64_dec(&STp->stats->in_flight); in st_do_stats()
520 struct st_request *SRpnt = req->end_io_data; in st_scsi_execute_end()
521 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end()
524 STp->buffer->cmdstat.midlevel_result = SRpnt->result = scmd->result; in st_scsi_execute_end()
525 STp->buffer->cmdstat.residual = scmd->resid_len; in st_scsi_execute_end()
529 tmp = SRpnt->bio; in st_scsi_execute_end()
530 if (scmd->sense_len) in st_scsi_execute_end()
531 memcpy(SRpnt->sense, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE); in st_scsi_execute_end()
532 if (SRpnt->waiting) in st_scsi_execute_end()
533 complete(SRpnt->waiting); in st_scsi_execute_end()
545 struct rq_map_data *mdata = &SRpnt->stp->buffer->map_data; in st_scsi_execute()
547 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute()
550 req = scsi_alloc_request(SRpnt->stp->device->request_queue, in st_scsi_execute()
556 req->rq_flags |= RQF_QUIET; in st_scsi_execute()
558 mdata->null_mapped = 1; in st_scsi_execute()
561 err = blk_rq_map_user(req->q, req, mdata, NULL, bufflen, in st_scsi_execute()
569 atomic64_inc(&STp->stats->in_flight); in st_scsi_execute()
571 atomic_set(&STp->stats->last_write_size, bufflen); in st_scsi_execute()
572 STp->stats->write_time = ktime_get(); in st_scsi_execute()
574 atomic_set(&STp->stats->last_read_size, bufflen); in st_scsi_execute()
575 STp->stats->read_time = ktime_get(); in st_scsi_execute()
577 STp->stats->other_time = ktime_get(); in st_scsi_execute()
580 SRpnt->bio = req->bio; in st_scsi_execute()
581 scmd->cmd_len = COMMAND_SIZE(cmd[0]); in st_scsi_execute()
582 memcpy(scmd->cmnd, cmd, scmd->cmd_len); in st_scsi_execute()
583 req->timeout = timeout; in st_scsi_execute()
584 scmd->allowed = retries; in st_scsi_execute()
585 req->end_io = st_scsi_execute_end; in st_scsi_execute()
586 req->end_io_data = SRpnt; in st_scsi_execute()
600 struct rq_map_data *mdata = &STp->buffer->map_data; in st_do_scsi()
604 if (!do_wait && ((STp->buffer)->last_SRpnt)) { in st_do_scsi()
608 (STp->buffer)->syscall_result = (-EINTR); in st_do_scsi()
610 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
623 (STp->buffer)->last_SRpnt = SRpnt; in st_do_scsi()
625 waiting = &STp->wait; in st_do_scsi()
627 SRpnt->waiting = waiting; in st_do_scsi()
629 if (STp->buffer->do_dio) { in st_do_scsi()
630 mdata->page_order = 0; in st_do_scsi()
631 mdata->nr_entries = STp->buffer->sg_segs; in st_do_scsi()
632 mdata->pages = STp->buffer->mapped_pages; in st_do_scsi()
634 mdata->page_order = STp->buffer->reserved_page_order; in st_do_scsi()
635 mdata->nr_entries = in st_do_scsi()
636 DIV_ROUND_UP(bytes, PAGE_SIZE << mdata->page_order); in st_do_scsi()
637 mdata->pages = STp->buffer->reserved_pages; in st_do_scsi()
638 mdata->offset = 0; in st_do_scsi()
641 memcpy(SRpnt->cmd, cmd, sizeof(SRpnt->cmd)); in st_do_scsi()
642 STp->buffer->cmdstat.have_sense = 0; in st_do_scsi()
643 STp->buffer->syscall_result = 0; in st_do_scsi()
649 (STp->buffer)->syscall_result = (-EBUSY); in st_do_scsi()
650 (STp->buffer)->last_SRpnt = NULL; in st_do_scsi()
653 SRpnt->waiting = NULL; in st_do_scsi()
654 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in st_do_scsi()
661 /* Handle the write-behind checking (waits for completion). Returns -ENOSPC if
662 write has been correct but EOM early warning reached, -EIO if write ended in
673 STbuffer = STp->buffer; in write_behind_check()
674 if (!STbuffer->writing) in write_behind_check()
678 if (STp->write_pending) in write_behind_check()
679 STp->nbr_waits++; in write_behind_check()
681 STp->nbr_finished++; in write_behind_check()
684 wait_for_completion(&(STp->wait)); in write_behind_check()
685 SRpnt = STbuffer->last_SRpnt; in write_behind_check()
686 STbuffer->last_SRpnt = NULL; in write_behind_check()
687 SRpnt->waiting = NULL; in write_behind_check()
689 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); in write_behind_check()
692 STbuffer->buffer_bytes -= STbuffer->writing; in write_behind_check()
693 STps = &(STp->ps[STp->partition]); in write_behind_check()
694 if (STps->drv_block >= 0) { in write_behind_check()
695 if (STp->block_size == 0) in write_behind_check()
696 STps->drv_block++; in write_behind_check()
698 STps->drv_block += STbuffer->writing / STp->block_size; in write_behind_check()
701 cmdstatp = &STbuffer->cmdstat; in write_behind_check()
702 if (STbuffer->syscall_result) { in write_behind_check()
703 retval = -EIO; in write_behind_check()
704 if (cmdstatp->have_sense && !cmdstatp->deferred && in write_behind_check()
705 (cmdstatp->flags & SENSE_EOM) && in write_behind_check()
706 (cmdstatp->sense_hdr.sense_key == NO_SENSE || in write_behind_check()
707 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR)) { in write_behind_check()
708 /* EOM at write-behind, has all data been written? */ in write_behind_check()
709 if (!cmdstatp->remainder_valid || in write_behind_check()
710 cmdstatp->uremainder64 == 0) in write_behind_check()
711 retval = -ENOSPC; in write_behind_check()
713 if (retval == -EIO) in write_behind_check()
714 STps->drv_block = -1; in write_behind_check()
716 STbuffer->writing = 0; in write_behind_check()
721 STbuffer->cmdstat.midlevel_result, retval);) /* end DEB */ in write_behind_check()
740 cmd[2] = cmd[3] = cmd[4] = 0xff; /* -1 filemarks */ in cross_eof()
747 STp->device->request_queue->rq_timeout, in cross_eof()
750 return (STp->buffer)->syscall_result; in cross_eof()
755 if ((STp->buffer)->cmdstat.midlevel_result != 0) in cross_eof()
760 return (STp->buffer)->syscall_result; in cross_eof()
778 if (STp->dirty == 1) { in st_flush_write_buffer()
780 transfer = STp->buffer->buffer_bytes; in st_flush_write_buffer()
786 blks = transfer / STp->block_size; in st_flush_write_buffer()
792 STp->device->request_queue->rq_timeout, in st_flush_write_buffer()
795 return (STp->buffer)->syscall_result; in st_flush_write_buffer()
797 STps = &(STp->ps[STp->partition]); in st_flush_write_buffer()
798 if ((STp->buffer)->syscall_result != 0) { in st_flush_write_buffer()
799 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush_write_buffer()
801 if (cmdstatp->have_sense && !cmdstatp->deferred && in st_flush_write_buffer()
802 (cmdstatp->flags & SENSE_EOM) && in st_flush_write_buffer()
803 (cmdstatp->sense_hdr.sense_key == NO_SENSE || in st_flush_write_buffer()
804 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) && in st_flush_write_buffer()
805 (!cmdstatp->remainder_valid || in st_flush_write_buffer()
806 cmdstatp->uremainder64 == 0)) { /* All written at EOM early warning */ in st_flush_write_buffer()
807 STp->dirty = 0; in st_flush_write_buffer()
808 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
809 if (STps->drv_block >= 0) in st_flush_write_buffer()
810 STps->drv_block += blks; in st_flush_write_buffer()
811 result = (-ENOSPC); in st_flush_write_buffer()
814 STps->drv_block = (-1); in st_flush_write_buffer()
815 result = (-EIO); in st_flush_write_buffer()
818 if (STps->drv_block >= 0) in st_flush_write_buffer()
819 STps->drv_block += blks; in st_flush_write_buffer()
820 STp->dirty = 0; in st_flush_write_buffer()
821 (STp->buffer)->buffer_bytes = 0; in st_flush_write_buffer()
837 if (STp->ready != ST_READY) in flush_buffer()
844 if (STp->pos_unknown) in flush_buffer()
845 return (-EIO); in flush_buffer()
847 STps = &(STp->ps[STp->partition]); in flush_buffer()
848 if (STps->rw == ST_WRITING) /* Writing */ in flush_buffer()
851 if (STp->block_size == 0) in flush_buffer()
854 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
855 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
856 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
857 STp->block_size; in flush_buffer()
858 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
859 (STp->buffer)->read_pointer = 0; in flush_buffer()
862 if (STps->eof == ST_FM_HIT) { in flush_buffer()
865 STps->eof = ST_NOEOF; in flush_buffer()
867 if (STps->drv_file >= 0) in flush_buffer()
868 STps->drv_file++; in flush_buffer()
869 STps->drv_block = 0; in flush_buffer()
874 } else if (STps->eof == ST_FM_HIT) { in flush_buffer()
875 if (STps->drv_file >= 0) in flush_buffer()
876 STps->drv_file++; in flush_buffer()
877 STps->drv_block = 0; in flush_buffer()
878 STps->eof = ST_NOEOF; in flush_buffer()
890 if (!STp->density_changed && in set_mode_densblk()
891 STm->default_density >= 0 && in set_mode_densblk()
892 STm->default_density != STp->density) { in set_mode_densblk()
893 arg = STm->default_density; in set_mode_densblk()
896 arg = STp->density; in set_mode_densblk()
898 if (!STp->blksize_changed && in set_mode_densblk()
899 STm->default_blksize >= 0 && in set_mode_densblk()
900 STm->default_blksize != STp->block_size) { in set_mode_densblk()
901 arg |= STm->default_blksize; in set_mode_densblk()
904 arg |= STp->block_size; in set_mode_densblk()
910 STm->default_blksize, STm->default_density); in set_mode_densblk()
912 return (-EINVAL); in set_mode_densblk()
925 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
928 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
930 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
941 STp->pos_unknown = 0; in reset_state()
943 STps = &(STp->ps[i]); in reset_state()
944 STps->rw = ST_IDLE; in reset_state()
945 STps->eof = ST_NOEOF; in reset_state()
946 STps->at_sm = 0; in reset_state()
947 STps->last_block_valid = 0; in reset_state()
948 STps->drv_block = -1; in reset_state()
949 STps->drv_file = -1; in reset_state()
951 if (STp->can_partitions) { in reset_state()
952 STp->partition = find_partition(STp); in reset_state()
953 if (STp->partition < 0) in reset_state()
954 STp->partition = 0; in reset_state()
955 STp->new_partition = STp->partition; in reset_state()
974 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
982 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
985 retval = (STp->buffer)->syscall_result; in test_ready()
989 if (cmdstatp->have_sense) { in test_ready()
991 scode = cmdstatp->sense_hdr.sense_key; in test_ready()
1000 retval = (-EIO); in test_ready()
1008 retval = (-EINTR); in test_ready()
1015 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
1016 cmdstatp->sense_hdr.asc == 0x3a) /* Check ASC */ in test_ready()
1025 retval = (STp->buffer)->syscall_result; in test_ready()
1046 unsigned short st_flags = filp->f_flags; in check_tape()
1053 STp->ready = ST_READY; in check_tape()
1055 if (mode != STp->current_mode) { in check_tape()
1057 STp->current_mode, mode); in check_tape()
1059 STp->current_mode = mode; in check_tape()
1061 STm = &(STp->modes[STp->current_mode]); in check_tape()
1063 saved_cleaning = STp->cleaning_req; in check_tape()
1064 STp->cleaning_req = 0; in check_tape()
1066 do_wait = ((filp->f_flags & O_NONBLOCK) == 0); in check_tape()
1073 STp->pos_unknown = 0; in check_tape()
1074 STp->partition = STp->new_partition = 0; in check_tape()
1075 if (STp->can_partitions) in check_tape()
1076 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1079 STps = &(STp->ps[i]); in check_tape()
1080 STps->rw = ST_IDLE; in check_tape()
1081 STps->eof = ST_NOEOF; in check_tape()
1082 STps->at_sm = 0; in check_tape()
1083 STps->last_block_valid = 0; in check_tape()
1084 STps->drv_block = 0; in check_tape()
1085 STps->drv_file = 0; in check_tape()
1090 STp->cleaning_req |= saved_cleaning; in check_tape()
1094 STp->ready = ST_NO_TAPE; in check_tape()
1096 STp->ready = ST_NOT_READY; in check_tape()
1098 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1099 STp->write_prot = 0; in check_tape()
1100 STp->block_size = 0; in check_tape()
1101 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1102 STp->partition = STp->new_partition = 0; in check_tape()
1103 STp->door_locked = ST_UNLOCKED; in check_tape()
1108 if (STp->omit_blklims) in check_tape()
1109 STp->min_block = STp->max_block = (-1); in check_tape()
1115 STp->device->request_queue->rq_timeout, in check_tape()
1118 retval = (STp->buffer)->syscall_result; in check_tape()
1122 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1123 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1124 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1125 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1126 (STp->buffer)->b_data[5]; in check_tape()
1127 if ( DEB( debugging || ) !STp->inited) in check_tape()
1129 "Block limits %d - %d bytes.\n", in check_tape()
1130 STp->min_block, STp->max_block); in check_tape()
1132 STp->min_block = STp->max_block = (-1); in check_tape()
1142 STp->device->request_queue->rq_timeout, in check_tape()
1145 retval = (STp->buffer)->syscall_result; in check_tape()
1149 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1151 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1152 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1153 STp->drv_write_prot = 0; in check_tape()
1157 (STp->buffer)->b_data[0], in check_tape()
1158 (STp->buffer)->b_data[1], in check_tape()
1159 (STp->buffer)->b_data[2], in check_tape()
1160 (STp->buffer)->b_data[3]); in check_tape()
1162 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1163 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1164 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1165 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1166 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1169 STp->density, in check_tape()
1170 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1171 (STp->buffer)->b_data[6] * 256 + in check_tape()
1172 (STp->buffer)->b_data[7], in check_tape()
1173 STp->drv_buffer); in check_tape()
1175 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1176 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1178 "non-buffered tape: disabling " in check_tape()
1180 STp->immediate_filemark = 0; in check_tape()
1185 STp->inited = 1; in check_tape()
1187 if (STp->block_size > 0) in check_tape()
1188 (STp->buffer)->buffer_blocks = in check_tape()
1189 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1191 (STp->buffer)->buffer_blocks = 1; in check_tape()
1192 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1195 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1196 (STp->buffer)->buffer_blocks); in check_tape()
1198 if (STp->drv_write_prot) { in check_tape()
1199 STp->write_prot = 1; in check_tape()
1206 retval = (-EROFS); in check_tape()
1211 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1216 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1217 retval = STp->partition; in check_tape()
1220 STp->new_partition = STp->partition; in check_tape()
1221 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1225 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1226 STp->compression_changed = 0; in check_tape()
1227 if (!(STm->defaults_for_writes) && in check_tape()
1231 if (STp->default_drvbuffer != 0xff) { in check_tape()
1232 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1236 STp->default_drvbuffer); in check_tape()
1251 int i, retval = (-EIO); in st_open()
1262 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); in st_open()
1265 return -ENXIO; in st_open()
1268 filp->private_data = STp; in st_open()
1271 if (STp->in_use) { in st_open()
1275 return (-EBUSY); in st_open()
1278 STp->in_use = 1; in st_open()
1280 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1282 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1283 retval = -EIO; in st_open()
1287 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1288 retval = (-ENXIO); in st_open()
1293 if (!enlarge_buffer(STp->buffer, PAGE_SIZE)) { in st_open()
1296 retval = (-EOVERFLOW); in st_open()
1300 (STp->buffer)->cleared = 0; in st_open()
1301 (STp->buffer)->writing = 0; in st_open()
1302 (STp->buffer)->syscall_result = 0; in st_open()
1304 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1306 STp->dirty = 0; in st_open()
1308 STps = &(STp->ps[i]); in st_open()
1309 STps->rw = ST_IDLE; in st_open()
1311 STp->try_dio_now = STp->try_dio; in st_open()
1312 STp->recover_count = 0; in st_open()
1313 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1314 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1319 if ((filp->f_flags & O_NONBLOCK) == 0 && in st_open()
1321 if (STp->ready == NO_TAPE) in st_open()
1322 retval = (-ENOMEDIUM); in st_open()
1324 retval = (-EIO); in st_open()
1330 normalize_buffer(STp->buffer); in st_open()
1332 STp->in_use = 0; in st_open()
1335 scsi_autopm_put_device(STp->device); in st_open()
1348 struct scsi_tape *STp = filp->private_data; in st_flush()
1349 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1350 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1355 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1357 if (result != 0 && result != (-ENOSPC)) in st_flush()
1361 if (STp->can_partitions && in st_flush()
1369 DEBC( if (STp->nbr_requests) in st_flush()
1372 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1373 STp->nbr_pages)); in st_flush()
1375 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1376 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1380 STp->nbr_waits, STp->nbr_finished); in st_flush()
1384 if (STp->immediate_filemark) in st_flush()
1386 cmd[4] = 1 + STp->two_fm; in st_flush()
1389 STp->device->request_queue->rq_timeout, in st_flush()
1392 result = (STp->buffer)->syscall_result; in st_flush()
1396 if (STp->buffer->syscall_result == 0 || in st_flush()
1397 (cmdstatp->have_sense && !cmdstatp->deferred && in st_flush()
1398 (cmdstatp->flags & SENSE_EOM) && in st_flush()
1399 (cmdstatp->sense_hdr.sense_key == NO_SENSE || in st_flush()
1400 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) && in st_flush()
1401 (!cmdstatp->remainder_valid || cmdstatp->uremainder64 == 0))) { in st_flush()
1405 if (STps->drv_file >= 0) in st_flush()
1406 STps->drv_file++; in st_flush()
1407 STps->drv_block = 0; in st_flush()
1408 if (STp->two_fm) in st_flush()
1410 STps->eof = ST_FM; in st_flush()
1418 result = (-EIO); in st_flush()
1422 } else if (!STp->rew_at_close) { in st_flush()
1423 STps = &(STp->ps[STp->partition]); in st_flush()
1424 if (!STm->sysv || STps->rw != ST_READING) { in st_flush()
1425 if (STp->can_bsr) in st_flush()
1427 else if (STps->eof == ST_FM_HIT) { in st_flush()
1430 if (STps->drv_file >= 0) in st_flush()
1431 STps->drv_file++; in st_flush()
1432 STps->drv_block = 0; in st_flush()
1433 STps->eof = ST_FM; in st_flush()
1435 STps->eof = ST_NOEOF; in st_flush()
1437 } else if ((STps->eof == ST_NOEOF && in st_flush()
1439 STps->eof == ST_FM_HIT) { in st_flush()
1440 if (STps->drv_file >= 0) in st_flush()
1441 STps->drv_file++; in st_flush()
1442 STps->drv_block = 0; in st_flush()
1443 STps->eof = ST_FM; in st_flush()
1448 if (STp->rew_at_close) { in st_flush()
1461 struct scsi_tape *STp = filp->private_data; in st_release()
1463 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1466 normalize_buffer(STp->buffer); in st_release()
1468 STp->in_use = 0; in st_release()
1470 scsi_autopm_put_device(STp->device); in st_release()
1487 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1488 retval = (-ENXIO); in rw_checks()
1492 if (STp->ready != ST_READY) { in rw_checks()
1493 if (STp->ready == ST_NO_TAPE) in rw_checks()
1494 retval = (-ENOMEDIUM); in rw_checks()
1496 retval = (-EIO); in rw_checks()
1500 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1501 retval = (-ENXIO); in rw_checks()
1510 if (STp->pos_unknown) { in rw_checks()
1511 retval = (-EIO); in rw_checks()
1519 if (!STp->in_use) { in rw_checks()
1522 retval = (-EIO); in rw_checks()
1526 if (STp->can_partitions && in rw_checks()
1530 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1531 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1532 retval = (-EINVAL); in rw_checks()
1536 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1538 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1549 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1552 i = STp->try_dio_now && try_rdio; in setup_buffering()
1554 i = STp->try_dio_now && try_wdio; in setup_buffering()
1557 STp->device->request_queue)) == 0) { in setup_buffering()
1558 i = sgl_map_user_pages(STbp, STbp->use_sg, (unsigned long)buf, in setup_buffering()
1561 STbp->do_dio = i; in setup_buffering()
1562 STbp->buffer_bytes = 0; /* can be used as transfer counter */ in setup_buffering()
1565 STbp->do_dio = 0; /* fall back to buffering with any error */ in setup_buffering()
1566 STbp->sg_segs = STbp->do_dio; in setup_buffering()
1568 if (STbp->do_dio) { in setup_buffering()
1569 STp->nbr_dio++; in setup_buffering()
1570 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1574 STbp->do_dio = 0; in setup_buffering()
1575 DEB( STp->nbr_requests++; ) in setup_buffering()
1577 if (!STbp->do_dio) { in setup_buffering()
1578 if (STp->block_size) in setup_buffering()
1579 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1580 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1585 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1589 if (bufsize > STbp->buffer_size && in setup_buffering()
1594 retval = (-EOVERFLOW); in setup_buffering()
1597 if (STp->block_size) in setup_buffering()
1598 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1611 STbp = STp->buffer; in release_buffering()
1612 if (STbp->do_dio) { in release_buffering()
1613 sgl_unmap_user_pages(STbp, STbp->do_dio, is_read); in release_buffering()
1614 STbp->do_dio = 0; in release_buffering()
1615 STbp->sg_segs = 0; in release_buffering()
1632 struct scsi_tape *STp = filp->private_data; in st_write()
1637 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1638 return -ERESTARTSYS; in st_write()
1645 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1648 retval = (-EINVAL); in st_write()
1652 STm = &(STp->modes[STp->current_mode]); in st_write()
1653 STps = &(STp->ps[STp->partition]); in st_write()
1655 if (STp->write_prot) { in st_write()
1656 retval = (-EACCES); in st_write()
1661 if (STps->rw == ST_READING) { in st_write()
1665 STps->rw = ST_WRITING; in st_write()
1666 } else if (STps->rw != ST_WRITING && in st_write()
1667 STps->drv_file == 0 && STps->drv_block == 0) { in st_write()
1670 if (STm->default_compression != ST_DONT_TOUCH && in st_write()
1671 !(STp->compression_changed)) { in st_write()
1672 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1676 retval = (-EINVAL); in st_write()
1683 STbp = STp->buffer; in st_write()
1686 if (i == -ENOSPC) in st_write()
1687 STps->eof = ST_EOM_OK; in st_write()
1689 STps->eof = ST_EOM_ERROR; in st_write()
1692 if (STps->eof == ST_EOM_OK) { in st_write()
1693 STps->eof = ST_EOD_1; /* allow next write */ in st_write()
1694 retval = (-ENOSPC); in st_write()
1697 else if (STps->eof == ST_EOM_ERROR) { in st_write()
1698 retval = (-EIO); in st_write()
1704 if (STp->block_size != 0 && in st_write()
1705 !STbp->do_dio && in st_write()
1707 copy_from_user(&i, buf + count - 1, 1) != 0)) { in st_write()
1708 retval = (-EFAULT); in st_write()
1720 cmd[1] = (STp->block_size != 0); in st_write()
1722 STps->rw = ST_WRITING; in st_write()
1727 if (STbp->do_dio) { in st_write()
1731 if (STp->block_size == 0) in st_write()
1734 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1735 STbp->buffer_bytes; in st_write()
1746 count -= do_count; in st_write()
1749 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1750 STm->do_async_writes && STps->eof < ST_EOM_OK; in st_write()
1752 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1753 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1754 STbp->buffer_bytes < STbp->buffer_size) { in st_write()
1755 STp->dirty = 1; in st_write()
1762 if (STp->block_size == 0) in st_write()
1765 if (!STbp->do_dio) in st_write()
1766 blks = STbp->buffer_bytes; in st_write()
1769 blks /= STp->block_size; in st_write()
1770 transfer = blks * STp->block_size; in st_write()
1777 STp->device->request_queue->rq_timeout, in st_write()
1780 retval = STbp->syscall_result; in st_write()
1783 if (async_write && !STbp->syscall_result) { in st_write()
1784 STbp->writing = transfer; in st_write()
1785 STp->dirty = !(STbp->writing == in st_write()
1786 STbp->buffer_bytes); in st_write()
1788 DEB( STp->write_pending = 1; ) in st_write()
1792 if (STbp->syscall_result != 0) { in st_write()
1793 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1796 if (cmdstatp->have_sense && (cmdstatp->flags & SENSE_EOM)) { in st_write()
1797 scode = cmdstatp->sense_hdr.sense_key; in st_write()
1798 if (cmdstatp->remainder_valid) in st_write()
1799 undone = (int)cmdstatp->uremainder64; in st_write()
1800 else if (STp->block_size == 0 && in st_write()
1805 if (STp->block_size != 0) in st_write()
1806 undone *= STp->block_size; in st_write()
1810 b_point -= undone; in st_write()
1811 do_count -= undone; in st_write()
1812 if (STp->block_size) in st_write()
1813 blks = (transfer - undone) / STp->block_size; in st_write()
1814 STps->eof = ST_EOM_OK; in st_write()
1819 if (STp->block_size == 0 || in st_write()
1821 retval = (-ENOSPC); /* EOM within current request */ in st_write()
1828 if (!retry_eot && !cmdstatp->deferred && in st_write()
1830 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1832 if (STps->drv_block >= 0) { in st_write()
1833 STps->drv_block += (transfer - undone) / in st_write()
1834 STp->block_size; in st_write()
1836 STps->eof = ST_EOM_OK; in st_write()
1840 STp->buffer->buffer_bytes); in st_write()
1846 count -= do_count; in st_write()
1848 STps->eof = ST_EOM_ERROR; in st_write()
1849 STps->drv_block = (-1); /* Too cautious? */ in st_write()
1850 retval = (-EIO); /* EOM for old data */ in st_write()
1857 STps->drv_block = (-1); /* Too cautious? */ in st_write()
1858 retval = STbp->syscall_result; in st_write()
1863 if (STps->drv_block >= 0) { in st_write()
1864 if (STp->block_size == 0) in st_write()
1865 STps->drv_block += (do_count > 0); in st_write()
1867 STps->drv_block += blks; in st_write()
1870 STbp->buffer_bytes = 0; in st_write()
1871 STp->dirty = 0; in st_write()
1875 retval = total - count; in st_write()
1880 if (STps->eof == ST_EOD_1) in st_write()
1881 STps->eof = ST_EOM_OK; in st_write()
1882 else if (STps->eof != ST_EOM_OK) in st_write()
1883 STps->eof = ST_NOEOF; in st_write()
1884 retval = total - count; in st_write()
1890 mutex_unlock(&STp->lock); in st_write()
1915 STm = &(STp->modes[STp->current_mode]); in read_tape()
1916 STps = &(STp->ps[STp->partition]); in read_tape()
1917 if (STps->eof == ST_FM_HIT) in read_tape()
1919 STbp = STp->buffer; in read_tape()
1921 if (STp->block_size == 0) in read_tape()
1924 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1925 blks = (STp->buffer)->buffer_blocks; in read_tape()
1926 bytes = blks * STp->block_size; in read_tape()
1929 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1930 bytes = (STp->buffer)->buffer_size; in read_tape()
1931 blks = bytes / STp->block_size; in read_tape()
1932 bytes = blks * STp->block_size; in read_tape()
1938 cmd[1] = (STp->block_size != 0); in read_tape()
1939 if (!cmd[1] && STp->sili) in read_tape()
1947 STp->device->request_queue->rq_timeout, in read_tape()
1952 return STbp->syscall_result; in read_tape()
1954 STbp->read_pointer = 0; in read_tape()
1955 STps->at_sm = 0; in read_tape()
1958 if (STbp->syscall_result) { in read_tape()
1959 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1964 SRpnt->sense[0], SRpnt->sense[1], in read_tape()
1965 SRpnt->sense[2], SRpnt->sense[3], in read_tape()
1966 SRpnt->sense[4], SRpnt->sense[5], in read_tape()
1967 SRpnt->sense[6], SRpnt->sense[7]); in read_tape()
1968 if (cmdstatp->have_sense) { in read_tape()
1970 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK) in read_tape()
1971 cmdstatp->flags &= 0xcf; /* No need for EOM in this case */ in read_tape()
1973 if (cmdstatp->flags != 0) { /* EOF, EOM, or ILI */ in read_tape()
1975 if (cmdstatp->remainder_valid) in read_tape()
1976 transfer = (int)cmdstatp->uremainder64; in read_tape()
1979 if (cmdstatp->sense_hdr.sense_key == MEDIUM_ERROR) { in read_tape()
1980 if (STp->block_size == 0) in read_tape()
1983 cmdstatp->flags &= ~SENSE_ILI; in read_tape()
1986 if (cmdstatp->flags & SENSE_ILI) { /* ILI */ in read_tape()
1987 if (STp->block_size == 0 && in read_tape()
1993 bytes - transfer, in read_tape()
1995 if (STps->drv_block >= 0) in read_tape()
1996 STps->drv_block += 1; in read_tape()
1997 STbp->buffer_bytes = 0; in read_tape()
1998 return (-ENOMEM); in read_tape()
1999 } else if (STp->block_size == 0) { in read_tape()
2000 STbp->buffer_bytes = bytes - transfer; in read_tape()
2008 if (STps->drv_block >= 0) in read_tape()
2009 STps->drv_block += blks - transfer + 1; in read_tape()
2011 return (-EIO); in read_tape()
2014 STbp->buffer_bytes = (blks - transfer) * in read_tape()
2015 STp->block_size; in read_tape()
2020 STbp->buffer_bytes); in read_tape()
2021 if (STps->drv_block >= 0) in read_tape()
2022 STps->drv_block += 1; in read_tape()
2024 return (-EIO); in read_tape()
2026 } else if (cmdstatp->flags & SENSE_FMK) { /* FM overrides EOM */ in read_tape()
2027 if (STps->eof != ST_FM_HIT) in read_tape()
2028 STps->eof = ST_FM_HIT; in read_tape()
2030 STps->eof = ST_EOD_2; in read_tape()
2031 if (STp->block_size == 0) in read_tape()
2032 STbp->buffer_bytes = 0; in read_tape()
2034 STbp->buffer_bytes = in read_tape()
2035 bytes - transfer * STp->block_size; in read_tape()
2038 STbp->buffer_bytes); in read_tape()
2039 } else if (cmdstatp->flags & SENSE_EOM) { in read_tape()
2040 if (STps->eof == ST_FM) in read_tape()
2041 STps->eof = ST_EOD_1; in read_tape()
2043 STps->eof = ST_EOM_OK; in read_tape()
2044 if (STp->block_size == 0) in read_tape()
2045 STbp->buffer_bytes = bytes - transfer; in read_tape()
2047 STbp->buffer_bytes = in read_tape()
2048 bytes - transfer * STp->block_size; in read_tape()
2052 STbp->buffer_bytes); in read_tape()
2058 STps->drv_block = (-1); in read_tape()
2059 if (STps->eof == ST_FM && in read_tape()
2060 cmdstatp->sense_hdr.sense_key == BLANK_CHECK) { in read_tape()
2064 STps->eof = ST_EOD_2; /* First BLANK_CHECK after FM */ in read_tape()
2066 retval = (-EIO); in read_tape()
2069 if (STbp->buffer_bytes < 0) /* Caused by bogus sense data */ in read_tape()
2070 STbp->buffer_bytes = 0; in read_tape()
2073 else { /* Non-extended sense */ in read_tape()
2074 retval = STbp->syscall_result; in read_tape()
2080 STbp->buffer_bytes = bytes; in read_tape()
2081 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2082 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2085 if (STps->drv_block >= 0) { in read_tape()
2086 if (STp->block_size == 0) in read_tape()
2087 STps->drv_block++; in read_tape()
2089 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2104 struct scsi_tape *STp = filp->private_data; in st_read()
2107 struct st_buffer *STbp = STp->buffer; in st_read()
2109 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2110 return -ERESTARTSYS; in st_read()
2116 STm = &(STp->modes[STp->current_mode]); in st_read()
2117 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2118 if (!STm->do_read_ahead) { in st_read()
2119 retval = (-EINVAL); /* Read must be integral number of blocks */ in st_read()
2122 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2125 STps = &(STp->ps[STp->partition]); in st_read()
2126 if (STps->rw == ST_WRITING) { in st_read()
2130 STps->rw = ST_READING; in st_read()
2133 if (debugging && STps->eof != ST_NOEOF) in st_read()
2136 STps->eof, STbp->buffer_bytes); in st_read()
2142 do_dio = STbp->do_dio; in st_read()
2144 if (STbp->buffer_bytes == 0 && in st_read()
2145 STps->eof >= ST_EOD_1) { in st_read()
2146 if (STps->eof < ST_EOD) { in st_read()
2147 STps->eof += 1; in st_read()
2151 retval = (-EIO); /* EOM or Blank Check */ in st_read()
2160 copy_from_user(&i, buf + count - 1, 1) != 0 || in st_read()
2161 copy_to_user(buf + count - 1, &i, 1) != 0) { in st_read()
2162 retval = (-EFAULT); in st_read()
2167 STps->rw = ST_READING; in st_read()
2174 if (STbp->buffer_bytes == 0) { in st_read()
2175 special = read_tape(STp, count - total, &SRpnt); in st_read()
2183 if (STbp->buffer_bytes > 0) { in st_read()
2185 if (debugging && STps->eof != ST_NOEOF) in st_read()
2188 STps->eof, STbp->buffer_bytes, in st_read()
2189 (int)(count - total)); in st_read()
2191 transfer = STbp->buffer_bytes < count - total ? in st_read()
2192 STbp->buffer_bytes : count - total; in st_read()
2204 if (STp->block_size == 0) in st_read()
2212 if (STps->eof == ST_FM_HIT) { in st_read()
2213 STps->eof = ST_FM; in st_read()
2214 STps->drv_block = 0; in st_read()
2215 if (STps->drv_file >= 0) in st_read()
2216 STps->drv_file++; in st_read()
2217 } else if (STps->eof == ST_EOD_1) { in st_read()
2218 STps->eof = ST_EOD_2; in st_read()
2219 STps->drv_block = 0; in st_read()
2220 if (STps->drv_file >= 0) in st_read()
2221 STps->drv_file++; in st_read()
2222 } else if (STps->eof == ST_EOD_2) in st_read()
2223 STps->eof = ST_EOD; in st_read()
2224 } else if (STps->eof == ST_FM) in st_read()
2225 STps->eof = ST_NOEOF; in st_read()
2235 STbp->buffer_bytes = 0; in st_read()
2237 mutex_unlock(&STp->lock); in st_read()
2252 STp->current_mode, STm->do_buffer_writes, in DEB()
2253 STm->do_async_writes, STm->do_read_ahead); in DEB()
2257 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2258 STp->do_auto_lock); in DEB()
2261 "partitions: %d, s2 log: %d\n", in DEB()
2262 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2263 STp->can_partitions, STp->scsi2_logical); in DEB()
2267 STm->sysv, STp->immediate, STp->sili, in DEB()
2268 STp->immediate_filemark); in DEB()
2283 STm = &(STp->modes[STp->current_mode]);
2284 if (!STm->defined) {
2285 cd0 = STm->cdevs[0];
2286 cd1 = STm->cdevs[1];
2287 d0 = STm->devs[0];
2288 d1 = STm->devs[1];
2289 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2290 STm->cdevs[0] = cd0;
2291 STm->cdevs[1] = cd1;
2292 STm->devs[0] = d0;
2293 STm->devs[1] = d1;
2296 STp->current_mode);
2301 STm->do_buffer_writes = (options & MT_ST_BUFFER_WRITES) != 0;
2302 STm->do_async_writes = (options & MT_ST_ASYNC_WRITES) != 0;
2303 STm->defaults_for_writes = (options & MT_ST_DEF_WRITES) != 0;
2304 STm->do_read_ahead = (options & MT_ST_READ_AHEAD) != 0;
2305 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2306 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2307 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2308 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2309 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2310 if ((STp->device)->scsi_level >= SCSI_2)
2311 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2312 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2313 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2314 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2315 STm->sysv = (options & MT_ST_SYSV) != 0;
2316 STp->sili = (options & MT_ST_SILI) != 0;
2322 STm->do_buffer_writes = value;
2324 STm->do_async_writes = value;
2326 STm->defaults_for_writes = value;
2328 STm->do_read_ahead = value;
2330 STp->two_fm = value;
2332 STp->fast_mteom = value;
2334 STp->do_auto_lock = value;
2336 STp->can_bsr = value;
2338 STp->omit_blklims = value;
2339 if ((STp->device)->scsi_level >= SCSI_2 &&
2341 STp->can_partitions = value;
2343 STp->scsi2_logical = value;
2345 STp->immediate = value;
2347 STp->immediate_filemark = value;
2349 STm->sysv = value;
2351 STp->sili = value;
2361 STm->default_blksize = (-1);
2364 STm->default_blksize = value;
2366 "%d bytes.\n", STm->default_blksize);
2367 if (STp->ready == ST_READY) {
2368 STp->blksize_changed = 0;
2375 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2379 blk_queue_rq_timeout(STp->device->request_queue,
2389 return (-EINVAL);
2390 STp->cln_mode = value;
2391 STp->cln_sense_mask = (options >> 8) & 0xff;
2392 STp->cln_sense_value = (options >> 16) & 0xff;
2395 value, STp->cln_sense_mask, STp->cln_sense_value);
2401 STm->default_density = (-1);
2405 STm->default_density = value & 0xff;
2407 STm->default_density);
2408 if (STp->ready == ST_READY) {
2409 STp->density_changed = 0;
2415 STp->default_drvbuffer = 0xff;
2419 STp->default_drvbuffer = value & 7;
2422 STp->default_drvbuffer);
2423 if (STp->ready == ST_READY)
2424 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2428 STm->default_compression = ST_DONT_TOUCH;
2433 STp->c_algo = (value & 0xff00) >> 8;
2436 STp->c_algo);
2439 STm->default_compression = (value & 1 ? ST_YES : ST_NO);
2443 if (STp->ready == ST_READY) {
2444 STp->compression_changed = 0;
2445 st_compression(STp, (STm->default_compression == ST_YES));
2451 return (-EIO);
2491 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2493 return (STp->buffer)->syscall_result; in read_mode_page()
2497 return STp->buffer->syscall_result; in read_mode_page()
2502 in the buffer is correctly formatted. The long timeout is used if slow is non-zero. */
2513 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2514 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2517 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2518 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2519 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2520 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2523 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2527 return (STp->buffer)->syscall_result; in write_mode_page()
2531 return STp->buffer->syscall_result; in write_mode_page()
2548 The block descriptors are read and written because Sony SDT-7000 does not
2556 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2558 if (STp->ready != ST_READY) in st_compression()
2559 return (-EIO); in st_compression()
2565 return (-EIO); in st_compression()
2575 return (-EIO); in st_compression()
2581 if (STp->c_algo != 0) in st_compression()
2582 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2586 if (STp->c_algo != 0) in st_compression()
2593 return (-EIO); in st_compression()
2597 STp->compression_changed = 1; in st_compression()
2605 int retval = (-EIO), timeout; in do_load_unload()
2610 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2611 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2612 return (-ENOMEDIUM); in do_load_unload()
2614 return (-EIO); in do_load_unload()
2628 load_code - MT_ST_HPLOADER_OFFSET); in do_load_unload()
2629 cmd[3] = load_code - MT_ST_HPLOADER_OFFSET; /* MediaID field of C1553A */ in do_load_unload()
2631 if (STp->immediate) { in do_load_unload()
2633 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2636 timeout = STp->long_timeout; in do_load_unload()
2648 return (STp->buffer)->syscall_result; in do_load_unload()
2650 retval = (STp->buffer)->syscall_result; in do_load_unload()
2656 STp->rew_at_close = 0; in do_load_unload()
2657 STp->ready = ST_NO_TAPE; in do_load_unload()
2660 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2667 STps = &(STp->ps[STp->partition]); in do_load_unload()
2668 STps->drv_file = STps->drv_block = (-1); in do_load_unload()
2679 s32 sc; in deb_space_print() local
2684 sc = sign_extend32(get_unaligned_be24(&cmd[2]), 23); in deb_space_print()
2686 sc = -sc; in deb_space_print()
2688 direction ? "backward" : "forward", sc, units); in deb_space_print()
2710 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2711 if (STp->ready != ST_READY) { in st_int_ioctl()
2712 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2713 return (-ENOMEDIUM); in st_int_ioctl()
2715 return (-EIO); in st_int_ioctl()
2717 timeout = STp->long_timeout; in st_int_ioctl()
2718 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2719 fileno = STps->drv_file; in st_int_ioctl()
2720 blkno = STps->drv_block; in st_int_ioctl()
2721 at_sm = STps->at_sm; in st_int_ioctl()
2746 ltmp = (-arg); in st_int_ioctl()
2752 fileno -= arg; in st_int_ioctl()
2753 blkno = (-1); /* We can't know the block number */ in st_int_ioctl()
2770 ltmp = (-arg); in st_int_ioctl()
2776 blkno -= arg; in st_int_ioctl()
2787 blkno = fileno = (-1); in st_int_ioctl()
2794 ltmp = (-arg); in st_int_ioctl()
2800 blkno = fileno = (-1); in st_int_ioctl()
2807 if (STp->write_prot) in st_int_ioctl()
2808 return (-EACCES); in st_int_ioctl()
2813 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2818 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2840 if (STp->immediate) { in st_int_ioctl()
2842 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2852 if (STp->immediate) { in st_int_ioctl()
2854 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2861 if (!STp->fast_mteom) { in st_int_ioctl()
2864 fileno = STps->drv_file; in st_int_ioctl()
2865 if (STps->eof >= ST_EOD_1) in st_int_ioctl()
2872 fileno = (-1); in st_int_ioctl()
2876 blkno = -1; in st_int_ioctl()
2880 if (STp->write_prot) in st_int_ioctl()
2881 return (-EACCES); in st_int_ioctl()
2883 cmd[1] = (arg ? 1 : 0); /* Long erase with non-zero argument */ in st_int_ioctl()
2884 if (STp->immediate) { in st_int_ioctl()
2886 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2889 timeout = STp->long_timeout * 8; in st_int_ioctl()
2899 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in st_int_ioctl()
2900 return (-EIO); /* Not allowed if data in buffer */ in st_int_ioctl()
2903 STp->max_block > 0 && in st_int_ioctl()
2904 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block || in st_int_ioctl()
2905 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) { in st_int_ioctl()
2907 return (-EINVAL); in st_int_ioctl()
2910 if ((STp->use_pf & USE_PF)) in st_int_ioctl()
2915 memset((STp->buffer)->b_data, 0, 12); in st_int_ioctl()
2917 (STp->buffer)->b_data[2] = (arg & 7) << 4; in st_int_ioctl()
2919 (STp->buffer)->b_data[2] = in st_int_ioctl()
2920 STp->drv_buffer << 4; in st_int_ioctl()
2921 (STp->buffer)->b_data[3] = 8; /* block descriptor length */ in st_int_ioctl()
2923 (STp->buffer)->b_data[4] = arg; in st_int_ioctl()
2924 STp->density_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2926 (STp->buffer)->b_data[4] = arg >> 24; in st_int_ioctl()
2928 (STp->buffer)->b_data[4] = STp->density; in st_int_ioctl()
2932 STp->blksize_changed = 1; /* At least we tried ;-) */ in st_int_ioctl()
2934 ltmp = STp->block_size; in st_int_ioctl()
2935 (STp->buffer)->b_data[9] = (ltmp >> 16); in st_int_ioctl()
2936 (STp->buffer)->b_data[10] = (ltmp >> 8); in st_int_ioctl()
2937 (STp->buffer)->b_data[11] = ltmp; in st_int_ioctl()
2938 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2943 (STp->buffer)->b_data[9] * 65536 + in st_int_ioctl()
2944 (STp->buffer)->b_data[10] * 256 + in st_int_ioctl()
2945 (STp->buffer)->b_data[11]); in st_int_ioctl()
2949 (STp->buffer)->b_data[4]); in st_int_ioctl()
2953 ((STp->buffer)->b_data[2] >> 4) & 7); in st_int_ioctl()
2957 return (-ENOSYS); in st_int_ioctl()
2963 return (STp->buffer)->syscall_result; in st_int_ioctl()
2965 ioctl_result = (STp->buffer)->syscall_result; in st_int_ioctl()
2970 STps->drv_block = blkno; in st_int_ioctl()
2971 STps->drv_file = fileno; in st_int_ioctl()
2972 STps->at_sm = at_sm; in st_int_ioctl()
2980 STp->block_size = arg & MT_ST_BLKSIZE_MASK; in st_int_ioctl()
2981 if (STp->block_size != 0) { in st_int_ioctl()
2982 (STp->buffer)->buffer_blocks = in st_int_ioctl()
2983 (STp->buffer)->buffer_size / STp->block_size; in st_int_ioctl()
2985 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in st_int_ioctl()
2987 STp->density = arg >> MT_ST_DENSITY_SHIFT; in st_int_ioctl()
2989 STp->drv_buffer = (arg & 7); in st_int_ioctl()
2991 STp->density = arg; in st_int_ioctl()
2994 STps->eof = ST_EOD; in st_int_ioctl()
2996 STps->eof = ST_FM; in st_int_ioctl()
2998 STps->eof = ST_NOEOF; in st_int_ioctl()
3001 STps->rw = ST_IDLE; /* prevent automatic WEOF at close */ in st_int_ioctl()
3004 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_int_ioctl()
3006 if (cmdstatp->flags & SENSE_EOM) { in st_int_ioctl()
3009 STps->eof = ST_EOM_OK; in st_int_ioctl()
3010 STps->drv_block = 0; in st_int_ioctl()
3013 if (cmdstatp->remainder_valid) in st_int_ioctl()
3014 undone = (int)cmdstatp->uremainder64; in st_int_ioctl()
3019 cmdstatp->have_sense && in st_int_ioctl()
3020 (cmdstatp->flags & SENSE_EOM)) { in st_int_ioctl()
3021 if (cmdstatp->sense_hdr.sense_key == NO_SENSE || in st_int_ioctl()
3022 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) { in st_int_ioctl()
3024 STps->eof = ST_NOEOF; in st_int_ioctl()
3027 fileno -= undone; in st_int_ioctl()
3029 STps->eof = ST_NOEOF; in st_int_ioctl()
3031 STps->drv_file = fileno; in st_int_ioctl()
3034 STps->drv_file = fileno - undone; in st_int_ioctl()
3036 STps->drv_file = fileno; in st_int_ioctl()
3037 STps->drv_block = -1; in st_int_ioctl()
3038 STps->eof = ST_NOEOF; in st_int_ioctl()
3041 undone = (-undone); in st_int_ioctl()
3042 if (STps->drv_file >= 0) in st_int_ioctl()
3043 STps->drv_file = fileno + undone; in st_int_ioctl()
3044 STps->drv_block = 0; in st_int_ioctl()
3045 STps->eof = ST_NOEOF; in st_int_ioctl()
3047 if (cmdstatp->flags & SENSE_FMK) { /* Hit filemark */ in st_int_ioctl()
3048 if (STps->drv_file >= 0) in st_int_ioctl()
3049 STps->drv_file++; in st_int_ioctl()
3050 STps->drv_block = 0; in st_int_ioctl()
3051 STps->eof = ST_FM; in st_int_ioctl()
3054 STps->drv_block = blkno - undone; in st_int_ioctl()
3056 STps->drv_block = (-1); in st_int_ioctl()
3057 STps->eof = ST_NOEOF; in st_int_ioctl()
3060 if (cmdstatp->flags & SENSE_FMK) { /* Hit filemark */ in st_int_ioctl()
3061 STps->drv_file--; in st_int_ioctl()
3062 STps->drv_block = (-1); in st_int_ioctl()
3065 undone = (-undone); in st_int_ioctl()
3066 if (STps->drv_block >= 0) in st_int_ioctl()
3067 STps->drv_block = blkno + undone; in st_int_ioctl()
3069 STps->eof = ST_NOEOF; in st_int_ioctl()
3071 STps->drv_file = (-1); in st_int_ioctl()
3072 STps->drv_block = (-1); in st_int_ioctl()
3073 STps->eof = ST_EOD; in st_int_ioctl()
3078 if (cmdstatp->sense_hdr.sense_key == ILLEGAL_REQUEST && in st_int_ioctl()
3079 !(STp->use_pf & PF_TESTED)) { in st_int_ioctl()
3082 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED; in st_int_ioctl()
3088 STps->eof = ST_NOEOF; in st_int_ioctl()
3090 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK) in st_int_ioctl()
3091 STps->eof = ST_EOD; in st_int_ioctl()
3111 if (STp->ready != ST_READY) in get_location()
3112 return (-EIO); in get_location()
3115 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3120 if (!logical && !STp->scsi2_logical) in get_location()
3124 STp->device->request_queue->rq_timeout, in get_location()
3127 return (STp->buffer)->syscall_result; in get_location()
3129 if ((STp->buffer)->syscall_result != 0 || in get_location()
3130 (STp->device->scsi_level >= SCSI_2 && in get_location()
3131 ((STp->buffer)->b_data[0] & 4) != 0)) { in get_location()
3134 result = (-EIO); in get_location()
3137 if ((STp->device)->scsi_level < SCSI_2) { in get_location()
3138 *block = ((STp->buffer)->b_data[0] << 16) in get_location()
3139 + ((STp->buffer)->b_data[1] << 8) in get_location()
3140 + (STp->buffer)->b_data[2]; in get_location()
3143 *block = ((STp->buffer)->b_data[4] << 24) in get_location()
3144 + ((STp->buffer)->b_data[5] << 16) in get_location()
3145 + ((STp->buffer)->b_data[6] << 8) in get_location()
3146 + (STp->buffer)->b_data[7]; in get_location()
3147 *partition = (STp->buffer)->b_data[1]; in get_location()
3148 if (((STp->buffer)->b_data[0] & 0x80) && in get_location()
3149 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */ in get_location()
3150 STp->ps[0].drv_block = STp->ps[0].drv_file = 0; in get_location()
3174 if (STp->ready != ST_READY) in set_location()
3175 return (-EIO); in set_location()
3176 timeout = STp->long_timeout; in set_location()
3177 STps = &(STp->ps[STp->partition]); in set_location()
3182 return (-EIO); ) in set_location()
3185 if ((!STp->can_partitions && partition != 0) || in set_location()
3187 return (-EINVAL); in set_location()
3188 if (partition != STp->partition) { in set_location()
3190 STps->last_block_valid = 0; in set_location()
3192 STps->last_block_valid = 1; in set_location()
3193 STps->last_block_visited = blk; in set_location()
3196 blk, STp->partition); in set_location()
3201 if ((STp->device)->scsi_level < SCSI_2) { in set_location()
3213 if (!logical && !STp->scsi2_logical) in set_location()
3215 if (STp->partition != partition) { in set_location()
3219 "from %d to %d\n", STp->partition, in set_location()
3223 if (STp->immediate) { in set_location()
3225 timeout = STp->device->request_queue->rq_timeout; in set_location()
3231 return (STp->buffer)->syscall_result; in set_location()
3233 STps->drv_block = STps->drv_file = (-1); in set_location()
3234 STps->eof = ST_NOEOF; in set_location()
3235 if ((STp->buffer)->syscall_result != 0) { in set_location()
3236 result = (-EIO); in set_location()
3237 if (STp->can_partitions && in set_location()
3238 (STp->device)->scsi_level >= SCSI_2 && in set_location()
3240 STp->partition = p; in set_location()
3242 if (STp->can_partitions) { in set_location()
3243 STp->partition = partition; in set_location()
3244 STps = &(STp->ps[partition]); in set_location()
3245 if (!STps->last_block_valid || in set_location()
3246 STps->last_block_visited != block) { in set_location()
3247 STps->at_sm = 0; in set_location()
3248 STps->rw = ST_IDLE; in set_location()
3251 STps->at_sm = 0; in set_location()
3253 STps->drv_block = STps->drv_file = 0; in set_location()
3274 return (-EIO); in find_partition()
3284 if (STp->partition == STp->new_partition) in switch_partition()
3286 STps = &(STp->ps[STp->new_partition]); in switch_partition()
3287 if (!STps->last_block_valid) in switch_partition()
3288 STps->last_block_visited = 0; in switch_partition()
3289 return set_location(STp, STps->last_block_visited, STp->new_partition, 1); in switch_partition()
3309 /* Get the number of partitions on the tape. As a side effect reads the
3315 if (STp->ready != ST_READY) in nbr_partitions()
3316 return (-EIO); in nbr_partitions()
3322 result = (-EIO); in nbr_partitions()
3324 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH + in nbr_partitions()
3326 DEBC_printk(STp, "Number of partitions %d.\n", result); in nbr_partitions()
3336 int timeout = STp->long_timeout; in format_medium()
3343 if (STp->immediate) { in format_medium()
3345 timeout = STp->device->request_queue->rq_timeout; in format_medium()
3351 result = STp->buffer->syscall_result; in format_medium()
3356 /* Partition the tape into two partitions if size > 0 or one partition if
3359 The block descriptors are read and written because Sony SDT-7000 does not
3364 Michael Schaefer's Sony SDT-7000 returns two descriptors and the second is
3365 used to set the size of partition 1 (this is what the SCSI-3 standard specifies).
3367 partition size fields is greater than the maximum number of additional partitions
3370 For Seagate DDS drives the page length must be 8 when no partitions is defined
3375 For drives that advertize SCSI-3 or newer, use the SSC-3 methods.
3381 bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false; in partition_tape()
3394 size = -size; in partition_tape()
3398 bp = (STp->buffer)->b_data; in partition_tape()
3403 psd_cnt = (bp[pgo + MP_OFF_PAGE_LENGTH] + 2 - PART_PAGE_FIXED_LENGTH) / 2; in partition_tape()
3418 /* Use units scaling for large partitions if the device in partition_tape()
3438 result = -EINVAL; in partition_tape()
3472 "Formatting tape with two partitions (%i = %d MB).\n", in partition_tape()
3493 result = (-EIO); in partition_tape()
3509 struct scsi_tape *STp = file->private_data; in st_ioctl()
3513 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl()
3514 return -ERESTARTSYS; in st_ioctl()
3517 if (debugging && !STp->in_use) { in st_ioctl()
3519 retval = (-EIO); in st_ioctl()
3523 STm = &(STp->modes[STp->current_mode]); in st_ioctl()
3524 STps = &(STp->ps[STp->partition]); in st_ioctl()
3532 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl()
3533 file->f_flags & O_NDELAY); in st_ioctl()
3544 retval = (-EINVAL); in st_ioctl()
3550 retval = (-EFAULT); in st_ioctl()
3557 retval = (-EPERM); in st_ioctl()
3560 if (!STm->defined && in st_ioctl()
3563 retval = (-ENXIO); in st_ioctl()
3567 if (!STp->pos_unknown) { in st_ioctl()
3569 if (STps->eof == ST_FM_HIT) { in st_ioctl()
3572 mtc.mt_count -= 1; in st_ioctl()
3573 if (STps->drv_file >= 0) in st_ioctl()
3574 STps->drv_file += 1; in st_ioctl()
3577 if (STps->drv_file >= 0) in st_ioctl()
3578 STps->drv_file += 1; in st_ioctl()
3585 i = !STp->can_partitions || in st_ioctl()
3586 (STp->new_partition != STp->partition); in st_ioctl()
3600 if (STps->rw == ST_WRITING && in st_ioctl()
3611 STps->rw = ST_IDLE; in st_ioctl()
3626 retval = (-EIO); in st_ioctl()
3631 STp->device->was_reset = 0; in st_ioctl()
3637 STps->rw = ST_IDLE; /* Prevent automatic WEOF and fsf */ in st_ioctl()
3639 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl()
3649 if (!STp->can_partitions || in st_ioctl()
3651 retval = (-EINVAL); in st_ioctl()
3654 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl()
3655 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl()
3656 retval = (-EIO); in st_ioctl()
3659 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl()
3660 retval = (-EINVAL); in st_ioctl()
3663 STp->new_partition = mtc.mt_count; in st_ioctl()
3669 if (!STp->can_partitions) { in st_ioctl()
3670 retval = (-EINVAL); in st_ioctl()
3684 STp->ps[i].rw = ST_IDLE; in st_ioctl()
3685 STp->ps[i].at_sm = 0; in st_ioctl()
3686 STp->ps[i].last_block_valid = 0; in st_ioctl()
3688 STp->partition = STp->new_partition = 0; in st_ioctl()
3689 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl()
3690 STps->drv_block = STps->drv_file = 0; in st_ioctl()
3696 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl()
3697 if (!STp->can_partitions) in st_ioctl()
3698 STp->ps[0].rw = ST_IDLE; in st_ioctl()
3718 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl()
3730 if (!STm->defined) { in st_ioctl()
3731 retval = (-ENXIO); in st_ioctl()
3739 if (STp->can_partitions && in st_ioctl()
3749 retval = (-EINVAL); in st_ioctl()
3753 mt_status.mt_type = STp->tape_type; in st_ioctl()
3755 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl()
3756 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl()
3757 mt_status.mt_blkno = STps->drv_block; in st_ioctl()
3758 mt_status.mt_fileno = STps->drv_file; in st_ioctl()
3759 if (STp->block_size != 0) { in st_ioctl()
3760 if (STps->rw == ST_WRITING) in st_ioctl()
3762 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl()
3763 else if (STps->rw == ST_READING) in st_ioctl()
3764 mt_status.mt_blkno -= in st_ioctl()
3765 ((STp->buffer)->buffer_bytes + in st_ioctl()
3766 STp->block_size - 1) / STp->block_size; in st_ioctl()
3770 if (STp->drv_write_prot) in st_ioctl()
3778 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl()
3779 mt_status.mt_resid = STp->partition; in st_ioctl()
3780 if (STps->eof == ST_EOM_OK || STps->eof == ST_EOM_ERROR) in st_ioctl()
3782 else if (STps->eof >= ST_EOM_OK) in st_ioctl()
3784 if (STp->density == 1) in st_ioctl()
3786 else if (STp->density == 2) in st_ioctl()
3788 else if (STp->density == 3) in st_ioctl()
3790 if (STp->ready == ST_READY) in st_ioctl()
3792 if (STp->ready == ST_NO_TAPE) in st_ioctl()
3794 if (STps->at_sm) in st_ioctl()
3796 if (STm->do_async_writes || in st_ioctl()
3797 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl()
3798 STp->drv_buffer != 0) in st_ioctl()
3800 if (STp->cleaning_req) in st_ioctl()
3807 STp->recover_reg = 0; /* Clear after read */ in st_ioctl()
3813 retval = (-EINVAL); in st_ioctl()
3824 mutex_unlock(&STp->lock); in st_ioctl()
3831 return -EPERM; in st_ioctl()
3837 retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, cmd_in, p); in st_ioctl()
3840 STp->rew_at_close = 0; in st_ioctl()
3841 STp->ready = ST_NO_TAPE; in st_ioctl()
3846 mutex_unlock(&STp->lock); in st_ioctl()
3880 tb->frp_segs = 0; in new_tape_buffer()
3881 tb->use_sg = max_sg; in new_tape_buffer()
3882 tb->buffer_size = 0; in new_tape_buffer()
3884 tb->reserved_pages = kcalloc(max_sg, sizeof(struct page *), in new_tape_buffer()
3886 if (!tb->reserved_pages) { in new_tape_buffer()
3903 if (new_size <= STbuffer->buffer_size) in enlarge_buffer()
3906 if (STbuffer->buffer_size <= PAGE_SIZE) in enlarge_buffer()
3909 max_segs = STbuffer->use_sg; in enlarge_buffer()
3913 if (STbuffer->cleared) in enlarge_buffer()
3916 if (STbuffer->frp_segs) { in enlarge_buffer()
3917 order = STbuffer->reserved_page_order; in enlarge_buffer()
3925 STbuffer->reserved_page_order = order; in enlarge_buffer()
3934 for (segs = STbuffer->frp_segs, got = STbuffer->buffer_size; in enlarge_buffer()
3940 DEB(STbuffer->buffer_size = got); in enlarge_buffer()
3945 STbuffer->frp_segs += 1; in enlarge_buffer()
3947 STbuffer->buffer_size = got; in enlarge_buffer()
3948 STbuffer->reserved_pages[segs] = page; in enlarge_buffer()
3951 STbuffer->b_data = page_address(STbuffer->reserved_pages[0]); in enlarge_buffer()
3962 for (i=0; i < st_bp->frp_segs; i++) in clear_buffer()
3963 memset(page_address(st_bp->reserved_pages[i]), 0, in clear_buffer()
3964 PAGE_SIZE << st_bp->reserved_page_order); in clear_buffer()
3965 st_bp->cleared = 1; in clear_buffer()
3972 int i, order = STbuffer->reserved_page_order; in normalize_buffer()
3974 for (i = 0; i < STbuffer->frp_segs; i++) { in normalize_buffer()
3975 __free_pages(STbuffer->reserved_pages[i], order); in normalize_buffer()
3976 STbuffer->buffer_size -= (PAGE_SIZE << order); in normalize_buffer()
3978 STbuffer->frp_segs = 0; in normalize_buffer()
3979 STbuffer->sg_segs = 0; in normalize_buffer()
3980 STbuffer->reserved_page_order = 0; in normalize_buffer()
3981 STbuffer->map_data.offset = 0; in normalize_buffer()
3990 int length = PAGE_SIZE << st_bp->reserved_page_order; in append_to_buffer()
3992 for (i = 0, offset = st_bp->buffer_bytes; in append_to_buffer()
3993 i < st_bp->frp_segs && offset >= length; i++) in append_to_buffer()
3994 offset -= length; in append_to_buffer()
3995 if (i == st_bp->frp_segs) { /* Should never happen */ in append_to_buffer()
3997 return (-EIO); in append_to_buffer()
3999 for (; i < st_bp->frp_segs && do_count > 0; i++) { in append_to_buffer()
4000 struct page *page = st_bp->reserved_pages[i]; in append_to_buffer()
4001 cnt = length - offset < do_count ? length - offset : do_count; in append_to_buffer()
4004 return (-EFAULT); in append_to_buffer()
4005 do_count -= cnt; in append_to_buffer()
4006 st_bp->buffer_bytes += cnt; in append_to_buffer()
4011 return (-EIO); in append_to_buffer()
4022 int length = PAGE_SIZE << st_bp->reserved_page_order; in from_buffer()
4024 for (i = 0, offset = st_bp->read_pointer; in from_buffer()
4025 i < st_bp->frp_segs && offset >= length; i++) in from_buffer()
4026 offset -= length; in from_buffer()
4027 if (i == st_bp->frp_segs) { /* Should never happen */ in from_buffer()
4029 return (-EIO); in from_buffer()
4031 for (; i < st_bp->frp_segs && do_count > 0; i++) { in from_buffer()
4032 struct page *page = st_bp->reserved_pages[i]; in from_buffer()
4033 cnt = length - offset < do_count ? length - offset : do_count; in from_buffer()
4036 return (-EFAULT); in from_buffer()
4037 do_count -= cnt; in from_buffer()
4038 st_bp->buffer_bytes -= cnt; in from_buffer()
4039 st_bp->read_pointer += cnt; in from_buffer()
4044 return (-EIO); in from_buffer()
4055 int length = PAGE_SIZE << st_bp->reserved_page_order; in move_buffer_data()
4060 total=st_bp->buffer_bytes - offset; in move_buffer_data()
4061 for (src_seg=0; src_seg < st_bp->frp_segs; src_seg++) { in move_buffer_data()
4065 offset -= length; in move_buffer_data()
4068 st_bp->buffer_bytes = st_bp->read_pointer = total; in move_buffer_data()
4070 struct page *dpage = st_bp->reserved_pages[dst_seg]; in move_buffer_data()
4071 struct page *spage = st_bp->reserved_pages[src_seg]; in move_buffer_data()
4073 count = min(length - dst_offset, length - src_offset); in move_buffer_data()
4086 total -= count; in move_buffer_data()
4167 struct st_modedef *STm = &(tape->modes[mode]); in create_one_cdev()
4169 int dev_num = tape->index; in create_one_cdev()
4176 error = -ENOMEM; in create_one_cdev()
4179 cdev->owner = THIS_MODULE; in create_one_cdev()
4180 cdev->ops = &st_fops; in create_one_cdev()
4181 STm->cdevs[rew] = cdev; in create_one_cdev()
4185 pr_err("st%d: Can't add %s-rewind mode %d\n", dev_num, in create_one_cdev()
4191 i = mode << (4 - ST_NBR_MODE_BITS); in create_one_cdev()
4193 tape->name, st_formats[i]); in create_one_cdev()
4195 dev = device_create(&st_sysfs_class, &tape->device->sdev_gendev, in create_one_cdev()
4196 cdev_devno, &tape->modes[mode], "%s", name); in create_one_cdev()
4203 STm->devs[rew] = dev; in create_one_cdev()
4207 cdev_del(STm->cdevs[rew]); in create_one_cdev()
4209 STm->cdevs[rew] = NULL; in create_one_cdev()
4210 STm->devs[rew] = NULL; in create_one_cdev()
4226 return sysfs_create_link(&tape->device->sdev_gendev.kobj, in create_cdevs()
4227 &tape->modes[0].devs[0]->kobj, "tape"); in create_cdevs()
4233 sysfs_remove_link(&tape->device->sdev_gendev.kobj, "tape"); in remove_cdevs()
4235 struct st_modedef *STm = &(tape->modes[mode]); in remove_cdevs()
4237 if (STm->cdevs[rew]) in remove_cdevs()
4238 cdev_del(STm->cdevs[rew]); in remove_cdevs()
4239 if (STm->devs[rew]) in remove_cdevs()
4240 device_unregister(STm->devs[rew]); in remove_cdevs()
4254 if (SDp->type != TYPE_TAPE) in st_probe()
4255 return -ENODEV; in st_probe()
4260 "please mail to linux-scsi@vger.kernel.org.\n"); in st_probe()
4261 return -ENODEV; in st_probe()
4265 i = queue_max_segments(SDp->request_queue); in st_probe()
4282 kref_init(&tpnt->kref); in st_probe()
4284 tpnt->device = SDp; in st_probe()
4285 if (SDp->scsi_level <= 2) in st_probe()
4286 tpnt->tape_type = MT_ISSCSI1; in st_probe()
4288 tpnt->tape_type = MT_ISSCSI2; in st_probe()
4290 tpnt->buffer = buffer; in st_probe()
4291 tpnt->buffer->last_SRpnt = NULL; in st_probe()
4293 tpnt->inited = 0; in st_probe()
4294 tpnt->dirty = 0; in st_probe()
4295 tpnt->in_use = 0; in st_probe()
4296 tpnt->drv_buffer = 1; /* Try buffering if no mode sense */ in st_probe()
4297 tpnt->use_pf = (SDp->scsi_level >= SCSI_2); in st_probe()
4298 tpnt->density = 0; in st_probe()
4299 tpnt->do_auto_lock = ST_AUTO_LOCK; in st_probe()
4300 tpnt->can_bsr = (SDp->scsi_level > 2 ? 1 : ST_IN_FILE_POS); /* BSR mandatory in SCSI3 */ in st_probe()
4301 tpnt->can_partitions = 0; in st_probe()
4302 tpnt->two_fm = ST_TWO_FM; in st_probe()
4303 tpnt->fast_mteom = ST_FAST_MTEOM; in st_probe()
4304 tpnt->scsi2_logical = ST_SCSI2LOGICAL; in st_probe()
4305 tpnt->sili = ST_SILI; in st_probe()
4306 tpnt->immediate = ST_NOWAIT; in st_probe()
4307 tpnt->immediate_filemark = 0; in st_probe()
4308 tpnt->default_drvbuffer = 0xff; /* No forced buffering */ in st_probe()
4309 tpnt->partition = 0; in st_probe()
4310 tpnt->new_partition = 0; in st_probe()
4311 tpnt->nbr_partitions = 0; in st_probe()
4312 blk_queue_rq_timeout(tpnt->device->request_queue, ST_TIMEOUT); in st_probe()
4313 tpnt->long_timeout = ST_LONG_TIMEOUT; in st_probe()
4314 tpnt->try_dio = try_direct_io; in st_probe()
4317 STm = &(tpnt->modes[i]); in st_probe()
4318 STm->defined = 0; in st_probe()
4319 STm->sysv = ST_SYSV; in st_probe()
4320 STm->defaults_for_writes = 0; in st_probe()
4321 STm->do_async_writes = ST_ASYNC_WRITES; in st_probe()
4322 STm->do_buffer_writes = ST_BUFFER_WRITES; in st_probe()
4323 STm->do_read_ahead = ST_READ_AHEAD; in st_probe()
4324 STm->default_compression = ST_DONT_TOUCH; in st_probe()
4325 STm->default_blksize = (-1); /* No forced size */ in st_probe()
4326 STm->default_density = (-1); /* No forced density */ in st_probe()
4327 STm->tape = tpnt; in st_probe()
4331 STps = &(tpnt->ps[i]); in st_probe()
4332 STps->rw = ST_IDLE; in st_probe()
4333 STps->eof = ST_NOEOF; in st_probe()
4334 STps->at_sm = 0; in st_probe()
4335 STps->last_block_valid = 0; in st_probe()
4336 STps->drv_block = (-1); in st_probe()
4337 STps->drv_file = (-1); in st_probe()
4340 tpnt->current_mode = 0; in st_probe()
4341 tpnt->modes[0].defined = 1; in st_probe()
4343 tpnt->density_changed = tpnt->compression_changed = in st_probe()
4344 tpnt->blksize_changed = 0; in st_probe()
4345 mutex_init(&tpnt->lock); in st_probe()
4356 tpnt->index = error; in st_probe()
4357 sprintf(tpnt->name, "st%d", tpnt->index); in st_probe()
4358 tpnt->stats = kzalloc(sizeof(struct scsi_tape_stats), GFP_KERNEL); in st_probe()
4359 if (tpnt->stats == NULL) { in st_probe()
4374 "Attached scsi tape %s\n", tpnt->name); in st_probe()
4376 tpnt->name, tpnt->try_dio ? "yes" : "no", in st_probe()
4377 queue_dma_alignment(SDp->request_queue) + 1); in st_probe()
4383 kfree(tpnt->stats); in st_probe()
4386 idr_remove(&st_index_idr, tpnt->index); in st_probe()
4394 return -ENODEV; in st_probe()
4401 int index = tpnt->index; in st_remove()
4407 kref_put(&tpnt->kref, scsi_tape_release); in st_remove()
4416 * scsi_tape_release - Called to free the Scsi_Tape structure
4428 tpnt->device = NULL; in scsi_tape_release()
4430 if (tpnt->buffer) { in scsi_tape_release()
4431 normalize_buffer(tpnt->buffer); in scsi_tape_release()
4432 kfree(tpnt->buffer->reserved_pages); in scsi_tape_release()
4433 kfree(tpnt->buffer); in scsi_tape_release()
4436 kfree(tpnt->stats); in scsi_tape_release()
4503 /* The sysfs driver interface. Read-only at the moment */
4534 * other values have -EINVAL returned if they are passed in. in debug_flag_store()
4545 return -EINVAL; in debug_flag_store()
4574 l = snprintf(buf, PAGE_SIZE, "%d\n", STm->defined); in defined_show()
4586 l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_blksize); in default_blksize_show()
4599 fmt = STm->default_density >= 0 ? "0x%02x\n" : "%d\n"; in default_density_show()
4600 l = snprintf(buf, PAGE_SIZE, fmt, STm->default_density); in default_density_show()
4612 l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_compression - 1); in default_compression_show()
4621 struct scsi_tape *STp = STm->tape; in options_show()
4625 options = STm->do_buffer_writes ? MT_ST_BUFFER_WRITES : 0; in options_show()
4626 options |= STm->do_async_writes ? MT_ST_ASYNC_WRITES : 0; in options_show()
4627 options |= STm->do_read_ahead ? MT_ST_READ_AHEAD : 0; in options_show()
4629 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4630 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4631 options |= STm->defaults_for_writes ? MT_ST_DEF_WRITES : 0; in options_show()
4632 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4633 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4634 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4635 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4636 options |= STm->sysv ? MT_ST_SYSV : 0; in options_show()
4637 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4638 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4639 options |= STp->sili ? MT_ST_SILI : 0; in options_show()
4649 * read_cnt_show - return read count - count of reads made from tape drive
4660 (long long)atomic64_read(&STm->tape->stats->read_cnt)); in read_cnt_show()
4665 * read_byte_cnt_show - return read byte count - tape drives
4678 (long long)atomic64_read(&STm->tape->stats->read_byte_cnt)); in read_byte_cnt_show()
4683 * read_ns_show - return read ns - overall time spent waiting on reads in ns.
4694 (long long)atomic64_read(&STm->tape->stats->tot_read_time)); in read_ns_show()
4699 * write_cnt_show - write count - number of user calls
4711 (long long)atomic64_read(&STm->tape->stats->write_cnt)); in write_cnt_show()
4716 * write_byte_cnt_show - write byte count - raw count of
4728 (long long)atomic64_read(&STm->tape->stats->write_byte_cnt)); in write_byte_cnt_show()
4733 * write_ns_show - write ns - number of nanoseconds waiting on write
4745 (long long)atomic64_read(&STm->tape->stats->tot_write_time)); in write_ns_show()
4750 * in_flight_show - number of I/Os currently in flight -
4763 (long long)atomic64_read(&STm->tape->stats->in_flight)); in in_flight_show()
4768 * io_ns_show - io wait ns - this is the number of ns spent
4783 (long long)atomic64_read(&STm->tape->stats->tot_io_time)); in io_ns_show()
4788 * other_cnt_show - other io count - this is the number of
4802 (long long)atomic64_read(&STm->tape->stats->other_cnt)); in other_cnt_show()
4807 * resid_cnt_show - A count of the number of times we get a residual
4808 * count - this should indicate someone issuing reads larger than the
4820 (long long)atomic64_read(&STm->tape->stats->resid_cnt)); in resid_cnt_show()
4867 unsigned long end = (uaddr + count + PAGE_SIZE - 1) >> PAGE_SHIFT; in sgl_map_user_pages()
4869 const int nr_pages = end - start; in sgl_map_user_pages()
4872 struct rq_map_data *mdata = &STbp->map_data; in sgl_map_user_pages()
4876 return -EINVAL; in sgl_map_user_pages()
4880 return -ENOMEM; in sgl_map_user_pages()
4888 return -ENOMEM; in sgl_map_user_pages()
4906 mdata->offset = uaddr & ~PAGE_MASK; in sgl_map_user_pages()
4907 STbp->mapped_pages = pages; in sgl_map_user_pages()
4925 unpin_user_pages_dirty_lock(STbp->mapped_pages, nr_pages, dirtied); in sgl_unmap_user_pages()
4927 kfree(STbp->mapped_pages); in sgl_unmap_user_pages()
4928 STbp->mapped_pages = NULL; in sgl_unmap_user_pages()