xref: /csrg-svn/sys/vax/stand/ts.c (revision 33408)
123245Smckusick /*
229313Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
323245Smckusick  * All rights reserved.  The Berkeley software License Agreement
423245Smckusick  * specifies the terms and conditions for redistribution.
523245Smckusick  *
6*33408Skarels  *	@(#)ts.c	7.1 (Berkeley) 6/5/86
723245Smckusick  */
83268Swnj 
93268Swnj /*
103268Swnj  * TS11 tape driver
113268Swnj  */
129806Ssam #include "../machine/pte.h"
133268Swnj 
14*33408Skarels #include "param.h"
15*33408Skarels #include "inode.h"
16*33408Skarels #include "fs.h"
179186Ssam 
189186Ssam #include "../vaxuba/tsreg.h"
199186Ssam #include "../vaxuba/ubareg.h"
209186Ssam 
213268Swnj #include "saio.h"
223268Swnj #include "savax.h"
233268Swnj 
243268Swnj 
253268Swnj u_short	tsstd[] = { 0772520 };
263268Swnj 
273268Swnj struct	iob	ctsbuf;
283268Swnj 
293268Swnj u_short	ts_uba;			/* Unibus address of ts structure */
303268Swnj 
315158Sroot struct tsdevice *tsaddr = 0;
323268Swnj 
333268Swnj struct ts {
343268Swnj 	struct ts_cmd ts_cmd;
353268Swnj 	struct ts_char ts_char;
363268Swnj 	struct ts_sts ts_sts;
373268Swnj } ts;
383268Swnj 
393268Swnj tsopen(io)
403268Swnj 	register struct iob *io;
413268Swnj {
423268Swnj 	static struct ts *ts_ubaddr;
433344Swnj 	long i = 0;
443268Swnj 
453268Swnj 	if (tsaddr == 0)
467447Sroot 		tsaddr = (struct tsdevice *)ubamem(io->i_unit, tsstd[0]);
47*33408Skarels 	if (badaddr((char *)tsaddr, sizeof (short))) {
48*33408Skarels 		printf("nonexistent device\n");
49*33408Skarels 		return (ENXIO);
50*33408Skarels 	}
513344Swnj 	tsaddr->tssr = 0;
523344Swnj 	while ((tsaddr->tssr & TS_SSR)==0) {
537447Sroot 		DELAY(10);
543344Swnj 		if (++i > 1000000) {
553344Swnj 			printf("ts: not ready\n");
56*33408Skarels 			return (EUNIT);
573268Swnj 		}
583268Swnj 	}
593268Swnj 	if (tsaddr->tssr&TS_OFL) {
603268Swnj 		printf("ts: offline\n");
61*33408Skarels 		return (EUNIT);
623268Swnj 	}
633268Swnj 	if (tsaddr->tssr&TS_NBA) {
643344Swnj 		int i;
653344Swnj 
663268Swnj 		ctsbuf.i_ma = (caddr_t) &ts;
673268Swnj 		ctsbuf.i_cc = sizeof(ts);
683268Swnj 		if (ts_ubaddr == 0)
693344Swnj 			ts_ubaddr = (struct ts *)ubasetup(&ctsbuf, 2);
703344Swnj 		ts_uba = (u_short)((long)ts_ubaddr + (((long)ts_ubaddr>>16)&03));
713268Swnj 		ts.ts_char.char_addr = (int)&ts_ubaddr->ts_sts;
723268Swnj 		ts.ts_char.char_size = sizeof(ts.ts_sts);
733344Swnj 		ts.ts_char.char_mode = TS_ESS;
743344Swnj 		ts.ts_cmd.c_cmd = TS_ACK|TS_SETCHR;
753344Swnj 		i = (int)&ts_ubaddr->ts_char;
763344Swnj 		ts.ts_cmd.c_loba = i;
773344Swnj 		ts.ts_cmd.c_hiba = (i>>16)&3;
783268Swnj 		ts.ts_cmd.c_size = sizeof(ts.ts_char);
793268Swnj 		tsaddr->tsdb = ts_uba;
803268Swnj 	}
813268Swnj 	tsstrategy(io, TS_REW);
823268Swnj 	if (io->i_cc = io->i_boff)
833268Swnj 		tsstrategy(io, TS_SFORWF);
84*33408Skarels 	return (0);
853268Swnj }
863268Swnj 
873268Swnj tsclose(io)
883268Swnj 	register struct iob *io;
893268Swnj {
903344Swnj 
913268Swnj 	tsstrategy(io, TS_REW);
923268Swnj }
933268Swnj 
943268Swnj tsstrategy(io, func)
953268Swnj 	register struct iob *io;
963268Swnj {
973344Swnj 	register int errcnt, info = 0;
983268Swnj 
993268Swnj 	errcnt = 0;
1003268Swnj retry:
1013268Swnj 	while ((tsaddr->tssr & TS_SSR) == 0)
1023344Swnj 		DELAY(100);
1033344Swnj 	if (func == TS_REW || func == TS_SFORWF)
1043344Swnj 		ts.ts_cmd.c_repcnt = io->i_cc;
1053344Swnj 	else {
1063344Swnj 		info = ubasetup(io, 1);
1073344Swnj 		ts.ts_cmd.c_size = io->i_cc;
1083344Swnj 		ts.ts_cmd.c_loba = info;
1093344Swnj 		ts.ts_cmd.c_hiba = (info>>16)&3;
1103344Swnj 	}
1113268Swnj 	if (func == READ)
1123268Swnj 		func = TS_RCOM;
1133268Swnj 	else if (func == WRITE)
1143268Swnj 		func = TS_WCOM;
1153268Swnj 	ts.ts_cmd.c_cmd = TS_ACK|TS_CVC|func;
1163268Swnj 	tsaddr->tsdb = ts_uba;
1173344Swnj 	do
1183344Swnj 		DELAY(100)
1193344Swnj 	while ((tsaddr->tssr & TS_SSR) == 0);
1203344Swnj 	if (info)
1213344Swnj 		ubafree(io, info);
1223344Swnj 	if (ts.ts_sts.s_xs0 & TS_TMK)
1233268Swnj 		return (0);
1243268Swnj 	if (tsaddr->tssr & TS_SC) {
1257447Sroot 		printf("ts tape error: er=%b, xs0=%b\n",
1263349Swnj 		    tsaddr->tssr, TSSR_BITS,
1273349Swnj 		    ts.ts_sts.s_xs0, TSXS0_BITS);
1283268Swnj 		if (errcnt==10) {
1293349Swnj 			printf("ts: unrecovered error\n");
1303268Swnj 			return (-1);
1313268Swnj 		}
1323268Swnj 		errcnt++;
1333268Swnj 		if (func == TS_RCOM || func == TS_WCOM)
1343268Swnj 			func |= TS_RETRY;
1353268Swnj 		goto retry;
1363268Swnj 	}
1373268Swnj 	if (errcnt)
1383349Swnj 		printf("ts: recovered by retry\n");
1393268Swnj 	return (io->i_cc - ts.ts_sts.s_rbpcr);
1403268Swnj }
141