123320Smckusick /* 223320Smckusick * Copyright (c) 1982 Regents of the University of California. 323320Smckusick * All rights reserved. The Berkeley software License Agreement 423320Smckusick * specifies the terms and conditions for redistribution. 523320Smckusick * 6*27049Skarels * @(#)dh.c 6.16 (Berkeley) 04/12/86 723320Smckusick */ 813Sbill 91934Swnj #include "dh.h" 102643Swnj #if NDH > 0 1113Sbill /* 122479Swnj * DH-11/DM-11 driver 1313Sbill */ 149771Ssam #include "../machine/pte.h" 159771Ssam 162730Swnj #include "bk.h" 1716062Skarels #include "uba.h" 1817122Sbloom #include "param.h" 1917122Sbloom #include "conf.h" 2017122Sbloom #include "dir.h" 2117122Sbloom #include "user.h" 2217122Sbloom #include "proc.h" 2317122Sbloom #include "ioctl.h" 2417122Sbloom #include "tty.h" 2517122Sbloom #include "map.h" 2617122Sbloom #include "buf.h" 2717122Sbloom #include "vm.h" 2817122Sbloom #include "kernel.h" 2918311Sralph #include "syslog.h" 308472Sroot 3117122Sbloom #include "ubareg.h" 3217122Sbloom #include "ubavar.h" 3317122Sbloom #include "dhreg.h" 3417122Sbloom #include "dmreg.h" 358472Sroot 3617122Sbloom #include "bkmac.h" 3717122Sbloom #include "clist.h" 3817122Sbloom #include "file.h" 3917122Sbloom #include "uio.h" 4013Sbill 412468Swnj /* 422479Swnj * Definition of the driver for the auto-configuration program. 432479Swnj * There is one definition for the dh and one for the dm. 442468Swnj */ 4516190Skarels int dhprobe(), dhattach(), dhrint(), dhxint(), dhtimer(); 462974Swnj struct uba_device *dhinfo[NDH]; 472395Swnj u_short dhstd[] = { 0 }; 482395Swnj struct uba_driver dhdriver = 492605Swnj { dhprobe, 0, dhattach, 0, dhstd, "dh", dhinfo }; 502395Swnj 512605Swnj int dmprobe(), dmattach(), dmintr(); 522974Swnj struct uba_device *dminfo[NDH]; 532479Swnj u_short dmstd[] = { 0 }; 542479Swnj struct uba_driver dmdriver = 552605Swnj { dmprobe, 0, dmattach, 0, dmstd, "dm", dminfo }; 5613Sbill 576615Ssam #ifndef PORTSELECTOR 5825394Skarels #define ISPEED B9600 596615Ssam #define IFLAGS (EVENP|ODDP|ECHO) 606615Ssam #else 616615Ssam #define ISPEED B4800 626615Ssam #define IFLAGS (EVENP|ODDP) 636615Ssam #endif 646615Ssam 6516190Skarels #define FASTTIMER (hz/30) /* scan rate with silos on */ 6616190Skarels 6713Sbill /* 682479Swnj * Local variables for the driver 6913Sbill */ 702643Swnj short dhsar[NDH]; /* software copy of last bar */ 712643Swnj short dhsoftCAR[NDH]; 7213Sbill 732643Swnj struct tty dh11[NDH*16]; 742643Swnj int ndh11 = NDH*16; 752479Swnj int dhact; /* mask of active dh's */ 7616190Skarels int dhsilos; /* mask of dh's with silo in use */ 7716190Skarels int dhchars[NDH]; /* recent input count */ 7816190Skarels int dhrate[NDH]; /* smoothed input count */ 7916190Skarels int dhhighrate = 100; /* silo on if dhchars > dhhighrate */ 8016190Skarels int dhlowrate = 75; /* silo off if dhrate < dhlowrate */ 8116190Skarels static short timerstarted; 822479Swnj int dhstart(), ttrstrt(); 8313Sbill 842479Swnj /* 852479Swnj * The clist space is mapped by the driver onto each UNIBUS. 862479Swnj * The UBACVT macro converts a clist space address for unibus uban 872479Swnj * into an i/o space address for the DMA routine. 882479Swnj */ 8916062Skarels int dh_ubinfo[NUBA]; /* info about allocated unibus map */ 9016062Skarels int cbase[NUBA]; /* base address in unibus map */ 912479Swnj #define UBACVT(x, uban) (cbase[uban] + ((x)-(char *)cfree)) 9213Sbill 932456Swnj /* 942456Swnj * Routine for configuration to force a dh to interrupt. 952456Swnj * Set to transmit at 9600 baud, and cause a transmitter interrupt. 962456Swnj */ 972468Swnj /*ARGSUSED*/ 982605Swnj dhprobe(reg) 992395Swnj caddr_t reg; 1002395Swnj { 1012468Swnj register int br, cvec; /* these are ``value-result'' */ 1022479Swnj register struct dhdevice *dhaddr = (struct dhdevice *)reg; 1032395Swnj 1042605Swnj #ifdef lint 1052605Swnj br = 0; cvec = br; br = cvec; 1067384Sroot if (ndh11 == 0) ndh11 = 1; 1074932Swnj dhrint(0); dhxint(0); 1082605Swnj #endif 1092696Swnj #ifndef notdef 1102566Swnj dhaddr->un.dhcsr = DH_RIE|DH_MM|DH_RI; 1116380Swnj DELAY(1000); 1127384Sroot dhaddr->un.dhcsr &= ~DH_RI; 1132566Swnj dhaddr->un.dhcsr = 0; 1142566Swnj #else 1152456Swnj dhaddr->un.dhcsr = DH_TIE; 1162456Swnj DELAY(5); 1172456Swnj dhaddr->dhlpr = (B9600 << 10) | (B9600 << 6) | BITS7|PENABLE; 1182421Skre dhaddr->dhbcr = -1; 1192456Swnj dhaddr->dhcar = 0; 1202421Skre dhaddr->dhbar = 1; 1212456Swnj DELAY(100000); /* wait 1/10'th of a sec for interrupt */ 1222421Skre dhaddr->un.dhcsr = 0; 1232456Swnj if (cvec && cvec != 0x200) 1242456Swnj cvec -= 4; /* transmit -> receive */ 1252482Swnj #endif 1267408Skre return (sizeof (struct dhdevice)); 1272395Swnj } 1282395Swnj 1292456Swnj /* 1302605Swnj * Routine called to attach a dh. 1312456Swnj */ 1322605Swnj dhattach(ui) 1332974Swnj struct uba_device *ui; 1342395Swnj { 1352395Swnj 1362566Swnj dhsoftCAR[ui->ui_unit] = ui->ui_flags; 13726219Skarels cbase[ui->ui_ubanum] = -1; 1382395Swnj } 1392395Swnj 14013Sbill /* 1412479Swnj * Configuration routine to cause a dm to interrupt. 1422479Swnj */ 1432605Swnj dmprobe(reg) 1442605Swnj caddr_t reg; 1452479Swnj { 1462479Swnj register int br, vec; /* value-result */ 1472605Swnj register struct dmdevice *dmaddr = (struct dmdevice *)reg; 1482479Swnj 1492605Swnj #ifdef lint 1503101Swnj br = 0; vec = br; br = vec; 1516185Ssam dmintr(0); 1522605Swnj #endif 1532479Swnj dmaddr->dmcsr = DM_DONE|DM_IE; 1542479Swnj DELAY(20); 1552479Swnj dmaddr->dmcsr = 0; 1562605Swnj return (1); 1572479Swnj } 1582479Swnj 1592605Swnj /*ARGSUSED*/ 1602605Swnj dmattach(ui) 1612974Swnj struct uba_device *ui; 1622479Swnj { 1632479Swnj 1642479Swnj /* no local state to set up */ 1652479Swnj } 1662479Swnj 1672479Swnj /* 1682468Swnj * Open a DH11 line, mapping the clist onto the uba if this 1692468Swnj * is the first dh on this uba. Turn on this dh if this is 1702468Swnj * the first use of it. Also do a dmopen to wait for carrier. 17113Sbill */ 17213Sbill /*ARGSUSED*/ 17313Sbill dhopen(dev, flag) 1742395Swnj dev_t dev; 17513Sbill { 17613Sbill register struct tty *tp; 1772395Swnj register int unit, dh; 1782479Swnj register struct dhdevice *addr; 1792974Swnj register struct uba_device *ui; 18013Sbill int s; 18113Sbill 1822395Swnj unit = minor(dev); 1832395Swnj dh = unit >> 4; 1848566Sroot if (unit >= NDH*16 || (ui = dhinfo[dh])== 0 || ui->ui_alive == 0) 1858566Sroot return (ENXIO); 1862395Swnj tp = &dh11[unit]; 1878566Sroot if (tp->t_state&TS_XCLUDE && u.u_uid!=0) 1888566Sroot return (EBUSY); 1892479Swnj addr = (struct dhdevice *)ui->ui_addr; 19013Sbill tp->t_addr = (caddr_t)addr; 19113Sbill tp->t_oproc = dhstart; 1925406Swnj tp->t_state |= TS_WOPEN; 1932468Swnj /* 1942468Swnj * While setting up state for this uba and this dh, 1952468Swnj * block uba resets which can clear the state. 1962468Swnj */ 1972468Swnj s = spl5(); 19826219Skarels if (cbase[ui->ui_ubanum] == -1) { 1992395Swnj dh_ubinfo[ui->ui_ubanum] = 2002421Skre uballoc(ui->ui_ubanum, (caddr_t)cfree, 20125433Skarels nclist*sizeof(struct cblock), 0); 20226219Skarels cbase[ui->ui_ubanum] = UBAI_ADDR(dh_ubinfo[ui->ui_ubanum]); 20313Sbill } 20416190Skarels if (timerstarted == 0) { 20516190Skarels timerstarted++; 20616190Skarels timeout(dhtimer, (caddr_t) 0, hz); 20716190Skarels } 2082456Swnj if ((dhact&(1<<dh)) == 0) { 2092456Swnj addr->un.dhcsr |= DH_IE; 2102468Swnj dhact |= (1<<dh); 21116190Skarels addr->dhsilo = 0; 2122456Swnj } 21313Sbill splx(s); 2142468Swnj /* 215*27049Skarels * If this is first open, initialize tty state to default. 2162468Swnj */ 2175406Swnj if ((tp->t_state&TS_ISOPEN) == 0) { 21813Sbill ttychars(tp); 219*27049Skarels #ifndef PORTSELECTOR 220*27049Skarels if (tp->t_ispeed == 0) { 221*27049Skarels #else 222*27049Skarels tp->t_state |= TS_HUPCLS; 223*27049Skarels #endif PORTSELECTOR 224*27049Skarels tp->t_ispeed = ISPEED; 225*27049Skarels tp->t_ospeed = ISPEED; 226*27049Skarels tp->t_flags = IFLAGS; 227*27049Skarels #ifndef PORTSELECTOR 228*27049Skarels } 229*27049Skarels #endif PORTSELECTOR 2302395Swnj dhparam(unit); 23113Sbill } 2322468Swnj /* 2332468Swnj * Wait for carrier, then process line discipline specific open. 2342468Swnj */ 23513Sbill dmopen(dev); 2368566Sroot return ((*linesw[tp->t_line].l_open)(dev, tp)); 23713Sbill } 23813Sbill 23913Sbill /* 2402468Swnj * Close a DH11 line, turning off the DM11. 24113Sbill */ 24213Sbill /*ARGSUSED*/ 24313Sbill dhclose(dev, flag) 2442395Swnj dev_t dev; 2452395Swnj int flag; 24613Sbill { 24713Sbill register struct tty *tp; 2482395Swnj register unit; 24913Sbill 2502395Swnj unit = minor(dev); 2512395Swnj tp = &dh11[unit]; 25213Sbill (*linesw[tp->t_line].l_close)(tp); 2532479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); 2545406Swnj if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) 2552479Swnj dmctl(unit, DML_OFF, DMSET); 25613Sbill ttyclose(tp); 25713Sbill } 25813Sbill 2597725Sroot dhread(dev, uio) 2602395Swnj dev_t dev; 2617725Sroot struct uio *uio; 26213Sbill { 2638490Sroot register struct tty *tp = &dh11[minor(dev)]; 26413Sbill 2657725Sroot return ((*linesw[tp->t_line].l_read)(tp, uio)); 26613Sbill } 26713Sbill 2687831Sroot dhwrite(dev, uio) 2692395Swnj dev_t dev; 2707831Sroot struct uio *uio; 27113Sbill { 2728490Sroot register struct tty *tp = &dh11[minor(dev)]; 27313Sbill 2748490Sroot return ((*linesw[tp->t_line].l_write)(tp, uio)); 27513Sbill } 27613Sbill 27713Sbill /* 27813Sbill * DH11 receiver interrupt. 27913Sbill */ 2802395Swnj dhrint(dh) 2812395Swnj int dh; 28213Sbill { 28313Sbill register struct tty *tp; 2842395Swnj register c; 2852479Swnj register struct dhdevice *addr; 286117Sbill register struct tty *tp0; 2872974Swnj register struct uba_device *ui; 2882924Swnj int overrun = 0; 28913Sbill 2902395Swnj ui = dhinfo[dh]; 2912479Swnj if (ui == 0 || ui->ui_alive == 0) 2922479Swnj return; 2932479Swnj addr = (struct dhdevice *)ui->ui_addr; 2942468Swnj tp0 = &dh11[dh<<4]; 2952468Swnj /* 2962468Swnj * Loop fetching characters from the silo for this 2972468Swnj * dh until there are no more in the silo. 2982468Swnj */ 2992468Swnj while ((c = addr->dhrcr) < 0) { 3002468Swnj tp = tp0 + ((c>>8)&0xf); 30116190Skarels dhchars[dh]++; 3025406Swnj if ((tp->t_state&TS_ISOPEN)==0) { 30325394Skarels wakeup((caddr_t)&tp->t_rawq); 30425394Skarels #ifdef PORTSELECTOR 30525394Skarels if ((tp->t_state&TS_WOPEN) == 0) 3066615Ssam #endif 30725394Skarels continue; 30813Sbill } 3092468Swnj if (c & DH_PE) 31013Sbill if ((tp->t_flags&(EVENP|ODDP))==EVENP 31113Sbill || (tp->t_flags&(EVENP|ODDP))==ODDP ) 31213Sbill continue; 3132924Swnj if ((c & DH_DO) && overrun == 0) { 31424840Seric log(LOG_WARNING, "dh%d: silo overflow\n", dh); 3152924Swnj overrun = 1; 3162924Swnj } 3172468Swnj if (c & DH_FE) 3182468Swnj /* 3192468Swnj * At framing error (break) generate 3202468Swnj * a null (in raw mode, for getty), or a 3212468Swnj * interrupt (in cooked/cbreak mode). 3222468Swnj */ 32313Sbill if (tp->t_flags&RAW) 3242468Swnj c = 0; 32513Sbill else 3269549Ssam c = tp->t_intrc; 3272730Swnj #if NBK > 0 328139Sbill if (tp->t_line == NETLDISC) { 329117Sbill c &= 0177; 330168Sbill BKINPUT(c, tp); 331117Sbill } else 3322730Swnj #endif 3332468Swnj (*linesw[tp->t_line].l_rint)(c, tp); 33413Sbill } 33513Sbill } 33613Sbill 33713Sbill /* 3382468Swnj * Ioctl for DH11. 33913Sbill */ 34013Sbill /*ARGSUSED*/ 3417629Ssam dhioctl(dev, cmd, data, flag) 3427629Ssam caddr_t data; 34313Sbill { 34413Sbill register struct tty *tp; 3458566Sroot register int unit = minor(dev); 3468566Sroot int error; 34713Sbill 3482395Swnj tp = &dh11[unit]; 3498566Sroot error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); 3508566Sroot if (error >= 0) 3518566Sroot return (error); 3528566Sroot error = ttioctl(tp, cmd, data, flag); 3538566Sroot if (error >= 0) { 35417561Sbloom if (cmd == TIOCSETP || cmd == TIOCSETN || cmd == TIOCLBIS || 35517561Sbloom cmd == TIOCLBIC || cmd == TIOCLSET) 3562395Swnj dhparam(unit); 3578566Sroot return (error); 3588566Sroot } 3598566Sroot switch (cmd) { 3607629Ssam 361168Sbill case TIOCSBRK: 3622479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak |= 1<<(unit&017); 363168Sbill break; 3647629Ssam 365168Sbill case TIOCCBRK: 3662479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); 367168Sbill break; 3687629Ssam 369168Sbill case TIOCSDTR: 3702479Swnj dmctl(unit, DML_DTR|DML_RTS, DMBIS); 371168Sbill break; 3727629Ssam 373168Sbill case TIOCCDTR: 3742479Swnj dmctl(unit, DML_DTR|DML_RTS, DMBIC); 375168Sbill break; 3767629Ssam 377168Sbill default: 3788566Sroot return (ENOTTY); 379168Sbill } 3808566Sroot return (0); 38113Sbill } 38213Sbill 38313Sbill /* 38413Sbill * Set parameters from open or stty into the DH hardware 38513Sbill * registers. 38613Sbill */ 3872395Swnj dhparam(unit) 3882395Swnj register int unit; 38913Sbill { 39013Sbill register struct tty *tp; 3912479Swnj register struct dhdevice *addr; 3922395Swnj register int lpar; 393300Sbill int s; 39413Sbill 3952395Swnj tp = &dh11[unit]; 3962479Swnj addr = (struct dhdevice *)tp->t_addr; 3972468Swnj /* 3982468Swnj * Block interrupts so parameters will be set 3992468Swnj * before the line interrupts. 4002468Swnj */ 401300Sbill s = spl5(); 4022468Swnj addr->un.dhcsrl = (unit&0xf) | DH_IE; 40313Sbill if ((tp->t_ispeed)==0) { 4045406Swnj tp->t_state |= TS_HUPCLS; 4052479Swnj dmctl(unit, DML_OFF, DMSET); 40613Sbill return; 40713Sbill } 4082395Swnj lpar = ((tp->t_ospeed)<<10) | ((tp->t_ispeed)<<6); 4092468Swnj if ((tp->t_ispeed) == B134) 4102395Swnj lpar |= BITS6|PENABLE|HDUPLX; 41124269Slepreau else if (tp->t_flags & (RAW|LITOUT|PASS8)) 4122395Swnj lpar |= BITS8; 41313Sbill else 4142395Swnj lpar |= BITS7|PENABLE; 41513Sbill if ((tp->t_flags&EVENP) == 0) 4162395Swnj lpar |= OPAR; 4172468Swnj if ((tp->t_ospeed) == B110) 4182395Swnj lpar |= TWOSB; 4192395Swnj addr->dhlpr = lpar; 420300Sbill splx(s); 42113Sbill } 42213Sbill 42313Sbill /* 42413Sbill * DH11 transmitter interrupt. 42513Sbill * Restart each line which used to be active but has 42613Sbill * terminated transmission since the last interrupt. 42713Sbill */ 4282395Swnj dhxint(dh) 4292395Swnj int dh; 43013Sbill { 43113Sbill register struct tty *tp; 4322479Swnj register struct dhdevice *addr; 43313Sbill short ttybit, bar, *sbar; 4342974Swnj register struct uba_device *ui; 4352468Swnj register int unit; 4362605Swnj u_short cntr; 43713Sbill 4382395Swnj ui = dhinfo[dh]; 4392479Swnj addr = (struct dhdevice *)ui->ui_addr; 4402456Swnj if (addr->un.dhcsr & DH_NXM) { 4412456Swnj addr->un.dhcsr |= DH_CNI; 4422924Swnj printf("dh%d: NXM\n", dh); 443105Sbill } 4442395Swnj sbar = &dhsar[dh]; 44513Sbill bar = *sbar & ~addr->dhbar; 4462395Swnj unit = dh * 16; ttybit = 1; 4472468Swnj addr->un.dhcsr &= (short)~DH_TI; 4482468Swnj for (; bar; unit++, ttybit <<= 1) { 4492468Swnj if (bar & ttybit) { 45013Sbill *sbar &= ~ttybit; 45113Sbill bar &= ~ttybit; 4522395Swnj tp = &dh11[unit]; 4535406Swnj tp->t_state &= ~TS_BUSY; 4545406Swnj if (tp->t_state&TS_FLUSH) 4555406Swnj tp->t_state &= ~TS_FLUSH; 456113Sbill else { 4572456Swnj addr->un.dhcsrl = (unit&017)|DH_IE; 4582468Swnj /* 4592468Swnj * Do arithmetic in a short to make up 4602468Swnj * for lost 16&17 bits. 4612468Swnj */ 4622605Swnj cntr = addr->dhcar - 4632468Swnj UBACVT(tp->t_outq.c_cf, ui->ui_ubanum); 4643101Swnj ndflush(&tp->t_outq, (int)cntr); 465113Sbill } 466113Sbill if (tp->t_line) 46713Sbill (*linesw[tp->t_line].l_start)(tp); 468113Sbill else 46913Sbill dhstart(tp); 47013Sbill } 47113Sbill } 47213Sbill } 47313Sbill 47413Sbill /* 47513Sbill * Start (restart) transmission on the given DH11 line. 47613Sbill */ 47713Sbill dhstart(tp) 4782395Swnj register struct tty *tp; 47913Sbill { 4802479Swnj register struct dhdevice *addr; 4812468Swnj register int car, dh, unit, nch; 4822395Swnj int s; 48313Sbill 4842468Swnj unit = minor(tp->t_dev); 4852468Swnj dh = unit >> 4; 4862468Swnj unit &= 0xf; 4872479Swnj addr = (struct dhdevice *)tp->t_addr; 4882468Swnj 48913Sbill /* 4902468Swnj * Must hold interrupts in following code to prevent 4912468Swnj * state of the tp from changing. 49213Sbill */ 49313Sbill s = spl5(); 4942468Swnj /* 4952468Swnj * If it's currently active, or delaying, no need to do anything. 4962468Swnj */ 4975406Swnj if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 49813Sbill goto out; 4992468Swnj /* 5002468Swnj * If there are sleepers, and output has drained below low 5012468Swnj * water mark, wake up the sleepers. 5022468Swnj */ 5035406Swnj if (tp->t_outq.c_cc<=TTLOWAT(tp)) { 5045406Swnj if (tp->t_state&TS_ASLEEP) { 5055406Swnj tp->t_state &= ~TS_ASLEEP; 5065406Swnj wakeup((caddr_t)&tp->t_outq); 5075406Swnj } 5085406Swnj if (tp->t_wsel) { 5095406Swnj selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); 5105406Swnj tp->t_wsel = 0; 5115406Swnj tp->t_state &= ~TS_WCOLL; 5125406Swnj } 51313Sbill } 5142468Swnj /* 5152468Swnj * Now restart transmission unless the output queue is 5162468Swnj * empty. 5172468Swnj */ 51813Sbill if (tp->t_outq.c_cc == 0) 51913Sbill goto out; 5209549Ssam if (tp->t_flags & (RAW|LITOUT)) 52113Sbill nch = ndqb(&tp->t_outq, 0); 5222395Swnj else { 52313Sbill nch = ndqb(&tp->t_outq, 0200); 5242468Swnj /* 5252468Swnj * If first thing on queue is a delay process it. 5262468Swnj */ 52713Sbill if (nch == 0) { 52813Sbill nch = getc(&tp->t_outq); 5292468Swnj timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6); 5305406Swnj tp->t_state |= TS_TIMEOUT; 53113Sbill goto out; 53213Sbill } 53313Sbill } 5342468Swnj /* 5352468Swnj * If characters to transmit, restart transmission. 5362468Swnj */ 53713Sbill if (nch) { 5382468Swnj car = UBACVT(tp->t_outq.c_cf, dhinfo[dh]->ui_ubanum); 5392468Swnj addr->un.dhcsrl = unit|((car>>12)&0x30)|DH_IE; 5403586Sroot /* 5413586Sroot * The following nonsense with short word 5423586Sroot * is to make sure the dhbar |= word below 5433586Sroot * is done with an interlocking bisw2 instruction. 5443586Sroot */ 5453586Sroot { short word = 1 << unit; 5463586Sroot dhsar[dh] |= word; 5472468Swnj addr->dhcar = car; 54813Sbill addr->dhbcr = -nch; 5493586Sroot addr->dhbar |= word; 5503586Sroot } 5515406Swnj tp->t_state |= TS_BUSY; 55213Sbill } 5532395Swnj out: 55413Sbill splx(s); 55513Sbill } 55613Sbill 55713Sbill /* 5582468Swnj * Stop output on a line, e.g. for ^S/^Q or output flush. 55913Sbill */ 56013Sbill /*ARGSUSED*/ 56113Sbill dhstop(tp, flag) 5622468Swnj register struct tty *tp; 56313Sbill { 5642479Swnj register struct dhdevice *addr; 5652395Swnj register int unit, s; 56613Sbill 5672479Swnj addr = (struct dhdevice *)tp->t_addr; 5682468Swnj /* 5692468Swnj * Block input/output interrupts while messing with state. 5702468Swnj */ 5712468Swnj s = spl5(); 5725406Swnj if (tp->t_state & TS_BUSY) { 5732468Swnj /* 5742468Swnj * Device is transmitting; stop output 5752468Swnj * by selecting the line and setting the byte 5762468Swnj * count to -1. We will clean up later 5772468Swnj * by examining the address where the dh stopped. 5782468Swnj */ 5792395Swnj unit = minor(tp->t_dev); 5802456Swnj addr->un.dhcsrl = (unit&017) | DH_IE; 5815406Swnj if ((tp->t_state&TS_TTSTOP)==0) 5825406Swnj tp->t_state |= TS_FLUSH; 583113Sbill addr->dhbcr = -1; 584113Sbill } 58513Sbill splx(s); 58613Sbill } 58713Sbill 588168Sbill /* 589280Sbill * Reset state of driver if UBA reset was necessary. 590280Sbill * Reset the csrl and lpr registers on open lines, and 591280Sbill * restart transmitters. 592280Sbill */ 5932395Swnj dhreset(uban) 5942468Swnj int uban; 595280Sbill { 5962395Swnj register int dh, unit; 597280Sbill register struct tty *tp; 5982974Swnj register struct uba_device *ui; 5992421Skre int i; 600280Sbill 6012395Swnj dh = 0; 6022643Swnj for (dh = 0; dh < NDH; dh++) { 6032421Skre ui = dhinfo[dh]; 6042421Skre if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban) 6052421Skre continue; 6062924Swnj printf(" dh%d", dh); 60726219Skarels if (dh_ubinfo[uban]) { 60825433Skarels dh_ubinfo[uban] = uballoc(uban, (caddr_t)cfree, 60925433Skarels nclist*sizeof (struct cblock), 0); 61026219Skarels cbase[uban] = UBAI_ADDR(dh_ubinfo[uban]); 61125433Skarels } 6122479Swnj ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE; 61316190Skarels ((struct dhdevice *)ui->ui_addr)->dhsilo = 0; 6142421Skre unit = dh * 16; 6152421Skre for (i = 0; i < 16; i++) { 6162421Skre tp = &dh11[unit]; 6175406Swnj if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { 6182421Skre dhparam(unit); 6192479Swnj dmctl(unit, DML_ON, DMSET); 6205406Swnj tp->t_state &= ~TS_BUSY; 6212421Skre dhstart(tp); 6222421Skre } 6232421Skre unit++; 624300Sbill } 625300Sbill } 62616190Skarels dhsilos = 0; 627280Sbill } 6282395Swnj 62916190Skarels int dhtransitions, dhslowtimers, dhfasttimers; /*DEBUG*/ 6302468Swnj /* 63116190Skarels * At software clock interrupt time, check status. 63216190Skarels * Empty all the dh silos that are in use, and decide whether 63316190Skarels * to turn any silos off or on. 6342468Swnj */ 6352456Swnj dhtimer() 6362456Swnj { 63716190Skarels register int dh, s; 63816190Skarels static int timercalls; 6392456Swnj 64016190Skarels if (dhsilos) { 64116190Skarels dhfasttimers++; /*DEBUG*/ 64216190Skarels timercalls++; 64316190Skarels s = spl5(); 64416190Skarels for (dh = 0; dh < NDH; dh++) 64516190Skarels if (dhsilos & (1 << dh)) 64616190Skarels dhrint(dh); 64716190Skarels splx(s); 64816190Skarels } 64916190Skarels if ((dhsilos == 0) || ((timercalls += FASTTIMER) >= hz)) { 65016190Skarels dhslowtimers++; /*DEBUG*/ 65116190Skarels timercalls = 0; 65216190Skarels for (dh = 0; dh < NDH; dh++) { 65316190Skarels ave(dhrate[dh], dhchars[dh], 8); 65416190Skarels if ((dhchars[dh] > dhhighrate) && 65516190Skarels ((dhsilos & (1 << dh)) == 0)) { 65616190Skarels ((struct dhdevice *)(dhinfo[dh]->ui_addr))->dhsilo = 65716190Skarels (dhchars[dh] > 500? 32 : 16); 65816190Skarels dhsilos |= (1 << dh); 65916190Skarels dhtransitions++; /*DEBUG*/ 66016190Skarels } else if ((dhsilos & (1 << dh)) && 66116190Skarels (dhrate[dh] < dhlowrate)) { 66216190Skarels ((struct dhdevice *)(dhinfo[dh]->ui_addr))->dhsilo = 0; 66316190Skarels dhsilos &= ~(1 << dh); 66416190Skarels } 66516190Skarels dhchars[dh] = 0; 66616190Skarels } 66716190Skarels } 66816190Skarels timeout(dhtimer, (caddr_t) 0, dhsilos? FASTTIMER: hz); 6692456Swnj } 6702456Swnj 6712468Swnj /* 6722479Swnj * Turn on the line associated with dh dev. 6732468Swnj */ 6742468Swnj dmopen(dev) 6752468Swnj dev_t dev; 6762468Swnj { 6772468Swnj register struct tty *tp; 6782468Swnj register struct dmdevice *addr; 6792974Swnj register struct uba_device *ui; 6802468Swnj register int unit; 6812468Swnj register int dm; 6823792Swnj int s; 6832468Swnj 6842468Swnj unit = minor(dev); 6852479Swnj dm = unit >> 4; 6862468Swnj tp = &dh11[unit]; 6872566Swnj unit &= 0xf; 68816942Skarels if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0) { 6895406Swnj tp->t_state |= TS_CARR_ON; 6902468Swnj return; 6912468Swnj } 6922468Swnj addr = (struct dmdevice *)ui->ui_addr; 6933792Swnj s = spl5(); 6942479Swnj addr->dmcsr &= ~DM_SE; 6952479Swnj while (addr->dmcsr & DM_BUSY) 6962468Swnj ; 6972566Swnj addr->dmcsr = unit; 6982479Swnj addr->dmlstat = DML_ON; 69916942Skarels if ((addr->dmlstat&DML_CAR) || (dhsoftCAR[dm]&(1<<unit))) 7005406Swnj tp->t_state |= TS_CARR_ON; 7013792Swnj addr->dmcsr = DM_IE|DM_SE; 7025406Swnj while ((tp->t_state&TS_CARR_ON)==0) 7032468Swnj sleep((caddr_t)&tp->t_rawq, TTIPRI); 7043792Swnj splx(s); 7052468Swnj } 7062468Swnj 7072468Swnj /* 7082468Swnj * Dump control bits into the DM registers. 7092468Swnj */ 7102468Swnj dmctl(dev, bits, how) 7112468Swnj dev_t dev; 7122468Swnj int bits, how; 7132468Swnj { 7142974Swnj register struct uba_device *ui; 7152468Swnj register struct dmdevice *addr; 7162468Swnj register int unit, s; 7172468Swnj int dm; 7182468Swnj 7192468Swnj unit = minor(dev); 7202468Swnj dm = unit >> 4; 7212468Swnj if ((ui = dminfo[dm]) == 0 || ui->ui_alive == 0) 7222468Swnj return; 7232468Swnj addr = (struct dmdevice *)ui->ui_addr; 7242468Swnj s = spl5(); 7252479Swnj addr->dmcsr &= ~DM_SE; 7262479Swnj while (addr->dmcsr & DM_BUSY) 7272468Swnj ; 7282468Swnj addr->dmcsr = unit & 0xf; 7292468Swnj switch(how) { 7302468Swnj case DMSET: 7312468Swnj addr->dmlstat = bits; 7322468Swnj break; 7332468Swnj case DMBIS: 7342468Swnj addr->dmlstat |= bits; 7352468Swnj break; 7362468Swnj case DMBIC: 7372468Swnj addr->dmlstat &= ~bits; 7382468Swnj break; 7392468Swnj } 7403792Swnj addr->dmcsr = DM_IE|DM_SE; 7412468Swnj splx(s); 7422468Swnj } 7432468Swnj 7442468Swnj /* 7452468Swnj * DM11 interrupt; deal with carrier transitions. 7462468Swnj */ 7472468Swnj dmintr(dm) 7482468Swnj register int dm; 7492468Swnj { 7502974Swnj register struct uba_device *ui; 7512468Swnj register struct tty *tp; 7522468Swnj register struct dmdevice *addr; 75316942Skarels int unit; 7542468Swnj 7552468Swnj ui = dminfo[dm]; 7562479Swnj if (ui == 0) 7572479Swnj return; 7582468Swnj addr = (struct dmdevice *)ui->ui_addr; 7593997Sroot if (addr->dmcsr&DM_DONE) { 7603997Sroot if (addr->dmcsr&DM_CF) { 76116942Skarels unit = addr->dmcsr & 0xf; 76216942Skarels tp = &dh11[(dm << 4) + unit]; 76325394Skarels if (addr->dmlstat & DML_CAR) 76425394Skarels (void)(*linesw[tp->t_line].l_modem)(tp, 1); 76525394Skarels else if ((dhsoftCAR[dm] & (1<<unit)) == 0 && 76625394Skarels (*linesw[tp->t_line].l_modem)(tp, 0) == 0) 76725394Skarels addr->dmlstat = 0; 7683997Sroot } 7693997Sroot addr->dmcsr = DM_IE|DM_SE; 7702468Swnj } 7712468Swnj } 7722625Swnj #endif 773