1*5159Sroot /* ht.c 4.6 81/12/01 */ 2319Sbill 3319Sbill /* 43262Swnj * TM03/TU?? tape driver 5319Sbill */ 6319Sbill 73262Swnj #include "../h/htreg.h" 8319Sbill #include "../h/param.h" 9319Sbill #include "../h/inode.h" 10422Sbill #include "../h/pte.h" 113262Swnj #include "../h/mbareg.h" 12319Sbill #include "saio.h" 133262Swnj #include "savax.h" 14319Sbill 153349Swnj short httypes[] = 163349Swnj { MBDT_TM03, MBDT_TE16, MBDT_TU45, MBDT_TU77, 0 }; 173349Swnj 183349Swnj #define MASKREG(reg) ((reg)&0xffff) 193349Swnj 20319Sbill htopen(io) 213262Swnj register struct iob *io; 22319Sbill { 233262Swnj register int skip; 243262Swnj register struct htdevice *htaddr = (struct htdevice *)mbadrv(io->i_unit); 25319Sbill int i; 26319Sbill 273349Swnj for (i = 0; httypes[i]; i++) 283349Swnj if (httypes[i] == (htaddr->htdt&MBDT_TYPE)) 293349Swnj goto found; 303349Swnj _stop("not a tape\n"); 313349Swnj found: 323262Swnj mbainit(UNITTOMBA(io->i_unit)); 333262Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 343262Swnj htstrategy(io, HT_REW); 35319Sbill skip = io->i_boff; 36319Sbill while (skip--) { 37319Sbill io->i_cc = -1; 383262Swnj while (htstrategy(io, HT_SFORW)) 39319Sbill ; 403262Swnj DELAY(65536); 413262Swnj htstrategy(io, HT_SENSE); 42319Sbill } 43319Sbill } 44319Sbill 45319Sbill htclose(io) 463262Swnj register struct iob *io; 47319Sbill { 483262Swnj 493262Swnj htstrategy(io, HT_REW); 50319Sbill } 51319Sbill 52319Sbill htstrategy(io, func) 533262Swnj register struct iob *io; 543262Swnj int func; 55319Sbill { 563262Swnj register int den, errcnt, ds; 57*5159Sroot int er; 58319Sbill short fc; 593262Swnj register struct htdevice *htaddr = 603262Swnj (struct htdevice *)mbadrv(io->i_unit); 61319Sbill 62319Sbill errcnt = 0; 63319Sbill retry: 643262Swnj den = HTTC_1600BPI|HTTC_PDP11; 653262Swnj htquiet(htaddr); 663349Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 673262Swnj htaddr->httc = den; 683262Swnj htaddr->htfc = -io->i_cc; 693262Swnj if (func == HT_SREV) { 703262Swnj htaddr->htfc = -1; 713262Swnj htaddr->htcs1 = HT_SREV|HT_GO; 723262Swnj return (0); 73319Sbill } 743274Swnj if (func == READ || func == WRITE) 753262Swnj mbastart(io, func); 76319Sbill else 773262Swnj htaddr->htcs1 = func|HT_GO; 783262Swnj htquiet(htaddr); 793262Swnj ds = htaddr->htds; 80*5159Sroot er = htaddr->hter; 813262Swnj if (ds & HTDS_TM) { 823262Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 833262Swnj return (0); 84319Sbill } 853262Swnj if (ds & HTDS_ERR) { 863262Swnj htaddr->htcs1 = HT_DCLR|HT_GO; 87*5159Sroot if ((er & HTER_CORCRC) == 0) { 88*5159Sroot printf("ht error: ds=%b, er=%b\n", 89*5159Sroot MASKREG(ds), HTDS_BITS, 90*5159Sroot MASKREG(er), HTER_BITS); 91*5159Sroot if (errcnt == 10) { 92*5159Sroot printf("ht: unrecovered error\n"); 93*5159Sroot return (-1); 94*5159Sroot } 95*5159Sroot errcnt++; 96*5159Sroot htstrategy(io, HT_SREV); 97*5159Sroot goto retry; 98319Sbill } 99319Sbill } 100319Sbill if (errcnt) 1013349Swnj printf("ht: recovered by retry\n"); 1023262Swnj fc = htaddr->htfc; 1033262Swnj return (io->i_cc+fc); 104319Sbill } 105319Sbill 1063262Swnj htquiet(htaddr) 1073262Swnj register struct htdevice *htaddr; 108319Sbill { 109319Sbill register int s; 110319Sbill 111319Sbill do 1123262Swnj s = htaddr->htds; 1133262Swnj while ((s & HTDS_DRY) == 0); 114319Sbill } 115*5159Sroot 116*5159Sroot 117