1*9186Ssam /* ht.c 4.8 82/11/13 */ 2319Sbill 3319Sbill /* 43262Swnj * TM03/TU?? tape driver 5319Sbill */ 6319Sbill 7319Sbill #include "../h/param.h" 8319Sbill #include "../h/inode.h" 9422Sbill #include "../h/pte.h" 106070Smckusic #include "../h/fs.h" 11*9186Ssam 12*9186Ssam #include "../vaxmba/htreg.h" 13*9186Ssam #include "../vaxmba/mbareg.h" 14*9186Ssam 15319Sbill #include "saio.h" 163262Swnj #include "savax.h" 17319Sbill 183349Swnj short httypes[] = 193349Swnj { MBDT_TM03, MBDT_TE16, MBDT_TU45, MBDT_TU77, 0 }; 203349Swnj 213349Swnj #define MASKREG(reg) ((reg)&0xffff) 223349Swnj 23319Sbill htopen(io) 243262Swnj register struct iob *io; 25319Sbill { 263262Swnj register int skip; 273262Swnj register struct htdevice *htaddr = (struct htdevice *)mbadrv(io->i_unit); 28319Sbill int i; 29319Sbill 303349Swnj for (i = 0; httypes[i]; i++) 313349Swnj if (httypes[i] == (htaddr->htdt&MBDT_TYPE)) 323349Swnj goto found; 333349Swnj _stop("not a tape\n"); 343349Swnj found: 353262Swnj mbainit(UNITTOMBA(io->i_unit)); 363262Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 373262Swnj htstrategy(io, HT_REW); 38319Sbill skip = io->i_boff; 39319Sbill while (skip--) { 40319Sbill io->i_cc = -1; 413262Swnj while (htstrategy(io, HT_SFORW)) 42319Sbill ; 433262Swnj DELAY(65536); 443262Swnj htstrategy(io, HT_SENSE); 45319Sbill } 46319Sbill } 47319Sbill 48319Sbill htclose(io) 493262Swnj register struct iob *io; 50319Sbill { 513262Swnj 523262Swnj htstrategy(io, HT_REW); 53319Sbill } 54319Sbill 55319Sbill htstrategy(io, func) 563262Swnj register struct iob *io; 573262Swnj int func; 58319Sbill { 593262Swnj register int den, errcnt, ds; 605159Sroot int er; 61319Sbill short fc; 623262Swnj register struct htdevice *htaddr = 633262Swnj (struct htdevice *)mbadrv(io->i_unit); 64319Sbill 65319Sbill errcnt = 0; 66319Sbill retry: 673262Swnj den = HTTC_1600BPI|HTTC_PDP11; 683262Swnj htquiet(htaddr); 693349Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 703262Swnj htaddr->httc = den; 713262Swnj htaddr->htfc = -io->i_cc; 723262Swnj if (func == HT_SREV) { 733262Swnj htaddr->htfc = -1; 743262Swnj htaddr->htcs1 = HT_SREV|HT_GO; 753262Swnj return (0); 76319Sbill } 773274Swnj if (func == READ || func == WRITE) 783262Swnj mbastart(io, func); 79319Sbill else 803262Swnj htaddr->htcs1 = func|HT_GO; 813262Swnj htquiet(htaddr); 823262Swnj ds = htaddr->htds; 835159Sroot er = htaddr->hter; 843262Swnj if (ds & HTDS_TM) { 853262Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 863262Swnj return (0); 87319Sbill } 883262Swnj if (ds & HTDS_ERR) { 893262Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 905159Sroot if ((er & HTER_CORCRC) == 0) { 915159Sroot printf("ht error: ds=%b, er=%b\n", 925159Sroot MASKREG(ds), HTDS_BITS, 935159Sroot MASKREG(er), HTER_BITS); 945159Sroot if (errcnt == 10) { 955159Sroot printf("ht: unrecovered error\n"); 965159Sroot return (-1); 975159Sroot } 985159Sroot errcnt++; 995159Sroot htstrategy(io, HT_SREV); 1005159Sroot goto retry; 101319Sbill } 102319Sbill } 103319Sbill if (errcnt) 1043349Swnj printf("ht: recovered by retry\n"); 1053262Swnj fc = htaddr->htfc; 1063262Swnj return (io->i_cc+fc); 107319Sbill } 108319Sbill 1093262Swnj htquiet(htaddr) 1103262Swnj register struct htdevice *htaddr; 111319Sbill { 112319Sbill register int s; 113319Sbill 114319Sbill do 1153262Swnj s = htaddr->htds; 1163262Swnj while ((s & HTDS_DRY) == 0); 117319Sbill } 1185159Sroot 1195159Sroot 120