1*17122Sbloom /* dh.c 6.5 84/08/30 */ 213Sbill 31934Swnj #include "dh.h" 42643Swnj #if NDH > 0 513Sbill /* 62479Swnj * DH-11/DM-11 driver 713Sbill */ 89771Ssam #include "../machine/pte.h" 99771Ssam 102730Swnj #include "bk.h" 1116062Skarels #include "uba.h" 12*17122Sbloom #include "param.h" 13*17122Sbloom #include "conf.h" 14*17122Sbloom #include "dir.h" 15*17122Sbloom #include "user.h" 16*17122Sbloom #include "proc.h" 17*17122Sbloom #include "ioctl.h" 18*17122Sbloom #include "tty.h" 19*17122Sbloom #include "map.h" 20*17122Sbloom #include "buf.h" 21*17122Sbloom #include "vm.h" 22*17122Sbloom #include "kernel.h" 238472Sroot 24*17122Sbloom #include "ubareg.h" 25*17122Sbloom #include "ubavar.h" 26*17122Sbloom #include "dhreg.h" 27*17122Sbloom #include "dmreg.h" 288472Sroot 29*17122Sbloom #include "bkmac.h" 30*17122Sbloom #include "clist.h" 31*17122Sbloom #include "file.h" 32*17122Sbloom #include "uio.h" 3313Sbill 342468Swnj /* 352479Swnj * Definition of the driver for the auto-configuration program. 362479Swnj * There is one definition for the dh and one for the dm. 372468Swnj */ 3816190Skarels int dhprobe(), dhattach(), dhrint(), dhxint(), dhtimer(); 392974Swnj struct uba_device *dhinfo[NDH]; 402395Swnj u_short dhstd[] = { 0 }; 412395Swnj struct uba_driver dhdriver = 422605Swnj { dhprobe, 0, dhattach, 0, dhstd, "dh", dhinfo }; 432395Swnj 442605Swnj int dmprobe(), dmattach(), dmintr(); 452974Swnj struct uba_device *dminfo[NDH]; 462479Swnj u_short dmstd[] = { 0 }; 472479Swnj struct uba_driver dmdriver = 482605Swnj { dmprobe, 0, dmattach, 0, dmstd, "dm", dminfo }; 4913Sbill 506615Ssam #ifndef PORTSELECTOR 516615Ssam #define ISPEED B300 526615Ssam #define IFLAGS (EVENP|ODDP|ECHO) 536615Ssam #else 546615Ssam #define ISPEED B4800 556615Ssam #define IFLAGS (EVENP|ODDP) 566615Ssam #endif 576615Ssam 5816190Skarels #define FASTTIMER (hz/30) /* scan rate with silos on */ 5916190Skarels 6013Sbill /* 612479Swnj * Local variables for the driver 6213Sbill */ 632643Swnj short dhsar[NDH]; /* software copy of last bar */ 642643Swnj short dhsoftCAR[NDH]; 6513Sbill 662643Swnj struct tty dh11[NDH*16]; 672643Swnj int ndh11 = NDH*16; 682479Swnj int dhact; /* mask of active dh's */ 6916190Skarels int dhsilos; /* mask of dh's with silo in use */ 7016190Skarels int dhchars[NDH]; /* recent input count */ 7116190Skarels int dhrate[NDH]; /* smoothed input count */ 7216190Skarels int dhhighrate = 100; /* silo on if dhchars > dhhighrate */ 7316190Skarels int dhlowrate = 75; /* silo off if dhrate < dhlowrate */ 7416190Skarels static short timerstarted; 752479Swnj int dhstart(), ttrstrt(); 7613Sbill 772479Swnj /* 782479Swnj * The clist space is mapped by the driver onto each UNIBUS. 792479Swnj * The UBACVT macro converts a clist space address for unibus uban 802479Swnj * into an i/o space address for the DMA routine. 812479Swnj */ 8216062Skarels int dh_ubinfo[NUBA]; /* info about allocated unibus map */ 8316062Skarels int cbase[NUBA]; /* base address in unibus map */ 842479Swnj #define UBACVT(x, uban) (cbase[uban] + ((x)-(char *)cfree)) 8513Sbill 862456Swnj /* 872456Swnj * Routine for configuration to force a dh to interrupt. 882456Swnj * Set to transmit at 9600 baud, and cause a transmitter interrupt. 892456Swnj */ 902468Swnj /*ARGSUSED*/ 912605Swnj dhprobe(reg) 922395Swnj caddr_t reg; 932395Swnj { 942468Swnj register int br, cvec; /* these are ``value-result'' */ 952479Swnj register struct dhdevice *dhaddr = (struct dhdevice *)reg; 962395Swnj 972605Swnj #ifdef lint 982605Swnj br = 0; cvec = br; br = cvec; 997384Sroot if (ndh11 == 0) ndh11 = 1; 1004932Swnj dhrint(0); dhxint(0); 1012605Swnj #endif 1022696Swnj #ifndef notdef 1032566Swnj dhaddr->un.dhcsr = DH_RIE|DH_MM|DH_RI; 1046380Swnj DELAY(1000); 1057384Sroot dhaddr->un.dhcsr &= ~DH_RI; 1062566Swnj dhaddr->un.dhcsr = 0; 1072566Swnj #else 1082456Swnj dhaddr->un.dhcsr = DH_TIE; 1092456Swnj DELAY(5); 1102456Swnj dhaddr->dhlpr = (B9600 << 10) | (B9600 << 6) | BITS7|PENABLE; 1112421Skre dhaddr->dhbcr = -1; 1122456Swnj dhaddr->dhcar = 0; 1132421Skre dhaddr->dhbar = 1; 1142456Swnj DELAY(100000); /* wait 1/10'th of a sec for interrupt */ 1152421Skre dhaddr->un.dhcsr = 0; 1162456Swnj if (cvec && cvec != 0x200) 1172456Swnj cvec -= 4; /* transmit -> receive */ 1182482Swnj #endif 1197408Skre return (sizeof (struct dhdevice)); 1202395Swnj } 1212395Swnj 1222456Swnj /* 1232605Swnj * Routine called to attach a dh. 1242456Swnj */ 1252605Swnj dhattach(ui) 1262974Swnj struct uba_device *ui; 1272395Swnj { 1282395Swnj 1292566Swnj dhsoftCAR[ui->ui_unit] = ui->ui_flags; 1302395Swnj } 1312395Swnj 13213Sbill /* 1332479Swnj * Configuration routine to cause a dm to interrupt. 1342479Swnj */ 1352605Swnj dmprobe(reg) 1362605Swnj caddr_t reg; 1372479Swnj { 1382479Swnj register int br, vec; /* value-result */ 1392605Swnj register struct dmdevice *dmaddr = (struct dmdevice *)reg; 1402479Swnj 1412605Swnj #ifdef lint 1423101Swnj br = 0; vec = br; br = vec; 1436185Ssam dmintr(0); 1442605Swnj #endif 1452479Swnj dmaddr->dmcsr = DM_DONE|DM_IE; 1462479Swnj DELAY(20); 1472479Swnj dmaddr->dmcsr = 0; 1482605Swnj return (1); 1492479Swnj } 1502479Swnj 1512605Swnj /*ARGSUSED*/ 1522605Swnj dmattach(ui) 1532974Swnj struct uba_device *ui; 1542479Swnj { 1552479Swnj 1562479Swnj /* no local state to set up */ 1572479Swnj } 1582479Swnj 1592479Swnj /* 1602468Swnj * Open a DH11 line, mapping the clist onto the uba if this 1612468Swnj * is the first dh on this uba. Turn on this dh if this is 1622468Swnj * the first use of it. Also do a dmopen to wait for carrier. 16313Sbill */ 16413Sbill /*ARGSUSED*/ 16513Sbill dhopen(dev, flag) 1662395Swnj dev_t dev; 16713Sbill { 16813Sbill register struct tty *tp; 1692395Swnj register int unit, dh; 1702479Swnj register struct dhdevice *addr; 1712974Swnj register struct uba_device *ui; 17213Sbill int s; 17313Sbill 1742395Swnj unit = minor(dev); 1752395Swnj dh = unit >> 4; 1768566Sroot if (unit >= NDH*16 || (ui = dhinfo[dh])== 0 || ui->ui_alive == 0) 1778566Sroot return (ENXIO); 1782395Swnj tp = &dh11[unit]; 1798566Sroot if (tp->t_state&TS_XCLUDE && u.u_uid!=0) 1808566Sroot return (EBUSY); 1812479Swnj addr = (struct dhdevice *)ui->ui_addr; 18213Sbill tp->t_addr = (caddr_t)addr; 18313Sbill tp->t_oproc = dhstart; 1845406Swnj tp->t_state |= TS_WOPEN; 1852468Swnj /* 1862468Swnj * While setting up state for this uba and this dh, 1872468Swnj * block uba resets which can clear the state. 1882468Swnj */ 1892468Swnj s = spl5(); 1902421Skre if (dh_ubinfo[ui->ui_ubanum] == 0) { 191717Sbill /* 512+ is a kludge to try to get around a hardware problem */ 1922395Swnj dh_ubinfo[ui->ui_ubanum] = 1932421Skre uballoc(ui->ui_ubanum, (caddr_t)cfree, 1942770Swnj 512+nclist*sizeof(struct cblock), 0); 1952456Swnj cbase[ui->ui_ubanum] = dh_ubinfo[ui->ui_ubanum]&0x3ffff; 19613Sbill } 19716190Skarels if (timerstarted == 0) { 19816190Skarels timerstarted++; 19916190Skarels timeout(dhtimer, (caddr_t) 0, hz); 20016190Skarels } 2012456Swnj if ((dhact&(1<<dh)) == 0) { 2022456Swnj addr->un.dhcsr |= DH_IE; 2032468Swnj dhact |= (1<<dh); 20416190Skarels addr->dhsilo = 0; 2052456Swnj } 20613Sbill splx(s); 2072468Swnj /* 2082468Swnj * If this is first open, initialze tty state to default. 2092468Swnj */ 2105406Swnj if ((tp->t_state&TS_ISOPEN) == 0) { 21113Sbill ttychars(tp); 2126615Ssam #ifndef PORTSELECTOR 213168Sbill if (tp->t_ispeed == 0) { 2146615Ssam #endif 2156615Ssam tp->t_ispeed = ISPEED; 2166615Ssam tp->t_ospeed = ISPEED; 2176615Ssam tp->t_flags = IFLAGS; 2186615Ssam #ifndef PORTSELECTOR 219168Sbill } 2206615Ssam #endif 2212395Swnj dhparam(unit); 22213Sbill } 2232468Swnj /* 2242468Swnj * Wait for carrier, then process line discipline specific open. 2252468Swnj */ 22613Sbill dmopen(dev); 2278566Sroot return ((*linesw[tp->t_line].l_open)(dev, tp)); 22813Sbill } 22913Sbill 23013Sbill /* 2312468Swnj * Close a DH11 line, turning off the DM11. 23213Sbill */ 23313Sbill /*ARGSUSED*/ 23413Sbill dhclose(dev, flag) 2352395Swnj dev_t dev; 2362395Swnj int flag; 23713Sbill { 23813Sbill register struct tty *tp; 2392395Swnj register unit; 24013Sbill 2412395Swnj unit = minor(dev); 2422395Swnj tp = &dh11[unit]; 24313Sbill (*linesw[tp->t_line].l_close)(tp); 2442479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); 2455406Swnj if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) 2462479Swnj dmctl(unit, DML_OFF, DMSET); 24713Sbill ttyclose(tp); 24813Sbill } 24913Sbill 2507725Sroot dhread(dev, uio) 2512395Swnj dev_t dev; 2527725Sroot struct uio *uio; 25313Sbill { 2548490Sroot register struct tty *tp = &dh11[minor(dev)]; 25513Sbill 2567725Sroot return ((*linesw[tp->t_line].l_read)(tp, uio)); 25713Sbill } 25813Sbill 2597831Sroot dhwrite(dev, uio) 2602395Swnj dev_t dev; 2617831Sroot struct uio *uio; 26213Sbill { 2638490Sroot register struct tty *tp = &dh11[minor(dev)]; 26413Sbill 2658490Sroot return ((*linesw[tp->t_line].l_write)(tp, uio)); 26613Sbill } 26713Sbill 26813Sbill /* 26913Sbill * DH11 receiver interrupt. 27013Sbill */ 2712395Swnj dhrint(dh) 2722395Swnj int dh; 27313Sbill { 27413Sbill register struct tty *tp; 2752395Swnj register c; 2762479Swnj register struct dhdevice *addr; 277117Sbill register struct tty *tp0; 2782974Swnj register struct uba_device *ui; 2792924Swnj int overrun = 0; 28013Sbill 2812395Swnj ui = dhinfo[dh]; 2822479Swnj if (ui == 0 || ui->ui_alive == 0) 2832479Swnj return; 2842479Swnj addr = (struct dhdevice *)ui->ui_addr; 2852468Swnj tp0 = &dh11[dh<<4]; 2862468Swnj /* 2872468Swnj * Loop fetching characters from the silo for this 2882468Swnj * dh until there are no more in the silo. 2892468Swnj */ 2902468Swnj while ((c = addr->dhrcr) < 0) { 2912468Swnj tp = tp0 + ((c>>8)&0xf); 29216190Skarels dhchars[dh]++; 2936615Ssam #ifndef PORTSELECTOR 2945406Swnj if ((tp->t_state&TS_ISOPEN)==0) { 2956615Ssam #else 2966615Ssam if ((tp->t_state&(TS_ISOPEN|TS_WOPEN))==0) { 2976615Ssam #endif 29813Sbill wakeup((caddr_t)tp); 29913Sbill continue; 30013Sbill } 3012468Swnj if (c & DH_PE) 30213Sbill if ((tp->t_flags&(EVENP|ODDP))==EVENP 30313Sbill || (tp->t_flags&(EVENP|ODDP))==ODDP ) 30413Sbill continue; 3052924Swnj if ((c & DH_DO) && overrun == 0) { 3062924Swnj printf("dh%d: silo overflow\n", dh); 3072924Swnj overrun = 1; 3082924Swnj } 3092468Swnj if (c & DH_FE) 3102468Swnj /* 3112468Swnj * At framing error (break) generate 3122468Swnj * a null (in raw mode, for getty), or a 3132468Swnj * interrupt (in cooked/cbreak mode). 3142468Swnj */ 31513Sbill if (tp->t_flags&RAW) 3162468Swnj c = 0; 31713Sbill else 3189549Ssam c = tp->t_intrc; 3192730Swnj #if NBK > 0 320139Sbill if (tp->t_line == NETLDISC) { 321117Sbill c &= 0177; 322168Sbill BKINPUT(c, tp); 323117Sbill } else 3242730Swnj #endif 3252468Swnj (*linesw[tp->t_line].l_rint)(c, tp); 32613Sbill } 32713Sbill } 32813Sbill 32913Sbill /* 3302468Swnj * Ioctl for DH11. 33113Sbill */ 33213Sbill /*ARGSUSED*/ 3337629Ssam dhioctl(dev, cmd, data, flag) 3347629Ssam caddr_t data; 33513Sbill { 33613Sbill register struct tty *tp; 3378566Sroot register int unit = minor(dev); 3388566Sroot int error; 33913Sbill 3402395Swnj tp = &dh11[unit]; 3418566Sroot error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); 3428566Sroot if (error >= 0) 3438566Sroot return (error); 3448566Sroot error = ttioctl(tp, cmd, data, flag); 3458566Sroot if (error >= 0) { 3467629Ssam if (cmd == TIOCSETP || cmd == TIOCSETN) 3472395Swnj dhparam(unit); 3488566Sroot return (error); 3498566Sroot } 3508566Sroot switch (cmd) { 3517629Ssam 352168Sbill case TIOCSBRK: 3532479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak |= 1<<(unit&017); 354168Sbill break; 3557629Ssam 356168Sbill case TIOCCBRK: 3572479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); 358168Sbill break; 3597629Ssam 360168Sbill case TIOCSDTR: 3612479Swnj dmctl(unit, DML_DTR|DML_RTS, DMBIS); 362168Sbill break; 3637629Ssam 364168Sbill case TIOCCDTR: 3652479Swnj dmctl(unit, DML_DTR|DML_RTS, DMBIC); 366168Sbill break; 3677629Ssam 368168Sbill default: 3698566Sroot return (ENOTTY); 370168Sbill } 3718566Sroot return (0); 37213Sbill } 37313Sbill 37413Sbill /* 37513Sbill * Set parameters from open or stty into the DH hardware 37613Sbill * registers. 37713Sbill */ 3782395Swnj dhparam(unit) 3792395Swnj register int unit; 38013Sbill { 38113Sbill register struct tty *tp; 3822479Swnj register struct dhdevice *addr; 3832395Swnj register int lpar; 384300Sbill int s; 38513Sbill 3862395Swnj tp = &dh11[unit]; 3872479Swnj addr = (struct dhdevice *)tp->t_addr; 3882468Swnj /* 3892468Swnj * Block interrupts so parameters will be set 3902468Swnj * before the line interrupts. 3912468Swnj */ 392300Sbill s = spl5(); 3932468Swnj addr->un.dhcsrl = (unit&0xf) | DH_IE; 39413Sbill if ((tp->t_ispeed)==0) { 3955406Swnj tp->t_state |= TS_HUPCLS; 3962479Swnj dmctl(unit, DML_OFF, DMSET); 39713Sbill return; 39813Sbill } 3992395Swnj lpar = ((tp->t_ospeed)<<10) | ((tp->t_ispeed)<<6); 4002468Swnj if ((tp->t_ispeed) == B134) 4012395Swnj lpar |= BITS6|PENABLE|HDUPLX; 4029549Ssam else if (tp->t_flags & (RAW|LITOUT)) 4032395Swnj lpar |= BITS8; 40413Sbill else 4052395Swnj lpar |= BITS7|PENABLE; 40613Sbill if ((tp->t_flags&EVENP) == 0) 4072395Swnj lpar |= OPAR; 4082468Swnj if ((tp->t_ospeed) == B110) 4092395Swnj lpar |= TWOSB; 4102395Swnj addr->dhlpr = lpar; 411300Sbill splx(s); 41213Sbill } 41313Sbill 41413Sbill /* 41513Sbill * DH11 transmitter interrupt. 41613Sbill * Restart each line which used to be active but has 41713Sbill * terminated transmission since the last interrupt. 41813Sbill */ 4192395Swnj dhxint(dh) 4202395Swnj int dh; 42113Sbill { 42213Sbill register struct tty *tp; 4232479Swnj register struct dhdevice *addr; 42413Sbill short ttybit, bar, *sbar; 4252974Swnj register struct uba_device *ui; 4262468Swnj register int unit; 4272605Swnj u_short cntr; 42813Sbill 4292395Swnj ui = dhinfo[dh]; 4302479Swnj addr = (struct dhdevice *)ui->ui_addr; 4312456Swnj if (addr->un.dhcsr & DH_NXM) { 4322456Swnj addr->un.dhcsr |= DH_CNI; 4332924Swnj printf("dh%d: NXM\n", dh); 434105Sbill } 4352395Swnj sbar = &dhsar[dh]; 43613Sbill bar = *sbar & ~addr->dhbar; 4372395Swnj unit = dh * 16; ttybit = 1; 4382468Swnj addr->un.dhcsr &= (short)~DH_TI; 4392468Swnj for (; bar; unit++, ttybit <<= 1) { 4402468Swnj if (bar & ttybit) { 44113Sbill *sbar &= ~ttybit; 44213Sbill bar &= ~ttybit; 4432395Swnj tp = &dh11[unit]; 4445406Swnj tp->t_state &= ~TS_BUSY; 4455406Swnj if (tp->t_state&TS_FLUSH) 4465406Swnj tp->t_state &= ~TS_FLUSH; 447113Sbill else { 4482456Swnj addr->un.dhcsrl = (unit&017)|DH_IE; 4492468Swnj /* 4502468Swnj * Do arithmetic in a short to make up 4512468Swnj * for lost 16&17 bits. 4522468Swnj */ 4532605Swnj cntr = addr->dhcar - 4542468Swnj UBACVT(tp->t_outq.c_cf, ui->ui_ubanum); 4553101Swnj ndflush(&tp->t_outq, (int)cntr); 456113Sbill } 457113Sbill if (tp->t_line) 45813Sbill (*linesw[tp->t_line].l_start)(tp); 459113Sbill else 46013Sbill dhstart(tp); 46113Sbill } 46213Sbill } 46313Sbill } 46413Sbill 46513Sbill /* 46613Sbill * Start (restart) transmission on the given DH11 line. 46713Sbill */ 46813Sbill dhstart(tp) 4692395Swnj register struct tty *tp; 47013Sbill { 4712479Swnj register struct dhdevice *addr; 4722468Swnj register int car, dh, unit, nch; 4732395Swnj int s; 47413Sbill 4752468Swnj unit = minor(tp->t_dev); 4762468Swnj dh = unit >> 4; 4772468Swnj unit &= 0xf; 4782479Swnj addr = (struct dhdevice *)tp->t_addr; 4792468Swnj 48013Sbill /* 4812468Swnj * Must hold interrupts in following code to prevent 4822468Swnj * state of the tp from changing. 48313Sbill */ 48413Sbill s = spl5(); 4852468Swnj /* 4862468Swnj * If it's currently active, or delaying, no need to do anything. 4872468Swnj */ 4885406Swnj if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 48913Sbill goto out; 4902468Swnj /* 4912468Swnj * If there are sleepers, and output has drained below low 4922468Swnj * water mark, wake up the sleepers. 4932468Swnj */ 4945406Swnj if (tp->t_outq.c_cc<=TTLOWAT(tp)) { 4955406Swnj if (tp->t_state&TS_ASLEEP) { 4965406Swnj tp->t_state &= ~TS_ASLEEP; 4975406Swnj wakeup((caddr_t)&tp->t_outq); 4985406Swnj } 4995406Swnj if (tp->t_wsel) { 5005406Swnj selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); 5015406Swnj tp->t_wsel = 0; 5025406Swnj tp->t_state &= ~TS_WCOLL; 5035406Swnj } 50413Sbill } 5052468Swnj /* 5062468Swnj * Now restart transmission unless the output queue is 5072468Swnj * empty. 5082468Swnj */ 50913Sbill if (tp->t_outq.c_cc == 0) 51013Sbill goto out; 5119549Ssam if (tp->t_flags & (RAW|LITOUT)) 51213Sbill nch = ndqb(&tp->t_outq, 0); 5132395Swnj else { 51413Sbill nch = ndqb(&tp->t_outq, 0200); 5152468Swnj /* 5162468Swnj * If first thing on queue is a delay process it. 5172468Swnj */ 51813Sbill if (nch == 0) { 51913Sbill nch = getc(&tp->t_outq); 5202468Swnj timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6); 5215406Swnj tp->t_state |= TS_TIMEOUT; 52213Sbill goto out; 52313Sbill } 52413Sbill } 5252468Swnj /* 5262468Swnj * If characters to transmit, restart transmission. 5272468Swnj */ 52813Sbill if (nch) { 5292468Swnj car = UBACVT(tp->t_outq.c_cf, dhinfo[dh]->ui_ubanum); 5302468Swnj addr->un.dhcsrl = unit|((car>>12)&0x30)|DH_IE; 5313586Sroot /* 5323586Sroot * The following nonsense with short word 5333586Sroot * is to make sure the dhbar |= word below 5343586Sroot * is done with an interlocking bisw2 instruction. 5353586Sroot */ 5363586Sroot { short word = 1 << unit; 5373586Sroot dhsar[dh] |= word; 5382468Swnj addr->dhcar = car; 53913Sbill addr->dhbcr = -nch; 5403586Sroot addr->dhbar |= word; 5413586Sroot } 5425406Swnj tp->t_state |= TS_BUSY; 54313Sbill } 5442395Swnj out: 54513Sbill splx(s); 54613Sbill } 54713Sbill 54813Sbill /* 5492468Swnj * Stop output on a line, e.g. for ^S/^Q or output flush. 55013Sbill */ 55113Sbill /*ARGSUSED*/ 55213Sbill dhstop(tp, flag) 5532468Swnj register struct tty *tp; 55413Sbill { 5552479Swnj register struct dhdevice *addr; 5562395Swnj register int unit, s; 55713Sbill 5582479Swnj addr = (struct dhdevice *)tp->t_addr; 5592468Swnj /* 5602468Swnj * Block input/output interrupts while messing with state. 5612468Swnj */ 5622468Swnj s = spl5(); 5635406Swnj if (tp->t_state & TS_BUSY) { 5642468Swnj /* 5652468Swnj * Device is transmitting; stop output 5662468Swnj * by selecting the line and setting the byte 5672468Swnj * count to -1. We will clean up later 5682468Swnj * by examining the address where the dh stopped. 5692468Swnj */ 5702395Swnj unit = minor(tp->t_dev); 5712456Swnj addr->un.dhcsrl = (unit&017) | DH_IE; 5725406Swnj if ((tp->t_state&TS_TTSTOP)==0) 5735406Swnj tp->t_state |= TS_FLUSH; 574113Sbill addr->dhbcr = -1; 575113Sbill } 57613Sbill splx(s); 57713Sbill } 57813Sbill 579168Sbill /* 580280Sbill * Reset state of driver if UBA reset was necessary. 581280Sbill * Reset the csrl and lpr registers on open lines, and 582280Sbill * restart transmitters. 583280Sbill */ 5842395Swnj dhreset(uban) 5852468Swnj int uban; 586280Sbill { 5872395Swnj register int dh, unit; 588280Sbill register struct tty *tp; 5892974Swnj register struct uba_device *ui; 5902421Skre int i; 591280Sbill 5922421Skre if (dh_ubinfo[uban] == 0) 5932421Skre return; 5942421Skre dh_ubinfo[uban] = uballoc(uban, (caddr_t)cfree, 5952770Swnj 512+nclist*sizeof (struct cblock), 0); 5962421Skre cbase[uban] = dh_ubinfo[uban]&0x3ffff; 5972395Swnj dh = 0; 5982643Swnj for (dh = 0; dh < NDH; dh++) { 5992421Skre ui = dhinfo[dh]; 6002421Skre if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban) 6012421Skre continue; 6022924Swnj printf(" dh%d", dh); 6032479Swnj ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE; 60416190Skarels ((struct dhdevice *)ui->ui_addr)->dhsilo = 0; 6052421Skre unit = dh * 16; 6062421Skre for (i = 0; i < 16; i++) { 6072421Skre tp = &dh11[unit]; 6085406Swnj if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { 6092421Skre dhparam(unit); 6102479Swnj dmctl(unit, DML_ON, DMSET); 6115406Swnj tp->t_state &= ~TS_BUSY; 6122421Skre dhstart(tp); 6132421Skre } 6142421Skre unit++; 615300Sbill } 616300Sbill } 61716190Skarels dhsilos = 0; 618280Sbill } 6192395Swnj 62016190Skarels int dhtransitions, dhslowtimers, dhfasttimers; /*DEBUG*/ 6212468Swnj /* 62216190Skarels * At software clock interrupt time, check status. 62316190Skarels * Empty all the dh silos that are in use, and decide whether 62416190Skarels * to turn any silos off or on. 6252468Swnj */ 6262456Swnj dhtimer() 6272456Swnj { 62816190Skarels register int dh, s; 62916190Skarels static int timercalls; 6302456Swnj 63116190Skarels if (dhsilos) { 63216190Skarels dhfasttimers++; /*DEBUG*/ 63316190Skarels timercalls++; 63416190Skarels s = spl5(); 63516190Skarels for (dh = 0; dh < NDH; dh++) 63616190Skarels if (dhsilos & (1 << dh)) 63716190Skarels dhrint(dh); 63816190Skarels splx(s); 63916190Skarels } 64016190Skarels if ((dhsilos == 0) || ((timercalls += FASTTIMER) >= hz)) { 64116190Skarels dhslowtimers++; /*DEBUG*/ 64216190Skarels timercalls = 0; 64316190Skarels for (dh = 0; dh < NDH; dh++) { 64416190Skarels ave(dhrate[dh], dhchars[dh], 8); 64516190Skarels if ((dhchars[dh] > dhhighrate) && 64616190Skarels ((dhsilos & (1 << dh)) == 0)) { 64716190Skarels ((struct dhdevice *)(dhinfo[dh]->ui_addr))->dhsilo = 64816190Skarels (dhchars[dh] > 500? 32 : 16); 64916190Skarels dhsilos |= (1 << dh); 65016190Skarels dhtransitions++; /*DEBUG*/ 65116190Skarels } else if ((dhsilos & (1 << dh)) && 65216190Skarels (dhrate[dh] < dhlowrate)) { 65316190Skarels ((struct dhdevice *)(dhinfo[dh]->ui_addr))->dhsilo = 0; 65416190Skarels dhsilos &= ~(1 << dh); 65516190Skarels } 65616190Skarels dhchars[dh] = 0; 65716190Skarels } 65816190Skarels } 65916190Skarels timeout(dhtimer, (caddr_t) 0, dhsilos? FASTTIMER: hz); 6602456Swnj } 6612456Swnj 6622468Swnj /* 6632479Swnj * Turn on the line associated with dh dev. 6642468Swnj */ 6652468Swnj dmopen(dev) 6662468Swnj dev_t dev; 6672468Swnj { 6682468Swnj register struct tty *tp; 6692468Swnj register struct dmdevice *addr; 6702974Swnj register struct uba_device *ui; 6712468Swnj register int unit; 6722468Swnj register int dm; 6733792Swnj int s; 6742468Swnj 6752468Swnj unit = minor(dev); 6762479Swnj dm = unit >> 4; 6772468Swnj tp = &dh11[unit]; 6782566Swnj unit &= 0xf; 67916942Skarels if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0) { 6805406Swnj tp->t_state |= TS_CARR_ON; 6812468Swnj return; 6822468Swnj } 6832468Swnj addr = (struct dmdevice *)ui->ui_addr; 6843792Swnj s = spl5(); 6852479Swnj addr->dmcsr &= ~DM_SE; 6862479Swnj while (addr->dmcsr & DM_BUSY) 6872468Swnj ; 6882566Swnj addr->dmcsr = unit; 6892479Swnj addr->dmlstat = DML_ON; 69016942Skarels if ((addr->dmlstat&DML_CAR) || (dhsoftCAR[dm]&(1<<unit))) 6915406Swnj tp->t_state |= TS_CARR_ON; 6923792Swnj addr->dmcsr = DM_IE|DM_SE; 6935406Swnj while ((tp->t_state&TS_CARR_ON)==0) 6942468Swnj sleep((caddr_t)&tp->t_rawq, TTIPRI); 6953792Swnj splx(s); 6962468Swnj } 6972468Swnj 6982468Swnj /* 6992468Swnj * Dump control bits into the DM registers. 7002468Swnj */ 7012468Swnj dmctl(dev, bits, how) 7022468Swnj dev_t dev; 7032468Swnj int bits, how; 7042468Swnj { 7052974Swnj register struct uba_device *ui; 7062468Swnj register struct dmdevice *addr; 7072468Swnj register int unit, s; 7082468Swnj int dm; 7092468Swnj 7102468Swnj unit = minor(dev); 7112468Swnj dm = unit >> 4; 7122468Swnj if ((ui = dminfo[dm]) == 0 || ui->ui_alive == 0) 7132468Swnj return; 7142468Swnj addr = (struct dmdevice *)ui->ui_addr; 7152468Swnj s = spl5(); 7162479Swnj addr->dmcsr &= ~DM_SE; 7172479Swnj while (addr->dmcsr & DM_BUSY) 7182468Swnj ; 7192468Swnj addr->dmcsr = unit & 0xf; 7202468Swnj switch(how) { 7212468Swnj case DMSET: 7222468Swnj addr->dmlstat = bits; 7232468Swnj break; 7242468Swnj case DMBIS: 7252468Swnj addr->dmlstat |= bits; 7262468Swnj break; 7272468Swnj case DMBIC: 7282468Swnj addr->dmlstat &= ~bits; 7292468Swnj break; 7302468Swnj } 7313792Swnj addr->dmcsr = DM_IE|DM_SE; 7322468Swnj splx(s); 7332468Swnj } 7342468Swnj 7352468Swnj /* 7362468Swnj * DM11 interrupt; deal with carrier transitions. 7372468Swnj */ 7382468Swnj dmintr(dm) 7392468Swnj register int dm; 7402468Swnj { 7412974Swnj register struct uba_device *ui; 7422468Swnj register struct tty *tp; 7432468Swnj register struct dmdevice *addr; 74416942Skarels int unit; 7452468Swnj 7462468Swnj ui = dminfo[dm]; 7472479Swnj if (ui == 0) 7482479Swnj return; 7492468Swnj addr = (struct dmdevice *)ui->ui_addr; 7503997Sroot if (addr->dmcsr&DM_DONE) { 7513997Sroot if (addr->dmcsr&DM_CF) { 75216942Skarels unit = addr->dmcsr & 0xf; 75316942Skarels tp = &dh11[(dm << 4) + unit]; 7543997Sroot wakeup((caddr_t)&tp->t_rawq); 7559549Ssam if ((tp->t_state&TS_WOPEN) == 0 && 7569605Ssam (tp->t_flags & MDMBUF)) { 7573997Sroot if (addr->dmlstat & DML_CAR) { 7585406Swnj tp->t_state &= ~TS_TTSTOP; 7593997Sroot ttstart(tp); 7605406Swnj } else if ((tp->t_state&TS_TTSTOP) == 0) { 7615406Swnj tp->t_state |= TS_TTSTOP; 7623997Sroot dhstop(tp, 0); 7633997Sroot } 7643997Sroot } else if ((addr->dmlstat&DML_CAR)==0) { 7655406Swnj if ((tp->t_state&TS_WOPEN)==0 && 76616942Skarels (tp->t_flags & NOHANG) == 0 && 76716942Skarels (dhsoftCAR[dm] & (1<<unit)) == 0) { 7683997Sroot gsignal(tp->t_pgrp, SIGHUP); 7693997Sroot gsignal(tp->t_pgrp, SIGCONT); 7703997Sroot addr->dmlstat = 0; 77112775Ssam ttyflush(tp, FREAD|FWRITE); 7723997Sroot } 7735406Swnj tp->t_state &= ~TS_CARR_ON; 7743997Sroot } else 7755406Swnj tp->t_state |= TS_CARR_ON; 7763997Sroot } 7773997Sroot addr->dmcsr = DM_IE|DM_SE; 7782468Swnj } 7792468Swnj } 7802625Swnj #endif 781