Lines Matching refs:tape
230 static int pt_identify(struct pt_unit *tape);
266 static inline u8 DRIVE(struct pt_unit *tape) in DRIVE() argument
268 return 0xa0+0x10*tape->drive; in DRIVE()
271 static int pt_wait(struct pt_unit *tape, int go, int stop, char *fun, char *msg) in pt_wait() argument
274 struct pi_adapter *pi = tape->pi; in pt_wait()
290 tape->name, fun, msg, r, s, e, j, p); in pt_wait()
296 static int pt_command(struct pt_unit *tape, char *cmd, int dlen, char *fun) in pt_command() argument
298 struct pi_adapter *pi = tape->pi; in pt_command()
301 write_reg(pi, 6, DRIVE(tape)); in pt_command()
303 if (pt_wait(tape, STAT_BUSY | STAT_DRQ, 0, fun, "before command")) { in pt_command()
312 if (pt_wait(tape, STAT_BUSY, STAT_DRQ, fun, "command DRQ")) { in pt_command()
318 printk("%s: %s: command phase error\n", tape->name, fun); in pt_command()
328 static int pt_completion(struct pt_unit *tape, char *buf, char *fun) in pt_completion() argument
330 struct pi_adapter *pi = tape->pi; in pt_completion()
333 r = pt_wait(tape, STAT_BUSY, STAT_DRQ | STAT_READY | STAT_ERR, in pt_completion()
346 s = pt_wait(tape, STAT_BUSY, STAT_READY | STAT_ERR, fun, "data done"); in pt_completion()
353 static void pt_req_sense(struct pt_unit *tape, int quiet) in pt_req_sense() argument
359 r = pt_command(tape, rs_cmd, 16, "Request sense"); in pt_req_sense()
362 pt_completion(tape, buf, "Request sense"); in pt_req_sense()
364 tape->last_sense = -1; in pt_req_sense()
368 tape->name, buf[2] & 0xf, buf[12], buf[13]); in pt_req_sense()
369 tape->last_sense = (buf[2] & 0xf) | ((buf[12] & 0xff) << 8) in pt_req_sense()
374 static int pt_atapi(struct pt_unit *tape, char *cmd, int dlen, char *buf, char *fun) in pt_atapi() argument
378 r = pt_command(tape, cmd, dlen, fun); in pt_atapi()
381 r = pt_completion(tape, buf, fun); in pt_atapi()
383 pt_req_sense(tape, !fun); in pt_atapi()
393 static int pt_poll_dsc(struct pt_unit *tape, int pause, int tmo, char *msg) in pt_poll_dsc() argument
395 struct pi_adapter *pi = tape->pi; in pt_poll_dsc()
405 write_reg(pi, 6, DRIVE(tape)); in pt_poll_dsc()
414 printk("%s: %s DSC timeout\n", tape->name, msg); in pt_poll_dsc()
416 printk("%s: %s stat=0x%x err=0x%x\n", tape->name, msg, s, in pt_poll_dsc()
418 pt_req_sense(tape, 0); in pt_poll_dsc()
424 static void pt_media_access_cmd(struct pt_unit *tape, int tmo, char *cmd, char *fun) in pt_media_access_cmd() argument
426 if (pt_command(tape, cmd, 0, fun)) { in pt_media_access_cmd()
427 pt_req_sense(tape, 0); in pt_media_access_cmd()
430 pi_disconnect(tape->pi); in pt_media_access_cmd()
431 pt_poll_dsc(tape, HZ, tmo, fun); in pt_media_access_cmd()
434 static void pt_rewind(struct pt_unit *tape) in pt_rewind() argument
438 pt_media_access_cmd(tape, PT_REWIND_TMO, rw_cmd, "rewind"); in pt_rewind()
441 static void pt_write_fm(struct pt_unit *tape) in pt_write_fm() argument
445 pt_media_access_cmd(tape, PT_TMO, wm_cmd, "write filemark"); in pt_write_fm()
450 static int pt_reset(struct pt_unit *tape) in pt_reset() argument
452 struct pi_adapter *pi = tape->pi; in pt_reset()
457 write_reg(pi, 6, DRIVE(tape)); in pt_reset()
471 printk("%s: Reset (%d) signature = ", tape->name, k); in pt_reset()
483 static int pt_ready_wait(struct pt_unit *tape, int tmo) in pt_ready_wait() argument
490 tape->last_sense = 0; in pt_ready_wait()
491 pt_atapi(tape, tr_cmd, 0, NULL, DBMSG("test unit ready")); in pt_ready_wait()
492 p = tape->last_sense; in pt_ready_wait()
527 static int pt_identify(struct pt_unit *tape) in pt_identify() argument
539 s = pt_atapi(tape, id_cmd, 36, buf, "identify"); in pt_identify()
547 tape->name, tape->drive, dt); in pt_identify()
554 tape->flags = 0; in pt_identify()
555 tape->capacity = 0; in pt_identify()
556 tape->bs = 0; in pt_identify()
558 if (!pt_ready_wait(tape, PT_READY_TMO)) in pt_identify()
559 tape->flags |= PT_MEDIA; in pt_identify()
561 if (!pt_atapi(tape, ms_cmd, 36, buf, "mode sense")) { in pt_identify()
563 tape->flags |= PT_WRITE_OK; in pt_identify()
564 tape->bs = xn(buf, 10, 2); in pt_identify()
567 if (!pt_atapi(tape, ls_cmd, 36, buf, "log sense")) in pt_identify()
568 tape->capacity = xn(buf, 24, 4); in pt_identify()
570 printk("%s: %s %s, %s", tape->name, mf, id, ms[tape->drive]); in pt_identify()
571 if (!(tape->flags & PT_MEDIA)) in pt_identify()
574 if (!(tape->flags & PT_WRITE_OK)) in pt_identify()
576 printk(", blocksize %d, %d MB\n", tape->bs, tape->capacity / 1024); in pt_identify()
587 static int pt_probe(struct pt_unit *tape) in pt_probe() argument
589 if (tape->drive == -1) { in pt_probe()
590 for (tape->drive = 0; tape->drive <= 1; tape->drive++) in pt_probe()
591 if (!pt_reset(tape)) in pt_probe()
592 return pt_identify(tape); in pt_probe()
594 if (!pt_reset(tape)) in pt_probe()
595 return pt_identify(tape); in pt_probe()
602 struct pt_unit *tape; in pt_detect() local
610 struct pt_unit *tape = &pt[unit]; in pt_detect() local
611 tape->pi = &tape->pia; in pt_detect()
612 atomic_set(&tape->available, 1); in pt_detect()
613 tape->flags = 0; in pt_detect()
614 tape->last_sense = 0; in pt_detect()
615 tape->present = 0; in pt_detect()
616 tape->bufptr = NULL; in pt_detect()
617 tape->drive = DU[D_SLV]; in pt_detect()
618 snprintf(tape->name, PT_NAMELEN, "%s%d", name, unit); in pt_detect()
622 if (pi_init(tape->pi, 0, DU[D_PRT], DU[D_MOD], DU[D_UNI], in pt_detect()
624 verbose, tape->name)) { in pt_detect()
625 if (!pt_probe(tape)) { in pt_detect()
626 tape->present = 1; in pt_detect()
629 pi_release(tape->pi); in pt_detect()
633 tape = pt; in pt_detect()
634 if (pi_init(tape->pi, 1, -1, -1, -1, -1, -1, pt_scratch, in pt_detect()
635 PI_PT, verbose, tape->name)) { in pt_detect()
636 if (!pt_probe(tape)) { in pt_detect()
637 tape->present = 1; in pt_detect()
640 pi_release(tape->pi); in pt_detect()
654 struct pt_unit *tape = pt + unit; in pt_open() local
658 if (unit >= PT_UNITS || (!tape->present)) { in pt_open()
664 if (!atomic_dec_and_test(&tape->available)) in pt_open()
667 pt_identify(tape); in pt_open()
670 if (!(tape->flags & PT_MEDIA)) in pt_open()
674 if ((!(tape->flags & PT_WRITE_OK)) && (file->f_mode & FMODE_WRITE)) in pt_open()
678 tape->flags |= PT_REWIND; in pt_open()
681 tape->bufptr = kmalloc(PT_BUFSIZE, GFP_KERNEL); in pt_open()
682 if (tape->bufptr == NULL) { in pt_open()
683 printk("%s: buffer allocation failed\n", tape->name); in pt_open()
687 file->private_data = tape; in pt_open()
692 atomic_inc(&tape->available); in pt_open()
699 struct pt_unit *tape = file->private_data; in pt_ioctl() local
712 pt_rewind(tape); in pt_ioctl()
718 pt_write_fm(tape); in pt_ioctl()
724 printk(KERN_DEBUG "%s: Unimplemented mt_op %d\n", tape->name, in pt_ioctl()
737 struct pt_unit *tape = file->private_data; in pt_release() local
739 if (atomic_read(&tape->available) > 1) in pt_release()
742 if (tape->flags & PT_WRITING) in pt_release()
743 pt_write_fm(tape); in pt_release()
745 if (tape->flags & PT_REWIND) in pt_release()
746 pt_rewind(tape); in pt_release()
748 kfree(tape->bufptr); in pt_release()
749 tape->bufptr = NULL; in pt_release()
751 atomic_inc(&tape->available); in pt_release()
759 struct pt_unit *tape = filp->private_data; in pt_read() local
760 struct pi_adapter *pi = tape->pi; in pt_read()
764 if (!(tape->flags & (PT_READING | PT_WRITING))) { in pt_read()
765 tape->flags |= PT_READING; in pt_read()
766 if (pt_atapi(tape, rd_cmd, 0, NULL, "start read-ahead")) in pt_read()
768 } else if (tape->flags & PT_WRITING) in pt_read()
771 if (tape->flags & PT_EOF) in pt_read()
778 if (!pt_poll_dsc(tape, HZ / 100, PT_TMO, "read")) in pt_read()
784 b = (n - 1 + tape->bs) / tape->bs; in pt_read()
785 n = b * tape->bs; /* rounded up to even block */ in pt_read()
789 r = pt_command(tape, rd_cmd, n, "read"); in pt_read()
794 pt_req_sense(tape, 0); in pt_read()
800 r = pt_wait(tape, STAT_BUSY, in pt_read()
806 pt_req_sense(tape, 0); in pt_read()
811 tape->flags |= PT_EOF; in pt_read()
822 printk("%s: Phase error on read: %d\n", tape->name, in pt_read()
831 pi_read_block(pi, tape->bufptr, k); in pt_read()
836 if (copy_to_user(buf + t, tape->bufptr, b)) { in pt_read()
846 if (tape->flags & PT_EOF) in pt_read()
856 struct pt_unit *tape = filp->private_data; in pt_write() local
857 struct pi_adapter *pi = tape->pi; in pt_write()
861 if (!(tape->flags & PT_WRITE_OK)) in pt_write()
864 if (!(tape->flags & (PT_READING | PT_WRITING))) { in pt_write()
865 tape->flags |= PT_WRITING; in pt_write()
867 (tape, wr_cmd, 0, NULL, "start buffer-available mode")) in pt_write()
869 } else if (tape->flags & PT_READING) in pt_write()
872 if (tape->flags & PT_EOF) in pt_write()
879 if (!pt_poll_dsc(tape, HZ / 100, PT_TMO, "write")) in pt_write()
885 b = (n - 1 + tape->bs) / tape->bs; in pt_write()
886 n = b * tape->bs; /* rounded up to even block */ in pt_write()
890 r = pt_command(tape, wr_cmd, n, "write"); in pt_write()
895 pt_req_sense(tape, 0); in pt_write()
901 r = pt_wait(tape, STAT_BUSY, in pt_write()
907 pt_req_sense(tape, 0); in pt_write()
912 tape->flags |= PT_EOF; in pt_write()
924 tape->name, p); in pt_write()
935 if (copy_from_user(tape->bufptr, buf + t, b)) { in pt_write()
939 pi_write_block(pi, tape->bufptr, k); in pt_write()
947 if (tape->flags & PT_EOF) in pt_write()