xref: /csrg-svn/sys/vax/stand/ht.c (revision 23227)
1*23227Smckusick /*
2*23227Smckusick  * Copyright (c) 1982 Regents of the University of California.
3*23227Smckusick  * All rights reserved.  The Berkeley software License Agreement
4*23227Smckusick  * specifies the terms and conditions for redistribution.
5*23227Smckusick  *
6*23227Smckusick  *	@(#)ht.c	6.2 (Berkeley) 06/08/85
7*23227Smckusick  */
8319Sbill 
9319Sbill /*
103262Swnj  * TM03/TU?? tape driver
11319Sbill  */
129804Ssam #include "../machine/pte.h"
13319Sbill 
14319Sbill #include "../h/param.h"
15319Sbill #include "../h/inode.h"
166070Smckusic #include "../h/fs.h"
179186Ssam 
189186Ssam #include "../vaxmba/htreg.h"
199186Ssam #include "../vaxmba/mbareg.h"
209186Ssam 
21319Sbill #include "saio.h"
223262Swnj #include "savax.h"
23319Sbill 
243349Swnj short	httypes[] =
253349Swnj 	{ MBDT_TM03, MBDT_TE16, MBDT_TU45, MBDT_TU77, 0 };
263349Swnj 
273349Swnj #define	MASKREG(reg)	((reg)&0xffff)
283349Swnj 
29319Sbill htopen(io)
303262Swnj 	register struct iob *io;
31319Sbill {
323262Swnj 	register int skip;
3310865Ssam 	register struct htdevice *htaddr =
3410865Ssam 	   (struct htdevice *)mbadrv(io->i_unit);
35319Sbill 	int i;
36319Sbill 
373349Swnj 	for (i = 0; httypes[i]; i++)
383349Swnj 		if (httypes[i] == (htaddr->htdt&MBDT_TYPE))
393349Swnj 			goto found;
403349Swnj 	_stop("not a tape\n");
413349Swnj found:
423262Swnj 	mbainit(UNITTOMBA(io->i_unit));
433262Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
443262Swnj 	htstrategy(io, HT_REW);
45319Sbill 	skip = io->i_boff;
46319Sbill 	while (skip--) {
47319Sbill 		io->i_cc = -1;
483262Swnj 		while (htstrategy(io, HT_SFORW))
49319Sbill 			;
503262Swnj 		DELAY(65536);
513262Swnj 		htstrategy(io, HT_SENSE);
52319Sbill 	}
53319Sbill }
54319Sbill 
55319Sbill htclose(io)
563262Swnj 	register struct iob *io;
57319Sbill {
583262Swnj 
593262Swnj 	htstrategy(io, HT_REW);
60319Sbill }
61319Sbill 
62319Sbill htstrategy(io, func)
633262Swnj 	register struct iob *io;
643262Swnj 	int func;
65319Sbill {
663262Swnj 	register int den, errcnt, ds;
675159Sroot 	int er;
68319Sbill 	short fc;
693262Swnj 	register struct htdevice *htaddr =
703262Swnj 	    (struct htdevice *)mbadrv(io->i_unit);
71319Sbill 
72319Sbill 	errcnt = 0;
73319Sbill retry:
743262Swnj 	den = HTTC_1600BPI|HTTC_PDP11;
753262Swnj 	htquiet(htaddr);
763349Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
773262Swnj 	htaddr->httc = den;
783262Swnj 	htaddr->htfc = -io->i_cc;
793262Swnj 	if (func == HT_SREV) {
803262Swnj 		htaddr->htfc = -1;
813262Swnj 		htaddr->htcs1 = HT_SREV|HT_GO;
823262Swnj 		return (0);
83319Sbill 	}
843274Swnj 	if (func == READ || func == WRITE)
853262Swnj 		mbastart(io, func);
86319Sbill 	else
873262Swnj 		htaddr->htcs1 = func|HT_GO;
883262Swnj 	htquiet(htaddr);
893262Swnj 	ds = htaddr->htds;
905159Sroot 	er = htaddr->hter;
913262Swnj 	if (ds & HTDS_TM) {
923262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
933262Swnj 		return (0);
94319Sbill 	}
953262Swnj 	if (ds & HTDS_ERR) {
963262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
975159Sroot 		if ((er & HTER_CORCRC) == 0) {
985159Sroot 			printf("ht error: ds=%b, er=%b\n",
995159Sroot 			    MASKREG(ds), HTDS_BITS,
1005159Sroot 			    MASKREG(er), HTER_BITS);
1015159Sroot 			if (errcnt == 10) {
1025159Sroot 				printf("ht: unrecovered error\n");
1035159Sroot 				return (-1);
1045159Sroot 			}
1055159Sroot 			errcnt++;
1065159Sroot 			htstrategy(io, HT_SREV);
1075159Sroot 			goto retry;
108319Sbill 		}
109319Sbill 	}
110319Sbill 	if (errcnt)
1113349Swnj 		printf("ht: recovered by retry\n");
1123262Swnj 	fc = htaddr->htfc;
1133262Swnj 	return (io->i_cc+fc);
114319Sbill }
115319Sbill 
1163262Swnj htquiet(htaddr)
1173262Swnj 	register struct htdevice *htaddr;
118319Sbill {
119319Sbill 	register int s;
120319Sbill 
121319Sbill 	do
1223262Swnj 		s = htaddr->htds;
1233262Swnj 	while ((s & HTDS_DRY) == 0);
124319Sbill }
125