xref: /csrg-svn/sys/vax/stand/ht.c (revision 3349)
1*3349Swnj /*	ht.c	4.5	81/03/22	*/
2319Sbill 
3319Sbill /*
43262Swnj  * TM03/TU?? tape driver
5319Sbill  */
6319Sbill 
73262Swnj #include "../h/htreg.h"
8319Sbill #include "../h/param.h"
9319Sbill #include "../h/inode.h"
10422Sbill #include "../h/pte.h"
113262Swnj #include "../h/mbareg.h"
12319Sbill #include "saio.h"
133262Swnj #include "savax.h"
14319Sbill 
15*3349Swnj short	httypes[] =
16*3349Swnj 	{ MBDT_TM03, MBDT_TE16, MBDT_TU45, MBDT_TU77, 0 };
17*3349Swnj 
18*3349Swnj #define	MASKREG(reg)	((reg)&0xffff)
19*3349Swnj 
20319Sbill htopen(io)
213262Swnj 	register struct iob *io;
22319Sbill {
233262Swnj 	register int skip;
243262Swnj 	register struct htdevice *htaddr = (struct htdevice *)mbadrv(io->i_unit);
25319Sbill 	int i;
26319Sbill 
27*3349Swnj 	for (i = 0; httypes[i]; i++)
28*3349Swnj 		if (httypes[i] == (htaddr->htdt&MBDT_TYPE))
29*3349Swnj 			goto found;
30*3349Swnj 	_stop("not a tape\n");
31*3349Swnj found:
323262Swnj 	mbainit(UNITTOMBA(io->i_unit));
333262Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
343262Swnj 	htstrategy(io, HT_REW);
35319Sbill 	skip = io->i_boff;
36319Sbill 	while (skip--) {
37319Sbill 		io->i_cc = -1;
383262Swnj 		while (htstrategy(io, HT_SFORW))
39319Sbill 			;
403262Swnj 		DELAY(65536);
413262Swnj 		htstrategy(io, HT_SENSE);
42319Sbill 	}
43319Sbill }
44319Sbill 
45319Sbill htclose(io)
463262Swnj 	register struct iob *io;
47319Sbill {
483262Swnj 
493262Swnj 	htstrategy(io, HT_REW);
50319Sbill }
51319Sbill 
52319Sbill htstrategy(io, func)
533262Swnj 	register struct iob *io;
543262Swnj 	int func;
55319Sbill {
563262Swnj 	register int den, errcnt, ds;
57319Sbill 	short fc;
583262Swnj 	register struct htdevice *htaddr =
593262Swnj 	    (struct htdevice *)mbadrv(io->i_unit);
60319Sbill 
61319Sbill 	errcnt = 0;
62319Sbill retry:
633262Swnj 	den = HTTC_1600BPI|HTTC_PDP11;
643262Swnj 	htquiet(htaddr);
65*3349Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
663262Swnj 	htaddr->httc = den;
673262Swnj 	htaddr->htfc = -io->i_cc;
683262Swnj 	if (func == HT_SREV) {
693262Swnj 		htaddr->htfc = -1;
703262Swnj 		htaddr->htcs1 = HT_SREV|HT_GO;
713262Swnj 		return (0);
72319Sbill 	}
733274Swnj 	if (func == READ || func == WRITE)
743262Swnj 		mbastart(io, func);
75319Sbill 	else
763262Swnj 		htaddr->htcs1 = func|HT_GO;
773262Swnj 	htquiet(htaddr);
783262Swnj 	ds = htaddr->htds;
793262Swnj 	if (ds & HTDS_TM) {
803262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
813262Swnj 		return (0);
82319Sbill 	}
833262Swnj 	if (ds & HTDS_ERR) {
84*3349Swnj 		printf("ht error: ds=%b, er=%b\n",
85*3349Swnj 		    MASKREG(htaddr->htds), HTDS_BITS,
86*3349Swnj 		    MASKREG(htaddr->hter), HTER_BITS);
873262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
88319Sbill 		if (errcnt == 10) {
89*3349Swnj 			printf("ht: unrecovered error\n");
903262Swnj 			return (-1);
91319Sbill 		}
92319Sbill 		errcnt++;
933262Swnj 		htstrategy(io, HT_SREV);
94319Sbill 		goto retry;
95319Sbill 	}
96319Sbill 	if (errcnt)
97*3349Swnj 		printf("ht: recovered by retry\n");
983262Swnj 	fc = htaddr->htfc;
993262Swnj 	return (io->i_cc+fc);
100319Sbill }
101319Sbill 
1023262Swnj htquiet(htaddr)
1033262Swnj 	register struct htdevice *htaddr;
104319Sbill {
105319Sbill 	register int s;
106319Sbill 
107319Sbill 	do
1083262Swnj 		s = htaddr->htds;
1093262Swnj 	while ((s & HTDS_DRY) == 0);
110319Sbill }
111