xref: /csrg-svn/sys/vax/stand/ht.c (revision 10865)
1*10865Ssam /*	ht.c	4.10	83/02/10	*/
2319Sbill 
3319Sbill /*
43262Swnj  * TM03/TU?? tape driver
5319Sbill  */
69804Ssam #include "../machine/pte.h"
7319Sbill 
8319Sbill #include "../h/param.h"
9319Sbill #include "../h/inode.h"
106070Smckusic #include "../h/fs.h"
119186Ssam 
129186Ssam #include "../vaxmba/htreg.h"
139186Ssam #include "../vaxmba/mbareg.h"
149186Ssam 
15319Sbill #include "saio.h"
163262Swnj #include "savax.h"
17319Sbill 
183349Swnj short	httypes[] =
193349Swnj 	{ MBDT_TM03, MBDT_TE16, MBDT_TU45, MBDT_TU77, 0 };
203349Swnj 
213349Swnj #define	MASKREG(reg)	((reg)&0xffff)
223349Swnj 
23319Sbill htopen(io)
243262Swnj 	register struct iob *io;
25319Sbill {
263262Swnj 	register int skip;
27*10865Ssam 	register struct htdevice *htaddr =
28*10865Ssam 	   (struct htdevice *)mbadrv(io->i_unit);
29319Sbill 	int i;
30319Sbill 
313349Swnj 	for (i = 0; httypes[i]; i++)
323349Swnj 		if (httypes[i] == (htaddr->htdt&MBDT_TYPE))
333349Swnj 			goto found;
343349Swnj 	_stop("not a tape\n");
353349Swnj found:
363262Swnj 	mbainit(UNITTOMBA(io->i_unit));
373262Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
383262Swnj 	htstrategy(io, HT_REW);
39319Sbill 	skip = io->i_boff;
40319Sbill 	while (skip--) {
41319Sbill 		io->i_cc = -1;
423262Swnj 		while (htstrategy(io, HT_SFORW))
43319Sbill 			;
443262Swnj 		DELAY(65536);
453262Swnj 		htstrategy(io, HT_SENSE);
46319Sbill 	}
47319Sbill }
48319Sbill 
49319Sbill htclose(io)
503262Swnj 	register struct iob *io;
51319Sbill {
523262Swnj 
533262Swnj 	htstrategy(io, HT_REW);
54319Sbill }
55319Sbill 
56319Sbill htstrategy(io, func)
573262Swnj 	register struct iob *io;
583262Swnj 	int func;
59319Sbill {
603262Swnj 	register int den, errcnt, ds;
615159Sroot 	int er;
62319Sbill 	short fc;
633262Swnj 	register struct htdevice *htaddr =
643262Swnj 	    (struct htdevice *)mbadrv(io->i_unit);
65319Sbill 
66319Sbill 	errcnt = 0;
67319Sbill retry:
683262Swnj 	den = HTTC_1600BPI|HTTC_PDP11;
693262Swnj 	htquiet(htaddr);
703349Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
713262Swnj 	htaddr->httc = den;
723262Swnj 	htaddr->htfc = -io->i_cc;
733262Swnj 	if (func == HT_SREV) {
743262Swnj 		htaddr->htfc = -1;
753262Swnj 		htaddr->htcs1 = HT_SREV|HT_GO;
763262Swnj 		return (0);
77319Sbill 	}
783274Swnj 	if (func == READ || func == WRITE)
793262Swnj 		mbastart(io, func);
80319Sbill 	else
813262Swnj 		htaddr->htcs1 = func|HT_GO;
823262Swnj 	htquiet(htaddr);
833262Swnj 	ds = htaddr->htds;
845159Sroot 	er = htaddr->hter;
853262Swnj 	if (ds & HTDS_TM) {
863262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
873262Swnj 		return (0);
88319Sbill 	}
893262Swnj 	if (ds & HTDS_ERR) {
903262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
915159Sroot 		if ((er & HTER_CORCRC) == 0) {
925159Sroot 			printf("ht error: ds=%b, er=%b\n",
935159Sroot 			    MASKREG(ds), HTDS_BITS,
945159Sroot 			    MASKREG(er), HTER_BITS);
955159Sroot 			if (errcnt == 10) {
965159Sroot 				printf("ht: unrecovered error\n");
975159Sroot 				return (-1);
985159Sroot 			}
995159Sroot 			errcnt++;
1005159Sroot 			htstrategy(io, HT_SREV);
1015159Sroot 			goto retry;
102319Sbill 		}
103319Sbill 	}
104319Sbill 	if (errcnt)
1053349Swnj 		printf("ht: recovered by retry\n");
1063262Swnj 	fc = htaddr->htfc;
1073262Swnj 	return (io->i_cc+fc);
108319Sbill }
109319Sbill 
1103262Swnj htquiet(htaddr)
1113262Swnj 	register struct htdevice *htaddr;
112319Sbill {
113319Sbill 	register int s;
114319Sbill 
115319Sbill 	do
1163262Swnj 		s = htaddr->htds;
1173262Swnj 	while ((s & HTDS_DRY) == 0);
118319Sbill }
119