Lines Matching +full:usb +full:- +full:sdp
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
61 is defined and non-zero. */
158 6-byte SCSI read and write commands. */
159 #if ST_FIXED_BUFFER_SIZE >= (2 << 24 - 1)
160 #error "Buffer size should not exceed (2 << 24 - 1) bytes!"
173 /* Remove mode bits and auto-rewind bit (7) */
175 (iminor(x) & ((1 << ST_MODE_SHIFT)-1)))
178 /* 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"}, \
238 {"OnStream", "USB", "", "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 */
295 static char * st_incompatible(struct scsi_device* SDp) in st_incompatible() argument
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()
314 return tape->disk->disk_name; in tape_name()
318 sdev_prefix_printk(prefix, (t)->device, tape_name(t), fmt, ##a)
329 const u8 *sense = SRpnt->sense; in st_analyze_sense()
331 s->have_sense = scsi_normalize_sense(SRpnt->sense, in st_analyze_sense()
332 SCSI_SENSE_BUFFERSIZE, &s->sense_hdr); in st_analyze_sense()
333 s->flags = 0; in st_analyze_sense()
335 if (s->have_sense) { in st_analyze_sense()
336 s->deferred = 0; in st_analyze_sense()
337 s->remainder_valid = in st_analyze_sense()
338 scsi_get_sense_info_fld(sense, SCSI_SENSE_BUFFERSIZE, &s->uremainder64); in st_analyze_sense()
341 s->deferred = 1; in st_analyze_sense()
344 s->fixed_format = 1; in st_analyze_sense()
345 s->flags = sense[2] & 0xe0; in st_analyze_sense()
348 s->deferred = 1; in st_analyze_sense()
351 s->fixed_format = 0; in st_analyze_sense()
353 s->flags = ucp ? (ucp[3] & 0xe0) : 0; in st_analyze_sense()
363 int result = SRpnt->result; in st_chk_result()
372 cmdstatp = &STp->buffer->cmdstat; in st_chk_result()
375 if (cmdstatp->have_sense) in st_chk_result()
376 scode = STp->buffer->cmdstat.sense_hdr.sense_key; in st_chk_result()
384 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], in st_chk_result()
385 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); in st_chk_result()
386 if (cmdstatp->have_sense) in st_chk_result()
387 __scsi_print_sense(STp->device, name, in st_chk_result()
388 SRpnt->sense, SCSI_SENSE_BUFFERSIZE); in st_chk_result()
391 if (!cmdstatp->have_sense) in st_chk_result()
395 else if (cmdstatp->have_sense && in st_chk_result()
401 SRpnt->cmd[0] != MODE_SENSE && in st_chk_result()
402 SRpnt->cmd[0] != TEST_UNIT_READY) { in st_chk_result()
404 __scsi_print_sense(STp->device, name, in st_chk_result()
405 SRpnt->sense, SCSI_SENSE_BUFFERSIZE); in st_chk_result()
409 if (cmdstatp->fixed_format && in st_chk_result()
410 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ in st_chk_result()
411 if (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) == STp->cln_sense_value); in st_chk_result()
415 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] & in st_chk_result()
416 STp->cln_sense_mask) != 0); in st_chk_result()
418 if (cmdstatp->have_sense && in st_chk_result()
419 cmdstatp->sense_hdr.asc == 0 && cmdstatp->sense_hdr.ascq == 0x17) in st_chk_result()
420 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ in st_chk_result()
422 STp->pos_unknown |= STp->device->was_reset; in st_chk_result()
424 if (cmdstatp->have_sense && in st_chk_result()
427 && SRpnt->cmd[0] != WRITE_6 in st_chk_result()
428 && SRpnt->cmd[0] != WRITE_FILEMARKS in st_chk_result()
431 STp->recover_count++; in st_chk_result()
432 STp->recover_reg++; in st_chk_result()
436 if (SRpnt->cmd[0] == READ_6) in st_chk_result()
438 else if (SRpnt->cmd[0] == WRITE_6) in st_chk_result()
444 stp, STp->recover_count); in st_chk_result()
447 if (cmdstatp->flags == 0) in st_chk_result()
450 return (-EIO); in st_chk_result()
459 streq->stp = stp; in st_allocate_request()
464 stp->buffer->syscall_result = -EINTR; in st_allocate_request()
466 stp->buffer->syscall_result = -EBUSY; in st_allocate_request()
482 if (scsi_req(req)->cmd[0] == WRITE_6) { in st_do_stats()
483 now = ktime_sub(now, STp->stats->write_time); in st_do_stats()
484 atomic64_add(ktime_to_ns(now), &STp->stats->tot_write_time); in st_do_stats()
485 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
486 atomic64_inc(&STp->stats->write_cnt); in st_do_stats()
487 if (scsi_req(req)->result) { in st_do_stats()
488 atomic64_add(atomic_read(&STp->stats->last_write_size) in st_do_stats()
489 - STp->buffer->cmdstat.residual, in st_do_stats()
490 &STp->stats->write_byte_cnt); in st_do_stats()
491 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
492 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
494 atomic64_add(atomic_read(&STp->stats->last_write_size), in st_do_stats()
495 &STp->stats->write_byte_cnt); in st_do_stats()
496 } else if (scsi_req(req)->cmd[0] == READ_6) { in st_do_stats()
497 now = ktime_sub(now, STp->stats->read_time); in st_do_stats()
498 atomic64_add(ktime_to_ns(now), &STp->stats->tot_read_time); in st_do_stats()
499 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
500 atomic64_inc(&STp->stats->read_cnt); in st_do_stats()
501 if (scsi_req(req)->result) { in st_do_stats()
502 atomic64_add(atomic_read(&STp->stats->last_read_size) in st_do_stats()
503 - STp->buffer->cmdstat.residual, in st_do_stats()
504 &STp->stats->read_byte_cnt); in st_do_stats()
505 if (STp->buffer->cmdstat.residual > 0) in st_do_stats()
506 atomic64_inc(&STp->stats->resid_cnt); in st_do_stats()
508 atomic64_add(atomic_read(&STp->stats->last_read_size), in st_do_stats()
509 &STp->stats->read_byte_cnt); in st_do_stats()
511 now = ktime_sub(now, STp->stats->other_time); in st_do_stats()
512 atomic64_add(ktime_to_ns(now), &STp->stats->tot_io_time); in st_do_stats()
513 atomic64_inc(&STp->stats->other_cnt); in st_do_stats()
515 atomic64_dec(&STp->stats->in_flight); in st_do_stats()
520 struct st_request *SRpnt = req->end_io_data; in st_scsi_execute_end()
522 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute_end()
525 STp->buffer->cmdstat.midlevel_result = SRpnt->result = rq->result; in st_scsi_execute_end()
526 STp->buffer->cmdstat.residual = rq->resid_len; in st_scsi_execute_end()
530 tmp = SRpnt->bio; in st_scsi_execute_end()
531 if (rq->sense_len) in st_scsi_execute_end()
532 memcpy(SRpnt->sense, rq->sense, SCSI_SENSE_BUFFERSIZE); in st_scsi_execute_end()
533 if (SRpnt->waiting) in st_scsi_execute_end()
534 complete(SRpnt->waiting); in st_scsi_execute_end()
546 struct rq_map_data *mdata = &SRpnt->stp->buffer->map_data; in st_scsi_execute()
548 struct scsi_tape *STp = SRpnt->stp; in st_scsi_execute()
550 req = blk_get_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 rq->cmd_len = COMMAND_SIZE(cmd[0]); in st_scsi_execute()
582 memset(rq->cmd, 0, BLK_MAX_CDB); in st_scsi_execute()
583 memcpy(rq->cmd, cmd, rq->cmd_len); in st_scsi_execute()
584 req->timeout = timeout; in st_scsi_execute()
585 rq->retries = retries; in st_scsi_execute()
586 req->end_io_data = SRpnt; in st_scsi_execute()
588 blk_execute_rq_nowait(req->q, NULL, req, 1, st_scsi_execute_end); 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()
841 if (STp->pos_unknown) in flush_buffer()
842 return (-EIO); in flush_buffer()
844 if (STp->ready != ST_READY) in flush_buffer()
846 STps = &(STp->ps[STp->partition]); in flush_buffer()
847 if (STps->rw == ST_WRITING) /* Writing */ in flush_buffer()
850 if (STp->block_size == 0) in flush_buffer()
853 backspace = ((STp->buffer)->buffer_bytes + in flush_buffer()
854 (STp->buffer)->read_pointer) / STp->block_size - in flush_buffer()
855 ((STp->buffer)->read_pointer + STp->block_size - 1) / in flush_buffer()
856 STp->block_size; in flush_buffer()
857 (STp->buffer)->buffer_bytes = 0; in flush_buffer()
858 (STp->buffer)->read_pointer = 0; in flush_buffer()
861 if (STps->eof == ST_FM_HIT) { in flush_buffer()
864 STps->eof = ST_NOEOF; in flush_buffer()
866 if (STps->drv_file >= 0) in flush_buffer()
867 STps->drv_file++; in flush_buffer()
868 STps->drv_block = 0; in flush_buffer()
873 } else if (STps->eof == ST_FM_HIT) { in flush_buffer()
874 if (STps->drv_file >= 0) in flush_buffer()
875 STps->drv_file++; in flush_buffer()
876 STps->drv_block = 0; in flush_buffer()
877 STps->eof = ST_NOEOF; in flush_buffer()
889 if (!STp->density_changed && in set_mode_densblk()
890 STm->default_density >= 0 && in set_mode_densblk()
891 STm->default_density != STp->density) { in set_mode_densblk()
892 arg = STm->default_density; in set_mode_densblk()
895 arg = STp->density; in set_mode_densblk()
897 if (!STp->blksize_changed && in set_mode_densblk()
898 STm->default_blksize >= 0 && in set_mode_densblk()
899 STm->default_blksize != STp->block_size) { in set_mode_densblk()
900 arg |= STm->default_blksize; in set_mode_densblk()
903 arg |= STp->block_size; in set_mode_densblk()
909 STm->default_blksize, STm->default_density); in set_mode_densblk()
911 return (-EINVAL); in set_mode_densblk()
924 retval = scsi_set_medium_removal(STp->device, in do_door_lock()
927 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; in do_door_lock()
929 STp->door_locked = ST_LOCK_FAILS; in do_door_lock()
940 STp->pos_unknown = 0; in reset_state()
942 STps = &(STp->ps[i]); in reset_state()
943 STps->rw = ST_IDLE; in reset_state()
944 STps->eof = ST_NOEOF; in reset_state()
945 STps->at_sm = 0; in reset_state()
946 STps->last_block_valid = 0; in reset_state()
947 STps->drv_block = -1; in reset_state()
948 STps->drv_file = -1; in reset_state()
950 if (STp->can_partitions) { in reset_state()
951 STp->partition = find_partition(STp); in reset_state()
952 if (STp->partition < 0) in reset_state()
953 STp->partition = 0; in reset_state()
954 STp->new_partition = STp->partition; in reset_state()
973 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in test_ready()
981 STp->long_timeout, MAX_READY_RETRIES, 1); in test_ready()
984 retval = (STp->buffer)->syscall_result; in test_ready()
988 if (cmdstatp->have_sense) { in test_ready()
990 scode = cmdstatp->sense_hdr.sense_key; in test_ready()
999 retval = (-EIO); in test_ready()
1007 retval = (-EINTR); in test_ready()
1014 if ((STp->device)->scsi_level >= SCSI_2 && in test_ready()
1015 cmdstatp->sense_hdr.asc == 0x3a) /* Check ASC */ in test_ready()
1024 retval = (STp->buffer)->syscall_result; in test_ready()
1045 unsigned short st_flags = filp->f_flags; in check_tape()
1052 STp->ready = ST_READY; in check_tape()
1054 if (mode != STp->current_mode) { in check_tape()
1056 STp->current_mode, mode); in check_tape()
1058 STp->current_mode = mode; in check_tape()
1060 STm = &(STp->modes[STp->current_mode]); in check_tape()
1062 saved_cleaning = STp->cleaning_req; in check_tape()
1063 STp->cleaning_req = 0; in check_tape()
1065 do_wait = ((filp->f_flags & O_NONBLOCK) == 0); in check_tape()
1072 STp->pos_unknown = 0; in check_tape()
1073 STp->partition = STp->new_partition = 0; in check_tape()
1074 if (STp->can_partitions) in check_tape()
1075 STp->nbr_partitions = 1; /* This guess will be updated later in check_tape()
1078 STps = &(STp->ps[i]); in check_tape()
1079 STps->rw = ST_IDLE; in check_tape()
1080 STps->eof = ST_NOEOF; in check_tape()
1081 STps->at_sm = 0; in check_tape()
1082 STps->last_block_valid = 0; in check_tape()
1083 STps->drv_block = 0; in check_tape()
1084 STps->drv_file = 0; in check_tape()
1089 STp->cleaning_req |= saved_cleaning; in check_tape()
1093 STp->ready = ST_NO_TAPE; in check_tape()
1095 STp->ready = ST_NOT_READY; in check_tape()
1097 STp->density = 0; /* Clear the erroneous "residue" */ in check_tape()
1098 STp->write_prot = 0; in check_tape()
1099 STp->block_size = 0; in check_tape()
1100 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in check_tape()
1101 STp->partition = STp->new_partition = 0; in check_tape()
1102 STp->door_locked = ST_UNLOCKED; in check_tape()
1107 if (STp->omit_blklims) in check_tape()
1108 STp->min_block = STp->max_block = (-1); in check_tape()
1114 STp->device->request_queue->rq_timeout, in check_tape()
1117 retval = (STp->buffer)->syscall_result; in check_tape()
1121 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) { in check_tape()
1122 STp->max_block = ((STp->buffer)->b_data[1] << 16) | in check_tape()
1123 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; in check_tape()
1124 STp->min_block = ((STp->buffer)->b_data[4] << 8) | in check_tape()
1125 (STp->buffer)->b_data[5]; in check_tape()
1126 if ( DEB( debugging || ) !STp->inited) in check_tape()
1128 "Block limits %d - %d bytes.\n", in check_tape()
1129 STp->min_block, STp->max_block); in check_tape()
1131 STp->min_block = STp->max_block = (-1); in check_tape()
1141 STp->device->request_queue->rq_timeout, in check_tape()
1144 retval = (STp->buffer)->syscall_result; in check_tape()
1148 if ((STp->buffer)->syscall_result != 0) { in check_tape()
1150 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */ in check_tape()
1151 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */ in check_tape()
1152 STp->drv_write_prot = 0; in check_tape()
1156 (STp->buffer)->b_data[0], in check_tape()
1157 (STp->buffer)->b_data[1], in check_tape()
1158 (STp->buffer)->b_data[2], in check_tape()
1159 (STp->buffer)->b_data[3]); in check_tape()
1161 if ((STp->buffer)->b_data[3] >= 8) { in check_tape()
1162 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7; in check_tape()
1163 STp->density = (STp->buffer)->b_data[4]; in check_tape()
1164 STp->block_size = (STp->buffer)->b_data[9] * 65536 + in check_tape()
1165 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11]; in check_tape()
1168 STp->density, in check_tape()
1169 (STp->buffer)->b_data[5] * 65536 + in check_tape()
1170 (STp->buffer)->b_data[6] * 256 + in check_tape()
1171 (STp->buffer)->b_data[7], in check_tape()
1172 STp->drv_buffer); in check_tape()
1174 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; in check_tape()
1175 if (!STp->drv_buffer && STp->immediate_filemark) { in check_tape()
1177 "non-buffered tape: disabling " in check_tape()
1179 STp->immediate_filemark = 0; in check_tape()
1184 STp->inited = 1; in check_tape()
1186 if (STp->block_size > 0) in check_tape()
1187 (STp->buffer)->buffer_blocks = in check_tape()
1188 (STp->buffer)->buffer_size / STp->block_size; in check_tape()
1190 (STp->buffer)->buffer_blocks = 1; in check_tape()
1191 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0; in check_tape()
1194 STp->block_size, (STp->buffer)->buffer_size, in check_tape()
1195 (STp->buffer)->buffer_blocks); in check_tape()
1197 if (STp->drv_write_prot) { in check_tape()
1198 STp->write_prot = 1; in check_tape()
1205 retval = (-EROFS); in check_tape()
1210 if (STp->can_partitions && STp->nbr_partitions < 1) { in check_tape()
1215 if ((STp->partition = find_partition(STp)) < 0) { in check_tape()
1216 retval = STp->partition; in check_tape()
1219 STp->new_partition = STp->partition; in check_tape()
1220 STp->nbr_partitions = 1; /* This guess will be updated when necessary */ in check_tape()
1224 STp->density_changed = STp->blksize_changed = 0; in check_tape()
1225 STp->compression_changed = 0; in check_tape()
1226 if (!(STm->defaults_for_writes) && in check_tape()
1230 if (STp->default_drvbuffer != 0xff) { in check_tape()
1231 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer)) in check_tape()
1235 STp->default_drvbuffer); in check_tape()
1250 int i, retval = (-EIO); in st_open()
1261 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); in st_open()
1264 return -ENXIO; in st_open()
1267 filp->private_data = STp; in st_open()
1270 if (STp->in_use) { in st_open()
1274 return (-EBUSY); in st_open()
1277 STp->in_use = 1; in st_open()
1279 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; in st_open()
1281 if (scsi_autopm_get_device(STp->device) < 0) { in st_open()
1282 retval = -EIO; in st_open()
1286 if (!scsi_block_when_processing_errors(STp->device)) { in st_open()
1287 retval = (-ENXIO); in st_open()
1292 if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) { in st_open()
1295 retval = (-EOVERFLOW); in st_open()
1299 (STp->buffer)->cleared = 0; in st_open()
1300 (STp->buffer)->writing = 0; in st_open()
1301 (STp->buffer)->syscall_result = 0; in st_open()
1303 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY); in st_open()
1305 STp->dirty = 0; in st_open()
1307 STps = &(STp->ps[i]); in st_open()
1308 STps->rw = ST_IDLE; in st_open()
1310 STp->try_dio_now = STp->try_dio; in st_open()
1311 STp->recover_count = 0; in st_open()
1312 DEB( STp->nbr_waits = STp->nbr_finished = 0; in st_open()
1313 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) in st_open()
1318 if ((filp->f_flags & O_NONBLOCK) == 0 && in st_open()
1320 if (STp->ready == NO_TAPE) in st_open()
1321 retval = (-ENOMEDIUM); in st_open()
1323 retval = (-EIO); in st_open()
1329 normalize_buffer(STp->buffer); in st_open()
1331 STp->in_use = 0; in st_open()
1334 scsi_autopm_put_device(STp->device); in st_open()
1347 struct scsi_tape *STp = filp->private_data; in st_flush()
1348 struct st_modedef *STm = &(STp->modes[STp->current_mode]); in st_flush()
1349 struct st_partstat *STps = &(STp->ps[STp->partition]); in st_flush()
1354 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1356 if (result != 0 && result != (-ENOSPC)) in st_flush()
1360 if (STp->can_partitions && in st_flush()
1368 DEBC( if (STp->nbr_requests) in st_flush()
1371 "pages %d.\n", STp->nbr_requests, STp->nbr_dio, in st_flush()
1372 STp->nbr_pages)); in st_flush()
1374 if (STps->rw == ST_WRITING && !STp->pos_unknown) { in st_flush()
1375 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_flush()
1379 STp->nbr_waits, STp->nbr_finished); in st_flush()
1383 if (STp->immediate_filemark) in st_flush()
1385 cmd[4] = 1 + STp->two_fm; in st_flush()
1388 STp->device->request_queue->rq_timeout, in st_flush()
1391 result = (STp->buffer)->syscall_result; in st_flush()
1395 if (STp->buffer->syscall_result == 0 || in st_flush()
1396 (cmdstatp->have_sense && !cmdstatp->deferred && in st_flush()
1397 (cmdstatp->flags & SENSE_EOM) && in st_flush()
1398 (cmdstatp->sense_hdr.sense_key == NO_SENSE || in st_flush()
1399 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) && in st_flush()
1400 (!cmdstatp->remainder_valid || cmdstatp->uremainder64 == 0))) { in st_flush()
1404 if (STps->drv_file >= 0) in st_flush()
1405 STps->drv_file++; in st_flush()
1406 STps->drv_block = 0; in st_flush()
1407 if (STp->two_fm) in st_flush()
1409 STps->eof = ST_FM; in st_flush()
1417 result = (-EIO); in st_flush()
1421 } else if (!STp->rew_at_close) { in st_flush()
1422 STps = &(STp->ps[STp->partition]); in st_flush()
1423 if (!STm->sysv || STps->rw != ST_READING) { in st_flush()
1424 if (STp->can_bsr) in st_flush()
1426 else if (STps->eof == ST_FM_HIT) { in st_flush()
1429 if (STps->drv_file >= 0) in st_flush()
1430 STps->drv_file++; in st_flush()
1431 STps->drv_block = 0; in st_flush()
1432 STps->eof = ST_FM; in st_flush()
1434 STps->eof = ST_NOEOF; in st_flush()
1436 } else if ((STps->eof == ST_NOEOF && in st_flush()
1438 STps->eof == ST_FM_HIT) { in st_flush()
1439 if (STps->drv_file >= 0) in st_flush()
1440 STps->drv_file++; in st_flush()
1441 STps->drv_block = 0; in st_flush()
1442 STps->eof = ST_FM; in st_flush()
1447 if (STp->rew_at_close) { in st_flush()
1460 struct scsi_tape *STp = filp->private_data; in st_release()
1462 if (STp->door_locked == ST_LOCKED_AUTO) in st_release()
1465 normalize_buffer(STp->buffer); in st_release()
1467 STp->in_use = 0; in st_release()
1469 scsi_autopm_put_device(STp->device); in st_release()
1486 if (!scsi_block_when_processing_errors(STp->device)) { in rw_checks()
1487 retval = (-ENXIO); in rw_checks()
1491 if (STp->ready != ST_READY) { in rw_checks()
1492 if (STp->ready == ST_NO_TAPE) in rw_checks()
1493 retval = (-ENOMEDIUM); in rw_checks()
1495 retval = (-EIO); in rw_checks()
1499 if (! STp->modes[STp->current_mode].defined) { in rw_checks()
1500 retval = (-ENXIO); in rw_checks()
1509 if (STp->pos_unknown) { in rw_checks()
1510 retval = (-EIO); in rw_checks()
1518 if (!STp->in_use) { in rw_checks()
1521 retval = (-EIO); in rw_checks()
1525 if (STp->can_partitions && in rw_checks()
1529 if (STp->block_size == 0 && STp->max_block > 0 && in rw_checks()
1530 (count < STp->min_block || count > STp->max_block)) { in rw_checks()
1531 retval = (-EINVAL); in rw_checks()
1535 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in rw_checks()
1537 STp->door_locked = ST_LOCKED_AUTO; in rw_checks()
1548 struct st_buffer *STbp = STp->buffer; in setup_buffering()
1551 i = STp->try_dio_now && try_rdio; in setup_buffering()
1553 i = STp->try_dio_now && try_wdio; in setup_buffering()
1556 STp->device->request_queue)) == 0) { in setup_buffering()
1557 i = sgl_map_user_pages(STbp, STbp->use_sg, (unsigned long)buf, in setup_buffering()
1560 STbp->do_dio = i; in setup_buffering()
1561 STbp->buffer_bytes = 0; /* can be used as transfer counter */ in setup_buffering()
1564 STbp->do_dio = 0; /* fall back to buffering with any error */ in setup_buffering()
1565 STbp->sg_segs = STbp->do_dio; in setup_buffering()
1567 if (STbp->do_dio) { in setup_buffering()
1568 STp->nbr_dio++; in setup_buffering()
1569 STp->nbr_pages += STbp->do_dio; in setup_buffering()
1573 STbp->do_dio = 0; in setup_buffering()
1574 DEB( STp->nbr_requests++; ) in setup_buffering()
1576 if (!STbp->do_dio) { in setup_buffering()
1577 if (STp->block_size) in setup_buffering()
1578 bufsize = STp->block_size > st_fixed_buffer_size ? in setup_buffering()
1579 STp->block_size : st_fixed_buffer_size; in setup_buffering()
1584 if (is_read && STp->sili && !STbp->cleared) in setup_buffering()
1588 if (bufsize > STbp->buffer_size && in setup_buffering()
1589 !enlarge_buffer(STbp, bufsize, STp->restr_dma)) { in setup_buffering()
1593 retval = (-EOVERFLOW); in setup_buffering()
1596 if (STp->block_size) in setup_buffering()
1597 STbp->buffer_blocks = bufsize / STp->block_size; in setup_buffering()
1610 STbp = STp->buffer; in release_buffering()
1611 if (STbp->do_dio) { in release_buffering()
1612 sgl_unmap_user_pages(STbp, STbp->do_dio, is_read); in release_buffering()
1613 STbp->do_dio = 0; in release_buffering()
1614 STbp->sg_segs = 0; in release_buffering()
1631 struct scsi_tape *STp = filp->private_data; in st_write()
1636 if (mutex_lock_interruptible(&STp->lock)) in st_write()
1637 return -ERESTARTSYS; in st_write()
1644 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_write()
1647 retval = (-EINVAL); in st_write()
1651 STm = &(STp->modes[STp->current_mode]); in st_write()
1652 STps = &(STp->ps[STp->partition]); in st_write()
1654 if (STp->write_prot) { in st_write()
1655 retval = (-EACCES); in st_write()
1660 if (STps->rw == ST_READING) { in st_write()
1664 STps->rw = ST_WRITING; in st_write()
1665 } else if (STps->rw != ST_WRITING && in st_write()
1666 STps->drv_file == 0 && STps->drv_block == 0) { in st_write()
1669 if (STm->default_compression != ST_DONT_TOUCH && in st_write()
1670 !(STp->compression_changed)) { in st_write()
1671 if (st_compression(STp, (STm->default_compression == ST_YES))) { in st_write()
1675 retval = (-EINVAL); in st_write()
1682 STbp = STp->buffer; in st_write()
1685 if (i == -ENOSPC) in st_write()
1686 STps->eof = ST_EOM_OK; in st_write()
1688 STps->eof = ST_EOM_ERROR; in st_write()
1691 if (STps->eof == ST_EOM_OK) { in st_write()
1692 STps->eof = ST_EOD_1; /* allow next write */ in st_write()
1693 retval = (-ENOSPC); in st_write()
1696 else if (STps->eof == ST_EOM_ERROR) { in st_write()
1697 retval = (-EIO); in st_write()
1703 if (STp->block_size != 0 && in st_write()
1704 !STbp->do_dio && in st_write()
1706 copy_from_user(&i, buf + count - 1, 1) != 0)) { in st_write()
1707 retval = (-EFAULT); in st_write()
1719 cmd[1] = (STp->block_size != 0); in st_write()
1721 STps->rw = ST_WRITING; in st_write()
1726 if (STbp->do_dio) { in st_write()
1730 if (STp->block_size == 0) in st_write()
1733 do_count = STbp->buffer_blocks * STp->block_size - in st_write()
1734 STbp->buffer_bytes; in st_write()
1745 count -= do_count; in st_write()
1748 async_write = STp->block_size == 0 && !STbp->do_dio && in st_write()
1749 STm->do_async_writes && STps->eof < ST_EOM_OK; in st_write()
1751 if (STp->block_size != 0 && STm->do_buffer_writes && in st_write()
1752 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK && in st_write()
1753 STbp->buffer_bytes < STbp->buffer_size) { in st_write()
1754 STp->dirty = 1; in st_write()
1761 if (STp->block_size == 0) in st_write()
1764 if (!STbp->do_dio) in st_write()
1765 blks = STbp->buffer_bytes; in st_write()
1768 blks /= STp->block_size; in st_write()
1769 transfer = blks * STp->block_size; in st_write()
1776 STp->device->request_queue->rq_timeout, in st_write()
1779 retval = STbp->syscall_result; in st_write()
1782 if (async_write && !STbp->syscall_result) { in st_write()
1783 STbp->writing = transfer; in st_write()
1784 STp->dirty = !(STbp->writing == in st_write()
1785 STbp->buffer_bytes); in st_write()
1787 DEB( STp->write_pending = 1; ) in st_write()
1791 if (STbp->syscall_result != 0) { in st_write()
1792 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in st_write()
1795 if (cmdstatp->have_sense && (cmdstatp->flags & SENSE_EOM)) { in st_write()
1796 scode = cmdstatp->sense_hdr.sense_key; in st_write()
1797 if (cmdstatp->remainder_valid) in st_write()
1798 undone = (int)cmdstatp->uremainder64; in st_write()
1799 else if (STp->block_size == 0 && in st_write()
1804 if (STp->block_size != 0) in st_write()
1805 undone *= STp->block_size; in st_write()
1809 b_point -= undone; in st_write()
1810 do_count -= undone; in st_write()
1811 if (STp->block_size) in st_write()
1812 blks = (transfer - undone) / STp->block_size; in st_write()
1813 STps->eof = ST_EOM_OK; in st_write()
1818 if (STp->block_size == 0 || in st_write()
1820 retval = (-ENOSPC); /* EOM within current request */ in st_write()
1827 if (!retry_eot && !cmdstatp->deferred && in st_write()
1829 move_buffer_data(STp->buffer, transfer - undone); in st_write()
1831 if (STps->drv_block >= 0) { in st_write()
1832 STps->drv_block += (transfer - undone) / in st_write()
1833 STp->block_size; in st_write()
1835 STps->eof = ST_EOM_OK; in st_write()
1839 STp->buffer->buffer_bytes); in st_write()
1845 count -= do_count; in st_write()
1847 STps->eof = ST_EOM_ERROR; in st_write()
1848 STps->drv_block = (-1); /* Too cautious? */ in st_write()
1849 retval = (-EIO); /* EOM for old data */ in st_write()
1856 STps->drv_block = (-1); /* Too cautious? */ in st_write()
1857 retval = STbp->syscall_result; in st_write()
1862 if (STps->drv_block >= 0) { in st_write()
1863 if (STp->block_size == 0) in st_write()
1864 STps->drv_block += (do_count > 0); in st_write()
1866 STps->drv_block += blks; in st_write()
1869 STbp->buffer_bytes = 0; in st_write()
1870 STp->dirty = 0; in st_write()
1874 retval = total - count; in st_write()
1879 if (STps->eof == ST_EOD_1) in st_write()
1880 STps->eof = ST_EOM_OK; in st_write()
1881 else if (STps->eof != ST_EOM_OK) in st_write()
1882 STps->eof = ST_NOEOF; in st_write()
1883 retval = total - count; in st_write()
1889 mutex_unlock(&STp->lock); in st_write()
1914 STm = &(STp->modes[STp->current_mode]); in read_tape()
1915 STps = &(STp->ps[STp->partition]); in read_tape()
1916 if (STps->eof == ST_FM_HIT) in read_tape()
1918 STbp = STp->buffer; in read_tape()
1920 if (STp->block_size == 0) in read_tape()
1923 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) { in read_tape()
1924 blks = (STp->buffer)->buffer_blocks; in read_tape()
1925 bytes = blks * STp->block_size; in read_tape()
1928 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size) in read_tape()
1929 bytes = (STp->buffer)->buffer_size; in read_tape()
1930 blks = bytes / STp->block_size; in read_tape()
1931 bytes = blks * STp->block_size; in read_tape()
1937 cmd[1] = (STp->block_size != 0); in read_tape()
1938 if (!cmd[1] && STp->sili) in read_tape()
1946 STp->device->request_queue->rq_timeout, in read_tape()
1951 return STbp->syscall_result; in read_tape()
1953 STbp->read_pointer = 0; in read_tape()
1954 STps->at_sm = 0; in read_tape()
1957 if (STbp->syscall_result) { in read_tape()
1958 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; in read_tape()
1963 SRpnt->sense[0], SRpnt->sense[1], in read_tape()
1964 SRpnt->sense[2], SRpnt->sense[3], in read_tape()
1965 SRpnt->sense[4], SRpnt->sense[5], in read_tape()
1966 SRpnt->sense[6], SRpnt->sense[7]); in read_tape()
1967 if (cmdstatp->have_sense) { in read_tape()
1969 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK) in read_tape()
1970 cmdstatp->flags &= 0xcf; /* No need for EOM in this case */ in read_tape()
1972 if (cmdstatp->flags != 0) { /* EOF, EOM, or ILI */ in read_tape()
1974 if (cmdstatp->remainder_valid) in read_tape()
1975 transfer = (int)cmdstatp->uremainder64; in read_tape()
1978 if (cmdstatp->sense_hdr.sense_key == MEDIUM_ERROR) { in read_tape()
1979 if (STp->block_size == 0) in read_tape()
1982 cmdstatp->flags &= ~SENSE_ILI; in read_tape()
1985 if (cmdstatp->flags & SENSE_ILI) { /* ILI */ in read_tape()
1986 if (STp->block_size == 0 && in read_tape()
1992 bytes - transfer, in read_tape()
1994 if (STps->drv_block >= 0) in read_tape()
1995 STps->drv_block += 1; in read_tape()
1996 STbp->buffer_bytes = 0; in read_tape()
1997 return (-ENOMEM); in read_tape()
1998 } else if (STp->block_size == 0) { in read_tape()
1999 STbp->buffer_bytes = bytes - transfer; in read_tape()
2007 if (STps->drv_block >= 0) in read_tape()
2008 STps->drv_block += blks - transfer + 1; in read_tape()
2010 return (-EIO); in read_tape()
2013 STbp->buffer_bytes = (blks - transfer) * in read_tape()
2014 STp->block_size; in read_tape()
2019 STbp->buffer_bytes); in read_tape()
2020 if (STps->drv_block >= 0) in read_tape()
2021 STps->drv_block += 1; in read_tape()
2023 return (-EIO); in read_tape()
2025 } else if (cmdstatp->flags & SENSE_FMK) { /* FM overrides EOM */ in read_tape()
2026 if (STps->eof != ST_FM_HIT) in read_tape()
2027 STps->eof = ST_FM_HIT; in read_tape()
2029 STps->eof = ST_EOD_2; in read_tape()
2030 if (STp->block_size == 0) in read_tape()
2031 STbp->buffer_bytes = 0; in read_tape()
2033 STbp->buffer_bytes = in read_tape()
2034 bytes - transfer * STp->block_size; in read_tape()
2037 STbp->buffer_bytes); in read_tape()
2038 } else if (cmdstatp->flags & SENSE_EOM) { in read_tape()
2039 if (STps->eof == ST_FM) in read_tape()
2040 STps->eof = ST_EOD_1; in read_tape()
2042 STps->eof = ST_EOM_OK; in read_tape()
2043 if (STp->block_size == 0) in read_tape()
2044 STbp->buffer_bytes = bytes - transfer; in read_tape()
2046 STbp->buffer_bytes = in read_tape()
2047 bytes - transfer * STp->block_size; in read_tape()
2051 STbp->buffer_bytes); in read_tape()
2057 STps->drv_block = (-1); in read_tape()
2058 if (STps->eof == ST_FM && in read_tape()
2059 cmdstatp->sense_hdr.sense_key == BLANK_CHECK) { in read_tape()
2063 STps->eof = ST_EOD_2; /* First BLANK_CHECK after FM */ in read_tape()
2065 retval = (-EIO); in read_tape()
2068 if (STbp->buffer_bytes < 0) /* Caused by bogus sense data */ in read_tape()
2069 STbp->buffer_bytes = 0; in read_tape()
2072 else { /* Non-extended sense */ in read_tape()
2073 retval = STbp->syscall_result; in read_tape()
2079 STbp->buffer_bytes = bytes; in read_tape()
2080 if (STp->sili) /* In fixed block mode residual is always zero here */ in read_tape()
2081 STbp->buffer_bytes -= STp->buffer->cmdstat.residual; in read_tape()
2084 if (STps->drv_block >= 0) { in read_tape()
2085 if (STp->block_size == 0) in read_tape()
2086 STps->drv_block++; in read_tape()
2088 STps->drv_block += STbp->buffer_bytes / STp->block_size; in read_tape()
2103 struct scsi_tape *STp = filp->private_data; in st_read()
2106 struct st_buffer *STbp = STp->buffer; in st_read()
2108 if (mutex_lock_interruptible(&STp->lock)) in st_read()
2109 return -ERESTARTSYS; in st_read()
2115 STm = &(STp->modes[STp->current_mode]); in st_read()
2116 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in st_read()
2117 if (!STm->do_read_ahead) { in st_read()
2118 retval = (-EINVAL); /* Read must be integral number of blocks */ in st_read()
2121 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */ in st_read()
2124 STps = &(STp->ps[STp->partition]); in st_read()
2125 if (STps->rw == ST_WRITING) { in st_read()
2129 STps->rw = ST_READING; in st_read()
2132 if (debugging && STps->eof != ST_NOEOF) in st_read()
2135 STps->eof, STbp->buffer_bytes); in st_read()
2141 do_dio = STbp->do_dio; in st_read()
2143 if (STbp->buffer_bytes == 0 && in st_read()
2144 STps->eof >= ST_EOD_1) { in st_read()
2145 if (STps->eof < ST_EOD) { in st_read()
2146 STps->eof += 1; in st_read()
2150 retval = (-EIO); /* EOM or Blank Check */ in st_read()
2159 copy_from_user(&i, buf + count - 1, 1) != 0 || in st_read()
2160 copy_to_user(buf + count - 1, &i, 1) != 0) { in st_read()
2161 retval = (-EFAULT); in st_read()
2166 STps->rw = ST_READING; in st_read()
2173 if (STbp->buffer_bytes == 0) { in st_read()
2174 special = read_tape(STp, count - total, &SRpnt); in st_read()
2182 if (STbp->buffer_bytes > 0) { in st_read()
2184 if (debugging && STps->eof != ST_NOEOF) in st_read()
2187 STps->eof, STbp->buffer_bytes, in st_read()
2188 (int)(count - total)); in st_read()
2190 transfer = STbp->buffer_bytes < count - total ? in st_read()
2191 STbp->buffer_bytes : count - total; in st_read()
2203 if (STp->block_size == 0) in st_read()
2211 if (STps->eof == ST_FM_HIT) { in st_read()
2212 STps->eof = ST_FM; in st_read()
2213 STps->drv_block = 0; in st_read()
2214 if (STps->drv_file >= 0) in st_read()
2215 STps->drv_file++; in st_read()
2216 } else if (STps->eof == ST_EOD_1) { in st_read()
2217 STps->eof = ST_EOD_2; in st_read()
2218 STps->drv_block = 0; in st_read()
2219 if (STps->drv_file >= 0) in st_read()
2220 STps->drv_file++; in st_read()
2221 } else if (STps->eof == ST_EOD_2) in st_read()
2222 STps->eof = ST_EOD; in st_read()
2223 } else if (STps->eof == ST_FM) in st_read()
2224 STps->eof = ST_NOEOF; in st_read()
2234 STbp->buffer_bytes = 0; in st_read()
2236 mutex_unlock(&STp->lock); in st_read()
2251 STp->current_mode, STm->do_buffer_writes, in DEB()
2252 STm->do_async_writes, STm->do_read_ahead); in DEB()
2256 STp->can_bsr, STp->two_fm, STp->fast_mteom, in DEB()
2257 STp->do_auto_lock); in DEB()
2261 STm->defaults_for_writes, STp->omit_blklims, in DEB()
2262 STp->can_partitions, STp->scsi2_logical); in DEB()
2266 STm->sysv, STp->immediate, STp->sili, in DEB()
2267 STp->immediate_filemark); in DEB()
2282 STm = &(STp->modes[STp->current_mode]);
2283 if (!STm->defined) {
2284 cd0 = STm->cdevs[0];
2285 cd1 = STm->cdevs[1];
2286 d0 = STm->devs[0];
2287 d1 = STm->devs[1];
2288 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2289 STm->cdevs[0] = cd0;
2290 STm->cdevs[1] = cd1;
2291 STm->devs[0] = d0;
2292 STm->devs[1] = d1;
2295 STp->current_mode);
2300 STm->do_buffer_writes = (options & MT_ST_BUFFER_WRITES) != 0;
2301 STm->do_async_writes = (options & MT_ST_ASYNC_WRITES) != 0;
2302 STm->defaults_for_writes = (options & MT_ST_DEF_WRITES) != 0;
2303 STm->do_read_ahead = (options & MT_ST_READ_AHEAD) != 0;
2304 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2305 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2306 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2307 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2308 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2309 if ((STp->device)->scsi_level >= SCSI_2)
2310 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2311 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2312 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2313 STp->immediate_filemark = (options & MT_ST_NOWAIT_EOF) != 0;
2314 STm->sysv = (options & MT_ST_SYSV) != 0;
2315 STp->sili = (options & MT_ST_SILI) != 0;
2321 STm->do_buffer_writes = value;
2323 STm->do_async_writes = value;
2325 STm->defaults_for_writes = value;
2327 STm->do_read_ahead = value;
2329 STp->two_fm = value;
2331 STp->fast_mteom = value;
2333 STp->do_auto_lock = value;
2335 STp->can_bsr = value;
2337 STp->omit_blklims = value;
2338 if ((STp->device)->scsi_level >= SCSI_2 &&
2340 STp->can_partitions = value;
2342 STp->scsi2_logical = value;
2344 STp->immediate = value;
2346 STp->immediate_filemark = value;
2348 STm->sysv = value;
2350 STp->sili = value;
2360 STm->default_blksize = (-1);
2363 STm->default_blksize = value;
2365 "%d bytes.\n", STm->default_blksize);
2366 if (STp->ready == ST_READY) {
2367 STp->blksize_changed = 0;
2374 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2378 blk_queue_rq_timeout(STp->device->request_queue,
2388 return (-EINVAL);
2389 STp->cln_mode = value;
2390 STp->cln_sense_mask = (options >> 8) & 0xff;
2391 STp->cln_sense_value = (options >> 16) & 0xff;
2394 value, STp->cln_sense_mask, STp->cln_sense_value);
2400 STm->default_density = (-1);
2404 STm->default_density = value & 0xff;
2406 STm->default_density);
2407 if (STp->ready == ST_READY) {
2408 STp->density_changed = 0;
2414 STp->default_drvbuffer = 0xff;
2418 STp->default_drvbuffer = value & 7;
2421 STp->default_drvbuffer);
2422 if (STp->ready == ST_READY)
2423 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2427 STm->default_compression = ST_DONT_TOUCH;
2432 STp->c_algo = (value & 0xff00) >> 8;
2435 STp->c_algo);
2438 STm->default_compression = (value & 1 ? ST_YES : ST_NO);
2442 if (STp->ready == ST_READY) {
2443 STp->compression_changed = 0;
2444 st_compression(STp, (STm->default_compression == ST_YES));
2450 return (-EIO);
2490 STp->device->request_queue->rq_timeout, 0, 1); in read_mode_page()
2492 return (STp->buffer)->syscall_result; in read_mode_page()
2496 return STp->buffer->syscall_result; in read_mode_page()
2501 in the buffer is correctly formatted. The long timeout is used if slow is non-zero. */
2512 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH]; in write_mode_page()
2513 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2; in write_mode_page()
2516 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0; in write_mode_page()
2517 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0; in write_mode_page()
2518 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; in write_mode_page()
2519 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; in write_mode_page()
2522 STp->long_timeout : STp->device->request_queue->rq_timeout; in write_mode_page()
2526 return (STp->buffer)->syscall_result; in write_mode_page()
2530 return STp->buffer->syscall_result; in write_mode_page()
2547 The block descriptors are read and written because Sony SDT-7000 does not
2555 unsigned char *b_data = (STp->buffer)->b_data; in st_compression()
2557 if (STp->ready != ST_READY) in st_compression()
2558 return (-EIO); in st_compression()
2564 return (-EIO); in st_compression()
2574 return (-EIO); in st_compression()
2580 if (STp->c_algo != 0) in st_compression()
2581 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo; in st_compression()
2585 if (STp->c_algo != 0) in st_compression()
2592 return (-EIO); in st_compression()
2596 STp->compression_changed = 1; in st_compression()
2604 int retval = (-EIO), timeout; in do_load_unload()
2609 if (STp->ready != ST_READY && !load_code) { in do_load_unload()
2610 if (STp->ready == ST_NO_TAPE) in do_load_unload()
2611 return (-ENOMEDIUM); in do_load_unload()
2613 return (-EIO); in do_load_unload()
2627 load_code - MT_ST_HPLOADER_OFFSET); in do_load_unload()
2628 cmd[3] = load_code - MT_ST_HPLOADER_OFFSET; /* MediaID field of C1553A */ in do_load_unload()
2630 if (STp->immediate) { in do_load_unload()
2632 timeout = STp->device->request_queue->rq_timeout; in do_load_unload()
2635 timeout = STp->long_timeout; in do_load_unload()
2647 return (STp->buffer)->syscall_result; in do_load_unload()
2649 retval = (STp->buffer)->syscall_result; in do_load_unload()
2655 STp->rew_at_close = 0; in do_load_unload()
2656 STp->ready = ST_NO_TAPE; in do_load_unload()
2659 STp->rew_at_close = STp->autorew_dev; in do_load_unload()
2666 STps = &(STp->ps[STp->partition]); in do_load_unload()
2667 STps->drv_file = STps->drv_block = (-1); in do_load_unload()
2685 sc = -sc; in deb_space_print()
2709 WARN_ON(STp->buffer->do_dio != 0); in st_int_ioctl()
2710 if (STp->ready != ST_READY) { in st_int_ioctl()
2711 if (STp->ready == ST_NO_TAPE) in st_int_ioctl()
2712 return (-ENOMEDIUM); in st_int_ioctl()
2714 return (-EIO); in st_int_ioctl()
2716 timeout = STp->long_timeout; in st_int_ioctl()
2717 STps = &(STp->ps[STp->partition]); in st_int_ioctl()
2718 fileno = STps->drv_file; in st_int_ioctl()
2719 blkno = STps->drv_block; in st_int_ioctl()
2720 at_sm = STps->at_sm; in st_int_ioctl()
2745 ltmp = (-arg); in st_int_ioctl()
2751 fileno -= arg; in st_int_ioctl()
2752 blkno = (-1); /* We can't know the block number */ in st_int_ioctl()
2769 ltmp = (-arg); in st_int_ioctl()
2775 blkno -= arg; in st_int_ioctl()
2786 blkno = fileno = (-1); in st_int_ioctl()
2793 ltmp = (-arg); in st_int_ioctl()
2799 blkno = fileno = (-1); in st_int_ioctl()
2806 if (STp->write_prot) in st_int_ioctl()
2807 return (-EACCES); in st_int_ioctl()
2812 (cmd_in == MTWEOF && STp->immediate_filemark)) in st_int_ioctl()
2817 timeout = STp->device->request_queue->rq_timeout; in st_int_ioctl()
2839 if (STp->immediate) { in st_int_ioctl()
2841 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()
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()
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()
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).
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()
3438 result = -EINVAL; in partition_tape()
3493 result = (-EIO); in partition_tape()
3508 struct scsi_tape *STp = file->private_data; in st_ioctl_common()
3512 if (mutex_lock_interruptible(&STp->lock)) in st_ioctl_common()
3513 return -ERESTARTSYS; in st_ioctl_common()
3516 if (debugging && !STp->in_use) { in st_ioctl_common()
3518 retval = (-EIO); in st_ioctl_common()
3522 STm = &(STp->modes[STp->current_mode]); in st_ioctl_common()
3523 STps = &(STp->ps[STp->partition]); in st_ioctl_common()
3531 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in, in st_ioctl_common()
3532 file->f_flags & O_NDELAY); in st_ioctl_common()
3543 retval = (-EINVAL); in st_ioctl_common()
3549 retval = (-EFAULT); in st_ioctl_common()
3556 retval = (-EPERM); in st_ioctl_common()
3559 if (!STm->defined && in st_ioctl_common()
3562 retval = (-ENXIO); in st_ioctl_common()
3566 if (!STp->pos_unknown) { in st_ioctl_common()
3568 if (STps->eof == ST_FM_HIT) { in st_ioctl_common()
3571 mtc.mt_count -= 1; in st_ioctl_common()
3572 if (STps->drv_file >= 0) in st_ioctl_common()
3573 STps->drv_file += 1; in st_ioctl_common()
3576 if (STps->drv_file >= 0) in st_ioctl_common()
3577 STps->drv_file += 1; in st_ioctl_common()
3584 i = !STp->can_partitions || in st_ioctl_common()
3585 (STp->new_partition != STp->partition); in st_ioctl_common()
3599 if (STps->rw == ST_WRITING && in st_ioctl_common()
3610 STps->rw = ST_IDLE; in st_ioctl_common()
3625 retval = (-EIO); in st_ioctl_common()
3630 STp->device->was_reset = 0; in st_ioctl_common()
3636 STps->rw = ST_IDLE; /* Prevent automatic WEOF and fsf */ in st_ioctl_common()
3638 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in st_ioctl_common()
3648 if (!STp->can_partitions || in st_ioctl_common()
3650 retval = (-EINVAL); in st_ioctl_common()
3653 if (mtc.mt_count >= STp->nbr_partitions && in st_ioctl_common()
3654 (STp->nbr_partitions = nbr_partitions(STp)) < 0) { in st_ioctl_common()
3655 retval = (-EIO); in st_ioctl_common()
3658 if (mtc.mt_count >= STp->nbr_partitions) { in st_ioctl_common()
3659 retval = (-EINVAL); in st_ioctl_common()
3662 STp->new_partition = mtc.mt_count; in st_ioctl_common()
3668 if (!STp->can_partitions) { in st_ioctl_common()
3669 retval = (-EINVAL); in st_ioctl_common()
3683 STp->ps[i].rw = ST_IDLE; in st_ioctl_common()
3684 STp->ps[i].at_sm = 0; in st_ioctl_common()
3685 STp->ps[i].last_block_valid = 0; in st_ioctl_common()
3687 STp->partition = STp->new_partition = 0; in st_ioctl_common()
3688 STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1; in st_ioctl_common()
3689 STps->drv_block = STps->drv_file = 0; in st_ioctl_common()
3695 i = set_location(STp, mtc.mt_count, STp->new_partition, 0); in st_ioctl_common()
3696 if (!STp->can_partitions) in st_ioctl_common()
3697 STp->ps[0].rw = ST_IDLE; in st_ioctl_common()
3717 if (STp->can_partitions && STp->ready == ST_READY && in st_ioctl_common()
3729 if (!STm->defined) { in st_ioctl_common()
3730 retval = (-ENXIO); in st_ioctl_common()
3738 if (STp->can_partitions && in st_ioctl_common()
3748 retval = (-EINVAL); in st_ioctl_common()
3752 mt_status.mt_type = STp->tape_type; in st_ioctl_common()
3754 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in st_ioctl_common()
3755 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in st_ioctl_common()
3756 mt_status.mt_blkno = STps->drv_block; in st_ioctl_common()
3757 mt_status.mt_fileno = STps->drv_file; in st_ioctl_common()
3758 if (STp->block_size != 0) { in st_ioctl_common()
3759 if (STps->rw == ST_WRITING) in st_ioctl_common()
3761 (STp->buffer)->buffer_bytes / STp->block_size; in st_ioctl_common()
3762 else if (STps->rw == ST_READING) in st_ioctl_common()
3763 mt_status.mt_blkno -= in st_ioctl_common()
3764 ((STp->buffer)->buffer_bytes + in st_ioctl_common()
3765 STp->block_size - 1) / STp->block_size; in st_ioctl_common()
3769 if (STp->drv_write_prot) in st_ioctl_common()
3777 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT); in st_ioctl_common()
3778 mt_status.mt_resid = STp->partition; in st_ioctl_common()
3779 if (STps->eof == ST_EOM_OK || STps->eof == ST_EOM_ERROR) in st_ioctl_common()
3781 else if (STps->eof >= ST_EOM_OK) in st_ioctl_common()
3783 if (STp->density == 1) in st_ioctl_common()
3785 else if (STp->density == 2) in st_ioctl_common()
3787 else if (STp->density == 3) in st_ioctl_common()
3789 if (STp->ready == ST_READY) in st_ioctl_common()
3791 if (STp->ready == ST_NO_TAPE) in st_ioctl_common()
3793 if (STps->at_sm) in st_ioctl_common()
3795 if (STm->do_async_writes || in st_ioctl_common()
3796 (STm->do_buffer_writes && STp->block_size != 0) || in st_ioctl_common()
3797 STp->drv_buffer != 0) in st_ioctl_common()
3799 if (STp->cleaning_req) in st_ioctl_common()
3806 STp->recover_reg = 0; /* Clear after read */ in st_ioctl_common()
3812 retval = (-EINVAL); in st_ioctl_common()
3823 mutex_unlock(&STp->lock); in st_ioctl_common()
3827 retval = scsi_ioctl(STp->device, cmd_in, p); in st_ioctl_common()
3829 STp->rew_at_close = 0; in st_ioctl_common()
3830 STp->ready = ST_NO_TAPE; in st_ioctl_common()
3843 i = -EPERM; in st_ioctl_common()
3845 i = scsi_cmd_ioctl(STp->disk->queue, STp->disk, in st_ioctl_common()
3846 file->f_mode, cmd_in, p); in st_ioctl_common()
3847 if (i != -ENOTTY) in st_ioctl_common()
3851 return -ENOTTY; in st_ioctl_common()
3854 mutex_unlock(&STp->lock); in st_ioctl_common()
3861 struct scsi_tape *STp = file->private_data; in st_ioctl()
3865 if (ret != -ENOTTY) in st_ioctl()
3868 return scsi_ioctl(STp->device, cmd_in, p); in st_ioctl()
3875 struct scsi_tape *STp = file->private_data; in st_compat_ioctl()
3887 if (ret != -ENOTTY) in st_compat_ioctl()
3890 return scsi_compat_ioctl(STp->device, cmd_in, p); in st_compat_ioctl()
3907 tb->frp_segs = 0; in new_tape_buffer()
3908 tb->use_sg = max_sg; in new_tape_buffer()
3909 tb->dma = need_dma; in new_tape_buffer()
3910 tb->buffer_size = 0; in new_tape_buffer()
3912 tb->reserved_pages = kcalloc(max_sg, sizeof(struct page *), in new_tape_buffer()
3914 if (!tb->reserved_pages) { in new_tape_buffer()
3931 if (new_size <= STbuffer->buffer_size) in enlarge_buffer()
3934 if (STbuffer->buffer_size <= PAGE_SIZE) in enlarge_buffer()
3937 max_segs = STbuffer->use_sg; in enlarge_buffer()
3943 if (STbuffer->cleared) in enlarge_buffer()
3946 if (STbuffer->frp_segs) { in enlarge_buffer()
3947 order = STbuffer->reserved_page_order; in enlarge_buffer()
3955 STbuffer->reserved_page_order = order; in enlarge_buffer()
3964 for (segs = STbuffer->frp_segs, got = STbuffer->buffer_size; in enlarge_buffer()
3970 DEB(STbuffer->buffer_size = got); in enlarge_buffer()
3975 STbuffer->frp_segs += 1; in enlarge_buffer()
3977 STbuffer->buffer_size = got; in enlarge_buffer()
3978 STbuffer->reserved_pages[segs] = page; in enlarge_buffer()
3981 STbuffer->b_data = page_address(STbuffer->reserved_pages[0]); in enlarge_buffer()
3992 for (i=0; i < st_bp->frp_segs; i++) in clear_buffer()
3993 memset(page_address(st_bp->reserved_pages[i]), 0, in clear_buffer()
3994 PAGE_SIZE << st_bp->reserved_page_order); in clear_buffer()
3995 st_bp->cleared = 1; in clear_buffer()
4002 int i, order = STbuffer->reserved_page_order; in normalize_buffer()
4004 for (i = 0; i < STbuffer->frp_segs; i++) { in normalize_buffer()
4005 __free_pages(STbuffer->reserved_pages[i], order); in normalize_buffer()
4006 STbuffer->buffer_size -= (PAGE_SIZE << order); in normalize_buffer()
4008 STbuffer->frp_segs = 0; in normalize_buffer()
4009 STbuffer->sg_segs = 0; in normalize_buffer()
4010 STbuffer->reserved_page_order = 0; in normalize_buffer()
4011 STbuffer->map_data.offset = 0; in normalize_buffer()
4020 int length = PAGE_SIZE << st_bp->reserved_page_order; in append_to_buffer()
4022 for (i = 0, offset = st_bp->buffer_bytes; in append_to_buffer()
4023 i < st_bp->frp_segs && offset >= length; i++) in append_to_buffer()
4024 offset -= length; in append_to_buffer()
4025 if (i == st_bp->frp_segs) { /* Should never happen */ in append_to_buffer()
4027 return (-EIO); in append_to_buffer()
4029 for (; i < st_bp->frp_segs && do_count > 0; i++) { in append_to_buffer()
4030 struct page *page = st_bp->reserved_pages[i]; in append_to_buffer()
4031 cnt = length - offset < do_count ? length - offset : do_count; in append_to_buffer()
4034 return (-EFAULT); in append_to_buffer()
4035 do_count -= cnt; in append_to_buffer()
4036 st_bp->buffer_bytes += cnt; in append_to_buffer()
4041 return (-EIO); in append_to_buffer()
4052 int length = PAGE_SIZE << st_bp->reserved_page_order; in from_buffer()
4054 for (i = 0, offset = st_bp->read_pointer; in from_buffer()
4055 i < st_bp->frp_segs && offset >= length; i++) in from_buffer()
4056 offset -= length; in from_buffer()
4057 if (i == st_bp->frp_segs) { /* Should never happen */ in from_buffer()
4059 return (-EIO); in from_buffer()
4061 for (; i < st_bp->frp_segs && do_count > 0; i++) { in from_buffer()
4062 struct page *page = st_bp->reserved_pages[i]; in from_buffer()
4063 cnt = length - offset < do_count ? length - offset : do_count; in from_buffer()
4066 return (-EFAULT); in from_buffer()
4067 do_count -= cnt; in from_buffer()
4068 st_bp->buffer_bytes -= cnt; in from_buffer()
4069 st_bp->read_pointer += cnt; in from_buffer()
4074 return (-EIO); in from_buffer()
4085 int length = PAGE_SIZE << st_bp->reserved_page_order; in move_buffer_data()
4090 total=st_bp->buffer_bytes - offset; in move_buffer_data()
4091 for (src_seg=0; src_seg < st_bp->frp_segs; src_seg++) { in move_buffer_data()
4095 offset -= length; in move_buffer_data()
4098 st_bp->buffer_bytes = st_bp->read_pointer = total; in move_buffer_data()
4100 struct page *dpage = st_bp->reserved_pages[dst_seg]; in move_buffer_data()
4101 struct page *spage = st_bp->reserved_pages[src_seg]; in move_buffer_data()
4103 count = min(length - dst_offset, length - src_offset); in move_buffer_data()
4116 total -= count; in move_buffer_data()
4197 struct st_modedef *STm = &(tape->modes[mode]); in create_one_cdev()
4199 int dev_num = tape->index; in create_one_cdev()
4206 error = -ENOMEM; in create_one_cdev()
4209 cdev->owner = THIS_MODULE; in create_one_cdev()
4210 cdev->ops = &st_fops; in create_one_cdev()
4211 STm->cdevs[rew] = cdev; in create_one_cdev()
4215 pr_err("st%d: Can't add %s-rewind mode %d\n", dev_num, in create_one_cdev()
4221 i = mode << (4 - ST_NBR_MODE_BITS); in create_one_cdev()
4223 tape->disk->disk_name, st_formats[i]); in create_one_cdev()
4225 dev = device_create(&st_sysfs_class, &tape->device->sdev_gendev, in create_one_cdev()
4226 cdev_devno, &tape->modes[mode], "%s", name); in create_one_cdev()
4233 STm->devs[rew] = dev; in create_one_cdev()
4237 cdev_del(STm->cdevs[rew]); in create_one_cdev()
4239 STm->cdevs[rew] = NULL; in create_one_cdev()
4240 STm->devs[rew] = NULL; in create_one_cdev()
4256 return sysfs_create_link(&tape->device->sdev_gendev.kobj, in create_cdevs()
4257 &tape->modes[0].devs[0]->kobj, "tape"); in create_cdevs()
4263 sysfs_remove_link(&tape->device->sdev_gendev.kobj, "tape"); in remove_cdevs()
4265 struct st_modedef *STm = &(tape->modes[mode]); in remove_cdevs()
4267 if (STm->cdevs[rew]) in remove_cdevs()
4268 cdev_del(STm->cdevs[rew]); in remove_cdevs()
4269 if (STm->devs[rew]) in remove_cdevs()
4270 device_unregister(STm->devs[rew]); in remove_cdevs()
4277 struct scsi_device *SDp = to_scsi_device(dev); in st_probe() local
4286 if (SDp->type != TYPE_TAPE) in st_probe()
4287 return -ENODEV; in st_probe()
4288 if ((stp = st_incompatible(SDp))) { in st_probe()
4289 sdev_printk(KERN_INFO, SDp, in st_probe()
4291 sdev_printk(KERN_INFO, SDp, in st_probe()
4292 "please mail to linux-scsi@vger.kernel.org.\n"); in st_probe()
4293 return -ENODEV; in st_probe()
4296 scsi_autopm_get_device(SDp); in st_probe()
4297 i = queue_max_segments(SDp->request_queue); in st_probe()
4300 buffer = new_tape_buffer((SDp->host)->unchecked_isa_dma, i); in st_probe()
4302 sdev_printk(KERN_ERR, SDp, in st_probe()
4310 sdev_printk(KERN_ERR, SDp, in st_probe()
4317 sdev_printk(KERN_ERR, SDp, in st_probe()
4321 kref_init(&tpnt->kref); in st_probe()
4322 tpnt->disk = disk; in st_probe()
4323 disk->private_data = &tpnt->driver; in st_probe()
4326 if (!blk_get_queue(SDp->request_queue)) in st_probe()
4328 disk->queue = SDp->request_queue; in st_probe()
4329 tpnt->driver = &st_template; in st_probe()
4331 tpnt->device = SDp; in st_probe()
4332 if (SDp->scsi_level <= 2) in st_probe()
4333 tpnt->tape_type = MT_ISSCSI1; in st_probe()
4335 tpnt->tape_type = MT_ISSCSI2; in st_probe()
4337 tpnt->buffer = buffer; in st_probe()
4338 tpnt->buffer->last_SRpnt = NULL; in st_probe()
4340 tpnt->inited = 0; in st_probe()
4341 tpnt->dirty = 0; in st_probe()
4342 tpnt->in_use = 0; in st_probe()
4343 tpnt->drv_buffer = 1; /* Try buffering if no mode sense */ in st_probe()
4344 tpnt->restr_dma = (SDp->host)->unchecked_isa_dma; in st_probe()
4345 tpnt->use_pf = (SDp->scsi_level >= SCSI_2); in st_probe()
4346 tpnt->density = 0; in st_probe()
4347 tpnt->do_auto_lock = ST_AUTO_LOCK; in st_probe()
4348 tpnt->can_bsr = (SDp->scsi_level > 2 ? 1 : ST_IN_FILE_POS); /* BSR mandatory in SCSI3 */ in st_probe()
4349 tpnt->can_partitions = 0; in st_probe()
4350 tpnt->two_fm = ST_TWO_FM; in st_probe()
4351 tpnt->fast_mteom = ST_FAST_MTEOM; in st_probe()
4352 tpnt->scsi2_logical = ST_SCSI2LOGICAL; in st_probe()
4353 tpnt->sili = ST_SILI; in st_probe()
4354 tpnt->immediate = ST_NOWAIT; in st_probe()
4355 tpnt->immediate_filemark = 0; in st_probe()
4356 tpnt->default_drvbuffer = 0xff; /* No forced buffering */ in st_probe()
4357 tpnt->partition = 0; in st_probe()
4358 tpnt->new_partition = 0; in st_probe()
4359 tpnt->nbr_partitions = 0; in st_probe()
4360 blk_queue_rq_timeout(tpnt->device->request_queue, ST_TIMEOUT); in st_probe()
4361 tpnt->long_timeout = ST_LONG_TIMEOUT; in st_probe()
4362 tpnt->try_dio = try_direct_io && !SDp->host->unchecked_isa_dma; in st_probe()
4365 STm = &(tpnt->modes[i]); in st_probe()
4366 STm->defined = 0; in st_probe()
4367 STm->sysv = ST_SYSV; in st_probe()
4368 STm->defaults_for_writes = 0; in st_probe()
4369 STm->do_async_writes = ST_ASYNC_WRITES; in st_probe()
4370 STm->do_buffer_writes = ST_BUFFER_WRITES; in st_probe()
4371 STm->do_read_ahead = ST_READ_AHEAD; in st_probe()
4372 STm->default_compression = ST_DONT_TOUCH; in st_probe()
4373 STm->default_blksize = (-1); /* No forced size */ in st_probe()
4374 STm->default_density = (-1); /* No forced density */ in st_probe()
4375 STm->tape = tpnt; in st_probe()
4379 STps = &(tpnt->ps[i]); in st_probe()
4380 STps->rw = ST_IDLE; in st_probe()
4381 STps->eof = ST_NOEOF; in st_probe()
4382 STps->at_sm = 0; in st_probe()
4383 STps->last_block_valid = 0; in st_probe()
4384 STps->drv_block = (-1); in st_probe()
4385 STps->drv_file = (-1); in st_probe()
4388 tpnt->current_mode = 0; in st_probe()
4389 tpnt->modes[0].defined = 1; in st_probe()
4391 tpnt->density_changed = tpnt->compression_changed = in st_probe()
4392 tpnt->blksize_changed = 0; in st_probe()
4393 mutex_init(&tpnt->lock); in st_probe()
4404 tpnt->index = error; in st_probe()
4405 sprintf(disk->disk_name, "st%d", tpnt->index); in st_probe()
4406 tpnt->stats = kzalloc(sizeof(struct scsi_tape_stats), GFP_KERNEL); in st_probe()
4407 if (tpnt->stats == NULL) { in st_probe()
4408 sdev_printk(KERN_ERR, SDp, in st_probe()
4419 scsi_autopm_put_device(SDp); in st_probe()
4421 sdev_printk(KERN_NOTICE, SDp, in st_probe()
4423 sdev_printk(KERN_INFO, SDp, "%s: try direct i/o: %s (alignment %d B)\n", in st_probe()
4424 tape_name(tpnt), tpnt->try_dio ? "yes" : "no", in st_probe()
4425 queue_dma_alignment(SDp->request_queue) + 1); in st_probe()
4431 kfree(tpnt->stats); in st_probe()
4434 idr_remove(&st_index_idr, tpnt->index); in st_probe()
4437 blk_put_queue(disk->queue); in st_probe()
4444 scsi_autopm_put_device(SDp); in st_probe()
4445 return -ENODEV; in st_probe()
4452 int index = tpnt->index; in st_remove()
4458 kref_put(&tpnt->kref, scsi_tape_release); in st_remove()
4467 * scsi_tape_release - Called to free the Scsi_Tape structure
4478 struct gendisk *disk = tpnt->disk; in scsi_tape_release()
4480 tpnt->device = NULL; in scsi_tape_release()
4482 if (tpnt->buffer) { in scsi_tape_release()
4483 normalize_buffer(tpnt->buffer); in scsi_tape_release()
4484 kfree(tpnt->buffer->reserved_pages); in scsi_tape_release()
4485 kfree(tpnt->buffer); in scsi_tape_release()
4488 disk->private_data = NULL; in scsi_tape_release()
4490 kfree(tpnt->stats); in scsi_tape_release()
4557 /* The sysfs driver interface. Read-only at the moment */
4588 * other values have -EINVAL returned if they are passed in. in debug_flag_store()
4599 return -EINVAL; in debug_flag_store()
4628 l = snprintf(buf, PAGE_SIZE, "%d\n", STm->defined); in defined_show()
4640 l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_blksize); in default_blksize_show()
4653 fmt = STm->default_density >= 0 ? "0x%02x\n" : "%d\n"; in default_density_show()
4654 l = snprintf(buf, PAGE_SIZE, fmt, STm->default_density); in default_density_show()
4666 l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_compression - 1); in default_compression_show()
4675 struct scsi_tape *STp = STm->tape; in options_show()
4679 options = STm->do_buffer_writes ? MT_ST_BUFFER_WRITES : 0; in options_show()
4680 options |= STm->do_async_writes ? MT_ST_ASYNC_WRITES : 0; in options_show()
4681 options |= STm->do_read_ahead ? MT_ST_READ_AHEAD : 0; in options_show()
4683 options |= STp->two_fm ? MT_ST_TWO_FM : 0; in options_show()
4684 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; in options_show()
4685 options |= STm->defaults_for_writes ? MT_ST_DEF_WRITES : 0; in options_show()
4686 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; in options_show()
4687 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; in options_show()
4688 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; in options_show()
4689 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; in options_show()
4690 options |= STm->sysv ? MT_ST_SYSV : 0; in options_show()
4691 options |= STp->immediate ? MT_ST_NOWAIT : 0; in options_show()
4692 options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0; in options_show()
4693 options |= STp->sili ? MT_ST_SILI : 0; in options_show()
4703 * read_cnt_show - return read count - count of reads made from tape drive
4714 (long long)atomic64_read(&STm->tape->stats->read_cnt)); in read_cnt_show()
4719 * read_byte_cnt_show - return read byte count - tape drives
4732 (long long)atomic64_read(&STm->tape->stats->read_byte_cnt)); in read_byte_cnt_show()
4737 * read_ns_show - return read ns - overall time spent waiting on reads in ns.
4748 (long long)atomic64_read(&STm->tape->stats->tot_read_time)); in read_ns_show()
4753 * write_cnt_show - write count - number of user calls
4765 (long long)atomic64_read(&STm->tape->stats->write_cnt)); in write_cnt_show()
4770 * write_byte_cnt_show - write byte count - raw count of
4782 (long long)atomic64_read(&STm->tape->stats->write_byte_cnt)); in write_byte_cnt_show()
4787 * write_ns_show - write ns - number of nanoseconds waiting on write
4799 (long long)atomic64_read(&STm->tape->stats->tot_write_time)); in write_ns_show()
4804 * in_flight_show - number of I/Os currently in flight -
4817 (long long)atomic64_read(&STm->tape->stats->in_flight)); in in_flight_show()
4822 * io_ns_show - io wait ns - this is the number of ns spent
4837 (long long)atomic64_read(&STm->tape->stats->tot_io_time)); in io_ns_show()
4842 * other_cnt_show - other io count - this is the number of
4856 (long long)atomic64_read(&STm->tape->stats->other_cnt)); in other_cnt_show()
4861 * resid_cnt_show - A count of the number of times we get a residual
4862 * count - this should indicate someone issuing reads larger than the
4874 (long long)atomic64_read(&STm->tape->stats->resid_cnt)); in resid_cnt_show()
4921 unsigned long end = (uaddr + count + PAGE_SIZE - 1) >> PAGE_SHIFT; in sgl_map_user_pages()
4923 const int nr_pages = end - start; in sgl_map_user_pages()
4926 struct rq_map_data *mdata = &STbp->map_data; in sgl_map_user_pages()
4930 return -EINVAL; in sgl_map_user_pages()
4934 return -ENOMEM; in sgl_map_user_pages()
4942 return -ENOMEM; in sgl_map_user_pages()
4960 mdata->offset = uaddr & ~PAGE_MASK; in sgl_map_user_pages()
4961 STbp->mapped_pages = pages; in sgl_map_user_pages()
4979 unpin_user_pages_dirty_lock(STbp->mapped_pages, nr_pages, dirtied); in sgl_unmap_user_pages()
4981 kfree(STbp->mapped_pages); in sgl_unmap_user_pages()
4982 STbp->mapped_pages = NULL; in sgl_unmap_user_pages()