Lines Matching refs:tape

2  * IDE ATAPI streaming tape driver.
15 * Documentation/ide/ChangeLog.ide-tape.1995-2002
18 #define DRV_NAME "ide-tape"
69 * The following parameter is used to select the point in the internal tape fifo
80 * function in ide-tape. There are two cases in which we poll for DSC:
83 * from/to the tape's data buffers, without causing an actual media access.
84 * In case the tape is not ready yet, we take out our request from the device
98 * timeout should be longer then the maximum execution time of a tape operation.
112 /* tape directions */
184 /* tape block size, usually 512 or 1024 bytes */
188 /* Copy of the tape's Capabilities and Mechanical Page */
194 * At most, there is only one ide-tape originated data transfer request
199 /* Data buffer size chosen based on the tape's recommendation */
208 /* Measures average tape speed */
215 /* the tape hardware is write protected */
217 /* the tape is write protected (hardware or opened as read-only) */
235 struct ide_tape_obj *tape = NULL;
240 tape = idetape_devs[i];
242 tape = ide_drv_g(disk, ide_tape_obj);
244 if (tape) {
245 if (ide_device_get(tape->drive))
246 tape = NULL;
248 get_device(&tape->dev);
252 return tape;
255 static void ide_tape_put(struct ide_tape_obj *tape)
257 ide_drive_t *drive = tape->drive;
260 put_device(&tape->dev);
271 idetape_tape_t *tape = drive->driver_data;
276 tape->sense_key = sense[2] & 0xF;
277 tape->asc = sense[12];
278 tape->ascq = sense[13];
282 rq->cmd[0], tape->sense_key, tape->asc, tape->ascq);
286 scsi_req(rq)->resid_len = tape->blk_size * get_unaligned_be32(&sense[3]);
296 if (tape->sense_key == 5) {
308 if ((sense[2] & 0x40) || (tape->sense_key == 0xd
309 && tape->asc == 0x0 && tape->ascq == 0x2)) {
315 if (tape->sense_key == 8) {
329 idetape_tape_t *tape = drive->driver_data;
348 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
352 (blk_rq_bytes(rq) - scsi_req(rq)->resid_len) / tape->blk_size;
354 tape->avg_size += blocks * tape->blk_size;
356 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
357 tape->avg_speed = tape->avg_size * HZ /
358 (jiffies - tape->avg_time) / 1024;
359 tape->avg_size = 0;
360 tape->avg_time = jiffies;
363 tape->first_frame += blocks;
381 idetape_tape_t *tape = drive->driver_data;
384 drive->hwif->rq->cmd[0], tape->dsc_poll_freq);
386 tape->postponed_rq = true;
388 ide_stall_queue(drive, tape->dsc_poll_freq);
393 idetape_tape_t *tape = drive->driver_data;
396 tape->dsc_polling_start = jiffies;
397 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
398 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
421 * Since the tape drive will not issue an interrupt, we have to poll for this
444 idetape_tape_t *tape = drive->driver_data;
463 tape->sense_key == 2 && tape->asc == 4 &&
464 (tape->ascq == 1 || tape->ascq == 8))) {
465 printk(KERN_ERR "ide-tape: %s: I/O error, "
468 tape->name, pc->c[0],
469 tape->sense_key, tape->asc,
470 tape->ascq);
489 /* A mode sense command is used to "sense" tape parameters. */
519 idetape_tape_t *tape = drive->driver_data;
529 printk(KERN_ERR "ide-tape: %s: I/O error, ",
530 tape->name);
544 static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
548 unsigned int length = blk_rq_sectors(rq) / (tape->blk_size >> 9);
554 if (blk_rq_bytes(rq) == tape->buffer_size)
571 idetape_tape_t *tape = drive->driver_data;
592 * If the tape is still busy, postpone our request and service
608 if (!tape->postponed_rq) {
609 tape->dsc_polling_start = jiffies;
610 tape->dsc_poll_freq = tape->best_dsc_rw_freq;
611 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
612 } else if (time_after(jiffies, tape->dsc_timeout)) {
613 printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
614 tape->name);
622 tape->dsc_polling_start +
624 tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
629 tape->postponed_rq = false;
633 pc = &tape->queued_pc;
634 ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
638 pc = &tape->queued_pc;
639 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6);
686 idetape_tape_t *tape = drive->driver_data;
687 struct gendisk *disk = tape->disk;
690 /* Wait for the tape to become ready */
696 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
697 || (tape->asc == 0x3A)) {
704 } else if (!(tape->sense_key == 2 && tape->asc == 4 &&
705 (tape->ascq == 1 || tape->ascq == 8)))
714 struct ide_tape_obj *tape = drive->driver_data;
719 rc = ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0);
728 idetape_tape_t *tape = drive->driver_data;
739 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer))
749 printk(KERN_INFO "ide-tape: Block location is unknown"
750 "to the tape\n");
758 tape->partition = buf[1];
759 tape->first_frame = be32_to_cpup((__be32 *)&buf[4]);
765 return tape->first_frame;
782 idetape_tape_t *tape = drive->driver_data;
784 if (tape->chrdev_dir != IDETAPE_DIR_READ)
788 tape->valid = 0;
789 if (tape->buf != NULL) {
790 kfree(tape->buf);
791 tape->buf = NULL;
794 tape->chrdev_dir = IDETAPE_DIR_NONE;
798 * Position the tape to the requested block using the LOCATE packet command.
806 idetape_tape_t *tape = drive->driver_data;
807 struct gendisk *disk = tape->disk;
811 if (tape->chrdev_dir == IDETAPE_DIR_READ)
828 idetape_tape_t *tape = drive->driver_data;
836 printk(KERN_INFO "ide-tape: %s: position_tape failed in"
837 " %s\n", tape->name, __func__);
849 idetape_tape_t *tape = drive->driver_data;
856 BUG_ON(size < 0 || size % tape->blk_size);
861 rq->rq_disk = tape->disk;
862 rq->__sector = tape->first_frame;
865 ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size,
871 blk_execute_rq(drive->queue, tape->disk, rq, 0);
875 tape->cur = tape->buf;
877 tape->valid = size;
879 tape->valid = 0;
924 idetape_tape_t *tape = drive->driver_data;
926 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
927 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer"
931 if (tape->buf) {
932 size_t aligned = roundup(tape->valid, tape->blk_size);
934 memset(tape->cur, 0, aligned - tape->valid);
936 kfree(tape->buf);
937 tape->buf = NULL;
939 tape->chrdev_dir = IDETAPE_DIR_NONE;
944 idetape_tape_t *tape = drive->driver_data;
949 if (tape->chrdev_dir == dir)
952 if (tape->chrdev_dir == IDETAPE_DIR_READ)
954 else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
959 if (tape->buf || tape->valid) {
960 printk(KERN_ERR "ide-tape: valid should be 0 now\n");
961 tape->valid = 0;
964 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
965 if (!tape->buf)
967 tape->chrdev_dir = dir;
968 tape->cur = tape->buf;
982 kfree(tape->buf);
983 tape->buf = NULL;
984 tape->chrdev_dir = IDETAPE_DIR_NONE;
994 idetape_tape_t *tape = drive->driver_data;
996 memset(tape->buf, 0, tape->buffer_size);
999 unsigned int count = min(tape->buffer_size, bcount);
1007 * Rewinds the tape to the Beginning Of the current Partition (BOP). We
1012 struct ide_tape_obj *tape = drive->driver_data;
1013 struct gendisk *disk = tape->disk;
1034 idetape_tape_t *tape = drive->driver_data;
1049 tape->best_dsc_rw_freq = config.dsc_rw_frequency;
1053 config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
1067 idetape_tape_t *tape = drive->driver_data;
1068 struct gendisk *disk = tape->disk;
1071 int sprev = !!(tape->caps[4] & 0x20);
1084 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1085 tape->valid = 0;
1109 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
1118 * The tape is optimized to maximize throughput when it is transferring an
1120 * the specific tape (26kB on my particular tape, 32kB for Onstream).
1133 struct ide_tape_obj *tape = file->private_data;
1134 ide_drive_t *drive = tape->drive;
1141 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
1143 if (count > tape->blk_size &&
1144 (count % tape->blk_size) == 0)
1145 tape->user_bs_factor = count / tape->blk_size;
1156 if (!tape->valid) {
1163 tape->buffer_size) <= 0)
1168 todo = min_t(size_t, count - done, tape->valid);
1169 if (copy_to_user(buf + done, tape->cur, todo))
1172 tape->cur += todo;
1173 tape->valid -= todo;
1188 struct ide_tape_obj *tape = file->private_data;
1189 ide_drive_t *drive = tape->drive;
1195 if (tape->write_prot)
1209 if (tape->valid == tape->buffer_size &&
1211 tape->buffer_size) <= 0)
1216 tape->buffer_size - tape->valid);
1217 if (copy_from_user(tape->cur, buf + done, todo))
1220 tape->cur += todo;
1221 tape->valid += todo;
1230 struct ide_tape_obj *tape = drive->driver_data;
1235 if (ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0)) {
1236 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
1246 * Note: MTBSF and MTBSFM are not supported when the tape doesn't support
1257 idetape_tape_t *tape = drive->driver_data;
1258 struct gendisk *disk = tape->disk;
1279 if (tape->write_prot)
1302 if (tape->door_locked) {
1304 tape->door_locked = DOOR_UNLOCKED;
1328 if (mt_count < tape->blk_size ||
1329 mt_count % tape->blk_size)
1331 tape->user_bs_factor = mt_count / tape->blk_size;
1341 mt_count * tape->user_bs_factor, tape->partition, 0);
1351 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
1357 tape->door_locked = DOOR_UNLOCKED;
1360 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
1369 * ide-tape ioctls are supported on both interfaces.
1374 struct ide_tape_obj *tape = file->private_data;
1375 ide_drive_t *drive = tape->drive;
1379 int block_offset = 0, position = tape->first_frame;
1384 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1389 block_offset = tape->valid /
1390 (tape->blk_size * tape->user_bs_factor);
1403 mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
1405 ((tape->blk_size * tape->user_bs_factor)
1408 if (tape->drv_write_prot)
1413 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
1416 if (tape->chrdev_dir == IDETAPE_DIR_READ)
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;
1459 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
1460 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
1461 if (tape->blk_size == 0) {
1462 printk(KERN_WARNING "ide-tape: Cannot deal with zero "
1464 tape->blk_size = 32768;
1468 tape->blk_size = (buf[4 + 5] << 16) +
1471 tape->drv_write_prot = (buf[2] & 0x80) >> 7;
1474 tape->blk_size, tape->drv_write_prot);
1481 idetape_tape_t *tape;
1489 tape = ide_tape_get(NULL, true, i);
1490 if (!tape) {
1495 drive = tape->drive;
1496 filp->private_data = tape;
1516 printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name);
1529 tape->write_prot = 1;
1531 tape->write_prot = tape->drv_write_prot;
1534 if (tape->write_prot) {
1543 /* Lock the tape drive door so user can't eject. */
1544 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
1545 if (!ide_set_media_lock(drive, tape->disk, 1)) {
1546 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
1547 tape->door_locked = DOOR_LOCKED;
1555 ide_tape_put(tape);
1564 idetape_tape_t *tape = drive->driver_data;
1567 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
1568 if (tape->buf != NULL) {
1569 idetape_pad_zeros(drive, tape->blk_size *
1570 (tape->user_bs_factor - 1));
1571 kfree(tape->buf);
1572 tape->buf = NULL;
1581 struct ide_tape_obj *tape = filp->private_data;
1582 ide_drive_t *drive = tape->drive;
1587 tape = drive->driver_data;
1591 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
1593 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1602 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
1603 if (tape->door_locked == DOOR_LOCKED) {
1604 if (!ide_set_media_lock(drive, tape->disk, 0))
1605 tape->door_locked = DOOR_UNLOCKED;
1609 ide_tape_put(tape);
1618 idetape_tape_t *tape = drive->driver_data;
1624 if (ide_queue_pc_tail(drive, tape->disk, &pc, pc_buf, pc.req_xfer)) {
1625 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
1626 tape->name);
1637 printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n",
1638 drive->name, tape->name, vendor_id, product_id, fw_rev);
1642 * Ask the tape about its various parameters. In particular, we will adjust our
1643 * data transfer buffer size to the recommended value as returned by the tape.
1647 idetape_tape_t *tape = drive->driver_data;
1653 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
1654 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
1656 tape->blk_size = 512;
1657 put_unaligned(52, (u16 *)&tape->caps[12]);
1658 put_unaligned(540, (u16 *)&tape->caps[14]);
1659 put_unaligned(6*52, (u16 *)&tape->caps[16]);
1674 printk(KERN_INFO "ide-tape: %s: invalid tape speed "
1679 printk(KERN_INFO "ide-tape: %s: invalid max_speed "
1684 memcpy(&tape->caps, caps, 20);
1691 tape->blk_size = 512;
1693 tape->blk_size = 1024;
1700 idetape_tape_t *tape = drive->driver_data; \
1701 return tape->field; \
1707 idetape_tape_t *tape = drive->driver_data; \
1708 tape->field = arg; \
1751 * 2. Ask the tape for its capabilities.
1758 static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
1762 u16 *ctl = (u16 *)&tape->caps[12];
1771 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
1772 tape->name);
1780 tape->minor = minor;
1781 tape->name[0] = 'h';
1782 tape->name[1] = 't';
1783 tape->name[2] = '0' + minor;
1784 tape->chrdev_dir = IDETAPE_DIR_NONE;
1789 tape->user_bs_factor = 1;
1790 tape->buffer_size = *ctl * tape->blk_size;
1791 while (tape->buffer_size > 0xffff) {
1792 printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
1794 tape->buffer_size = *ctl * tape->blk_size;
1798 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
1800 t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000);
1806 tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN,
1808 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
1810 drive->name, tape->name, *(u16 *)&tape->caps[14],
1811 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
1812 tape->buffer_size / 1024,
1813 jiffies_to_msecs(tape->best_dsc_rw_freq),
1816 ide_proc_register_driver(drive, tape->driver);
1821 idetape_tape_t *tape = drive->driver_data;
1823 ide_proc_unregister_driver(drive, tape->driver);
1824 device_del(&tape->dev);
1825 ide_unregister_region(tape->disk);
1828 put_device(&tape->dev);
1834 struct ide_tape_obj *tape = to_ide_drv(dev, ide_tape_obj);
1835 ide_drive_t *drive = tape->drive;
1836 struct gendisk *g = tape->disk;
1838 BUG_ON(tape->valid);
1842 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
1844 MKDEV(IDETAPE_MAJOR, tape->minor + 128));
1845 idetape_devs[tape->minor] = NULL;
1848 kfree(tape);
1855 idetape_tape_t *tape = drive->driver_data;
1857 seq_printf(m, "%s\n", tape->name);
1883 .name = "ide-tape",
1911 struct ide_tape_obj *tape;
1914 tape = ide_tape_get(bdev->bd_disk, false, 0);
1917 if (!tape)
1925 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
1928 ide_tape_put(tape);
1935 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
1936 ide_drive_t *drive = tape->drive;
1968 idetape_tape_t *tape;
1982 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
1986 tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL);
1987 if (tape == NULL) {
1988 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n",
1999 tape->dev.parent = &drive->gendev;
2000 tape->dev.release = ide_tape_release;
2001 dev_set_name(&tape->dev, "%s", dev_name(&drive->gendev));
2003 if (device_register(&tape->dev))
2006 tape->drive = drive;
2007 tape->driver = &idetape_driver;
2008 tape->disk = g;
2010 g->private_data = &tape->driver;
2012 drive->driver_data = tape;
2017 idetape_devs[minor] = tape;
2020 idetape_setup(drive, tape, minor);
2023 MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name);
2026 "n%s", tape->name);
2036 kfree(tape);
2060 printk(KERN_ERR "ide-tape: Failed to register chrdev"
2080 MODULE_ALIAS("ide:*m-tape*");