1*8568Sroot /* dz.c 4.46 82/10/17 */ 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" 2117Sbill #include "../h/conf.h" 22114Sbill #include "../h/bk.h" 23871Sbill #include "../h/file.h" 247727Sroot #include "../h/uio.h" 25145Sbill 268474Sroot #include "../vaxuba/pdma.h" 278474Sroot #include "../vaxuba/ubavar.h" 288474Sroot 292469Swnj /* 302469Swnj * Driver information for auto-configuration stuff. 312469Swnj */ 322606Swnj int dzprobe(), dzattach(), dzrint(); 332976Swnj struct uba_device *dzinfo[NDZ]; 342395Swnj u_short dzstd[] = { 0 }; 352395Swnj struct uba_driver dzdriver = 362606Swnj { dzprobe, 0, dzattach, 0, dzstd, "dz", dzinfo }; 372395Swnj 382645Swnj #define NDZLINE (NDZ*8) 3917Sbill 402469Swnj /* 412469Swnj * Registers and bits 422469Swnj */ 432469Swnj 445731Sroot /* bits in dzlpr */ 455731Sroot #define BITS7 0020 465731Sroot #define BITS8 0030 475731Sroot #define TWOSB 0040 482457Swnj #define PENABLE 0100 492457Swnj #define OPAR 0200 5017Sbill 515731Sroot /* bits in dzrbuf */ 522469Swnj #define DZ_PE 010000 532469Swnj #define DZ_FE 020000 542469Swnj #define DZ_DO 040000 552469Swnj 565731Sroot /* bits in dzcsr */ 575731Sroot #define DZ_32 000001 /* DZ32 mode */ 585731Sroot #define DZ_MIE 000002 /* Modem Interrupt Enable */ 595731Sroot #define DZ_CLR 000020 /* Reset dz */ 605731Sroot #define DZ_MSE 000040 /* Master Scan Enable */ 615731Sroot #define DZ_RIE 000100 /* Receiver Interrupt Enable */ 625731Sroot #define DZ_MSC 004000 /* Modem Status Change */ 632469Swnj #define DZ_SAE 010000 /* Silo Alarm Enable */ 642469Swnj #define DZ_TIE 040000 /* Transmit Interrupt Enable */ 655731Sroot #define DZ_IEN (DZ_32|DZ_MIE|DZ_MSE|DZ_RIE|DZ_TIE|DZ_SAE) 662469Swnj 675731Sroot /* flags for modem-control */ 685731Sroot #define DZ_ON DZ_DTR 692469Swnj #define DZ_OFF 0 705731Sroot 715731Sroot /* bits in dzlcs */ 725731Sroot #define DZ_ACK 0100000 /* ACK bit in dzlcs */ 735731Sroot #define DZ_RTS 0010000 /* Request To Send */ 745731Sroot #define DZ_ST 0004000 /* Secondary Transmit */ 755731Sroot #define DZ_BRK 0002000 /* Break */ 765731Sroot #define DZ_DTR 0001000 /* Data Terminal Ready */ 775731Sroot #define DZ_LE 0000400 /* Line Enable */ 785731Sroot #define DZ_DSR 0000200 /* Data Set Ready */ 795731Sroot #define DZ_RI 0000100 /* Ring Indicate */ 805731Sroot #define DZ_CD 0000040 /* Carrier Detect */ 815731Sroot #define DZ_CTS 0000020 /* Clear To Send */ 825731Sroot #define DZ_SR 0000010 /* Secondary Receive */ 8317Sbill 845731Sroot /* bits in dm lsr, copied from dh.c */ 855731Sroot #define DML_DSR 0000400 /* data set ready, not a real DM bit */ 865731Sroot #define DML_RNG 0000200 /* ring */ 875731Sroot #define DML_CAR 0000100 /* carrier detect */ 885731Sroot #define DML_CTS 0000040 /* clear to send */ 895731Sroot #define DML_SR 0000020 /* secondary receive */ 905731Sroot #define DML_ST 0000010 /* secondary transmit */ 915731Sroot #define DML_RTS 0000004 /* request to send */ 925731Sroot #define DML_DTR 0000002 /* data terminal ready */ 935731Sroot #define DML_LE 0000001 /* line enable */ 945731Sroot 952469Swnj int dzstart(), dzxint(), dzdma(); 96114Sbill int ttrstrt(); 972645Swnj struct tty dz_tty[NDZLINE]; 982645Swnj int dz_cnt = { NDZLINE }; 99119Sbill int dzact; 10017Sbill 10117Sbill struct device { 1025731Sroot short dzcsr; 1035731Sroot short dzrbuf; 1045731Sroot union { 1055731Sroot struct { 1065731Sroot char dztcr0; 1075731Sroot char dzdtr0; 1085731Sroot char dztbuf0; 1095731Sroot char dzbrk0; 1105731Sroot } dz11; 1115731Sroot struct { 1125731Sroot short dzlcs0; 1135731Sroot char dztbuf0; 1145731Sroot char dzlnen0; 1155731Sroot } dz32; 1165731Sroot } dzun; 11717Sbill }; 1185731Sroot 1195731Sroot #define dzlpr dzrbuf 1205731Sroot #define dzmsr dzun.dz11.dzbrk0 1215731Sroot #define dztcr dzun.dz11.dztcr0 1225731Sroot #define dzdtr dzun.dz11.dzdtr0 1235731Sroot #define dztbuf dzun.dz11.dztbuf0 1245731Sroot #define dzlcs dzun.dz32.dzlcs0 1255731Sroot #define dzbrk dzmsr 1265731Sroot #define dzlnen dzun.dz32.dzlnen0 1277406Skre #define dzmtsr dzun.dz32.dztbuf0 1285731Sroot 1295731Sroot #define dzwait(x) while (((x)->dzlcs & DZ_ACK) == 0) 1305731Sroot 1312469Swnj /* 1322469Swnj * Software copy of dzbrk since it isn't readable 1332469Swnj */ 1342645Swnj char dz_brk[NDZ]; 1352645Swnj char dzsoftCAR[NDZ]; 1365731Sroot char dz_lnen[NDZ]; /* saved line enable bits for DZ32 */ 13717Sbill 1382469Swnj /* 1395731Sroot * The dz11 doesn't interrupt on carrier transitions, so 1402469Swnj * we have to use a timer to watch it. 1412469Swnj */ 1422469Swnj char dz_timer; /* timer started? */ 1432469Swnj 1442469Swnj /* 1452469Swnj * Pdma structures for fast output code 1462469Swnj */ 1472645Swnj struct pdma dzpdma[NDZLINE]; 1482469Swnj 1492395Swnj char dz_speeds[] = 1506814Swnj { 0,020,021,022,023,024,0,025,026,027,030,032,034,036,037,0 }; 15117Sbill 1526616Ssam #ifndef PORTSELECTOR 1536616Ssam #define ISPEED B300 1546616Ssam #define IFLAGS (EVENP|ODDP|ECHO) 1556616Ssam #else 1566616Ssam #define ISPEED B4800 1576616Ssam #define IFLAGS (EVENP|ODDP) 1586616Ssam #endif 1596616Ssam 1602606Swnj dzprobe(reg) 1612395Swnj caddr_t reg; 1622395Swnj { 1632457Swnj register int br, cvec; 1642457Swnj register struct device *dzaddr = (struct device *)reg; 1652395Swnj 1662606Swnj #ifdef lint 1673102Swnj br = 0; cvec = br; br = cvec; 1684933Swnj dzrint(0); dzxint((struct tty *)0); 1692606Swnj #endif 1705731Sroot dzaddr->dzcsr = DZ_TIE|DZ_MSE|DZ_32; 1715731Sroot if (dzaddr->dzcsr & DZ_32) 1725731Sroot dzaddr->dzlnen = 1; 1735731Sroot else 1745731Sroot dzaddr->dztcr = 1; /* enable any line */ 1752457Swnj DELAY(100000); 1765731Sroot dzaddr->dzcsr = DZ_CLR|DZ_32; /* reset everything */ 1772457Swnj if (cvec && cvec != 0x200) 1782457Swnj cvec -= 4; 1797406Skre return (sizeof (struct device)); 1802395Swnj } 1812395Swnj 1822606Swnj dzattach(ui) 1832976Swnj register struct uba_device *ui; 1842395Swnj { 1852395Swnj register struct pdma *pdp = &dzpdma[ui->ui_unit*8]; 1862395Swnj register struct tty *tp = &dz_tty[ui->ui_unit*8]; 1872606Swnj register int cntr; 1882645Swnj extern dzscan(); 1892395Swnj 1902606Swnj for (cntr = 0; cntr < 8; cntr++) { 1912606Swnj pdp->p_addr = (struct device *)ui->ui_addr; 1922395Swnj pdp->p_arg = (int)tp; 1932395Swnj pdp->p_fcn = dzxint; 1942395Swnj pdp++, tp++; 1952395Swnj } 1962567Swnj dzsoftCAR[ui->ui_unit] = ui->ui_flags; 1972627Swnj if (dz_timer == 0) { 1982627Swnj dz_timer++; 1992756Swnj timeout(dzscan, (caddr_t)0, hz); 2002627Swnj } 2012395Swnj } 2022395Swnj 20317Sbill /*ARGSUSED*/ 2042395Swnj dzopen(dev, flag) 2052395Swnj dev_t dev; 20617Sbill { 20717Sbill register struct tty *tp; 2082395Swnj register int unit; 20917Sbill 2102395Swnj unit = minor(dev); 211*8568Sroot if (unit >= dz_cnt || dzpdma[unit].p_addr == 0) 212*8568Sroot return (ENXIO); 2132395Swnj tp = &dz_tty[unit]; 2142395Swnj tp->t_addr = (caddr_t)&dzpdma[unit]; 21517Sbill tp->t_oproc = dzstart; 2165407Swnj tp->t_state |= TS_WOPEN; 2175407Swnj if ((tp->t_state & TS_ISOPEN) == 0) { 21817Sbill ttychars(tp); 2196616Ssam tp->t_ospeed = tp->t_ispeed = ISPEED; 2206616Ssam tp->t_flags = IFLAGS; 2215407Swnj /* tp->t_state |= TS_HUPCLS; */ 2222395Swnj dzparam(unit); 223*8568Sroot } else if (tp->t_state&TS_XCLUDE && u.u_uid != 0) 224*8568Sroot return (EBUSY); 2256157Ssam (void) dzmctl(dev, DZ_ON, DMSET); 226114Sbill (void) spl5(); 2275407Swnj while ((tp->t_state & TS_CARR_ON) == 0) { 2285407Swnj tp->t_state |= TS_WOPEN; 22917Sbill sleep((caddr_t)&tp->t_rawq, TTIPRI); 23017Sbill } 231114Sbill (void) spl0(); 232*8568Sroot return ((*linesw[tp->t_line].l_open)(dev, tp)); 23317Sbill } 23417Sbill 2352395Swnj /*ARGSUSED*/ 2362395Swnj dzclose(dev, flag) 2372395Swnj dev_t dev; 23817Sbill { 23917Sbill register struct tty *tp; 2402395Swnj register int unit; 2415731Sroot register struct device *dzaddr; 2426150Ssam int dz; 24317Sbill 2442395Swnj unit = minor(dev); 2452395Swnj dz = unit >> 3; 2462395Swnj tp = &dz_tty[unit]; 24717Sbill (*linesw[tp->t_line].l_close)(tp); 2485731Sroot dzaddr = dzpdma[unit].p_addr; 2495731Sroot if (dzaddr->dzcsr&DZ_32) 2506157Ssam (void) dzmctl(dev, DZ_BRK, DMBIC); 2515731Sroot else 2525731Sroot dzaddr->dzbrk = (dz_brk[dz] &= ~(1 << (unit&07))); 2536842Swnj if ((tp->t_state&(TS_HUPCLS|TS_WOPEN)) || (tp->t_state&TS_ISOPEN) == 0) 2546157Ssam (void) dzmctl(dev, DZ_OFF, DMSET); 25517Sbill ttyclose(tp); 25617Sbill } 25717Sbill 2587727Sroot dzread(dev, uio) 2592395Swnj dev_t dev; 2607727Sroot struct uio *uio; 26117Sbill { 26217Sbill register struct tty *tp; 26317Sbill 2642395Swnj tp = &dz_tty[minor(dev)]; 2657727Sroot return ((*linesw[tp->t_line].l_read)(tp, uio)); 26617Sbill } 26717Sbill 2687833Sroot dzwrite(dev, uio) 2692395Swnj dev_t dev; 2707833Sroot struct uio *uio; 27117Sbill { 27217Sbill register struct tty *tp; 27317Sbill 2742395Swnj tp = &dz_tty[minor(dev)]; 2758531Sroot return ((*linesw[tp->t_line].l_write)(tp, uio)); 27617Sbill } 27717Sbill 278119Sbill /*ARGSUSED*/ 2792395Swnj dzrint(dz) 2802395Swnj int dz; 28117Sbill { 28217Sbill register struct tty *tp; 28317Sbill register int c; 28417Sbill register struct device *dzaddr; 285119Sbill register struct tty *tp0; 2862395Swnj register int unit; 2872923Swnj int overrun = 0; 28817Sbill 2892457Swnj if ((dzact & (1<<dz)) == 0) 2902457Swnj return; 2912457Swnj unit = dz * 8; 2922457Swnj dzaddr = dzpdma[unit].p_addr; 2932457Swnj tp0 = &dz_tty[unit]; 2945731Sroot dzaddr->dzcsr &= ~(DZ_RIE|DZ_MIE); /* the manual says this song */ 2955731Sroot dzaddr->dzcsr |= DZ_RIE|DZ_MIE; /* and dance is necessary */ 2965731Sroot while (dzaddr->dzcsr & DZ_MSC) { /* DZ32 modem change interrupt */ 2975731Sroot c = dzaddr->dzmtsr; 2985731Sroot tp = tp0 + (c&7); 2995731Sroot if (tp >= &dz_tty[dz_cnt]) 3005731Sroot break; 3015731Sroot dzaddr->dzlcs = c&7; /* get status of modem lines */ 3025731Sroot dzwait(dzaddr); /* wait for them */ 3035731Sroot if (c & DZ_CD) /* carrier status change? */ 3045731Sroot if (dzaddr->dzlcs & DZ_CD) { /* carrier up? */ 3055731Sroot if ((tp->t_state&TS_CARR_ON) == 0) { 3065731Sroot wakeup((caddr_t)&tp->t_rawq); 3075731Sroot tp->t_state |= TS_CARR_ON; 3085731Sroot } 3095731Sroot } else { /* no carrier */ 3105731Sroot if (tp->t_state&TS_CARR_ON) { 3115731Sroot gsignal(tp->t_pgrp, SIGHUP); 3125731Sroot gsignal(tp->t_pgrp, SIGCONT); 3135731Sroot dzaddr->dzlcs = DZ_ACK|(c&7); 3145731Sroot flushtty(tp, FREAD|FWRITE); 3155731Sroot } 3165731Sroot tp->t_state &= ~TS_CARR_ON; 3175731Sroot } 3185731Sroot } 3192457Swnj while ((c = dzaddr->dzrbuf) < 0) { /* char present */ 3202457Swnj tp = tp0 + ((c>>8)&07); 3212457Swnj if (tp >= &dz_tty[dz_cnt]) 32217Sbill continue; 3235407Swnj if ((tp->t_state & TS_ISOPEN) == 0) { 3242457Swnj wakeup((caddr_t)&tp->t_rawq); 3256616Ssam #ifdef PORTSELECTOR 3266616Ssam if ((tp->t_state&TS_WOPEN) == 0) 3276616Ssam #endif 3282457Swnj continue; 3292457Swnj } 3302469Swnj if (c&DZ_FE) 3312457Swnj if (tp->t_flags & RAW) 3322469Swnj c = 0; 3332457Swnj else 3342457Swnj c = tun.t_intrc; 3352923Swnj if (c&DZ_DO && overrun == 0) { 3365731Sroot /* printf("dz%d,%d: silo overflow\n", dz, (c>>8)&7); */ 3372923Swnj overrun = 1; 3382923Swnj } 3392469Swnj if (c&DZ_PE) 3402457Swnj if (((tp->t_flags & (EVENP|ODDP)) == EVENP) 3412457Swnj || ((tp->t_flags & (EVENP|ODDP)) == ODDP)) 34217Sbill continue; 3432731Swnj #if NBK > 0 3442457Swnj if (tp->t_line == NETLDISC) { 3452457Swnj c &= 0177; 3462457Swnj BKINPUT(c, tp); 3472457Swnj } else 3482731Swnj #endif 3492457Swnj (*linesw[tp->t_line].l_rint)(c, tp); 35017Sbill } 35117Sbill } 35217Sbill 35317Sbill /*ARGSUSED*/ 3547631Ssam dzioctl(dev, cmd, data, flag) 3552395Swnj dev_t dev; 3567631Ssam caddr_t data; 35717Sbill { 35817Sbill register struct tty *tp; 3592395Swnj register int unit = minor(dev); 3602395Swnj register int dz = unit >> 3; 3615731Sroot register struct device *dzaddr; 362*8568Sroot int error; 36317Sbill 3642395Swnj tp = &dz_tty[unit]; 365*8568Sroot error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); 366*8568Sroot if (error >= 0) 367*8568Sroot return (error); 368*8568Sroot error = ttioctl(tp, cmd, data, flag); 369*8568Sroot if (error >= 0) { 3707631Ssam if (cmd == TIOCSETP || cmd == TIOCSETN) 3712395Swnj dzparam(unit); 372*8568Sroot return (error); 373*8568Sroot } 374*8568Sroot switch (cmd) { 3752395Swnj 376170Sbill case TIOCSBRK: 3775731Sroot dzaddr = ((struct pdma *)(tp->t_addr))->p_addr; 3785731Sroot if (dzaddr->dzcsr&DZ_32) 3796157Ssam (void) dzmctl(dev, DZ_BRK, DMBIS); 3805731Sroot else 3815731Sroot dzaddr->dzbrk = (dz_brk[dz] |= 1 << (unit&07)); 382170Sbill break; 3837631Ssam 384170Sbill case TIOCCBRK: 3855731Sroot dzaddr = ((struct pdma *)(tp->t_addr))->p_addr; 3865731Sroot if (dzaddr->dzcsr&DZ_32) 3876157Ssam (void) dzmctl(dev, DZ_BRK, DMBIC); 3885731Sroot else 3895731Sroot dzaddr->dzbrk = (dz_brk[dz] &= ~(1 << (unit&07))); 390170Sbill break; 3917631Ssam 392170Sbill case TIOCSDTR: 3936157Ssam (void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIS); 394170Sbill break; 3957631Ssam 396170Sbill case TIOCCDTR: 3976157Ssam (void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIC); 398170Sbill break; 3997631Ssam 4005731Sroot case TIOCMSET: 4017631Ssam (void) dzmctl(dev, dmtodz(*(int *)data), DMSET); 4025731Sroot break; 4037631Ssam 4045731Sroot case TIOCMBIS: 4057631Ssam (void) dzmctl(dev, dmtodz(*(int *)data), DMBIS); 4065731Sroot break; 4077631Ssam 4085731Sroot case TIOCMBIC: 4097631Ssam (void) dzmctl(dev, dmtodz(*(int *)data), DMBIC); 4105731Sroot break; 4117631Ssam 4125731Sroot case TIOCMGET: 4137631Ssam *(int *)data = dztodm(dzmctl(dev, 0, DMGET)); 4145731Sroot break; 4157631Ssam 416170Sbill default: 417*8568Sroot return (ENOTTY); 418170Sbill } 419*8568Sroot return (0); 42017Sbill } 4215731Sroot 4225731Sroot dmtodz(bits) 4235731Sroot register int bits; 4245731Sroot { 4255731Sroot register int b; 4265731Sroot 4275731Sroot b = (bits >>1) & 0370; 4285731Sroot if (bits & DML_ST) b |= DZ_ST; 4295731Sroot if (bits & DML_RTS) b |= DZ_RTS; 4305731Sroot if (bits & DML_DTR) b |= DZ_DTR; 4315731Sroot if (bits & DML_LE) b |= DZ_LE; 4325731Sroot return(b); 4335731Sroot } 4345731Sroot 4355731Sroot dztodm(bits) 4365731Sroot register int bits; 4375731Sroot { 4385731Sroot register int b; 4395731Sroot 4405731Sroot b = (bits << 1) & 0360; 4415731Sroot if (bits & DZ_DSR) b |= DML_DSR; 4425731Sroot if (bits & DZ_DTR) b |= DML_DTR; 4435731Sroot if (bits & DZ_ST) b |= DML_ST; 4445731Sroot if (bits & DZ_RTS) b |= DML_RTS; 4455731Sroot return(b); 4465731Sroot } 44717Sbill 4482395Swnj dzparam(unit) 4492395Swnj register int unit; 45017Sbill { 45117Sbill register struct tty *tp; 45217Sbill register struct device *dzaddr; 4532395Swnj register int lpr; 45417Sbill 4552395Swnj tp = &dz_tty[unit]; 4562395Swnj dzaddr = dzpdma[unit].p_addr; 45717Sbill dzaddr->dzcsr = DZ_IEN; 4582395Swnj dzact |= (1<<(unit>>3)); 45917Sbill if (tp->t_ispeed == 0) { 4606157Ssam (void) dzmctl(unit, DZ_OFF, DMSET); /* hang up line */ 46117Sbill return; 46217Sbill } 4632395Swnj lpr = (dz_speeds[tp->t_ispeed]<<8) | (unit & 07); 4642296Swnj if ((tp->t_local&LLITOUT) || (tp->t_flags&RAW)) 46517Sbill lpr |= BITS8; 46617Sbill else 46717Sbill lpr |= (BITS7|PENABLE); 46817Sbill if ((tp->t_flags & EVENP) == 0) 46917Sbill lpr |= OPAR; 4702469Swnj if (tp->t_ispeed == B110) 4712469Swnj lpr |= TWOSB; 47217Sbill dzaddr->dzlpr = lpr; 47317Sbill } 47417Sbill 47517Sbill dzxint(tp) 4762395Swnj register struct tty *tp; 47717Sbill { 47817Sbill register struct pdma *dp; 4795731Sroot register s, dz, unit; 48017Sbill 4812469Swnj s = spl5(); /* block pdma interrupts */ 4822395Swnj dp = (struct pdma *)tp->t_addr; 4835407Swnj tp->t_state &= ~TS_BUSY; 4845407Swnj if (tp->t_state & TS_FLUSH) 4855407Swnj tp->t_state &= ~TS_FLUSH; 4865731Sroot else { 487281Sbill ndflush(&tp->t_outq, dp->p_mem-tp->t_outq.c_cf); 4885731Sroot dp->p_end = dp->p_mem = tp->t_outq.c_cf; 4895731Sroot } 49017Sbill if (tp->t_line) 49117Sbill (*linesw[tp->t_line].l_start)(tp); 49217Sbill else 49317Sbill dzstart(tp); 4945731Sroot dz = minor(tp->t_dev) >> 3; 4955731Sroot unit = minor(tp->t_dev) & 7; 4965407Swnj if (tp->t_outq.c_cc == 0 || (tp->t_state&TS_BUSY)==0) 4975731Sroot if (dp->p_addr->dzcsr & DZ_32) 4985731Sroot dp->p_addr->dzlnen = (dz_lnen[dz] &= ~(1<<unit)); 4995731Sroot else 5005731Sroot dp->p_addr->dztcr &= ~(1<<unit); 501145Sbill splx(s); 50217Sbill } 50317Sbill 50417Sbill dzstart(tp) 5052395Swnj register struct tty *tp; 50617Sbill { 50717Sbill register struct pdma *dp; 50817Sbill register struct device *dzaddr; 5092395Swnj register int cc; 5105731Sroot int s, dz, unit; 51117Sbill 5122395Swnj dp = (struct pdma *)tp->t_addr; 51317Sbill dzaddr = dp->p_addr; 5142395Swnj s = spl5(); 5155407Swnj if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 51617Sbill goto out; 5175407Swnj if (tp->t_outq.c_cc <= TTLOWAT(tp)) { 5185407Swnj if (tp->t_state&TS_ASLEEP) { 5195407Swnj tp->t_state &= ~TS_ASLEEP; 5205407Swnj wakeup((caddr_t)&tp->t_outq); 5215407Swnj } 5225407Swnj if (tp->t_wsel) { 5235407Swnj selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); 5245407Swnj tp->t_wsel = 0; 5255407Swnj tp->t_state &= ~TS_WCOLL; 5265407Swnj } 52717Sbill } 52817Sbill if (tp->t_outq.c_cc == 0) 52917Sbill goto out; 5305731Sroot if ((tp->t_flags&RAW) || (tp->t_local&LLITOUT)) 53117Sbill cc = ndqb(&tp->t_outq, 0); 53217Sbill else { 53317Sbill cc = ndqb(&tp->t_outq, 0200); 53417Sbill if (cc == 0) { 53517Sbill cc = getc(&tp->t_outq); 5362469Swnj timeout(ttrstrt, (caddr_t)tp, (cc&0x7f) + 6); 5375407Swnj tp->t_state |= TS_TIMEOUT; 53817Sbill goto out; 53917Sbill } 54017Sbill } 5415407Swnj tp->t_state |= TS_BUSY; 54217Sbill dp->p_end = dp->p_mem = tp->t_outq.c_cf; 54317Sbill dp->p_end += cc; 5445731Sroot dz = minor(tp->t_dev) >> 3; 5455731Sroot unit = minor(tp->t_dev) & 7; 5465731Sroot if (dzaddr->dzcsr & DZ_32) 5475731Sroot dzaddr->dzlnen = (dz_lnen[dz] |= (1<<unit)); 5485731Sroot else 5495731Sroot dzaddr->dztcr |= (1<<unit); 5502395Swnj out: 5512395Swnj splx(s); 55217Sbill } 55317Sbill 55417Sbill /* 55517Sbill * Stop output on a line. 55617Sbill */ 55717Sbill /*ARGSUSED*/ 55817Sbill dzstop(tp, flag) 5592395Swnj register struct tty *tp; 56017Sbill { 56117Sbill register struct pdma *dp; 56217Sbill register int s; 56317Sbill 5642395Swnj dp = (struct pdma *)tp->t_addr; 5652457Swnj s = spl5(); 5665407Swnj if (tp->t_state & TS_BUSY) { 56717Sbill dp->p_end = dp->p_mem; 5685407Swnj if ((tp->t_state&TS_TTSTOP)==0) 5695407Swnj tp->t_state |= TS_FLUSH; 57017Sbill } 57117Sbill splx(s); 57217Sbill } 57317Sbill 5745731Sroot dzmctl(dev, bits, how) 5755731Sroot dev_t dev; 5765731Sroot int bits, how; 57717Sbill { 57817Sbill register struct device *dzaddr; 5795731Sroot register int unit, mbits; 5805731Sroot int b, s; 5815731Sroot 5825731Sroot unit = minor(dev); 5835731Sroot b = 1<<(unit&7); 5842395Swnj dzaddr = dzpdma[unit].p_addr; 5855731Sroot s = spl5(); 5865731Sroot if (dzaddr->dzcsr & DZ_32) { 5875731Sroot dzwait(dzaddr) 5885731Sroot DELAY(100); /* IS 100 TOO MUCH? */ 5895731Sroot dzaddr->dzlcs = unit&7; 5905731Sroot DELAY(100); 5915731Sroot dzwait(dzaddr) 5925731Sroot DELAY(100); 5935731Sroot mbits = dzaddr->dzlcs; 5945731Sroot mbits &= 0177770; 5955731Sroot } else { 5965731Sroot mbits = (dzaddr->dzdtr & b) ? DZ_DTR : 0; 5975731Sroot mbits |= (dzaddr->dzmsr & b) ? DZ_CD : 0; 5985731Sroot mbits |= (dzaddr->dztbuf & b) ? DZ_RI : 0; 5995731Sroot } 6005731Sroot switch (how) { 6015731Sroot case DMSET: 6025731Sroot mbits = bits; 6035731Sroot break; 6045731Sroot 6055731Sroot case DMBIS: 6065731Sroot mbits |= bits; 6075731Sroot break; 6085731Sroot 6095731Sroot case DMBIC: 6105731Sroot mbits &= ~bits; 6115731Sroot break; 6125731Sroot 6135731Sroot case DMGET: 6145731Sroot (void) splx(s); 6155731Sroot return(mbits); 6165731Sroot } 6175731Sroot if (dzaddr->dzcsr & DZ_32) { 6185731Sroot mbits |= DZ_ACK|(unit&7); 6195731Sroot dzaddr->dzlcs = mbits; 6205731Sroot } else { 6215731Sroot if (mbits & DZ_DTR) 6225731Sroot dzaddr->dzdtr |= b; 6235731Sroot else 6245731Sroot dzaddr->dzdtr &= ~b; 6255731Sroot } 6265731Sroot (void) splx(s); 6275731Sroot return(mbits); 62817Sbill } 62917Sbill 63017Sbill dzscan() 63117Sbill { 63217Sbill register i; 63317Sbill register struct device *dzaddr; 63417Sbill register bit; 63517Sbill register struct tty *tp; 6365731Sroot register car; 63717Sbill 63817Sbill for (i = 0; i < dz_cnt ; i++) { 63917Sbill dzaddr = dzpdma[i].p_addr; 6402627Swnj if (dzaddr == 0) 6412627Swnj continue; 64217Sbill tp = &dz_tty[i]; 64317Sbill bit = 1<<(i&07); 6445731Sroot car = 0; 6455731Sroot if (dzsoftCAR[i>>3]&bit) 6465731Sroot car = 1; 6475731Sroot else if (dzaddr->dzcsr & DZ_32) { 6485731Sroot dzaddr->dzlcs = i&07; 6495731Sroot dzwait(dzaddr); 6505731Sroot car = dzaddr->dzlcs & DZ_CD; 6515731Sroot } else 6525731Sroot car = dzaddr->dzmsr&bit; 6535731Sroot if (car) { 65417Sbill /* carrier present */ 6555407Swnj if ((tp->t_state & TS_CARR_ON) == 0) { 65617Sbill wakeup((caddr_t)&tp->t_rawq); 6575407Swnj tp->t_state |= TS_CARR_ON; 65817Sbill } 65917Sbill } else { 6605407Swnj if ((tp->t_state&TS_CARR_ON) && 6612469Swnj (tp->t_local&LNOHANG)==0) { 66217Sbill /* carrier lost */ 6635407Swnj if (tp->t_state&TS_ISOPEN) { 664170Sbill gsignal(tp->t_pgrp, SIGHUP); 665205Sbill gsignal(tp->t_pgrp, SIGCONT); 666170Sbill dzaddr->dzdtr &= ~bit; 667871Sbill flushtty(tp, FREAD|FWRITE); 668170Sbill } 6695407Swnj tp->t_state &= ~TS_CARR_ON; 67017Sbill } 67117Sbill } 67217Sbill } 6732756Swnj timeout(dzscan, (caddr_t)0, 2*hz); 67417Sbill } 675119Sbill 676119Sbill dztimer() 677119Sbill { 6788160Sroot register int dz; 6798160Sroot register int s = spl5(); 680119Sbill 6812645Swnj for (dz = 0; dz < NDZ; dz++) 6822457Swnj dzrint(dz); 6838160Sroot splx(s); 684119Sbill } 685281Sbill 686281Sbill /* 687281Sbill * Reset state of driver if UBA reset was necessary. 688301Sbill * Reset parameters and restart transmission on open lines. 689281Sbill */ 6902395Swnj dzreset(uban) 6912422Skre int uban; 692281Sbill { 6932395Swnj register int unit; 694281Sbill register struct tty *tp; 6952976Swnj register struct uba_device *ui; 696281Sbill 6972645Swnj for (unit = 0; unit < NDZLINE; unit++) { 6982422Skre ui = dzinfo[unit >> 3]; 6992422Skre if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0) 7002422Skre continue; 7012923Swnj if (unit%8 == 0) 7022923Swnj printf(" dz%d", unit>>3); 7032395Swnj tp = &dz_tty[unit]; 7045407Swnj if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { 7052395Swnj dzparam(unit); 7066157Ssam (void) dzmctl(unit, DZ_ON, DMSET); 7075407Swnj tp->t_state &= ~TS_BUSY; 708301Sbill dzstart(tp); 709281Sbill } 710281Sbill } 711281Sbill dztimer(); 712281Sbill } 7131562Sbill #endif 714