123245Smckusick /*
235052Skarels * Copyright (c) 1982, 1986, 1988 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*49100Sbostic * @(#)ts.c 7.8 (Berkeley) 05/04/91
723245Smckusick */
83268Swnj
93268Swnj /*
103268Swnj * TS11 tape driver
113268Swnj */
123268Swnj
1345803Sbostic #include "sys/param.h"
149186Ssam
1545803Sbostic #include "../include/pte.h"
1635052Skarels
1745803Sbostic #include "../uba/tsreg.h"
1845803Sbostic #include "../uba/ubareg.h"
199186Ssam
2045803Sbostic #include "stand/saio.h"
213268Swnj #include "savax.h"
223268Swnj
2333532Sbostic #define MAXCTLR 1 /* all addresses must be specified */
2433532Sbostic u_short tsstd[MAXCTLR] = { 0772520 };
253268Swnj
263268Swnj struct iob ctsbuf;
273268Swnj
283268Swnj u_short ts_uba; /* Unibus address of ts structure */
293268Swnj
303268Swnj struct ts {
313268Swnj struct ts_cmd ts_cmd;
323268Swnj struct ts_char ts_char;
333268Swnj struct ts_sts ts_sts;
343268Swnj } ts;
353268Swnj
tsopen(io)363268Swnj tsopen(io)
373268Swnj register struct iob *io;
383268Swnj {
393268Swnj static struct ts *ts_ubaddr;
4033532Sbostic register struct tsdevice *tsaddr;
413344Swnj long i = 0;
423268Swnj
4335052Skarels if ((u_int)io->i_adapt >= nuba)
4435052Skarels return (EADAPT);
4533532Sbostic if ((u_int)io->i_ctlr >= MAXCTLR)
4633532Sbostic return (ECTLR);
4733532Sbostic /* TS11 only supports one transport per formatter */
4835052Skarels if (io->i_unit)
4933532Sbostic return(EUNIT);
5033532Sbostic tsaddr = (struct tsdevice *)ubamem(io->i_adapt, tsstd[io->i_ctlr]);
5133532Sbostic if (badaddr((char *)tsaddr, sizeof (short)))
5233408Skarels return (ENXIO);
533344Swnj tsaddr->tssr = 0;
543344Swnj while ((tsaddr->tssr & TS_SSR)==0) {
557447Sroot DELAY(10);
563344Swnj if (++i > 1000000) {
573344Swnj printf("ts: not ready\n");
5833532Sbostic return (ENXIO);
593268Swnj }
603268Swnj }
613268Swnj if (tsaddr->tssr&TS_OFL) {
623268Swnj printf("ts: offline\n");
6333532Sbostic return (ENXIO);
643268Swnj }
653268Swnj if (tsaddr->tssr&TS_NBA) {
663344Swnj int i;
673344Swnj
683268Swnj ctsbuf.i_ma = (caddr_t) &ts;
693268Swnj ctsbuf.i_cc = sizeof(ts);
703268Swnj if (ts_ubaddr == 0)
713344Swnj ts_ubaddr = (struct ts *)ubasetup(&ctsbuf, 2);
723344Swnj ts_uba = (u_short)((long)ts_ubaddr + (((long)ts_ubaddr>>16)&03));
733268Swnj ts.ts_char.char_addr = (int)&ts_ubaddr->ts_sts;
743268Swnj ts.ts_char.char_size = sizeof(ts.ts_sts);
753344Swnj ts.ts_char.char_mode = TS_ESS;
763344Swnj ts.ts_cmd.c_cmd = TS_ACK|TS_SETCHR;
773344Swnj i = (int)&ts_ubaddr->ts_char;
783344Swnj ts.ts_cmd.c_loba = i;
793344Swnj ts.ts_cmd.c_hiba = (i>>16)&3;
803268Swnj ts.ts_cmd.c_size = sizeof(ts.ts_char);
813268Swnj tsaddr->tsdb = ts_uba;
823268Swnj }
833268Swnj tsstrategy(io, TS_REW);
8433532Sbostic if (io->i_cc = io->i_part)
853268Swnj tsstrategy(io, TS_SFORWF);
8633408Skarels return (0);
873268Swnj }
883268Swnj
tsclose(io)893268Swnj tsclose(io)
903268Swnj register struct iob *io;
913268Swnj {
923268Swnj tsstrategy(io, TS_REW);
933268Swnj }
943268Swnj
tsstrategy(io,func)953268Swnj tsstrategy(io, func)
963268Swnj register struct iob *io;
973268Swnj {
9833532Sbostic register struct tsdevice *tsaddr;
9933532Sbostic register int errcnt, info;
1003268Swnj
10133532Sbostic tsaddr = (struct tsdevice *)ubamem(io->i_adapt, tsstd[io->i_ctlr]);
10233532Sbostic errcnt = info = 0;
1033268Swnj retry:
1043268Swnj while ((tsaddr->tssr & TS_SSR) == 0)
1053344Swnj DELAY(100);
1063344Swnj if (func == TS_REW || func == TS_SFORWF)
1073344Swnj ts.ts_cmd.c_repcnt = io->i_cc;
1083344Swnj else {
1093344Swnj info = ubasetup(io, 1);
1103344Swnj ts.ts_cmd.c_size = io->i_cc;
1113344Swnj ts.ts_cmd.c_loba = info;
1123344Swnj ts.ts_cmd.c_hiba = (info>>16)&3;
113*49100Sbostic if (func == F_READ)
11433532Sbostic func = TS_RCOM;
115*49100Sbostic else if (func == F_WRITE)
11633532Sbostic func = TS_WCOM;
1173344Swnj }
1183268Swnj ts.ts_cmd.c_cmd = TS_ACK|TS_CVC|func;
1193268Swnj tsaddr->tsdb = ts_uba;
1203344Swnj do
1213344Swnj DELAY(100)
1223344Swnj while ((tsaddr->tssr & TS_SSR) == 0);
1233344Swnj if (info)
1243344Swnj ubafree(io, info);
1253344Swnj if (ts.ts_sts.s_xs0 & TS_TMK)
1263268Swnj return (0);
1273268Swnj if (tsaddr->tssr & TS_SC) {
1287447Sroot printf("ts tape error: er=%b, xs0=%b\n",
1293349Swnj tsaddr->tssr, TSSR_BITS,
1303349Swnj ts.ts_sts.s_xs0, TSXS0_BITS);
13133532Sbostic if (errcnt++ == 10) {
1323349Swnj printf("ts: unrecovered error\n");
1333268Swnj return (-1);
1343268Swnj }
1353268Swnj if (func == TS_RCOM || func == TS_WCOM)
1363268Swnj func |= TS_RETRY;
1373268Swnj goto retry;
1383268Swnj }
1393268Swnj if (errcnt)
1403349Swnj printf("ts: recovered by retry\n");
1413268Swnj return (io->i_cc - ts.ts_sts.s_rbpcr);
1423268Swnj }
143