1*2730Swnj /* dh.c 4.25 81/02/26 */ 213Sbill 31934Swnj #include "dh.h" 42643Swnj #if NDH > 0 52456Swnj #define DELAY(i) { register int j = i; while (--j > 0); } 613Sbill /* 72479Swnj * DH-11/DM-11 driver 813Sbill */ 9*2730Swnj #include "bk.h" 1013Sbill #include "../h/param.h" 1113Sbill #include "../h/conf.h" 1213Sbill #include "../h/dir.h" 1313Sbill #include "../h/user.h" 1413Sbill #include "../h/tty.h" 1513Sbill #include "../h/map.h" 1613Sbill #include "../h/pte.h" 172395Swnj #include "../h/buf.h" 182566Swnj #include "../h/vm.h" 1913Sbill #include "../h/uba.h" 20113Sbill #include "../h/bk.h" 211561Sbill #include "../h/clist.h" 221786Sbill #include "../h/mx.h" 232468Swnj #include "../h/file.h" 2413Sbill 252468Swnj /* 262479Swnj * Definition of the driver for the auto-configuration program. 272479Swnj * There is one definition for the dh and one for the dm. 282468Swnj */ 292605Swnj int dhprobe(), dhattach(), dhrint(), dhxint(); 302643Swnj struct uba_dinfo *dhinfo[NDH]; 312395Swnj u_short dhstd[] = { 0 }; 322395Swnj struct uba_driver dhdriver = 332605Swnj { dhprobe, 0, dhattach, 0, dhstd, "dh", dhinfo }; 342395Swnj 352605Swnj int dmprobe(), dmattach(), dmintr(); 362643Swnj struct uba_dinfo *dminfo[NDH]; 372479Swnj u_short dmstd[] = { 0 }; 382479Swnj struct uba_driver dmdriver = 392605Swnj { dmprobe, 0, dmattach, 0, dmstd, "dm", dminfo }; 4013Sbill 412479Swnj struct dhdevice 422479Swnj { 432479Swnj union { 442479Swnj short dhcsr; /* control-status register */ 452479Swnj char dhcsrl; /* low byte for line select */ 462479Swnj } un; 472479Swnj short dhrcr; /* receive character register */ 482479Swnj short dhlpr; /* line parameter register */ 492479Swnj u_short dhcar; /* current address register */ 502479Swnj short dhbcr; /* byte count register */ 512479Swnj u_short dhbar; /* buffer active register */ 522479Swnj short dhbreak; /* break control register */ 532479Swnj short dhsilo; /* silo status register */ 542479Swnj }; 5513Sbill 562456Swnj /* Bits in dhcsr */ 572456Swnj #define DH_TI 0100000 /* transmit interrupt */ 582456Swnj #define DH_SI 0040000 /* storage interrupt */ 592456Swnj #define DH_TIE 0020000 /* transmit interrupt enable */ 602456Swnj #define DH_SIE 0010000 /* storage interrupt enable */ 612456Swnj #define DH_MC 0004000 /* master clear */ 622456Swnj #define DH_NXM 0002000 /* non-existant memory */ 632456Swnj #define DH_MM 0001000 /* maintenance mode */ 642456Swnj #define DH_CNI 0000400 /* clear non-existant memory interrupt */ 652456Swnj #define DH_RI 0000200 /* receiver interrupt */ 662456Swnj #define DH_RIE 0000100 /* receiver interrupt enable */ 6713Sbill 682479Swnj /* Bits in dhlpr */ 692479Swnj #define BITS6 01 702479Swnj #define BITS7 02 712479Swnj #define BITS8 03 722479Swnj #define TWOSB 04 732479Swnj #define PENABLE 020 742479Swnj /* DEC manuals incorrectly say this bit causes generation of even parity. */ 752479Swnj #define OPAR 040 762479Swnj #define HDUPLX 040000 772479Swnj 782456Swnj #define DH_IE (DH_TIE|DH_SIE|DH_RIE) 792456Swnj 802456Swnj /* Bits in dhrcr */ 812479Swnj #define DH_PE 0010000 /* parity error */ 822479Swnj #define DH_FE 0020000 /* framing error */ 832479Swnj #define DH_DO 0040000 /* data overrun */ 842456Swnj 852479Swnj struct dmdevice 862479Swnj { 872479Swnj short dmcsr; /* control status register */ 882479Swnj short dmlstat; /* line status register */ 892479Swnj short dmpad1[2]; 902479Swnj }; 912479Swnj 922479Swnj /* bits in dm csr */ 932479Swnj #define DM_RF 0100000 /* ring flag */ 942479Swnj #define DM_CF 0040000 /* carrier flag */ 952479Swnj #define DM_CTS 0020000 /* clear to send */ 962479Swnj #define DM_SRF 0010000 /* secondary receive flag */ 972479Swnj #define DM_CS 0004000 /* clear scan */ 982479Swnj #define DM_CM 0002000 /* clear multiplexor */ 992479Swnj #define DM_MM 0001000 /* maintenance mode */ 1002479Swnj #define DM_STP 0000400 /* step */ 1012479Swnj #define DM_DONE 0000200 /* scanner is done */ 1022479Swnj #define DM_IE 0000100 /* interrupt enable */ 1032479Swnj #define DM_SE 0000040 /* scan enable */ 1042479Swnj #define DM_BUSY 0000020 /* scan busy */ 1052479Swnj 1062479Swnj /* bits in dm lsr */ 1072479Swnj #define DML_RNG 0000200 /* ring */ 1082479Swnj #define DML_CAR 0000100 /* carrier detect */ 1092479Swnj #define DML_CTS 0000040 /* clear to send */ 1102479Swnj #define DML_SR 0000020 /* secondary receive */ 1112479Swnj #define DML_ST 0000010 /* secondary transmit */ 1122479Swnj #define DML_RTS 0000004 /* request to send */ 1132479Swnj #define DML_DTR 0000002 /* data terminal ready */ 1142479Swnj #define DML_LE 0000001 /* line enable */ 1152479Swnj 1162479Swnj #define DML_ON (DML_DTR|DML_LE) 1172479Swnj #define DML_OFF (DML_LE) 1182479Swnj 11913Sbill /* 1202479Swnj * Local variables for the driver 12113Sbill */ 1222643Swnj short dhsar[NDH]; /* software copy of last bar */ 1232643Swnj short dhsoftCAR[NDH]; 12413Sbill 1252643Swnj struct tty dh11[NDH*16]; 1262643Swnj int ndh11 = NDH*16; 1272479Swnj int dhact; /* mask of active dh's */ 1282479Swnj int dhstart(), ttrstrt(); 12913Sbill 1302479Swnj /* 1312479Swnj * The clist space is mapped by the driver onto each UNIBUS. 1322479Swnj * The UBACVT macro converts a clist space address for unibus uban 1332479Swnj * into an i/o space address for the DMA routine. 1342479Swnj */ 1352479Swnj int dh_ubinfo[MAXNUBA]; /* info about allocated unibus map */ 1362479Swnj int cbase[MAXNUBA]; /* base address in unibus map */ 1372479Swnj #define UBACVT(x, uban) (cbase[uban] + ((x)-(char *)cfree)) 13813Sbill 1392456Swnj /* 1402456Swnj * Routine for configuration to force a dh to interrupt. 1412456Swnj * Set to transmit at 9600 baud, and cause a transmitter interrupt. 1422456Swnj */ 1432468Swnj /*ARGSUSED*/ 1442605Swnj dhprobe(reg) 1452395Swnj caddr_t reg; 1462395Swnj { 1472468Swnj register int br, cvec; /* these are ``value-result'' */ 1482479Swnj register struct dhdevice *dhaddr = (struct dhdevice *)reg; 1492395Swnj 1502605Swnj #ifdef lint 1512605Swnj br = 0; cvec = br; br = cvec; 1522605Swnj #endif 1532696Swnj #ifndef notdef 1542566Swnj dhaddr->un.dhcsr = DH_RIE|DH_MM|DH_RI; 1552566Swnj DELAY(5); 1562566Swnj dhaddr->un.dhcsr = 0; 1572566Swnj #else 1582456Swnj dhaddr->un.dhcsr = DH_TIE; 1592456Swnj DELAY(5); 1602456Swnj dhaddr->dhlpr = (B9600 << 10) | (B9600 << 6) | BITS7|PENABLE; 1612421Skre dhaddr->dhbcr = -1; 1622456Swnj dhaddr->dhcar = 0; 1632421Skre dhaddr->dhbar = 1; 1642456Swnj DELAY(100000); /* wait 1/10'th of a sec for interrupt */ 1652421Skre dhaddr->un.dhcsr = 0; 1662456Swnj if (cvec && cvec != 0x200) 1672456Swnj cvec -= 4; /* transmit -> receive */ 1682482Swnj #endif 1692456Swnj return (1); 1702395Swnj } 1712395Swnj 1722456Swnj /* 1732605Swnj * Routine called to attach a dh. 1742456Swnj */ 1752605Swnj dhattach(ui) 1762395Swnj struct uba_dinfo *ui; 1772395Swnj { 1782395Swnj 1792566Swnj dhsoftCAR[ui->ui_unit] = ui->ui_flags; 1802395Swnj } 1812395Swnj 18213Sbill /* 1832479Swnj * Configuration routine to cause a dm to interrupt. 1842479Swnj */ 1852605Swnj dmprobe(reg) 1862605Swnj caddr_t reg; 1872479Swnj { 1882479Swnj register int br, vec; /* value-result */ 1892605Swnj register struct dmdevice *dmaddr = (struct dmdevice *)reg; 1902479Swnj 1912605Swnj #ifdef lint 1922605Swnj br = 0; cvec = br; br = cvec; 1932605Swnj #endif 1942479Swnj dmaddr->dmcsr = DM_DONE|DM_IE; 1952479Swnj DELAY(20); 1962479Swnj dmaddr->dmcsr = 0; 1972605Swnj return (1); 1982479Swnj } 1992479Swnj 2002605Swnj /*ARGSUSED*/ 2012605Swnj dmattach(ui) 2022479Swnj struct uba_dinfo *ui; 2032479Swnj { 2042479Swnj 2052479Swnj /* no local state to set up */ 2062479Swnj } 2072479Swnj 2082479Swnj /* 2092468Swnj * Open a DH11 line, mapping the clist onto the uba if this 2102468Swnj * is the first dh on this uba. Turn on this dh if this is 2112468Swnj * the first use of it. Also do a dmopen to wait for carrier. 21213Sbill */ 21313Sbill /*ARGSUSED*/ 21413Sbill dhopen(dev, flag) 2152395Swnj dev_t dev; 21613Sbill { 21713Sbill register struct tty *tp; 2182395Swnj register int unit, dh; 2192479Swnj register struct dhdevice *addr; 2202395Swnj register struct uba_dinfo *ui; 22113Sbill int s; 22213Sbill 2232395Swnj unit = minor(dev); 2242395Swnj dh = unit >> 4; 2252643Swnj if (unit >= NDH*16 || (ui = dhinfo[dh])== 0 || ui->ui_alive == 0) { 22613Sbill u.u_error = ENXIO; 22713Sbill return; 22813Sbill } 2292395Swnj tp = &dh11[unit]; 2302468Swnj if (tp->t_state&XCLUDE && u.u_uid!=0) { 2312468Swnj u.u_error = EBUSY; 2322468Swnj return; 2332468Swnj } 2342479Swnj addr = (struct dhdevice *)ui->ui_addr; 23513Sbill tp->t_addr = (caddr_t)addr; 23613Sbill tp->t_oproc = dhstart; 23713Sbill tp->t_iproc = NULL; 23813Sbill tp->t_state |= WOPEN; 2392468Swnj /* 2402468Swnj * While setting up state for this uba and this dh, 2412468Swnj * block uba resets which can clear the state. 2422468Swnj */ 2432468Swnj s = spl5(); 2442421Skre if (dh_ubinfo[ui->ui_ubanum] == 0) { 245717Sbill /* 512+ is a kludge to try to get around a hardware problem */ 2462395Swnj dh_ubinfo[ui->ui_ubanum] = 2472421Skre uballoc(ui->ui_ubanum, (caddr_t)cfree, 2482395Swnj 512+NCLIST*sizeof(struct cblock), 0); 2492456Swnj cbase[ui->ui_ubanum] = dh_ubinfo[ui->ui_ubanum]&0x3ffff; 25013Sbill } 2512456Swnj if ((dhact&(1<<dh)) == 0) { 2522456Swnj addr->un.dhcsr |= DH_IE; 2532468Swnj dhact |= (1<<dh); 2542456Swnj addr->dhsilo = 16; 2552456Swnj } 25613Sbill splx(s); 2572468Swnj /* 2582468Swnj * If this is first open, initialze tty state to default. 2592468Swnj */ 26013Sbill if ((tp->t_state&ISOPEN) == 0) { 26113Sbill ttychars(tp); 262168Sbill if (tp->t_ispeed == 0) { 2632456Swnj tp->t_ispeed = B300; 2642456Swnj tp->t_ospeed = B300; 265168Sbill tp->t_flags = ODDP|EVENP|ECHO; 266168Sbill } 2672395Swnj dhparam(unit); 26813Sbill } 2692468Swnj /* 2702468Swnj * Wait for carrier, then process line discipline specific open. 2712468Swnj */ 27213Sbill dmopen(dev); 2732395Swnj (*linesw[tp->t_line].l_open)(dev, tp); 27413Sbill } 27513Sbill 27613Sbill /* 2772468Swnj * Close a DH11 line, turning off the DM11. 27813Sbill */ 27913Sbill /*ARGSUSED*/ 28013Sbill dhclose(dev, flag) 2812395Swnj dev_t dev; 2822395Swnj int flag; 28313Sbill { 28413Sbill register struct tty *tp; 2852395Swnj register unit; 28613Sbill 2872395Swnj unit = minor(dev); 2882395Swnj tp = &dh11[unit]; 28913Sbill (*linesw[tp->t_line].l_close)(tp); 2902479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); 29113Sbill if (tp->t_state&HUPCLS || (tp->t_state&ISOPEN)==0) 2922479Swnj dmctl(unit, DML_OFF, DMSET); 29313Sbill ttyclose(tp); 29413Sbill } 29513Sbill 29613Sbill dhread(dev) 2972395Swnj dev_t dev; 29813Sbill { 2992395Swnj register struct tty *tp; 30013Sbill 3012395Swnj tp = &dh11[minor(dev)]; 30213Sbill (*linesw[tp->t_line].l_read)(tp); 30313Sbill } 30413Sbill 30513Sbill dhwrite(dev) 3062395Swnj dev_t dev; 30713Sbill { 3082395Swnj register struct tty *tp; 30913Sbill 3102395Swnj tp = &dh11[minor(dev)]; 31113Sbill (*linesw[tp->t_line].l_write)(tp); 31213Sbill } 31313Sbill 31413Sbill /* 31513Sbill * DH11 receiver interrupt. 31613Sbill */ 3172395Swnj dhrint(dh) 3182395Swnj int dh; 31913Sbill { 32013Sbill register struct tty *tp; 3212395Swnj register c; 3222479Swnj register struct dhdevice *addr; 323117Sbill register struct tty *tp0; 3242395Swnj register struct uba_dinfo *ui; 32513Sbill 3262395Swnj ui = dhinfo[dh]; 3272479Swnj if (ui == 0 || ui->ui_alive == 0) 3282479Swnj return; 3292479Swnj addr = (struct dhdevice *)ui->ui_addr; 3302468Swnj tp0 = &dh11[dh<<4]; 3312468Swnj /* 3322468Swnj * Loop fetching characters from the silo for this 3332468Swnj * dh until there are no more in the silo. 3342468Swnj */ 3352468Swnj while ((c = addr->dhrcr) < 0) { 3362468Swnj tp = tp0 + ((c>>8)&0xf); 3372468Swnj if ((tp->t_state&ISOPEN)==0) { 33813Sbill wakeup((caddr_t)tp); 33913Sbill continue; 34013Sbill } 3412468Swnj if (c & DH_PE) 34213Sbill if ((tp->t_flags&(EVENP|ODDP))==EVENP 34313Sbill || (tp->t_flags&(EVENP|ODDP))==ODDP ) 34413Sbill continue; 3452468Swnj if (c & DH_DO) 34613Sbill printf("O"); 3472468Swnj if (c & DH_FE) 3482468Swnj /* 3492468Swnj * At framing error (break) generate 3502468Swnj * a null (in raw mode, for getty), or a 3512468Swnj * interrupt (in cooked/cbreak mode). 3522468Swnj */ 35313Sbill if (tp->t_flags&RAW) 3542468Swnj c = 0; 35513Sbill else 356184Sbill c = tun.t_intrc; 357*2730Swnj #if NBK > 0 358139Sbill if (tp->t_line == NETLDISC) { 359117Sbill c &= 0177; 360168Sbill BKINPUT(c, tp); 361117Sbill } else 362*2730Swnj #endif 3632468Swnj (*linesw[tp->t_line].l_rint)(c, tp); 36413Sbill } 36513Sbill } 36613Sbill 36713Sbill /* 3682468Swnj * Ioctl for DH11. 36913Sbill */ 37013Sbill /*ARGSUSED*/ 37113Sbill dhioctl(dev, cmd, addr, flag) 3722395Swnj caddr_t addr; 37313Sbill { 37413Sbill register struct tty *tp; 3752395Swnj register unit = minor(dev); 37613Sbill 3772395Swnj tp = &dh11[unit]; 378113Sbill cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr); 3792468Swnj if (cmd == 0) 380113Sbill return; 3811895Swnj if (ttioctl(tp, cmd, addr, flag)) { 3822468Swnj if (cmd==TIOCSETP || cmd==TIOCSETN) 3832395Swnj dhparam(unit); 384168Sbill } else switch(cmd) { 385168Sbill case TIOCSBRK: 3862479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak |= 1<<(unit&017); 387168Sbill break; 388168Sbill case TIOCCBRK: 3892479Swnj ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); 390168Sbill break; 391168Sbill case TIOCSDTR: 3922479Swnj dmctl(unit, DML_DTR|DML_RTS, DMBIS); 393168Sbill break; 394168Sbill case TIOCCDTR: 3952479Swnj dmctl(unit, DML_DTR|DML_RTS, DMBIC); 396168Sbill break; 397168Sbill default: 39813Sbill u.u_error = ENOTTY; 399168Sbill } 40013Sbill } 40113Sbill 40213Sbill /* 40313Sbill * Set parameters from open or stty into the DH hardware 40413Sbill * registers. 40513Sbill */ 4062395Swnj dhparam(unit) 4072395Swnj register int unit; 40813Sbill { 40913Sbill register struct tty *tp; 4102479Swnj register struct dhdevice *addr; 4112395Swnj register int lpar; 412300Sbill int s; 41313Sbill 4142395Swnj tp = &dh11[unit]; 4152479Swnj addr = (struct dhdevice *)tp->t_addr; 4162468Swnj /* 4172468Swnj * Block interrupts so parameters will be set 4182468Swnj * before the line interrupts. 4192468Swnj */ 420300Sbill s = spl5(); 4212468Swnj addr->un.dhcsrl = (unit&0xf) | DH_IE; 42213Sbill if ((tp->t_ispeed)==0) { 42313Sbill tp->t_state |= HUPCLS; 4242479Swnj dmctl(unit, DML_OFF, DMSET); 42513Sbill return; 42613Sbill } 4272395Swnj lpar = ((tp->t_ospeed)<<10) | ((tp->t_ispeed)<<6); 4282468Swnj if ((tp->t_ispeed) == B134) 4292395Swnj lpar |= BITS6|PENABLE|HDUPLX; 4302312Skre else if ((tp->t_flags&RAW) || (tp->t_local&LLITOUT)) 4312395Swnj lpar |= BITS8; 43213Sbill else 4332395Swnj lpar |= BITS7|PENABLE; 43413Sbill if ((tp->t_flags&EVENP) == 0) 4352395Swnj lpar |= OPAR; 4362468Swnj if ((tp->t_ospeed) == B110) 4372395Swnj lpar |= TWOSB; 4382395Swnj addr->dhlpr = lpar; 439300Sbill splx(s); 44013Sbill } 44113Sbill 44213Sbill /* 44313Sbill * DH11 transmitter interrupt. 44413Sbill * Restart each line which used to be active but has 44513Sbill * terminated transmission since the last interrupt. 44613Sbill */ 4472395Swnj dhxint(dh) 4482395Swnj int dh; 44913Sbill { 45013Sbill register struct tty *tp; 4512479Swnj register struct dhdevice *addr; 45213Sbill short ttybit, bar, *sbar; 4532395Swnj register struct uba_dinfo *ui; 4542468Swnj register int unit; 4552605Swnj u_short cntr; 45613Sbill 4572395Swnj ui = dhinfo[dh]; 4582479Swnj addr = (struct dhdevice *)ui->ui_addr; 4592456Swnj if (addr->un.dhcsr & DH_NXM) { 4602456Swnj addr->un.dhcsr |= DH_CNI; 4612468Swnj printf("dh%d NXM\n", dh); 462105Sbill } 4632395Swnj sbar = &dhsar[dh]; 46413Sbill bar = *sbar & ~addr->dhbar; 4652395Swnj unit = dh * 16; ttybit = 1; 4662468Swnj addr->un.dhcsr &= (short)~DH_TI; 4672468Swnj for (; bar; unit++, ttybit <<= 1) { 4682468Swnj if (bar & ttybit) { 46913Sbill *sbar &= ~ttybit; 47013Sbill bar &= ~ttybit; 4712395Swnj tp = &dh11[unit]; 472113Sbill tp->t_state &= ~BUSY; 473113Sbill if (tp->t_state&FLUSH) 474113Sbill tp->t_state &= ~FLUSH; 475113Sbill else { 4762456Swnj addr->un.dhcsrl = (unit&017)|DH_IE; 4772468Swnj /* 4782468Swnj * Do arithmetic in a short to make up 4792468Swnj * for lost 16&17 bits. 4802468Swnj */ 4812605Swnj cntr = addr->dhcar - 4822468Swnj UBACVT(tp->t_outq.c_cf, ui->ui_ubanum); 4832605Swnj ndflush(&tp->t_outq, cntr); 484113Sbill } 485113Sbill if (tp->t_line) 48613Sbill (*linesw[tp->t_line].l_start)(tp); 487113Sbill else 48813Sbill dhstart(tp); 48913Sbill } 49013Sbill } 49113Sbill } 49213Sbill 49313Sbill /* 49413Sbill * Start (restart) transmission on the given DH11 line. 49513Sbill */ 49613Sbill dhstart(tp) 4972395Swnj register struct tty *tp; 49813Sbill { 4992479Swnj register struct dhdevice *addr; 5002468Swnj register int car, dh, unit, nch; 5012395Swnj int s; 50213Sbill 5032468Swnj unit = minor(tp->t_dev); 5042468Swnj dh = unit >> 4; 5052468Swnj unit &= 0xf; 5062479Swnj addr = (struct dhdevice *)tp->t_addr; 5072468Swnj 50813Sbill /* 5092468Swnj * Must hold interrupts in following code to prevent 5102468Swnj * state of the tp from changing. 51113Sbill */ 51213Sbill s = spl5(); 5132468Swnj /* 5142468Swnj * If it's currently active, or delaying, no need to do anything. 5152468Swnj */ 51613Sbill if (tp->t_state&(TIMEOUT|BUSY|TTSTOP)) 51713Sbill goto out; 5182468Swnj /* 5192468Swnj * If there are sleepers, and output has drained below low 5202468Swnj * water mark, wake up the sleepers. 5212468Swnj */ 5222395Swnj if ((tp->t_state&ASLEEP) && tp->t_outq.c_cc<=TTLOWAT(tp)) { 52313Sbill tp->t_state &= ~ASLEEP; 52413Sbill if (tp->t_chan) 525168Sbill mcstart(tp->t_chan, (caddr_t)&tp->t_outq); 526168Sbill else 52713Sbill wakeup((caddr_t)&tp->t_outq); 52813Sbill } 5292468Swnj /* 5302468Swnj * Now restart transmission unless the output queue is 5312468Swnj * empty. 5322468Swnj */ 53313Sbill if (tp->t_outq.c_cc == 0) 53413Sbill goto out; 5352395Swnj if (tp->t_flags & RAW) 53613Sbill nch = ndqb(&tp->t_outq, 0); 5372395Swnj else { 53813Sbill nch = ndqb(&tp->t_outq, 0200); 5392468Swnj /* 5402468Swnj * If first thing on queue is a delay process it. 5412468Swnj */ 54213Sbill if (nch == 0) { 54313Sbill nch = getc(&tp->t_outq); 5442468Swnj timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6); 54513Sbill tp->t_state |= TIMEOUT; 54613Sbill goto out; 54713Sbill } 54813Sbill } 5492468Swnj /* 5502468Swnj * If characters to transmit, restart transmission. 5512468Swnj */ 55213Sbill if (nch) { 5532468Swnj car = UBACVT(tp->t_outq.c_cf, dhinfo[dh]->ui_ubanum); 5542468Swnj addr->un.dhcsrl = unit|((car>>12)&0x30)|DH_IE; 5552468Swnj unit = 1 << unit; 5562468Swnj dhsar[dh] |= unit; 5572468Swnj addr->dhcar = car; 55813Sbill addr->dhbcr = -nch; 5592468Swnj addr->dhbar |= unit; 56013Sbill tp->t_state |= BUSY; 56113Sbill } 5622395Swnj out: 56313Sbill splx(s); 56413Sbill } 56513Sbill 56613Sbill /* 5672468Swnj * Stop output on a line, e.g. for ^S/^Q or output flush. 56813Sbill */ 56913Sbill /*ARGSUSED*/ 57013Sbill dhstop(tp, flag) 5712468Swnj register struct tty *tp; 57213Sbill { 5732479Swnj register struct dhdevice *addr; 5742395Swnj register int unit, s; 57513Sbill 5762479Swnj addr = (struct dhdevice *)tp->t_addr; 5772468Swnj /* 5782468Swnj * Block input/output interrupts while messing with state. 5792468Swnj */ 5802468Swnj s = spl5(); 581113Sbill if (tp->t_state & BUSY) { 5822468Swnj /* 5832468Swnj * Device is transmitting; stop output 5842468Swnj * by selecting the line and setting the byte 5852468Swnj * count to -1. We will clean up later 5862468Swnj * by examining the address where the dh stopped. 5872468Swnj */ 5882395Swnj unit = minor(tp->t_dev); 5892456Swnj addr->un.dhcsrl = (unit&017) | DH_IE; 59013Sbill if ((tp->t_state&TTSTOP)==0) 59113Sbill tp->t_state |= FLUSH; 592113Sbill addr->dhbcr = -1; 593113Sbill } 59413Sbill splx(s); 59513Sbill } 59613Sbill 597168Sbill /* 598280Sbill * Reset state of driver if UBA reset was necessary. 599280Sbill * Reset the csrl and lpr registers on open lines, and 600280Sbill * restart transmitters. 601280Sbill */ 6022395Swnj dhreset(uban) 6032468Swnj int uban; 604280Sbill { 6052395Swnj register int dh, unit; 606280Sbill register struct tty *tp; 6072395Swnj register struct uba_dinfo *ui; 6082421Skre int i; 609280Sbill 6102421Skre if (dh_ubinfo[uban] == 0) 6112421Skre return; 612280Sbill printf(" dh"); 6132421Skre ubarelse(uban, &dh_ubinfo[uban]); 6142421Skre dh_ubinfo[uban] = uballoc(uban, (caddr_t)cfree, 6152421Skre 512+NCLIST*sizeof (struct cblock), 0); 6162421Skre cbase[uban] = dh_ubinfo[uban]&0x3ffff; 6172395Swnj dh = 0; 6182643Swnj for (dh = 0; dh < NDH; dh++) { 6192421Skre ui = dhinfo[dh]; 6202421Skre if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban) 6212421Skre continue; 6222479Swnj ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE; 6232479Swnj ((struct dhdevice *)ui->ui_addr)->dhsilo = 16; 6242421Skre unit = dh * 16; 6252421Skre for (i = 0; i < 16; i++) { 6262421Skre tp = &dh11[unit]; 6272421Skre if (tp->t_state & (ISOPEN|WOPEN)) { 6282421Skre dhparam(unit); 6292479Swnj dmctl(unit, DML_ON, DMSET); 6302421Skre tp->t_state &= ~BUSY; 6312421Skre dhstart(tp); 6322421Skre } 6332421Skre unit++; 634300Sbill } 635300Sbill } 636300Sbill dhtimer(); 637280Sbill } 6382395Swnj 6392468Swnj /* 6402468Swnj * At software clock interrupt time or after a UNIBUS reset 6412468Swnj * empty all the dh silos. 6422468Swnj */ 6432456Swnj dhtimer() 6442456Swnj { 6452456Swnj register int dh; 6462456Swnj 6472643Swnj for (dh = 0; dh < NDH; dh++) 6482456Swnj dhrint(dh); 6492456Swnj } 6502456Swnj 6512468Swnj /* 6522479Swnj * Turn on the line associated with dh dev. 6532468Swnj */ 6542468Swnj dmopen(dev) 6552468Swnj dev_t dev; 6562468Swnj { 6572468Swnj register struct tty *tp; 6582468Swnj register struct dmdevice *addr; 6592468Swnj register struct uba_dinfo *ui; 6602468Swnj register int unit; 6612468Swnj register int dm; 6622468Swnj 6632468Swnj unit = minor(dev); 6642479Swnj dm = unit >> 4; 6652468Swnj tp = &dh11[unit]; 6662566Swnj unit &= 0xf; 6672643Swnj if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0 || 6682566Swnj (dhsoftCAR[dm]&(1<<unit))) { 6692468Swnj tp->t_state |= CARR_ON; 6702468Swnj return; 6712468Swnj } 6722468Swnj addr = (struct dmdevice *)ui->ui_addr; 6732468Swnj spl5(); 6742479Swnj addr->dmcsr &= ~DM_SE; 6752479Swnj while (addr->dmcsr & DM_BUSY) 6762468Swnj ; 6772566Swnj addr->dmcsr = unit; 6782479Swnj addr->dmlstat = DML_ON; 6792479Swnj if (addr->dmlstat&DML_CAR) 6802468Swnj tp->t_state |= CARR_ON; 6812479Swnj addr->dmcsr = DH_IE|DM_SE; 6822468Swnj while ((tp->t_state&CARR_ON)==0) 6832468Swnj sleep((caddr_t)&tp->t_rawq, TTIPRI); 6842468Swnj spl0(); 6852468Swnj } 6862468Swnj 6872468Swnj /* 6882468Swnj * Dump control bits into the DM registers. 6892468Swnj */ 6902468Swnj dmctl(dev, bits, how) 6912468Swnj dev_t dev; 6922468Swnj int bits, how; 6932468Swnj { 6942468Swnj register struct uba_dinfo *ui; 6952468Swnj register struct dmdevice *addr; 6962468Swnj register int unit, s; 6972468Swnj int dm; 6982468Swnj 6992468Swnj unit = minor(dev); 7002468Swnj dm = unit >> 4; 7012468Swnj if ((ui = dminfo[dm]) == 0 || ui->ui_alive == 0) 7022468Swnj return; 7032468Swnj addr = (struct dmdevice *)ui->ui_addr; 7042468Swnj s = spl5(); 7052479Swnj addr->dmcsr &= ~DM_SE; 7062479Swnj while (addr->dmcsr & DM_BUSY) 7072468Swnj ; 7082468Swnj addr->dmcsr = unit & 0xf; 7092468Swnj switch(how) { 7102468Swnj case DMSET: 7112468Swnj addr->dmlstat = bits; 7122468Swnj break; 7132468Swnj case DMBIS: 7142468Swnj addr->dmlstat |= bits; 7152468Swnj break; 7162468Swnj case DMBIC: 7172468Swnj addr->dmlstat &= ~bits; 7182468Swnj break; 7192468Swnj } 7202479Swnj addr->dmcsr = DH_IE|DM_SE; 7212468Swnj splx(s); 7222468Swnj } 7232468Swnj 7242468Swnj /* 7252468Swnj * DM11 interrupt; deal with carrier transitions. 7262468Swnj */ 7272468Swnj dmintr(dm) 7282468Swnj register int dm; 7292468Swnj { 7302468Swnj register struct uba_dinfo *ui; 7312468Swnj register struct tty *tp; 7322468Swnj register struct dmdevice *addr; 7332468Swnj 7342468Swnj ui = dminfo[dm]; 7352479Swnj if (ui == 0) 7362479Swnj return; 7372468Swnj addr = (struct dmdevice *)ui->ui_addr; 7382479Swnj if (addr->dmcsr&DM_DONE && addr->dmcsr&DM_CF) { 7392468Swnj tp = &dh11[(dm<<4)+(addr->dmcsr&0xf)]; 7402468Swnj wakeup((caddr_t)&tp->t_rawq); 7412468Swnj if ((tp->t_state&WOPEN)==0 && 7422468Swnj (tp->t_local&LMDMBUF)) { 7432479Swnj if (addr->dmlstat & DML_CAR) { 7442468Swnj tp->t_state &= ~TTSTOP; 7452468Swnj ttstart(tp); 7462468Swnj } else if ((tp->t_state&TTSTOP) == 0) { 7472468Swnj tp->t_state |= TTSTOP; 7482468Swnj dhstop(tp, 0); 7492468Swnj } 7502479Swnj } else if ((addr->dmlstat&DML_CAR)==0) { 7512468Swnj if ((tp->t_state&WOPEN)==0 && 7522468Swnj (tp->t_local&LNOHANG)==0) { 7532468Swnj gsignal(tp->t_pgrp, SIGHUP); 7542468Swnj gsignal(tp->t_pgrp, SIGCONT); 7552468Swnj addr->dmlstat = 0; 7562468Swnj flushtty(tp, FREAD|FWRITE); 7572468Swnj } 7582468Swnj tp->t_state &= ~CARR_ON; 7592468Swnj } else 7602468Swnj tp->t_state |= CARR_ON; 7612479Swnj addr->dmcsr = DH_IE|DM_SE; 7622468Swnj } 7632468Swnj } 7642625Swnj #endif 765