xref: /csrg-svn/sys/vax/stand/ts.c (revision 33532)
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*33532Sbostic  *	@(#)ts.c	7.4 (Berkeley) 02/22/88
723245Smckusick  */
83268Swnj 
93268Swnj /*
103268Swnj  * TS11 tape driver
113268Swnj  */
129806Ssam #include "../machine/pte.h"
133268Swnj 
1433408Skarels #include "param.h"
1533408Skarels #include "inode.h"
1633408Skarels #include "fs.h"
179186Ssam 
189186Ssam #include "../vaxuba/tsreg.h"
199186Ssam #include "../vaxuba/ubareg.h"
209186Ssam 
213268Swnj #include "saio.h"
223268Swnj #include "savax.h"
233268Swnj 
24*33532Sbostic #define	MAXCTLR		1		/* all addresses must be specified */
25*33532Sbostic u_short	tsstd[MAXCTLR] = { 0772520 };
263268Swnj 
273268Swnj struct	iob	ctsbuf;
283268Swnj 
293268Swnj u_short	ts_uba;			/* Unibus address of ts structure */
303268Swnj 
313268Swnj struct ts {
323268Swnj 	struct ts_cmd ts_cmd;
333268Swnj 	struct ts_char ts_char;
343268Swnj 	struct ts_sts ts_sts;
353268Swnj } ts;
363268Swnj 
373268Swnj tsopen(io)
383268Swnj 	register struct iob *io;
393268Swnj {
403268Swnj 	static struct ts *ts_ubaddr;
41*33532Sbostic 	register struct tsdevice *tsaddr;
423344Swnj 	long i = 0;
433268Swnj 
44*33532Sbostic 	if ((u_int)io->i_ctlr >= MAXCTLR)
45*33532Sbostic 		return (ECTLR);
46*33532Sbostic 	/* TS11 only supports one transport per formatter */
47*33532Sbostic 	if ((u_int)io->i_unit)
48*33532Sbostic 		return(EUNIT);
49*33532Sbostic 	tsaddr = (struct tsdevice *)ubamem(io->i_adapt, tsstd[io->i_ctlr]);
50*33532Sbostic 	if (badaddr((char *)tsaddr, sizeof (short)))
5133408Skarels 		return (ENXIO);
523344Swnj 	tsaddr->tssr = 0;
533344Swnj 	while ((tsaddr->tssr & TS_SSR)==0) {
547447Sroot 		DELAY(10);
553344Swnj 		if (++i > 1000000) {
563344Swnj 			printf("ts: not ready\n");
57*33532Sbostic 			return (ENXIO);
583268Swnj 		}
593268Swnj 	}
603268Swnj 	if (tsaddr->tssr&TS_OFL) {
613268Swnj 		printf("ts: offline\n");
62*33532Sbostic 		return (ENXIO);
633268Swnj 	}
643268Swnj 	if (tsaddr->tssr&TS_NBA) {
653344Swnj 		int i;
663344Swnj 
673268Swnj 		ctsbuf.i_ma = (caddr_t) &ts;
683268Swnj 		ctsbuf.i_cc = sizeof(ts);
693268Swnj 		if (ts_ubaddr == 0)
703344Swnj 			ts_ubaddr = (struct ts *)ubasetup(&ctsbuf, 2);
713344Swnj 		ts_uba = (u_short)((long)ts_ubaddr + (((long)ts_ubaddr>>16)&03));
723268Swnj 		ts.ts_char.char_addr = (int)&ts_ubaddr->ts_sts;
733268Swnj 		ts.ts_char.char_size = sizeof(ts.ts_sts);
743344Swnj 		ts.ts_char.char_mode = TS_ESS;
753344Swnj 		ts.ts_cmd.c_cmd = TS_ACK|TS_SETCHR;
763344Swnj 		i = (int)&ts_ubaddr->ts_char;
773344Swnj 		ts.ts_cmd.c_loba = i;
783344Swnj 		ts.ts_cmd.c_hiba = (i>>16)&3;
793268Swnj 		ts.ts_cmd.c_size = sizeof(ts.ts_char);
803268Swnj 		tsaddr->tsdb = ts_uba;
813268Swnj 	}
823268Swnj 	tsstrategy(io, TS_REW);
83*33532Sbostic 	if (io->i_cc = io->i_part)
843268Swnj 		tsstrategy(io, TS_SFORWF);
8533408Skarels 	return (0);
863268Swnj }
873268Swnj 
883268Swnj tsclose(io)
893268Swnj 	register struct iob *io;
903268Swnj {
913268Swnj 	tsstrategy(io, TS_REW);
923268Swnj }
933268Swnj 
943268Swnj tsstrategy(io, func)
953268Swnj 	register struct iob *io;
963268Swnj {
97*33532Sbostic 	register struct tsdevice *tsaddr;
98*33532Sbostic 	register int errcnt, info;
993268Swnj 
100*33532Sbostic 	tsaddr = (struct tsdevice *)ubamem(io->i_adapt, tsstd[io->i_ctlr]);
101*33532Sbostic 	errcnt = info = 0;
1023268Swnj retry:
1033268Swnj 	while ((tsaddr->tssr & TS_SSR) == 0)
1043344Swnj 		DELAY(100);
1053344Swnj 	if (func == TS_REW || func == TS_SFORWF)
1063344Swnj 		ts.ts_cmd.c_repcnt = io->i_cc;
1073344Swnj 	else {
1083344Swnj 		info = ubasetup(io, 1);
1093344Swnj 		ts.ts_cmd.c_size = io->i_cc;
1103344Swnj 		ts.ts_cmd.c_loba = info;
1113344Swnj 		ts.ts_cmd.c_hiba = (info>>16)&3;
112*33532Sbostic 		if (func == READ)
113*33532Sbostic 			func = TS_RCOM;
114*33532Sbostic 		else if (func == WRITE)
115*33532Sbostic 			func = TS_WCOM;
1163344Swnj 	}
1173268Swnj 	ts.ts_cmd.c_cmd = TS_ACK|TS_CVC|func;
1183268Swnj 	tsaddr->tsdb = ts_uba;
1193344Swnj 	do
1203344Swnj 		DELAY(100)
1213344Swnj 	while ((tsaddr->tssr & TS_SSR) == 0);
1223344Swnj 	if (info)
1233344Swnj 		ubafree(io, info);
1243344Swnj 	if (ts.ts_sts.s_xs0 & TS_TMK)
1253268Swnj 		return (0);
1263268Swnj 	if (tsaddr->tssr & TS_SC) {
1277447Sroot 		printf("ts tape error: er=%b, xs0=%b\n",
1283349Swnj 		    tsaddr->tssr, TSSR_BITS,
1293349Swnj 		    ts.ts_sts.s_xs0, TSXS0_BITS);
130*33532Sbostic 		if (errcnt++ == 10) {
1313349Swnj 			printf("ts: unrecovered error\n");
1323268Swnj 			return (-1);
1333268Swnj 		}
1343268Swnj 		if (func == TS_RCOM || func == TS_WCOM)
1353268Swnj 			func |= TS_RETRY;
1363268Swnj 		goto retry;
1373268Swnj 	}
1383268Swnj 	if (errcnt)
1393349Swnj 		printf("ts: recovered by retry\n");
1403268Swnj 	return (io->i_cc - ts.ts_sts.s_rbpcr);
1413268Swnj }
142