1*8160Sroot /* dz.c 4.43 82/09/12 */ 217Sbill 31935Swnj #include "dz.h" 42645Swnj #if NDZ > 0 517Sbill /* 65731Sroot * DZ-11 and DZ32 Driver 72469Swnj * 82469Swnj * This driver mimics dh.c; see it for explanation of common code. 917Sbill */ 102731Swnj #include "bk.h" 1117Sbill #include "../h/param.h" 1217Sbill #include "../h/systm.h" 1317Sbill #include "../h/tty.h" 1417Sbill #include "../h/dir.h" 1517Sbill #include "../h/user.h" 166157Ssam #include "../h/proc.h" 1717Sbill #include "../h/map.h" 1817Sbill #include "../h/pte.h" 192395Swnj #include "../h/buf.h" 202567Swnj #include "../h/vm.h" 212976Swnj #include "../h/ubavar.h" 2217Sbill #include "../h/conf.h" 2317Sbill #include "../h/pdma.h" 24114Sbill #include "../h/bk.h" 25871Sbill #include "../h/file.h" 267727Sroot #include "../h/uio.h" 27145Sbill 282469Swnj /* 292469Swnj * Driver information for auto-configuration stuff. 302469Swnj */ 312606Swnj int dzprobe(), dzattach(), dzrint(); 322976Swnj struct uba_device *dzinfo[NDZ]; 332395Swnj u_short dzstd[] = { 0 }; 342395Swnj struct uba_driver dzdriver = 352606Swnj { dzprobe, 0, dzattach, 0, dzstd, "dz", dzinfo }; 362395Swnj 372645Swnj #define NDZLINE (NDZ*8) 3817Sbill 392469Swnj /* 402469Swnj * Registers and bits 412469Swnj */ 422469Swnj 435731Sroot /* bits in dzlpr */ 445731Sroot #define BITS7 0020 455731Sroot #define BITS8 0030 465731Sroot #define TWOSB 0040 472457Swnj #define PENABLE 0100 482457Swnj #define OPAR 0200 4917Sbill 505731Sroot /* bits in dzrbuf */ 512469Swnj #define DZ_PE 010000 522469Swnj #define DZ_FE 020000 532469Swnj #define DZ_DO 040000 542469Swnj 555731Sroot /* bits in dzcsr */ 565731Sroot #define DZ_32 000001 /* DZ32 mode */ 575731Sroot #define DZ_MIE 000002 /* Modem Interrupt Enable */ 585731Sroot #define DZ_CLR 000020 /* Reset dz */ 595731Sroot #define DZ_MSE 000040 /* Master Scan Enable */ 605731Sroot #define DZ_RIE 000100 /* Receiver Interrupt Enable */ 615731Sroot #define DZ_MSC 004000 /* Modem Status Change */ 622469Swnj #define DZ_SAE 010000 /* Silo Alarm Enable */ 632469Swnj #define DZ_TIE 040000 /* Transmit Interrupt Enable */ 645731Sroot #define DZ_IEN (DZ_32|DZ_MIE|DZ_MSE|DZ_RIE|DZ_TIE|DZ_SAE) 652469Swnj 665731Sroot /* flags for modem-control */ 675731Sroot #define DZ_ON DZ_DTR 682469Swnj #define DZ_OFF 0 695731Sroot 705731Sroot /* bits in dzlcs */ 715731Sroot #define DZ_ACK 0100000 /* ACK bit in dzlcs */ 725731Sroot #define DZ_RTS 0010000 /* Request To Send */ 735731Sroot #define DZ_ST 0004000 /* Secondary Transmit */ 745731Sroot #define DZ_BRK 0002000 /* Break */ 755731Sroot #define DZ_DTR 0001000 /* Data Terminal Ready */ 765731Sroot #define DZ_LE 0000400 /* Line Enable */ 775731Sroot #define DZ_DSR 0000200 /* Data Set Ready */ 785731Sroot #define DZ_RI 0000100 /* Ring Indicate */ 795731Sroot #define DZ_CD 0000040 /* Carrier Detect */ 805731Sroot #define DZ_CTS 0000020 /* Clear To Send */ 815731Sroot #define DZ_SR 0000010 /* Secondary Receive */ 8217Sbill 835731Sroot /* bits in dm lsr, copied from dh.c */ 845731Sroot #define DML_DSR 0000400 /* data set ready, not a real DM bit */ 855731Sroot #define DML_RNG 0000200 /* ring */ 865731Sroot #define DML_CAR 0000100 /* carrier detect */ 875731Sroot #define DML_CTS 0000040 /* clear to send */ 885731Sroot #define DML_SR 0000020 /* secondary receive */ 895731Sroot #define DML_ST 0000010 /* secondary transmit */ 905731Sroot #define DML_RTS 0000004 /* request to send */ 915731Sroot #define DML_DTR 0000002 /* data terminal ready */ 925731Sroot #define DML_LE 0000001 /* line enable */ 935731Sroot 942469Swnj int dzstart(), dzxint(), dzdma(); 95114Sbill int ttrstrt(); 962645Swnj struct tty dz_tty[NDZLINE]; 972645Swnj int dz_cnt = { NDZLINE }; 98119Sbill int dzact; 9917Sbill 10017Sbill struct device { 1015731Sroot short dzcsr; 1025731Sroot short dzrbuf; 1035731Sroot union { 1045731Sroot struct { 1055731Sroot char dztcr0; 1065731Sroot char dzdtr0; 1075731Sroot char dztbuf0; 1085731Sroot char dzbrk0; 1095731Sroot } dz11; 1105731Sroot struct { 1115731Sroot short dzlcs0; 1125731Sroot char dztbuf0; 1135731Sroot char dzlnen0; 1145731Sroot } dz32; 1155731Sroot } dzun; 11617Sbill }; 1175731Sroot 1185731Sroot #define dzlpr dzrbuf 1195731Sroot #define dzmsr dzun.dz11.dzbrk0 1205731Sroot #define dztcr dzun.dz11.dztcr0 1215731Sroot #define dzdtr dzun.dz11.dzdtr0 1225731Sroot #define dztbuf dzun.dz11.dztbuf0 1235731Sroot #define dzlcs dzun.dz32.dzlcs0 1245731Sroot #define dzbrk dzmsr 1255731Sroot #define dzlnen dzun.dz32.dzlnen0 1267406Skre #define dzmtsr dzun.dz32.dztbuf0 1275731Sroot 1285731Sroot #define dzwait(x) while (((x)->dzlcs & DZ_ACK) == 0) 1295731Sroot 1302469Swnj /* 1312469Swnj * Software copy of dzbrk since it isn't readable 1322469Swnj */ 1332645Swnj char dz_brk[NDZ]; 1342645Swnj char dzsoftCAR[NDZ]; 1355731Sroot char dz_lnen[NDZ]; /* saved line enable bits for DZ32 */ 13617Sbill 1372469Swnj /* 1385731Sroot * The dz11 doesn't interrupt on carrier transitions, so 1392469Swnj * we have to use a timer to watch it. 1402469Swnj */ 1412469Swnj char dz_timer; /* timer started? */ 1422469Swnj 1432469Swnj /* 1442469Swnj * Pdma structures for fast output code 1452469Swnj */ 1462645Swnj struct pdma dzpdma[NDZLINE]; 1472469Swnj 1482395Swnj char dz_speeds[] = 1496814Swnj { 0,020,021,022,023,024,0,025,026,027,030,032,034,036,037,0 }; 15017Sbill 1516616Ssam #ifndef PORTSELECTOR 1526616Ssam #define ISPEED B300 1536616Ssam #define IFLAGS (EVENP|ODDP|ECHO) 1546616Ssam #else 1556616Ssam #define ISPEED B4800 1566616Ssam #define IFLAGS (EVENP|ODDP) 1576616Ssam #endif 1586616Ssam 1592606Swnj dzprobe(reg) 1602395Swnj caddr_t reg; 1612395Swnj { 1622457Swnj register int br, cvec; 1632457Swnj register struct device *dzaddr = (struct device *)reg; 1642395Swnj 1652606Swnj #ifdef lint 1663102Swnj br = 0; cvec = br; br = cvec; 1674933Swnj dzrint(0); dzxint((struct tty *)0); 1682606Swnj #endif 1695731Sroot dzaddr->dzcsr = DZ_TIE|DZ_MSE|DZ_32; 1705731Sroot if (dzaddr->dzcsr & DZ_32) 1715731Sroot dzaddr->dzlnen = 1; 1725731Sroot else 1735731Sroot dzaddr->dztcr = 1; /* enable any line */ 1742457Swnj DELAY(100000); 1755731Sroot dzaddr->dzcsr = DZ_CLR|DZ_32; /* reset everything */ 1762457Swnj if (cvec && cvec != 0x200) 1772457Swnj cvec -= 4; 1787406Skre return (sizeof (struct device)); 1792395Swnj } 1802395Swnj 1812606Swnj dzattach(ui) 1822976Swnj register struct uba_device *ui; 1832395Swnj { 1842395Swnj register struct pdma *pdp = &dzpdma[ui->ui_unit*8]; 1852395Swnj register struct tty *tp = &dz_tty[ui->ui_unit*8]; 1862606Swnj register int cntr; 1872645Swnj extern dzscan(); 1882395Swnj 1892606Swnj for (cntr = 0; cntr < 8; cntr++) { 1902606Swnj pdp->p_addr = (struct device *)ui->ui_addr; 1912395Swnj pdp->p_arg = (int)tp; 1922395Swnj pdp->p_fcn = dzxint; 1932395Swnj pdp++, tp++; 1942395Swnj } 1952567Swnj dzsoftCAR[ui->ui_unit] = ui->ui_flags; 1962627Swnj if (dz_timer == 0) { 1972627Swnj dz_timer++; 1982756Swnj timeout(dzscan, (caddr_t)0, hz); 1992627Swnj } 2002395Swnj } 2012395Swnj 20217Sbill /*ARGSUSED*/ 2032395Swnj dzopen(dev, flag) 2042395Swnj dev_t dev; 20517Sbill { 20617Sbill register struct tty *tp; 2072395Swnj register int unit; 20817Sbill 2092395Swnj unit = minor(dev); 2102395Swnj if (unit >= dz_cnt || dzpdma[unit].p_addr == 0) { 21117Sbill u.u_error = ENXIO; 21217Sbill return; 21317Sbill } 2142395Swnj tp = &dz_tty[unit]; 2152395Swnj tp->t_addr = (caddr_t)&dzpdma[unit]; 21617Sbill tp->t_oproc = dzstart; 2175407Swnj tp->t_state |= TS_WOPEN; 2185407Swnj if ((tp->t_state & TS_ISOPEN) == 0) { 21917Sbill ttychars(tp); 2206616Ssam tp->t_ospeed = tp->t_ispeed = ISPEED; 2216616Ssam tp->t_flags = IFLAGS; 2225407Swnj /* tp->t_state |= TS_HUPCLS; */ 2232395Swnj dzparam(unit); 2245407Swnj } else if (tp->t_state&TS_XCLUDE && u.u_uid != 0) { 22517Sbill u.u_error = EBUSY; 22617Sbill return; 22717Sbill } 2286157Ssam (void) dzmctl(dev, DZ_ON, DMSET); 229114Sbill (void) spl5(); 2305407Swnj while ((tp->t_state & TS_CARR_ON) == 0) { 2315407Swnj tp->t_state |= TS_WOPEN; 23217Sbill sleep((caddr_t)&tp->t_rawq, TTIPRI); 23317Sbill } 234114Sbill (void) spl0(); 2352395Swnj (*linesw[tp->t_line].l_open)(dev, tp); 23617Sbill } 23717Sbill 2382395Swnj /*ARGSUSED*/ 2392395Swnj dzclose(dev, flag) 2402395Swnj dev_t dev; 24117Sbill { 24217Sbill register struct tty *tp; 2432395Swnj register int unit; 2445731Sroot register struct device *dzaddr; 2456150Ssam int dz; 24617Sbill 2472395Swnj unit = minor(dev); 2482395Swnj dz = unit >> 3; 2492395Swnj tp = &dz_tty[unit]; 25017Sbill (*linesw[tp->t_line].l_close)(tp); 2515731Sroot dzaddr = dzpdma[unit].p_addr; 2525731Sroot if (dzaddr->dzcsr&DZ_32) 2536157Ssam (void) dzmctl(dev, DZ_BRK, DMBIC); 2545731Sroot else 2555731Sroot dzaddr->dzbrk = (dz_brk[dz] &= ~(1 << (unit&07))); 2566842Swnj if ((tp->t_state&(TS_HUPCLS|TS_WOPEN)) || (tp->t_state&TS_ISOPEN) == 0) 2576157Ssam (void) dzmctl(dev, DZ_OFF, DMSET); 25817Sbill ttyclose(tp); 25917Sbill } 26017Sbill 2617727Sroot dzread(dev, uio) 2622395Swnj dev_t dev; 2637727Sroot struct uio *uio; 26417Sbill { 26517Sbill register struct tty *tp; 26617Sbill 2672395Swnj tp = &dz_tty[minor(dev)]; 2687727Sroot return ((*linesw[tp->t_line].l_read)(tp, uio)); 26917Sbill } 27017Sbill 2717833Sroot dzwrite(dev, uio) 2722395Swnj dev_t dev; 2737833Sroot struct uio *uio; 27417Sbill { 27517Sbill register struct tty *tp; 27617Sbill 2772395Swnj tp = &dz_tty[minor(dev)]; 2787833Sroot (*linesw[tp->t_line].l_write)(tp, uio); 27917Sbill } 28017Sbill 281119Sbill /*ARGSUSED*/ 2822395Swnj dzrint(dz) 2832395Swnj int dz; 28417Sbill { 28517Sbill register struct tty *tp; 28617Sbill register int c; 28717Sbill register struct device *dzaddr; 288119Sbill register struct tty *tp0; 2892395Swnj register int unit; 2902923Swnj int overrun = 0; 29117Sbill 2922457Swnj if ((dzact & (1<<dz)) == 0) 2932457Swnj return; 2942457Swnj unit = dz * 8; 2952457Swnj dzaddr = dzpdma[unit].p_addr; 2962457Swnj tp0 = &dz_tty[unit]; 2975731Sroot dzaddr->dzcsr &= ~(DZ_RIE|DZ_MIE); /* the manual says this song */ 2985731Sroot dzaddr->dzcsr |= DZ_RIE|DZ_MIE; /* and dance is necessary */ 2995731Sroot while (dzaddr->dzcsr & DZ_MSC) { /* DZ32 modem change interrupt */ 3005731Sroot c = dzaddr->dzmtsr; 3015731Sroot tp = tp0 + (c&7); 3025731Sroot if (tp >= &dz_tty[dz_cnt]) 3035731Sroot break; 3045731Sroot dzaddr->dzlcs = c&7; /* get status of modem lines */ 3055731Sroot dzwait(dzaddr); /* wait for them */ 3065731Sroot if (c & DZ_CD) /* carrier status change? */ 3075731Sroot if (dzaddr->dzlcs & DZ_CD) { /* carrier up? */ 3085731Sroot if ((tp->t_state&TS_CARR_ON) == 0) { 3095731Sroot wakeup((caddr_t)&tp->t_rawq); 3105731Sroot tp->t_state |= TS_CARR_ON; 3115731Sroot } 3125731Sroot } else { /* no carrier */ 3135731Sroot if (tp->t_state&TS_CARR_ON) { 3145731Sroot gsignal(tp->t_pgrp, SIGHUP); 3155731Sroot gsignal(tp->t_pgrp, SIGCONT); 3165731Sroot dzaddr->dzlcs = DZ_ACK|(c&7); 3175731Sroot flushtty(tp, FREAD|FWRITE); 3185731Sroot } 3195731Sroot tp->t_state &= ~TS_CARR_ON; 3205731Sroot } 3215731Sroot } 3222457Swnj while ((c = dzaddr->dzrbuf) < 0) { /* char present */ 3232457Swnj tp = tp0 + ((c>>8)&07); 3242457Swnj if (tp >= &dz_tty[dz_cnt]) 32517Sbill continue; 3265407Swnj if ((tp->t_state & TS_ISOPEN) == 0) { 3272457Swnj wakeup((caddr_t)&tp->t_rawq); 3286616Ssam #ifdef PORTSELECTOR 3296616Ssam if ((tp->t_state&TS_WOPEN) == 0) 3306616Ssam #endif 3312457Swnj continue; 3322457Swnj } 3332469Swnj if (c&DZ_FE) 3342457Swnj if (tp->t_flags & RAW) 3352469Swnj c = 0; 3362457Swnj else 3372457Swnj c = tun.t_intrc; 3382923Swnj if (c&DZ_DO && overrun == 0) { 3395731Sroot /* printf("dz%d,%d: silo overflow\n", dz, (c>>8)&7); */ 3402923Swnj overrun = 1; 3412923Swnj } 3422469Swnj if (c&DZ_PE) 3432457Swnj if (((tp->t_flags & (EVENP|ODDP)) == EVENP) 3442457Swnj || ((tp->t_flags & (EVENP|ODDP)) == ODDP)) 34517Sbill continue; 3462731Swnj #if NBK > 0 3472457Swnj if (tp->t_line == NETLDISC) { 3482457Swnj c &= 0177; 3492457Swnj BKINPUT(c, tp); 3502457Swnj } else 3512731Swnj #endif 3522457Swnj (*linesw[tp->t_line].l_rint)(c, tp); 35317Sbill } 35417Sbill } 35517Sbill 35617Sbill /*ARGSUSED*/ 3577631Ssam dzioctl(dev, cmd, data, flag) 3582395Swnj dev_t dev; 3597631Ssam caddr_t data; 36017Sbill { 36117Sbill register struct tty *tp; 3622395Swnj register int unit = minor(dev); 3632395Swnj register int dz = unit >> 3; 3645731Sroot register struct device *dzaddr; 36517Sbill 3662395Swnj tp = &dz_tty[unit]; 3677631Ssam cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); 368114Sbill if (cmd == 0) 369114Sbill return; 3707631Ssam if (ttioctl(tp, cmd, data, flag)) { 3717631Ssam if (cmd == TIOCSETP || cmd == TIOCSETN) 3722395Swnj dzparam(unit); 373170Sbill } else switch(cmd) { 3742395Swnj 375170Sbill case TIOCSBRK: 3765731Sroot dzaddr = ((struct pdma *)(tp->t_addr))->p_addr; 3775731Sroot if (dzaddr->dzcsr&DZ_32) 3786157Ssam (void) dzmctl(dev, DZ_BRK, DMBIS); 3795731Sroot else 3805731Sroot dzaddr->dzbrk = (dz_brk[dz] |= 1 << (unit&07)); 381170Sbill break; 3827631Ssam 383170Sbill case TIOCCBRK: 3845731Sroot dzaddr = ((struct pdma *)(tp->t_addr))->p_addr; 3855731Sroot if (dzaddr->dzcsr&DZ_32) 3866157Ssam (void) dzmctl(dev, DZ_BRK, DMBIC); 3875731Sroot else 3885731Sroot dzaddr->dzbrk = (dz_brk[dz] &= ~(1 << (unit&07))); 389170Sbill break; 3907631Ssam 391170Sbill case TIOCSDTR: 3926157Ssam (void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIS); 393170Sbill break; 3947631Ssam 395170Sbill case TIOCCDTR: 3966157Ssam (void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIC); 397170Sbill break; 3987631Ssam 3995731Sroot case TIOCMSET: 4007631Ssam (void) dzmctl(dev, dmtodz(*(int *)data), DMSET); 4015731Sroot break; 4027631Ssam 4035731Sroot case TIOCMBIS: 4047631Ssam (void) dzmctl(dev, dmtodz(*(int *)data), DMBIS); 4055731Sroot break; 4067631Ssam 4075731Sroot case TIOCMBIC: 4087631Ssam (void) dzmctl(dev, dmtodz(*(int *)data), DMBIC); 4095731Sroot break; 4107631Ssam 4115731Sroot case TIOCMGET: 4127631Ssam *(int *)data = dztodm(dzmctl(dev, 0, DMGET)); 4135731Sroot break; 4147631Ssam 415170Sbill default: 41617Sbill u.u_error = ENOTTY; 417170Sbill } 41817Sbill } 4195731Sroot 4205731Sroot dmtodz(bits) 4215731Sroot register int bits; 4225731Sroot { 4235731Sroot register int b; 4245731Sroot 4255731Sroot b = (bits >>1) & 0370; 4265731Sroot if (bits & DML_ST) b |= DZ_ST; 4275731Sroot if (bits & DML_RTS) b |= DZ_RTS; 4285731Sroot if (bits & DML_DTR) b |= DZ_DTR; 4295731Sroot if (bits & DML_LE) b |= DZ_LE; 4305731Sroot return(b); 4315731Sroot } 4325731Sroot 4335731Sroot dztodm(bits) 4345731Sroot register int bits; 4355731Sroot { 4365731Sroot register int b; 4375731Sroot 4385731Sroot b = (bits << 1) & 0360; 4395731Sroot if (bits & DZ_DSR) b |= DML_DSR; 4405731Sroot if (bits & DZ_DTR) b |= DML_DTR; 4415731Sroot if (bits & DZ_ST) b |= DML_ST; 4425731Sroot if (bits & DZ_RTS) b |= DML_RTS; 4435731Sroot return(b); 4445731Sroot } 44517Sbill 4462395Swnj dzparam(unit) 4472395Swnj register int unit; 44817Sbill { 44917Sbill register struct tty *tp; 45017Sbill register struct device *dzaddr; 4512395Swnj register int lpr; 45217Sbill 4532395Swnj tp = &dz_tty[unit]; 4542395Swnj dzaddr = dzpdma[unit].p_addr; 45517Sbill dzaddr->dzcsr = DZ_IEN; 4562395Swnj dzact |= (1<<(unit>>3)); 45717Sbill if (tp->t_ispeed == 0) { 4586157Ssam (void) dzmctl(unit, DZ_OFF, DMSET); /* hang up line */ 45917Sbill return; 46017Sbill } 4612395Swnj lpr = (dz_speeds[tp->t_ispeed]<<8) | (unit & 07); 4622296Swnj if ((tp->t_local&LLITOUT) || (tp->t_flags&RAW)) 46317Sbill lpr |= BITS8; 46417Sbill else 46517Sbill lpr |= (BITS7|PENABLE); 46617Sbill if ((tp->t_flags & EVENP) == 0) 46717Sbill lpr |= OPAR; 4682469Swnj if (tp->t_ispeed == B110) 4692469Swnj lpr |= TWOSB; 47017Sbill dzaddr->dzlpr = lpr; 47117Sbill } 47217Sbill 47317Sbill dzxint(tp) 4742395Swnj register struct tty *tp; 47517Sbill { 47617Sbill register struct pdma *dp; 4775731Sroot register s, dz, unit; 47817Sbill 4792469Swnj s = spl5(); /* block pdma interrupts */ 4802395Swnj dp = (struct pdma *)tp->t_addr; 4815407Swnj tp->t_state &= ~TS_BUSY; 4825407Swnj if (tp->t_state & TS_FLUSH) 4835407Swnj tp->t_state &= ~TS_FLUSH; 4845731Sroot else { 485281Sbill ndflush(&tp->t_outq, dp->p_mem-tp->t_outq.c_cf); 4865731Sroot dp->p_end = dp->p_mem = tp->t_outq.c_cf; 4875731Sroot } 48817Sbill if (tp->t_line) 48917Sbill (*linesw[tp->t_line].l_start)(tp); 49017Sbill else 49117Sbill dzstart(tp); 4925731Sroot dz = minor(tp->t_dev) >> 3; 4935731Sroot unit = minor(tp->t_dev) & 7; 4945407Swnj if (tp->t_outq.c_cc == 0 || (tp->t_state&TS_BUSY)==0) 4955731Sroot if (dp->p_addr->dzcsr & DZ_32) 4965731Sroot dp->p_addr->dzlnen = (dz_lnen[dz] &= ~(1<<unit)); 4975731Sroot else 4985731Sroot dp->p_addr->dztcr &= ~(1<<unit); 499145Sbill splx(s); 50017Sbill } 50117Sbill 50217Sbill dzstart(tp) 5032395Swnj register struct tty *tp; 50417Sbill { 50517Sbill register struct pdma *dp; 50617Sbill register struct device *dzaddr; 5072395Swnj register int cc; 5085731Sroot int s, dz, unit; 50917Sbill 5102395Swnj dp = (struct pdma *)tp->t_addr; 51117Sbill dzaddr = dp->p_addr; 5122395Swnj s = spl5(); 5135407Swnj if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 51417Sbill goto out; 5155407Swnj if (tp->t_outq.c_cc <= TTLOWAT(tp)) { 5165407Swnj if (tp->t_state&TS_ASLEEP) { 5175407Swnj tp->t_state &= ~TS_ASLEEP; 5185407Swnj wakeup((caddr_t)&tp->t_outq); 5195407Swnj } 5205407Swnj if (tp->t_wsel) { 5215407Swnj selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); 5225407Swnj tp->t_wsel = 0; 5235407Swnj tp->t_state &= ~TS_WCOLL; 5245407Swnj } 52517Sbill } 52617Sbill if (tp->t_outq.c_cc == 0) 52717Sbill goto out; 5285731Sroot if ((tp->t_flags&RAW) || (tp->t_local&LLITOUT)) 52917Sbill cc = ndqb(&tp->t_outq, 0); 53017Sbill else { 53117Sbill cc = ndqb(&tp->t_outq, 0200); 53217Sbill if (cc == 0) { 53317Sbill cc = getc(&tp->t_outq); 5342469Swnj timeout(ttrstrt, (caddr_t)tp, (cc&0x7f) + 6); 5355407Swnj tp->t_state |= TS_TIMEOUT; 53617Sbill goto out; 53717Sbill } 53817Sbill } 5395407Swnj tp->t_state |= TS_BUSY; 54017Sbill dp->p_end = dp->p_mem = tp->t_outq.c_cf; 54117Sbill dp->p_end += cc; 5425731Sroot dz = minor(tp->t_dev) >> 3; 5435731Sroot unit = minor(tp->t_dev) & 7; 5445731Sroot if (dzaddr->dzcsr & DZ_32) 5455731Sroot dzaddr->dzlnen = (dz_lnen[dz] |= (1<<unit)); 5465731Sroot else 5475731Sroot dzaddr->dztcr |= (1<<unit); 5482395Swnj out: 5492395Swnj splx(s); 55017Sbill } 55117Sbill 55217Sbill /* 55317Sbill * Stop output on a line. 55417Sbill */ 55517Sbill /*ARGSUSED*/ 55617Sbill dzstop(tp, flag) 5572395Swnj register struct tty *tp; 55817Sbill { 55917Sbill register struct pdma *dp; 56017Sbill register int s; 56117Sbill 5622395Swnj dp = (struct pdma *)tp->t_addr; 5632457Swnj s = spl5(); 5645407Swnj if (tp->t_state & TS_BUSY) { 56517Sbill dp->p_end = dp->p_mem; 5665407Swnj if ((tp->t_state&TS_TTSTOP)==0) 5675407Swnj tp->t_state |= TS_FLUSH; 56817Sbill } 56917Sbill splx(s); 57017Sbill } 57117Sbill 5725731Sroot dzmctl(dev, bits, how) 5735731Sroot dev_t dev; 5745731Sroot int bits, how; 57517Sbill { 57617Sbill register struct device *dzaddr; 5775731Sroot register int unit, mbits; 5785731Sroot int b, s; 5795731Sroot 5805731Sroot unit = minor(dev); 5815731Sroot b = 1<<(unit&7); 5822395Swnj dzaddr = dzpdma[unit].p_addr; 5835731Sroot s = spl5(); 5845731Sroot if (dzaddr->dzcsr & DZ_32) { 5855731Sroot dzwait(dzaddr) 5865731Sroot DELAY(100); /* IS 100 TOO MUCH? */ 5875731Sroot dzaddr->dzlcs = unit&7; 5885731Sroot DELAY(100); 5895731Sroot dzwait(dzaddr) 5905731Sroot DELAY(100); 5915731Sroot mbits = dzaddr->dzlcs; 5925731Sroot mbits &= 0177770; 5935731Sroot } else { 5945731Sroot mbits = (dzaddr->dzdtr & b) ? DZ_DTR : 0; 5955731Sroot mbits |= (dzaddr->dzmsr & b) ? DZ_CD : 0; 5965731Sroot mbits |= (dzaddr->dztbuf & b) ? DZ_RI : 0; 5975731Sroot } 5985731Sroot switch (how) { 5995731Sroot case DMSET: 6005731Sroot mbits = bits; 6015731Sroot break; 6025731Sroot 6035731Sroot case DMBIS: 6045731Sroot mbits |= bits; 6055731Sroot break; 6065731Sroot 6075731Sroot case DMBIC: 6085731Sroot mbits &= ~bits; 6095731Sroot break; 6105731Sroot 6115731Sroot case DMGET: 6125731Sroot (void) splx(s); 6135731Sroot return(mbits); 6145731Sroot } 6155731Sroot if (dzaddr->dzcsr & DZ_32) { 6165731Sroot mbits |= DZ_ACK|(unit&7); 6175731Sroot dzaddr->dzlcs = mbits; 6185731Sroot } else { 6195731Sroot if (mbits & DZ_DTR) 6205731Sroot dzaddr->dzdtr |= b; 6215731Sroot else 6225731Sroot dzaddr->dzdtr &= ~b; 6235731Sroot } 6245731Sroot (void) splx(s); 6255731Sroot return(mbits); 62617Sbill } 62717Sbill 62817Sbill dzscan() 62917Sbill { 63017Sbill register i; 63117Sbill register struct device *dzaddr; 63217Sbill register bit; 63317Sbill register struct tty *tp; 6345731Sroot register car; 63517Sbill 63617Sbill for (i = 0; i < dz_cnt ; i++) { 63717Sbill dzaddr = dzpdma[i].p_addr; 6382627Swnj if (dzaddr == 0) 6392627Swnj continue; 64017Sbill tp = &dz_tty[i]; 64117Sbill bit = 1<<(i&07); 6425731Sroot car = 0; 6435731Sroot if (dzsoftCAR[i>>3]&bit) 6445731Sroot car = 1; 6455731Sroot else if (dzaddr->dzcsr & DZ_32) { 6465731Sroot dzaddr->dzlcs = i&07; 6475731Sroot dzwait(dzaddr); 6485731Sroot car = dzaddr->dzlcs & DZ_CD; 6495731Sroot } else 6505731Sroot car = dzaddr->dzmsr&bit; 6515731Sroot if (car) { 65217Sbill /* carrier present */ 6535407Swnj if ((tp->t_state & TS_CARR_ON) == 0) { 65417Sbill wakeup((caddr_t)&tp->t_rawq); 6555407Swnj tp->t_state |= TS_CARR_ON; 65617Sbill } 65717Sbill } else { 6585407Swnj if ((tp->t_state&TS_CARR_ON) && 6592469Swnj (tp->t_local&LNOHANG)==0) { 66017Sbill /* carrier lost */ 6615407Swnj if (tp->t_state&TS_ISOPEN) { 662170Sbill gsignal(tp->t_pgrp, SIGHUP); 663205Sbill gsignal(tp->t_pgrp, SIGCONT); 664170Sbill dzaddr->dzdtr &= ~bit; 665871Sbill flushtty(tp, FREAD|FWRITE); 666170Sbill } 6675407Swnj tp->t_state &= ~TS_CARR_ON; 66817Sbill } 66917Sbill } 67017Sbill } 6712756Swnj timeout(dzscan, (caddr_t)0, 2*hz); 67217Sbill } 673119Sbill 674119Sbill dztimer() 675119Sbill { 676*8160Sroot register int dz; 677*8160Sroot register int s = spl5(); 678119Sbill 6792645Swnj for (dz = 0; dz < NDZ; dz++) 6802457Swnj dzrint(dz); 681*8160Sroot splx(s); 682119Sbill } 683281Sbill 684281Sbill /* 685281Sbill * Reset state of driver if UBA reset was necessary. 686301Sbill * Reset parameters and restart transmission on open lines. 687281Sbill */ 6882395Swnj dzreset(uban) 6892422Skre int uban; 690281Sbill { 6912395Swnj register int unit; 692281Sbill register struct tty *tp; 6932976Swnj register struct uba_device *ui; 694281Sbill 6952645Swnj for (unit = 0; unit < NDZLINE; unit++) { 6962422Skre ui = dzinfo[unit >> 3]; 6972422Skre if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0) 6982422Skre continue; 6992923Swnj if (unit%8 == 0) 7002923Swnj printf(" dz%d", unit>>3); 7012395Swnj tp = &dz_tty[unit]; 7025407Swnj if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { 7032395Swnj dzparam(unit); 7046157Ssam (void) dzmctl(unit, DZ_ON, DMSET); 7055407Swnj tp->t_state &= ~TS_BUSY; 706301Sbill dzstart(tp); 707281Sbill } 708281Sbill } 709281Sbill dztimer(); 710281Sbill } 7111562Sbill #endif 712