xref: /csrg-svn/sys/vax/stand/ht.c (revision 6070)
1*6070Smckusic /*	ht.c	4.7	82/03/07	*/
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"
12*6070Smckusic #include "../h/fs.h"
13319Sbill #include "saio.h"
143262Swnj #include "savax.h"
15319Sbill 
163349Swnj short	httypes[] =
173349Swnj 	{ MBDT_TM03, MBDT_TE16, MBDT_TU45, MBDT_TU77, 0 };
183349Swnj 
193349Swnj #define	MASKREG(reg)	((reg)&0xffff)
203349Swnj 
21319Sbill htopen(io)
223262Swnj 	register struct iob *io;
23319Sbill {
243262Swnj 	register int skip;
253262Swnj 	register struct htdevice *htaddr = (struct htdevice *)mbadrv(io->i_unit);
26319Sbill 	int i;
27319Sbill 
283349Swnj 	for (i = 0; httypes[i]; i++)
293349Swnj 		if (httypes[i] == (htaddr->htdt&MBDT_TYPE))
303349Swnj 			goto found;
313349Swnj 	_stop("not a tape\n");
323349Swnj found:
333262Swnj 	mbainit(UNITTOMBA(io->i_unit));
343262Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
353262Swnj 	htstrategy(io, HT_REW);
36319Sbill 	skip = io->i_boff;
37319Sbill 	while (skip--) {
38319Sbill 		io->i_cc = -1;
393262Swnj 		while (htstrategy(io, HT_SFORW))
40319Sbill 			;
413262Swnj 		DELAY(65536);
423262Swnj 		htstrategy(io, HT_SENSE);
43319Sbill 	}
44319Sbill }
45319Sbill 
46319Sbill htclose(io)
473262Swnj 	register struct iob *io;
48319Sbill {
493262Swnj 
503262Swnj 	htstrategy(io, HT_REW);
51319Sbill }
52319Sbill 
53319Sbill htstrategy(io, func)
543262Swnj 	register struct iob *io;
553262Swnj 	int func;
56319Sbill {
573262Swnj 	register int den, errcnt, ds;
585159Sroot 	int er;
59319Sbill 	short fc;
603262Swnj 	register struct htdevice *htaddr =
613262Swnj 	    (struct htdevice *)mbadrv(io->i_unit);
62319Sbill 
63319Sbill 	errcnt = 0;
64319Sbill retry:
653262Swnj 	den = HTTC_1600BPI|HTTC_PDP11;
663262Swnj 	htquiet(htaddr);
673349Swnj 	htaddr->htcs1 = HT_DCLR|HT_GO;
683262Swnj 	htaddr->httc = den;
693262Swnj 	htaddr->htfc = -io->i_cc;
703262Swnj 	if (func == HT_SREV) {
713262Swnj 		htaddr->htfc = -1;
723262Swnj 		htaddr->htcs1 = HT_SREV|HT_GO;
733262Swnj 		return (0);
74319Sbill 	}
753274Swnj 	if (func == READ || func == WRITE)
763262Swnj 		mbastart(io, func);
77319Sbill 	else
783262Swnj 		htaddr->htcs1 = func|HT_GO;
793262Swnj 	htquiet(htaddr);
803262Swnj 	ds = htaddr->htds;
815159Sroot 	er = htaddr->hter;
823262Swnj 	if (ds & HTDS_TM) {
833262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
843262Swnj 		return (0);
85319Sbill 	}
863262Swnj 	if (ds & HTDS_ERR) {
873262Swnj 		htaddr->htcs1 = HT_DCLR|HT_GO;
885159Sroot 		if ((er & HTER_CORCRC) == 0) {
895159Sroot 			printf("ht error: ds=%b, er=%b\n",
905159Sroot 			    MASKREG(ds), HTDS_BITS,
915159Sroot 			    MASKREG(er), HTER_BITS);
925159Sroot 			if (errcnt == 10) {
935159Sroot 				printf("ht: unrecovered error\n");
945159Sroot 				return (-1);
955159Sroot 			}
965159Sroot 			errcnt++;
975159Sroot 			htstrategy(io, HT_SREV);
985159Sroot 			goto retry;
99319Sbill 		}
100319Sbill 	}
101319Sbill 	if (errcnt)
1023349Swnj 		printf("ht: recovered by retry\n");
1033262Swnj 	fc = htaddr->htfc;
1043262Swnj 	return (io->i_cc+fc);
105319Sbill }
106319Sbill 
1073262Swnj htquiet(htaddr)
1083262Swnj 	register struct htdevice *htaddr;
109319Sbill {
110319Sbill 	register int s;
111319Sbill 
112319Sbill 	do
1133262Swnj 		s = htaddr->htds;
1143262Swnj 	while ((s & HTDS_DRY) == 0);
115319Sbill }
1165159Sroot 
1175159Sroot 
118