Lines Matching refs:tape

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