123245Smckusick /* 2*29313Smckusick * 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*29313Smckusick * @(#)ts.c 7.1 (Berkeley) 06/05/86 723245Smckusick */ 83268Swnj 93268Swnj /* 103268Swnj * TS11 tape driver 113268Swnj */ 129806Ssam #include "../machine/pte.h" 133268Swnj 143268Swnj #include "../h/param.h" 153268Swnj #include "../h/inode.h" 167447Sroot #include "../h/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]); 473344Swnj tsaddr->tssr = 0; 483344Swnj while ((tsaddr->tssr & TS_SSR)==0) { 497447Sroot DELAY(10); 503344Swnj if (++i > 1000000) { 513344Swnj printf("ts: not ready\n"); 523344Swnj return; 533268Swnj } 543268Swnj } 553268Swnj if (tsaddr->tssr&TS_OFL) { 563268Swnj printf("ts: offline\n"); 573268Swnj return; 583268Swnj } 593268Swnj if (tsaddr->tssr&TS_NBA) { 603344Swnj int i; 613344Swnj 623268Swnj ctsbuf.i_ma = (caddr_t) &ts; 633268Swnj ctsbuf.i_cc = sizeof(ts); 643268Swnj if (ts_ubaddr == 0) 653344Swnj ts_ubaddr = (struct ts *)ubasetup(&ctsbuf, 2); 663344Swnj ts_uba = (u_short)((long)ts_ubaddr + (((long)ts_ubaddr>>16)&03)); 673268Swnj ts.ts_char.char_addr = (int)&ts_ubaddr->ts_sts; 683268Swnj ts.ts_char.char_size = sizeof(ts.ts_sts); 693344Swnj ts.ts_char.char_mode = TS_ESS; 703344Swnj ts.ts_cmd.c_cmd = TS_ACK|TS_SETCHR; 713344Swnj i = (int)&ts_ubaddr->ts_char; 723344Swnj ts.ts_cmd.c_loba = i; 733344Swnj ts.ts_cmd.c_hiba = (i>>16)&3; 743268Swnj ts.ts_cmd.c_size = sizeof(ts.ts_char); 753268Swnj tsaddr->tsdb = ts_uba; 763268Swnj } 773268Swnj tsstrategy(io, TS_REW); 783268Swnj if (io->i_cc = io->i_boff) 793268Swnj tsstrategy(io, TS_SFORWF); 803268Swnj } 813268Swnj 823268Swnj tsclose(io) 833268Swnj register struct iob *io; 843268Swnj { 853344Swnj 863268Swnj tsstrategy(io, TS_REW); 873268Swnj } 883268Swnj 893268Swnj tsstrategy(io, func) 903268Swnj register struct iob *io; 913268Swnj { 923344Swnj register int errcnt, info = 0; 933268Swnj 943268Swnj errcnt = 0; 953268Swnj retry: 963268Swnj while ((tsaddr->tssr & TS_SSR) == 0) 973344Swnj DELAY(100); 983344Swnj if (func == TS_REW || func == TS_SFORWF) 993344Swnj ts.ts_cmd.c_repcnt = io->i_cc; 1003344Swnj else { 1013344Swnj info = ubasetup(io, 1); 1023344Swnj ts.ts_cmd.c_size = io->i_cc; 1033344Swnj ts.ts_cmd.c_loba = info; 1043344Swnj ts.ts_cmd.c_hiba = (info>>16)&3; 1053344Swnj } 1063268Swnj if (func == READ) 1073268Swnj func = TS_RCOM; 1083268Swnj else if (func == WRITE) 1093268Swnj func = TS_WCOM; 1103268Swnj ts.ts_cmd.c_cmd = TS_ACK|TS_CVC|func; 1113268Swnj tsaddr->tsdb = ts_uba; 1123344Swnj do 1133344Swnj DELAY(100) 1143344Swnj while ((tsaddr->tssr & TS_SSR) == 0); 1153344Swnj if (info) 1163344Swnj ubafree(io, info); 1173344Swnj if (ts.ts_sts.s_xs0 & TS_TMK) 1183268Swnj return (0); 1193268Swnj if (tsaddr->tssr & TS_SC) { 1207447Sroot printf("ts tape error: er=%b, xs0=%b\n", 1213349Swnj tsaddr->tssr, TSSR_BITS, 1223349Swnj ts.ts_sts.s_xs0, TSXS0_BITS); 1233268Swnj if (errcnt==10) { 1243349Swnj printf("ts: unrecovered error\n"); 1253268Swnj return (-1); 1263268Swnj } 1273268Swnj errcnt++; 1283268Swnj if (func == TS_RCOM || func == TS_WCOM) 1293268Swnj func |= TS_RETRY; 1303268Swnj goto retry; 1313268Swnj } 1323268Swnj if (errcnt) 1333349Swnj printf("ts: recovered by retry\n"); 1343268Swnj return (io->i_cc - ts.ts_sts.s_rbpcr); 1353268Swnj } 136