Lines Matching refs:tape
5 This is the high-level driver for parallel port ATAPI tape
13 writes are padded to full tape blocks, so reading back a file
17 port ATAPI tape drive, but if their individual parameters are
204 /* bits in tape->flags */
224 int capacity; /* Size of tape in KB */
230 static int pt_identify(struct pt_unit *tape);
267 static inline u8 DRIVE(struct pt_unit *tape)
269 return 0xa0+0x10*tape->drive;
272 static int pt_wait(struct pt_unit *tape, int go, int stop, char *fun, char *msg)
275 struct pi_adapter *pi = tape->pi;
291 tape->name, fun, msg, r, s, e, j, p);
297 static int pt_command(struct pt_unit *tape, char *cmd, int dlen, char *fun)
299 struct pi_adapter *pi = tape->pi;
302 write_reg(pi, 6, DRIVE(tape));
304 if (pt_wait(tape, STAT_BUSY | STAT_DRQ, 0, fun, "before command")) {
313 if (pt_wait(tape, STAT_BUSY, STAT_DRQ, fun, "command DRQ")) {
319 printk("%s: %s: command phase error\n", tape->name, fun);
329 static int pt_completion(struct pt_unit *tape, char *buf, char *fun)
331 struct pi_adapter *pi = tape->pi;
334 r = pt_wait(tape, STAT_BUSY, STAT_DRQ | STAT_READY | STAT_ERR,
347 s = pt_wait(tape, STAT_BUSY, STAT_READY | STAT_ERR, fun, "data done");
354 static void pt_req_sense(struct pt_unit *tape, int quiet)
360 r = pt_command(tape, rs_cmd, 16, "Request sense");
363 pt_completion(tape, buf, "Request sense");
365 tape->last_sense = -1;
369 tape->name, buf[2] & 0xf, buf[12], buf[13]);
370 tape->last_sense = (buf[2] & 0xf) | ((buf[12] & 0xff) << 8)
375 static int pt_atapi(struct pt_unit *tape, char *cmd, int dlen, char *buf, char *fun)
379 r = pt_command(tape, cmd, dlen, fun);
382 r = pt_completion(tape, buf, fun);
384 pt_req_sense(tape, !fun);
394 static int pt_poll_dsc(struct pt_unit *tape, int pause, int tmo, char *msg)
396 struct pi_adapter *pi = tape->pi;
406 write_reg(pi, 6, DRIVE(tape));
415 printk("%s: %s DSC timeout\n", tape->name, msg);
417 printk("%s: %s stat=0x%x err=0x%x\n", tape->name, msg, s,
419 pt_req_sense(tape, 0);
425 static void pt_media_access_cmd(struct pt_unit *tape, int tmo, char *cmd, char *fun)
427 if (pt_command(tape, cmd, 0, fun)) {
428 pt_req_sense(tape, 0);
431 pi_disconnect(tape->pi);
432 pt_poll_dsc(tape, HZ, tmo, fun);
435 static void pt_rewind(struct pt_unit *tape)
439 pt_media_access_cmd(tape, PT_REWIND_TMO, rw_cmd, "rewind");
442 static void pt_write_fm(struct pt_unit *tape)
446 pt_media_access_cmd(tape, PT_TMO, wm_cmd, "write filemark");
451 static int pt_reset(struct pt_unit *tape)
453 struct pi_adapter *pi = tape->pi;
458 write_reg(pi, 6, DRIVE(tape));
472 printk("%s: Reset (%d) signature = ", tape->name, k);
484 static int pt_ready_wait(struct pt_unit *tape, int tmo)
491 tape->last_sense = 0;
492 pt_atapi(tape, tr_cmd, 0, NULL, DBMSG("test unit ready"));
493 p = tape->last_sense;
528 static int pt_identify(struct pt_unit *tape)
540 s = pt_atapi(tape, id_cmd, 36, buf, "identify");
548 tape->name, tape->drive, dt);
555 tape->flags = 0;
556 tape->capacity = 0;
557 tape->bs = 0;
559 if (!pt_ready_wait(tape, PT_READY_TMO))
560 tape->flags |= PT_MEDIA;
562 if (!pt_atapi(tape, ms_cmd, 36, buf, "mode sense")) {
564 tape->flags |= PT_WRITE_OK;
565 tape->bs = xn(buf, 10, 2);
568 if (!pt_atapi(tape, ls_cmd, 36, buf, "log sense"))
569 tape->capacity = xn(buf, 24, 4);
571 printk("%s: %s %s, %s", tape->name, mf, id, ms[tape->drive]);
572 if (!(tape->flags & PT_MEDIA))
575 if (!(tape->flags & PT_WRITE_OK))
577 printk(", blocksize %d, %d MB\n", tape->bs, tape->capacity / 1024);
588 static int pt_probe(struct pt_unit *tape)
590 if (tape->drive == -1) {
591 for (tape->drive = 0; tape->drive <= 1; tape->drive++)
592 if (!pt_reset(tape))
593 return pt_identify(tape);
595 if (!pt_reset(tape))
596 return pt_identify(tape);
603 struct pt_unit *tape;
617 struct pt_unit *tape = &pt[unit];
618 tape->pi = &tape->pia;
619 atomic_set(&tape->available, 1);
620 tape->flags = 0;
621 tape->last_sense = 0;
622 tape->present = 0;
623 tape->bufptr = NULL;
624 tape->drive = DU[D_SLV];
625 snprintf(tape->name, PT_NAMELEN, "%s%d", name, unit);
629 if (pi_init(tape->pi, 0, DU[D_PRT], DU[D_MOD], DU[D_UNI],
631 verbose, tape->name)) {
632 if (!pt_probe(tape)) {
633 tape->present = 1;
636 pi_release(tape->pi);
640 tape = pt;
641 if (pi_init(tape->pi, 1, -1, -1, -1, -1, -1, pt_scratch,
642 PI_PT, verbose, tape->name)) {
643 if (!pt_probe(tape)) {
644 tape->present = 1;
647 pi_release(tape->pi);
655 printk("%s: No ATAPI tape drive detected\n", name);
662 struct pt_unit *tape = pt + unit;
666 if (unit >= PT_UNITS || (!tape->present)) {
672 if (!atomic_dec_and_test(&tape->available))
675 pt_identify(tape);
678 if (!(tape->flags & PT_MEDIA))
682 if ((!(tape->flags & PT_WRITE_OK)) && (file->f_mode & FMODE_WRITE))
686 tape->flags |= PT_REWIND;
689 tape->bufptr = kmalloc(PT_BUFSIZE, GFP_KERNEL);
690 if (tape->bufptr == NULL) {
691 printk("%s: buffer allocation failed\n", tape->name);
695 file->private_data = tape;
700 atomic_inc(&tape->available);
707 struct pt_unit *tape = file->private_data;
720 pt_rewind(tape);
726 pt_write_fm(tape);
732 printk(KERN_DEBUG "%s: Unimplemented mt_op %d\n", tape->name,
745 struct pt_unit *tape = file->private_data;
747 if (atomic_read(&tape->available) > 1)
750 if (tape->flags & PT_WRITING)
751 pt_write_fm(tape);
753 if (tape->flags & PT_REWIND)
754 pt_rewind(tape);
756 kfree(tape->bufptr);
757 tape->bufptr = NULL;
759 atomic_inc(&tape->available);
767 struct pt_unit *tape = filp->private_data;
768 struct pi_adapter *pi = tape->pi;
772 if (!(tape->flags & (PT_READING | PT_WRITING))) {
773 tape->flags |= PT_READING;
774 if (pt_atapi(tape, rd_cmd, 0, NULL, "start read-ahead"))
776 } else if (tape->flags & PT_WRITING)
779 if (tape->flags & PT_EOF)
786 if (!pt_poll_dsc(tape, HZ / 100, PT_TMO, "read"))
792 b = (n - 1 + tape->bs) / tape->bs;
793 n = b * tape->bs; /* rounded up to even block */
797 r = pt_command(tape, rd_cmd, n, "read");
802 pt_req_sense(tape, 0);
808 r = pt_wait(tape, STAT_BUSY,
814 pt_req_sense(tape, 0);
819 tape->flags |= PT_EOF;
830 printk("%s: Phase error on read: %d\n", tape->name,
839 pi_read_block(pi, tape->bufptr, k);
844 if (copy_to_user(buf + t, tape->bufptr, b)) {
854 if (tape->flags & PT_EOF)
864 struct pt_unit *tape = filp->private_data;
865 struct pi_adapter *pi = tape->pi;
869 if (!(tape->flags & PT_WRITE_OK))
872 if (!(tape->flags & (PT_READING | PT_WRITING))) {
873 tape->flags |= PT_WRITING;
875 (tape, wr_cmd, 0, NULL, "start buffer-available mode"))
877 } else if (tape->flags & PT_READING)
880 if (tape->flags & PT_EOF)
887 if (!pt_poll_dsc(tape, HZ / 100, PT_TMO, "write"))
893 b = (n - 1 + tape->bs) / tape->bs;
894 n = b * tape->bs; /* rounded up to even block */
898 r = pt_command(tape, wr_cmd, n, "write");
903 pt_req_sense(tape, 0);
909 r = pt_wait(tape, STAT_BUSY,
915 pt_req_sense(tape, 0);
920 tape->flags |= PT_EOF;
932 tape->name, p);
943 if (copy_from_user(tape->bufptr, buf + t, b)) {
947 pi_write_block(pi, tape->bufptr, k);
955 if (tape->flags & PT_EOF)