Lines Matching +full:sense +full:- +full:freq

4  * Copyright (C) 1995-1999  Gadi Oxman <gadio@netvision.net.il>
5 * Copyright (C) 2003-2005 Bartlomiej Zolnierkiewicz
8 * of the faculty of electrical engineering in the Technion - Israel's
15 * Documentation/ide/ChangeLog.ide-tape.1995-2002
18 #define DRV_NAME "ide-tape"
61 * After each failed packet command we issue a request sense command and retry
80 * function in ide-tape. There are two cases in which we poll for DSC:
93 * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST
95 * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min).
133 /* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
194 * At most, there is only one ide-tape originated data transfer request
217 /* the tape is write protected (hardware or opened as read-only) */
245 if (ide_device_get(tape->drive)) in ide_tape_get()
248 get_device(&tape->dev); in ide_tape_get()
257 ide_drive_t *drive = tape->drive; in ide_tape_put()
260 put_device(&tape->dev); in ide_tape_put()
266 * called on each failed packet command retry to analyze the request sense. We
271 idetape_tape_t *tape = drive->driver_data; in idetape_analyze_error()
272 struct ide_atapi_pc *pc = drive->failed_pc; in idetape_analyze_error()
273 struct request *rq = drive->hwif->rq; in idetape_analyze_error()
274 u8 *sense = bio_data(rq->bio); in idetape_analyze_error() local
276 tape->sense_key = sense[2] & 0xF; in idetape_analyze_error()
277 tape->asc = sense[12]; in idetape_analyze_error()
278 tape->ascq = sense[13]; in idetape_analyze_error()
281 "cmd: 0x%x, sense key = %x, asc = %x, ascq = %x", in idetape_analyze_error()
282 rq->cmd[0], tape->sense_key, tape->asc, tape->ascq); in idetape_analyze_error()
285 if (pc->flags & PC_FLAG_DMA_ERROR) in idetape_analyze_error()
286 scsi_req(rq)->resid_len = tape->blk_size * get_unaligned_be32(&sense[3]); in idetape_analyze_error()
289 * If error was the result of a zero-length read or write command, in idetape_analyze_error()
290 * with sense key=5, asc=0x22, ascq=0, let it slide. Some drives in idetape_analyze_error()
291 * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes. in idetape_analyze_error()
293 if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6) in idetape_analyze_error()
295 && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) { in idetape_analyze_error()
296 if (tape->sense_key == 5) { in idetape_analyze_error()
298 pc->error = 0; in idetape_analyze_error()
300 pc->flags |= PC_FLAG_ABORT; in idetape_analyze_error()
303 if (pc->c[0] == READ_6 && (sense[2] & 0x80)) { in idetape_analyze_error()
304 pc->error = IDE_DRV_ERROR_FILEMARK; in idetape_analyze_error()
305 pc->flags |= PC_FLAG_ABORT; in idetape_analyze_error()
307 if (pc->c[0] == WRITE_6) { in idetape_analyze_error()
308 if ((sense[2] & 0x40) || (tape->sense_key == 0xd in idetape_analyze_error()
309 && tape->asc == 0x0 && tape->ascq == 0x2)) { in idetape_analyze_error()
310 pc->error = IDE_DRV_ERROR_EOD; in idetape_analyze_error()
311 pc->flags |= PC_FLAG_ABORT; in idetape_analyze_error()
314 if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { in idetape_analyze_error()
315 if (tape->sense_key == 8) { in idetape_analyze_error()
316 pc->error = IDE_DRV_ERROR_EOD; in idetape_analyze_error()
317 pc->flags |= PC_FLAG_ABORT; in idetape_analyze_error()
319 if (!(pc->flags & PC_FLAG_ABORT) && in idetape_analyze_error()
320 (blk_rq_bytes(rq) - scsi_req(rq)->resid_len)) in idetape_analyze_error()
321 pc->retries = IDETAPE_MAX_PC_RETRIES + 1; in idetape_analyze_error()
329 idetape_tape_t *tape = drive->driver_data; in ide_tape_callback()
330 struct ide_atapi_pc *pc = drive->pc; in ide_tape_callback()
331 struct request *rq = drive->hwif->rq; in ide_tape_callback()
332 int uptodate = pc->error ? 0 : 1; in ide_tape_callback()
335 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc: %d, err: %d", rq->cmd[0], in ide_tape_callback()
341 if (drive->failed_pc == pc) in ide_tape_callback()
342 drive->failed_pc = NULL; in ide_tape_callback()
344 if (pc->c[0] == REQUEST_SENSE) { in ide_tape_callback()
348 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE " in ide_tape_callback()
349 "itself - Aborting request!\n"); in ide_tape_callback()
350 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { in ide_tape_callback()
352 (blk_rq_bytes(rq) - scsi_req(rq)->resid_len) / tape->blk_size; in ide_tape_callback()
354 tape->avg_size += blocks * tape->blk_size; in ide_tape_callback()
356 if (time_after_eq(jiffies, tape->avg_time + HZ)) { in ide_tape_callback()
357 tape->avg_speed = tape->avg_size * HZ / in ide_tape_callback()
358 (jiffies - tape->avg_time) / 1024; in ide_tape_callback()
359 tape->avg_size = 0; in ide_tape_callback()
360 tape->avg_time = jiffies; in ide_tape_callback()
363 tape->first_frame += blocks; in ide_tape_callback()
365 if (pc->error) { in ide_tape_callback()
367 err = pc->error; in ide_tape_callback()
370 scsi_req(rq)->result = err; in ide_tape_callback()
381 idetape_tape_t *tape = drive->driver_data; in ide_tape_stall_queue()
384 drive->hwif->rq->cmd[0], tape->dsc_poll_freq); in ide_tape_stall_queue()
386 tape->postponed_rq = true; in ide_tape_stall_queue()
388 ide_stall_queue(drive, tape->dsc_poll_freq); in ide_tape_stall_queue()
393 idetape_tape_t *tape = drive->driver_data; in ide_tape_handle_dsc()
396 tape->dsc_polling_start = jiffies; in ide_tape_handle_dsc()
397 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST; in ide_tape_handle_dsc()
398 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT; in ide_tape_handle_dsc()
406 * The current Packet Command is available in drive->pc, and will not change
431 * 5. In case an error was found, we queue a request sense packet command in
444 idetape_tape_t *tape = drive->driver_data; in ide_tape_issue_pc()
445 struct request *rq = drive->hwif->rq; in ide_tape_issue_pc()
447 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) in ide_tape_issue_pc()
448 drive->failed_pc = pc; in ide_tape_issue_pc()
451 drive->pc = pc; in ide_tape_issue_pc()
453 if (pc->retries > IDETAPE_MAX_PC_RETRIES || in ide_tape_issue_pc()
454 (pc->flags & PC_FLAG_ABORT)) { in ide_tape_issue_pc()
461 if (!(pc->flags & PC_FLAG_ABORT)) { in ide_tape_issue_pc()
462 if (!(pc->c[0] == TEST_UNIT_READY && in ide_tape_issue_pc()
463 tape->sense_key == 2 && tape->asc == 4 && in ide_tape_issue_pc()
464 (tape->ascq == 1 || tape->ascq == 8))) { in ide_tape_issue_pc()
465 printk(KERN_ERR "ide-tape: %s: I/O error, " in ide_tape_issue_pc()
468 tape->name, pc->c[0], in ide_tape_issue_pc()
469 tape->sense_key, tape->asc, in ide_tape_issue_pc()
470 tape->ascq); in ide_tape_issue_pc()
473 pc->error = IDE_DRV_ERROR_GENERAL; in ide_tape_issue_pc()
476 drive->failed_pc = NULL; in ide_tape_issue_pc()
477 drive->pc_callback(drive, 0); in ide_tape_issue_pc()
481 ide_debug_log(IDE_DBG_SENSE, "retry #%d, cmd: 0x%02x", pc->retries, in ide_tape_issue_pc()
482 pc->c[0]); in ide_tape_issue_pc()
484 pc->retries++; in ide_tape_issue_pc()
489 /* A mode sense command is used to "sense" tape parameters. */
493 pc->c[0] = MODE_SENSE; in idetape_create_mode_sense_cmd()
495 /* DBD = 1 - Don't return block descriptors */ in idetape_create_mode_sense_cmd()
496 pc->c[1] = 8; in idetape_create_mode_sense_cmd()
497 pc->c[2] = page_code; in idetape_create_mode_sense_cmd()
499 * Changed pc->c[3] to 0 (255 will at best return unused info). in idetape_create_mode_sense_cmd()
505 pc->c[3] = 0; in idetape_create_mode_sense_cmd()
507 pc->c[4] = 255; in idetape_create_mode_sense_cmd()
509 pc->req_xfer = 12; in idetape_create_mode_sense_cmd()
511 pc->req_xfer = 24; in idetape_create_mode_sense_cmd()
513 pc->req_xfer = 50; in idetape_create_mode_sense_cmd()
518 ide_hwif_t *hwif = drive->hwif; in idetape_media_access_finished()
519 idetape_tape_t *tape = drive->driver_data; in idetape_media_access_finished()
520 struct ide_atapi_pc *pc = drive->pc; in idetape_media_access_finished()
523 stat = hwif->tp_ops->read_status(hwif); in idetape_media_access_finished()
528 if (pc->c[0] != TEST_UNIT_READY) in idetape_media_access_finished()
529 printk(KERN_ERR "ide-tape: %s: I/O error, ", in idetape_media_access_finished()
530 tape->name); in idetape_media_access_finished()
535 pc->error = 0; in idetape_media_access_finished()
537 pc->error = IDE_DRV_ERROR_GENERAL; in idetape_media_access_finished()
538 drive->failed_pc = NULL; in idetape_media_access_finished()
540 drive->pc_callback(drive, 0); in idetape_media_access_finished()
548 unsigned int length = blk_rq_sectors(rq) / (tape->blk_size >> 9); in ide_tape_create_rw_cmd()
551 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); in ide_tape_create_rw_cmd()
552 pc->c[1] = 1; in ide_tape_create_rw_cmd()
554 if (blk_rq_bytes(rq) == tape->buffer_size) in ide_tape_create_rw_cmd()
555 pc->flags |= PC_FLAG_DMA_OK; in ide_tape_create_rw_cmd()
558 pc->c[0] = READ_6; in ide_tape_create_rw_cmd()
560 pc->c[0] = WRITE_6; in ide_tape_create_rw_cmd()
561 pc->flags |= PC_FLAG_WRITING; in ide_tape_create_rw_cmd()
564 memcpy(scsi_req(rq)->cmd, pc->c, 12); in ide_tape_create_rw_cmd()
570 ide_hwif_t *hwif = drive->hwif; in idetape_do_request()
571 idetape_tape_t *tape = drive->driver_data; in idetape_do_request()
578 req->cmd[0], (unsigned long long)blk_rq_pos(rq), in idetape_do_request()
582 BUG_ON(ide_req(rq)->type != ATA_PRIV_MISC && in idetape_do_request()
583 ide_req(rq)->type != ATA_PRIV_SENSE); in idetape_do_request()
586 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) { in idetape_do_request()
587 pc = drive->failed_pc; in idetape_do_request()
595 stat = hwif->tp_ops->read_status(hwif); in idetape_do_request()
597 if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 && in idetape_do_request()
598 (req->cmd[13] & REQ_IDETAPE_PC2) == 0) in idetape_do_request()
599 drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; in idetape_do_request()
601 if (drive->dev_flags & IDE_DFLAG_POST_RESET) { in idetape_do_request()
602 drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; in idetape_do_request()
603 drive->dev_flags &= ~IDE_DFLAG_POST_RESET; in idetape_do_request()
606 if (!(drive->atapi_flags & IDE_AFLAG_IGNORE_DSC) && in idetape_do_request()
608 if (!tape->postponed_rq) { in idetape_do_request()
609 tape->dsc_polling_start = jiffies; in idetape_do_request()
610 tape->dsc_poll_freq = tape->best_dsc_rw_freq; in idetape_do_request()
611 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT; in idetape_do_request()
612 } else if (time_after(jiffies, tape->dsc_timeout)) { in idetape_do_request()
613 printk(KERN_ERR "ide-tape: %s: DSC timeout\n", in idetape_do_request()
614 tape->name); in idetape_do_request()
615 if (req->cmd[13] & REQ_IDETAPE_PC2) { in idetape_do_request()
622 tape->dsc_polling_start + in idetape_do_request()
624 tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW; in idetape_do_request()
628 drive->atapi_flags &= ~IDE_AFLAG_IGNORE_DSC; in idetape_do_request()
629 tape->postponed_rq = false; in idetape_do_request()
632 if (req->cmd[13] & REQ_IDETAPE_READ) { in idetape_do_request()
633 pc = &tape->queued_pc; in idetape_do_request()
637 if (req->cmd[13] & REQ_IDETAPE_WRITE) { in idetape_do_request()
638 pc = &tape->queued_pc; in idetape_do_request()
642 if (req->cmd[13] & REQ_IDETAPE_PC1) { in idetape_do_request()
643 pc = (struct ide_atapi_pc *)ide_req(rq)->special; in idetape_do_request()
644 req->cmd[13] &= ~(REQ_IDETAPE_PC1); in idetape_do_request()
645 req->cmd[13] |= REQ_IDETAPE_PC2; in idetape_do_request()
648 if (req->cmd[13] & REQ_IDETAPE_PC2) { in idetape_do_request()
655 /* prepare sense request for this command */ in idetape_do_request()
679 pc->c[0] = WRITE_FILEMARKS; in idetape_create_write_filemark_cmd()
680 pc->c[4] = write_filemark; in idetape_create_write_filemark_cmd()
681 pc->flags |= PC_FLAG_WAIT_FOR_DSC; in idetape_create_write_filemark_cmd()
686 idetape_tape_t *tape = drive->driver_data; in idetape_wait_ready()
687 struct gendisk *disk = tape->disk; in idetape_wait_ready()
691 set_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), &drive->atapi_flags); in idetape_wait_ready()
696 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) in idetape_wait_ready()
697 || (tape->asc == 0x3A)) { in idetape_wait_ready()
700 return -ENOMEDIUM; in idetape_wait_ready()
704 } else if (!(tape->sense_key == 2 && tape->asc == 4 && in idetape_wait_ready()
705 (tape->ascq == 1 || tape->ascq == 8))) in idetape_wait_ready()
706 return -EIO; in idetape_wait_ready()
709 return -EIO; in idetape_wait_ready()
714 struct ide_tape_obj *tape = drive->driver_data; in idetape_flush_tape_buffers()
719 rc = ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0); in idetape_flush_tape_buffers()
728 idetape_tape_t *tape = drive->driver_data; in ide_tape_read_position()
739 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) in ide_tape_read_position()
740 return -1; in ide_tape_read_position()
743 ide_debug_log(IDE_DBG_FUNC, "BOP - %s", in ide_tape_read_position()
745 ide_debug_log(IDE_DBG_FUNC, "EOP - %s", in ide_tape_read_position()
749 printk(KERN_INFO "ide-tape: Block location is unknown" in ide_tape_read_position()
752 &drive->atapi_flags); in ide_tape_read_position()
753 return -1; in ide_tape_read_position()
758 tape->partition = buf[1]; in ide_tape_read_position()
759 tape->first_frame = be32_to_cpup((__be32 *)&buf[4]); in ide_tape_read_position()
761 &drive->atapi_flags); in ide_tape_read_position()
765 return tape->first_frame; in ide_tape_read_position()
773 pc->c[0] = POSITION_TO_ELEMENT; in idetape_create_locate_cmd()
774 pc->c[1] = 2; in idetape_create_locate_cmd()
775 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); in idetape_create_locate_cmd()
776 pc->c[8] = partition; in idetape_create_locate_cmd()
777 pc->flags |= PC_FLAG_WAIT_FOR_DSC; in idetape_create_locate_cmd()
782 idetape_tape_t *tape = drive->driver_data; in __ide_tape_discard_merge_buffer()
784 if (tape->chrdev_dir != IDETAPE_DIR_READ) in __ide_tape_discard_merge_buffer()
787 clear_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags); in __ide_tape_discard_merge_buffer()
788 tape->valid = 0; in __ide_tape_discard_merge_buffer()
789 if (tape->buf != NULL) { in __ide_tape_discard_merge_buffer()
790 kfree(tape->buf); in __ide_tape_discard_merge_buffer()
791 tape->buf = NULL; in __ide_tape_discard_merge_buffer()
794 tape->chrdev_dir = IDETAPE_DIR_NONE; in __ide_tape_discard_merge_buffer()
806 idetape_tape_t *tape = drive->driver_data; in idetape_position_tape()
807 struct gendisk *disk = tape->disk; in idetape_position_tape()
811 if (tape->chrdev_dir == IDETAPE_DIR_READ) in idetape_position_tape()
828 idetape_tape_t *tape = drive->driver_data; in ide_tape_discard_merge_buffer()
836 printk(KERN_INFO "ide-tape: %s: position_tape failed in" in ide_tape_discard_merge_buffer()
837 " %s\n", tape->name, __func__); in ide_tape_discard_merge_buffer()
849 idetape_tape_t *tape = drive->driver_data; in idetape_queue_rw_tail()
856 BUG_ON(size < 0 || size % tape->blk_size); in idetape_queue_rw_tail()
858 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0); in idetape_queue_rw_tail()
859 ide_req(rq)->type = ATA_PRIV_MISC; in idetape_queue_rw_tail()
860 scsi_req(rq)->cmd[13] = cmd; in idetape_queue_rw_tail()
861 rq->rq_disk = tape->disk; in idetape_queue_rw_tail()
862 rq->__sector = tape->first_frame; in idetape_queue_rw_tail()
865 ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size, in idetape_queue_rw_tail()
871 blk_execute_rq(drive->queue, tape->disk, rq, 0); in idetape_queue_rw_tail()
874 size -= scsi_req(rq)->resid_len; in idetape_queue_rw_tail()
875 tape->cur = tape->buf; in idetape_queue_rw_tail()
877 tape->valid = size; in idetape_queue_rw_tail()
879 tape->valid = 0; in idetape_queue_rw_tail()
882 if (scsi_req(rq)->result == IDE_DRV_ERROR_GENERAL) in idetape_queue_rw_tail()
883 ret = -EIO; in idetape_queue_rw_tail()
892 pc->c[0] = INQUIRY; in idetape_create_inquiry_cmd()
893 pc->c[4] = 254; in idetape_create_inquiry_cmd()
894 pc->req_xfer = 254; in idetape_create_inquiry_cmd()
901 pc->c[0] = REZERO_UNIT; in idetape_create_rewind_cmd()
902 pc->flags |= PC_FLAG_WAIT_FOR_DSC; in idetape_create_rewind_cmd()
908 pc->c[0] = ERASE; in idetape_create_erase_cmd()
909 pc->c[1] = 1; in idetape_create_erase_cmd()
910 pc->flags |= PC_FLAG_WAIT_FOR_DSC; in idetape_create_erase_cmd()
916 pc->c[0] = SPACE; in idetape_create_space_cmd()
917 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); in idetape_create_space_cmd()
918 pc->c[1] = cmd; in idetape_create_space_cmd()
919 pc->flags |= PC_FLAG_WAIT_FOR_DSC; in idetape_create_space_cmd()
924 idetape_tape_t *tape = drive->driver_data; in ide_tape_flush_merge_buffer()
926 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { in ide_tape_flush_merge_buffer()
927 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer" in ide_tape_flush_merge_buffer()
931 if (tape->buf) { in ide_tape_flush_merge_buffer()
932 size_t aligned = roundup(tape->valid, tape->blk_size); in ide_tape_flush_merge_buffer()
934 memset(tape->cur, 0, aligned - tape->valid); in ide_tape_flush_merge_buffer()
936 kfree(tape->buf); in ide_tape_flush_merge_buffer()
937 tape->buf = NULL; in ide_tape_flush_merge_buffer()
939 tape->chrdev_dir = IDETAPE_DIR_NONE; in ide_tape_flush_merge_buffer()
944 idetape_tape_t *tape = drive->driver_data; in idetape_init_rw()
949 if (tape->chrdev_dir == dir) in idetape_init_rw()
952 if (tape->chrdev_dir == IDETAPE_DIR_READ) in idetape_init_rw()
954 else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { in idetape_init_rw()
959 if (tape->buf || tape->valid) { in idetape_init_rw()
960 printk(KERN_ERR "ide-tape: valid should be 0 now\n"); in idetape_init_rw()
961 tape->valid = 0; in idetape_init_rw()
964 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL); in idetape_init_rw()
965 if (!tape->buf) in idetape_init_rw()
966 return -ENOMEM; in idetape_init_rw()
967 tape->chrdev_dir = dir; in idetape_init_rw()
968 tape->cur = tape->buf; in idetape_init_rw()
976 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) { in idetape_init_rw()
982 kfree(tape->buf); in idetape_init_rw()
983 tape->buf = NULL; in idetape_init_rw()
984 tape->chrdev_dir = IDETAPE_DIR_NONE; in idetape_init_rw()
994 idetape_tape_t *tape = drive->driver_data; in idetape_pad_zeros()
996 memset(tape->buf, 0, tape->buffer_size); in idetape_pad_zeros()
999 unsigned int count = min(tape->buffer_size, bcount); in idetape_pad_zeros()
1002 bcount -= count; in idetape_pad_zeros()
1012 struct ide_tape_obj *tape = drive->driver_data; in idetape_rewind_tape()
1013 struct gendisk *disk = tape->disk; in idetape_rewind_tape()
1034 idetape_tape_t *tape = drive->driver_data; in idetape_blkdev_ioctl()
1048 return -EFAULT; in idetape_blkdev_ioctl()
1049 tape->best_dsc_rw_freq = config.dsc_rw_frequency; in idetape_blkdev_ioctl()
1053 config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq; in idetape_blkdev_ioctl()
1056 return -EFAULT; in idetape_blkdev_ioctl()
1059 return -EIO; in idetape_blkdev_ioctl()
1067 idetape_tape_t *tape = drive->driver_data; in idetape_space_over_filemarks()
1068 struct gendisk *disk = tape->disk; in idetape_space_over_filemarks()
1071 int sprev = !!(tape->caps[4] & 0x20); in idetape_space_over_filemarks()
1080 return -EIO; in idetape_space_over_filemarks()
1081 mt_count = -mt_count; in idetape_space_over_filemarks()
1084 if (tape->chrdev_dir == IDETAPE_DIR_READ) { in idetape_space_over_filemarks()
1085 tape->valid = 0; in idetape_space_over_filemarks()
1087 &drive->atapi_flags)) in idetape_space_over_filemarks()
1095 idetape_create_space_cmd(&pc, mt_count - count, in idetape_space_over_filemarks()
1101 return -EIO; in idetape_space_over_filemarks()
1103 mt_count - count); in idetape_space_over_filemarks()
1106 count = (MTBSFM == mt_op ? 1 : -1); in idetape_space_over_filemarks()
1109 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", in idetape_space_over_filemarks()
1111 return -EIO; in idetape_space_over_filemarks()
1123 * continuous view of the media - any mix of block sizes (even 1 byte) on the
1133 struct ide_tape_obj *tape = file->private_data; in idetape_chrdev_read()
1134 ide_drive_t *drive = tape->drive; in idetape_chrdev_read()
1141 if (tape->chrdev_dir != IDETAPE_DIR_READ) { in idetape_chrdev_read()
1142 if (test_bit(ilog2(IDE_AFLAG_DETECT_BS), &drive->atapi_flags)) in idetape_chrdev_read()
1143 if (count > tape->blk_size && in idetape_chrdev_read()
1144 (count % tape->blk_size) == 0) in idetape_chrdev_read()
1145 tape->user_bs_factor = count / tape->blk_size; in idetape_chrdev_read()
1156 if (!tape->valid) { in idetape_chrdev_read()
1159 &drive->atapi_flags)) in idetape_chrdev_read()
1163 tape->buffer_size) <= 0) in idetape_chrdev_read()
1168 todo = min_t(size_t, count - done, tape->valid); in idetape_chrdev_read()
1169 if (copy_to_user(buf + done, tape->cur, todo)) in idetape_chrdev_read()
1170 ret = -EFAULT; in idetape_chrdev_read()
1172 tape->cur += todo; in idetape_chrdev_read()
1173 tape->valid -= todo; in idetape_chrdev_read()
1177 if (!done && test_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags)) { in idetape_chrdev_read()
1188 struct ide_tape_obj *tape = file->private_data; in idetape_chrdev_write()
1189 ide_drive_t *drive = tape->drive; in idetape_chrdev_write()
1195 if (tape->write_prot) in idetape_chrdev_write()
1196 return -EACCES; in idetape_chrdev_write()
1209 if (tape->valid == tape->buffer_size && in idetape_chrdev_write()
1211 tape->buffer_size) <= 0) in idetape_chrdev_write()
1215 todo = min_t(size_t, count - done, in idetape_chrdev_write()
1216 tape->buffer_size - tape->valid); in idetape_chrdev_write()
1217 if (copy_from_user(tape->cur, buf + done, todo)) in idetape_chrdev_write()
1218 ret = -EFAULT; in idetape_chrdev_write()
1220 tape->cur += todo; in idetape_chrdev_write()
1221 tape->valid += todo; in idetape_chrdev_write()
1230 struct ide_tape_obj *tape = drive->driver_data; in idetape_write_filemark()
1235 if (ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0)) { in idetape_write_filemark()
1236 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); in idetape_write_filemark()
1237 return -EIO; in idetape_write_filemark()
1257 idetape_tape_t *tape = drive->driver_data; in idetape_mtioctop()
1258 struct gendisk *disk = tape->disk; in idetape_mtioctop()
1279 if (tape->write_prot) in idetape_mtioctop()
1280 return -EACCES; in idetape_mtioctop()
1291 return -EIO; in idetape_mtioctop()
1302 if (tape->door_locked) { in idetape_mtioctop()
1304 tape->door_locked = DOOR_UNLOCKED; in idetape_mtioctop()
1310 &drive->atapi_flags); in idetape_mtioctop()
1328 if (mt_count < tape->blk_size || in idetape_mtioctop()
1329 mt_count % tape->blk_size) in idetape_mtioctop()
1330 return -EIO; in idetape_mtioctop()
1331 tape->user_bs_factor = mt_count / tape->blk_size; in idetape_mtioctop()
1333 &drive->atapi_flags); in idetape_mtioctop()
1336 &drive->atapi_flags); in idetape_mtioctop()
1341 mt_count * tape->user_bs_factor, tape->partition, 0); in idetape_mtioctop()
1351 tape->door_locked = DOOR_EXPLICITLY_LOCKED; in idetape_mtioctop()
1357 tape->door_locked = DOOR_UNLOCKED; in idetape_mtioctop()
1360 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", in idetape_mtioctop()
1362 return -EIO; in idetape_mtioctop()
1369 * ide-tape ioctls are supported on both interfaces.
1374 struct ide_tape_obj *tape = file->private_data; in do_idetape_chrdev_ioctl()
1375 ide_drive_t *drive = tape->drive; in do_idetape_chrdev_ioctl()
1379 int block_offset = 0, position = tape->first_frame; in do_idetape_chrdev_ioctl()
1384 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { in do_idetape_chrdev_ioctl()
1389 block_offset = tape->valid / in do_idetape_chrdev_ioctl()
1390 (tape->blk_size * tape->user_bs_factor); in do_idetape_chrdev_ioctl()
1393 return -EIO; in do_idetape_chrdev_ioctl()
1398 return -EFAULT; in do_idetape_chrdev_ioctl()
1403 mtget.mt_blkno = position / tape->user_bs_factor - block_offset; in do_idetape_chrdev_ioctl()
1405 ((tape->blk_size * tape->user_bs_factor) in do_idetape_chrdev_ioctl()
1408 if (tape->drv_write_prot) in do_idetape_chrdev_ioctl()
1413 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset; in do_idetape_chrdev_ioctl()
1416 if (tape->chrdev_dir == IDETAPE_DIR_READ) in do_idetape_chrdev_ioctl()
1449 * Do a mode sense page 0 with block descriptor and if it succeeds set the tape
1454 idetape_tape_t *tape = drive->driver_data; in ide_tape_get_bsize_from_bdesc()
1459 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) { in ide_tape_get_bsize_from_bdesc()
1460 printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); in ide_tape_get_bsize_from_bdesc()
1461 if (tape->blk_size == 0) { in ide_tape_get_bsize_from_bdesc()
1462 printk(KERN_WARNING "ide-tape: Cannot deal with zero " in ide_tape_get_bsize_from_bdesc()
1464 tape->blk_size = 32768; in ide_tape_get_bsize_from_bdesc()
1468 tape->blk_size = (buf[4 + 5] << 16) + in ide_tape_get_bsize_from_bdesc()
1471 tape->drv_write_prot = (buf[2] & 0x80) >> 7; in ide_tape_get_bsize_from_bdesc()
1474 tape->blk_size, tape->drv_write_prot); in ide_tape_get_bsize_from_bdesc()
1485 return -ENXIO; in idetape_chrdev_open()
1492 return -ENXIO; in idetape_chrdev_open()
1495 drive = tape->drive; in idetape_chrdev_open()
1496 filp->private_data = tape; in idetape_chrdev_open()
1505 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); in idetape_chrdev_open()
1508 if (test_and_set_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags)) { in idetape_chrdev_open()
1509 retval = -EBUSY; in idetape_chrdev_open()
1515 clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); in idetape_chrdev_open()
1516 printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name); in idetape_chrdev_open()
1521 if (!test_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), &drive->atapi_flags)) in idetape_chrdev_open()
1527 /* Set write protect flag if device is opened as read-only. */ in idetape_chrdev_open()
1528 if ((filp->f_flags & O_ACCMODE) == O_RDONLY) in idetape_chrdev_open()
1529 tape->write_prot = 1; in idetape_chrdev_open()
1531 tape->write_prot = tape->drv_write_prot; in idetape_chrdev_open()
1534 if (tape->write_prot) { in idetape_chrdev_open()
1535 if ((filp->f_flags & O_ACCMODE) == O_WRONLY || in idetape_chrdev_open()
1536 (filp->f_flags & O_ACCMODE) == O_RDWR) { in idetape_chrdev_open()
1537 clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); in idetape_chrdev_open()
1538 retval = -EROFS; in idetape_chrdev_open()
1544 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { in idetape_chrdev_open()
1545 if (!ide_set_media_lock(drive, tape->disk, 1)) { in idetape_chrdev_open()
1546 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) in idetape_chrdev_open()
1547 tape->door_locked = DOOR_LOCKED; in idetape_chrdev_open()
1564 idetape_tape_t *tape = drive->driver_data; in idetape_write_release()
1567 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL); in idetape_write_release()
1568 if (tape->buf != NULL) { in idetape_write_release()
1569 idetape_pad_zeros(drive, tape->blk_size * in idetape_write_release()
1570 (tape->user_bs_factor - 1)); in idetape_write_release()
1571 kfree(tape->buf); in idetape_write_release()
1572 tape->buf = NULL; in idetape_write_release()
1581 struct ide_tape_obj *tape = filp->private_data; in idetape_chrdev_release()
1582 ide_drive_t *drive = tape->drive; in idetape_chrdev_release()
1587 tape = drive->driver_data; in idetape_chrdev_release()
1591 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) in idetape_chrdev_release()
1593 if (tape->chrdev_dir == IDETAPE_DIR_READ) { in idetape_chrdev_release()
1599 &drive->atapi_flags)) in idetape_chrdev_release()
1602 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { in idetape_chrdev_release()
1603 if (tape->door_locked == DOOR_LOCKED) { in idetape_chrdev_release()
1604 if (!ide_set_media_lock(drive, tape->disk, 0)) in idetape_chrdev_release()
1605 tape->door_locked = DOOR_UNLOCKED; in idetape_chrdev_release()
1608 clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); in idetape_chrdev_release()
1618 idetape_tape_t *tape = drive->driver_data; in idetape_get_inquiry_results()
1624 if (ide_queue_pc_tail(drive, tape->disk, &pc, pc_buf, pc.req_xfer)) { in idetape_get_inquiry_results()
1625 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", in idetape_get_inquiry_results()
1626 tape->name); in idetape_get_inquiry_results()
1637 printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n", in idetape_get_inquiry_results()
1638 drive->name, tape->name, vendor_id, product_id, fw_rev); in idetape_get_inquiry_results()
1647 idetape_tape_t *tape = drive->driver_data; in idetape_get_mode_sense_results()
1653 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) { in idetape_get_mode_sense_results()
1654 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" in idetape_get_mode_sense_results()
1656 tape->blk_size = 512; in idetape_get_mode_sense_results()
1657 put_unaligned(52, (u16 *)&tape->caps[12]); in idetape_get_mode_sense_results()
1658 put_unaligned(540, (u16 *)&tape->caps[14]); in idetape_get_mode_sense_results()
1659 put_unaligned(6*52, (u16 *)&tape->caps[16]); in idetape_get_mode_sense_results()
1674 printk(KERN_INFO "ide-tape: %s: invalid tape speed " in idetape_get_mode_sense_results()
1675 "(assuming 650KB/sec)\n", drive->name); in idetape_get_mode_sense_results()
1679 printk(KERN_INFO "ide-tape: %s: invalid max_speed " in idetape_get_mode_sense_results()
1680 "(assuming 650KB/sec)\n", drive->name); in idetape_get_mode_sense_results()
1684 memcpy(&tape->caps, caps, 20); in idetape_get_mode_sense_results()
1688 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; in idetape_get_mode_sense_results()
1691 tape->blk_size = 512; in idetape_get_mode_sense_results()
1693 tape->blk_size = 1024; in idetape_get_mode_sense_results()
1700 idetape_tape_t *tape = drive->driver_data; \
1701 return tape->field; \
1707 idetape_tape_t *tape = drive->driver_data; \
1708 tape->field = arg; \
1762 u16 *ctl = (u16 *)&tape->caps[12]; in idetape_setup()
1766 drive->pc_callback = ide_tape_callback; in idetape_setup()
1768 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; in idetape_setup()
1770 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { in idetape_setup()
1771 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", in idetape_setup()
1772 tape->name); in idetape_setup()
1773 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; in idetape_setup()
1777 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401")) in idetape_setup()
1778 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; in idetape_setup()
1780 tape->minor = minor; in idetape_setup()
1781 tape->name[0] = 'h'; in idetape_setup()
1782 tape->name[1] = 't'; in idetape_setup()
1783 tape->name[2] = '0' + minor; in idetape_setup()
1784 tape->chrdev_dir = IDETAPE_DIR_NONE; in idetape_setup()
1789 tape->user_bs_factor = 1; in idetape_setup()
1790 tape->buffer_size = *ctl * tape->blk_size; in idetape_setup()
1791 while (tape->buffer_size > 0xffff) { in idetape_setup()
1792 printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); in idetape_setup()
1794 tape->buffer_size = *ctl * tape->blk_size; in idetape_setup()
1797 /* select the "best" DSC read/write polling freq */ in idetape_setup()
1798 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); in idetape_setup()
1800 t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000); in idetape_setup()
1803 * Ensure that the number we got makes sense; limit it within in idetape_setup()
1806 tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN, in idetape_setup()
1808 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " in idetape_setup()
1810 drive->name, tape->name, *(u16 *)&tape->caps[14], in idetape_setup()
1811 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size, in idetape_setup()
1812 tape->buffer_size / 1024, in idetape_setup()
1813 jiffies_to_msecs(tape->best_dsc_rw_freq), in idetape_setup()
1814 (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : ""); in idetape_setup()
1816 ide_proc_register_driver(drive, tape->driver); in idetape_setup()
1821 idetape_tape_t *tape = drive->driver_data; in ide_tape_remove()
1823 ide_proc_unregister_driver(drive, tape->driver); in ide_tape_remove()
1824 device_del(&tape->dev); in ide_tape_remove()
1825 ide_unregister_region(tape->disk); in ide_tape_remove()
1828 put_device(&tape->dev); in ide_tape_remove()
1835 ide_drive_t *drive = tape->drive; in ide_tape_release()
1836 struct gendisk *g = tape->disk; in ide_tape_release()
1838 BUG_ON(tape->valid); in ide_tape_release()
1840 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; in ide_tape_release()
1841 drive->driver_data = NULL; in ide_tape_release()
1842 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); in ide_tape_release()
1844 MKDEV(IDETAPE_MAJOR, tape->minor + 128)); in ide_tape_release()
1845 idetape_devs[tape->minor] = NULL; in ide_tape_release()
1846 g->private_data = NULL; in ide_tape_release()
1854 ide_drive_t *drive = (ide_drive_t *) m->private; in idetape_name_proc_show()
1855 idetape_tape_t *tape = drive->driver_data; in idetape_name_proc_show()
1857 seq_printf(m, "%s\n", tape->name); in idetape_name_proc_show()
1883 .name = "ide-tape",
1914 tape = ide_tape_get(bdev->bd_disk, false, 0); in idetape_open()
1918 return -ENXIO; in idetape_open()
1935 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj); in idetape_ioctl()
1936 ide_drive_t *drive = tape->drive; in idetape_ioctl()
1941 if (err == -EINVAL) in idetape_ioctl()
1974 if (!strstr(DRV_NAME, drive->driver_req)) in ide_tape_probe()
1977 if (drive->media != ide_tape) in ide_tape_probe()
1980 if ((drive->dev_flags & IDE_DFLAG_ID_READ) && in ide_tape_probe()
1982 printk(KERN_ERR "ide-tape: %s: not supported by this version of" in ide_tape_probe()
1983 " the driver\n", drive->name); in ide_tape_probe()
1988 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n", in ide_tape_probe()
1989 drive->name); in ide_tape_probe()
1999 tape->dev.parent = &drive->gendev; in ide_tape_probe()
2000 tape->dev.release = ide_tape_release; in ide_tape_probe()
2001 dev_set_name(&tape->dev, "%s", dev_name(&drive->gendev)); in ide_tape_probe()
2003 if (device_register(&tape->dev)) in ide_tape_probe()
2006 tape->drive = drive; in ide_tape_probe()
2007 tape->driver = &idetape_driver; in ide_tape_probe()
2008 tape->disk = g; in ide_tape_probe()
2010 g->private_data = &tape->driver; in ide_tape_probe()
2012 drive->driver_data = tape; in ide_tape_probe()
2022 device_create(idetape_sysfs_class, &drive->gendev, in ide_tape_probe()
2023 MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name); in ide_tape_probe()
2024 device_create(idetape_sysfs_class, &drive->gendev, in ide_tape_probe()
2026 "n%s", tape->name); in ide_tape_probe()
2028 g->fops = &idetape_block_ops; in ide_tape_probe()
2038 return -ENODEV; in ide_tape_probe()
2055 error = -EBUSY; in idetape_init()
2060 printk(KERN_ERR "ide-tape: Failed to register chrdev" in idetape_init()
2062 error = -EBUSY; in idetape_init()
2080 MODULE_ALIAS("ide:*m-tape*");