xref: /csrg-svn/sys/vax/uba/dz.c (revision 7631)
1*7631Ssam /*	dz.c	4.40	82/08/01	*/
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"
26145Sbill 
272469Swnj /*
282469Swnj  * Driver information for auto-configuration stuff.
292469Swnj  */
302606Swnj int	dzprobe(), dzattach(), dzrint();
312976Swnj struct	uba_device *dzinfo[NDZ];
322395Swnj u_short	dzstd[] = { 0 };
332395Swnj struct	uba_driver dzdriver =
342606Swnj 	{ dzprobe, 0, dzattach, 0, dzstd, "dz", dzinfo };
352395Swnj 
362645Swnj #define	NDZLINE 	(NDZ*8)
3717Sbill 
382469Swnj /*
392469Swnj  * Registers and bits
402469Swnj  */
412469Swnj 
425731Sroot /* bits in dzlpr */
435731Sroot #define	BITS7	0020
445731Sroot #define	BITS8	0030
455731Sroot #define	TWOSB	0040
462457Swnj #define	PENABLE	0100
472457Swnj #define	OPAR	0200
4817Sbill 
495731Sroot /* bits in dzrbuf */
502469Swnj #define	DZ_PE	010000
512469Swnj #define	DZ_FE	020000
522469Swnj #define	DZ_DO	040000
532469Swnj 
545731Sroot /* bits in dzcsr */
555731Sroot #define	DZ_32	000001		/* DZ32 mode */
565731Sroot #define	DZ_MIE	000002		/* Modem Interrupt Enable */
575731Sroot #define	DZ_CLR	000020		/* Reset dz */
585731Sroot #define	DZ_MSE	000040		/* Master Scan Enable */
595731Sroot #define	DZ_RIE	000100		/* Receiver Interrupt Enable */
605731Sroot #define DZ_MSC	004000		/* Modem Status Change */
612469Swnj #define	DZ_SAE	010000		/* Silo Alarm Enable */
622469Swnj #define	DZ_TIE	040000		/* Transmit Interrupt Enable */
635731Sroot #define	DZ_IEN	(DZ_32|DZ_MIE|DZ_MSE|DZ_RIE|DZ_TIE|DZ_SAE)
642469Swnj 
655731Sroot /* flags for modem-control */
665731Sroot #define	DZ_ON	DZ_DTR
672469Swnj #define	DZ_OFF	0
685731Sroot 
695731Sroot /* bits in dzlcs */
705731Sroot #define DZ_ACK	0100000		/* ACK bit in dzlcs */
715731Sroot #define DZ_RTS	0010000		/* Request To Send */
725731Sroot #define	DZ_ST	0004000		/* Secondary Transmit */
735731Sroot #define	DZ_BRK	0002000		/* Break */
745731Sroot #define DZ_DTR	0001000		/* Data Terminal Ready */
755731Sroot #define	DZ_LE	0000400		/* Line Enable */
765731Sroot #define	DZ_DSR	0000200		/* Data Set Ready */
775731Sroot #define	DZ_RI	0000100		/* Ring Indicate */
785731Sroot #define DZ_CD	0000040		/* Carrier Detect */
795731Sroot #define	DZ_CTS	0000020		/* Clear To Send */
805731Sroot #define	DZ_SR	0000010		/* Secondary Receive */
8117Sbill 
825731Sroot /* bits in dm lsr, copied from dh.c */
835731Sroot #define	DML_DSR		0000400		/* data set ready, not a real DM bit */
845731Sroot #define	DML_RNG		0000200		/* ring */
855731Sroot #define	DML_CAR		0000100		/* carrier detect */
865731Sroot #define	DML_CTS		0000040		/* clear to send */
875731Sroot #define	DML_SR		0000020		/* secondary receive */
885731Sroot #define	DML_ST		0000010		/* secondary transmit */
895731Sroot #define	DML_RTS		0000004		/* request to send */
905731Sroot #define	DML_DTR		0000002		/* data terminal ready */
915731Sroot #define	DML_LE		0000001		/* line enable */
925731Sroot 
932469Swnj int	dzstart(), dzxint(), dzdma();
94114Sbill int	ttrstrt();
952645Swnj struct	tty dz_tty[NDZLINE];
962645Swnj int	dz_cnt = { NDZLINE };
97119Sbill int	dzact;
9817Sbill 
9917Sbill struct device {
1005731Sroot 	short dzcsr;
1015731Sroot 	short dzrbuf;
1025731Sroot 	union {
1035731Sroot 		struct {
1045731Sroot 			char	dztcr0;
1055731Sroot 			char	dzdtr0;
1065731Sroot 			char	dztbuf0;
1075731Sroot 			char	dzbrk0;
1085731Sroot 		} dz11;
1095731Sroot 		struct {
1105731Sroot 			short	dzlcs0;
1115731Sroot 			char	dztbuf0;
1125731Sroot 			char	dzlnen0;
1135731Sroot 		} dz32;
1145731Sroot 	} dzun;
11517Sbill };
1165731Sroot 
1175731Sroot #define dzlpr	dzrbuf
1185731Sroot #define dzmsr	dzun.dz11.dzbrk0
1195731Sroot #define dztcr	dzun.dz11.dztcr0
1205731Sroot #define dzdtr	dzun.dz11.dzdtr0
1215731Sroot #define dztbuf	dzun.dz11.dztbuf0
1225731Sroot #define dzlcs	dzun.dz32.dzlcs0
1235731Sroot #define	dzbrk	dzmsr
1245731Sroot #define dzlnen	dzun.dz32.dzlnen0
1257406Skre #define dzmtsr	dzun.dz32.dztbuf0
1265731Sroot 
1275731Sroot #define dzwait(x)	while (((x)->dzlcs & DZ_ACK) == 0)
1285731Sroot 
1292469Swnj /*
1302469Swnj  * Software copy of dzbrk since it isn't readable
1312469Swnj  */
1322645Swnj char	dz_brk[NDZ];
1332645Swnj char	dzsoftCAR[NDZ];
1345731Sroot char	dz_lnen[NDZ];	/* saved line enable bits for DZ32 */
13517Sbill 
1362469Swnj /*
1375731Sroot  * The dz11 doesn't interrupt on carrier transitions, so
1382469Swnj  * we have to use a timer to watch it.
1392469Swnj  */
1402469Swnj char	dz_timer;		/* timer started? */
1412469Swnj 
1422469Swnj /*
1432469Swnj  * Pdma structures for fast output code
1442469Swnj  */
1452645Swnj struct	pdma dzpdma[NDZLINE];
1462469Swnj 
1472395Swnj char	dz_speeds[] =
1486814Swnj 	{ 0,020,021,022,023,024,0,025,026,027,030,032,034,036,037,0 };
14917Sbill 
1506616Ssam #ifndef PORTSELECTOR
1516616Ssam #define	ISPEED	B300
1526616Ssam #define	IFLAGS	(EVENP|ODDP|ECHO)
1536616Ssam #else
1546616Ssam #define	ISPEED	B4800
1556616Ssam #define	IFLAGS	(EVENP|ODDP)
1566616Ssam #endif
1576616Ssam 
1582606Swnj dzprobe(reg)
1592395Swnj 	caddr_t reg;
1602395Swnj {
1612457Swnj 	register int br, cvec;
1622457Swnj 	register struct device *dzaddr = (struct device *)reg;
1632395Swnj 
1642606Swnj #ifdef lint
1653102Swnj 	br = 0; cvec = br; br = cvec;
1664933Swnj 	dzrint(0); dzxint((struct tty *)0);
1672606Swnj #endif
1685731Sroot 	dzaddr->dzcsr = DZ_TIE|DZ_MSE|DZ_32;
1695731Sroot 	if (dzaddr->dzcsr & DZ_32)
1705731Sroot 		dzaddr->dzlnen = 1;
1715731Sroot 	else
1725731Sroot 		dzaddr->dztcr = 1;		/* enable any line */
1732457Swnj 	DELAY(100000);
1745731Sroot 	dzaddr->dzcsr = DZ_CLR|DZ_32;		/* reset everything */
1752457Swnj 	if (cvec && cvec != 0x200)
1762457Swnj 		cvec -= 4;
1777406Skre 	return (sizeof (struct device));
1782395Swnj }
1792395Swnj 
1802606Swnj dzattach(ui)
1812976Swnj 	register struct uba_device *ui;
1822395Swnj {
1832395Swnj 	register struct pdma *pdp = &dzpdma[ui->ui_unit*8];
1842395Swnj 	register struct tty *tp = &dz_tty[ui->ui_unit*8];
1852606Swnj 	register int cntr;
1862645Swnj 	extern dzscan();
1872395Swnj 
1882606Swnj 	for (cntr = 0; cntr < 8; cntr++) {
1892606Swnj 		pdp->p_addr = (struct device *)ui->ui_addr;
1902395Swnj 		pdp->p_arg = (int)tp;
1912395Swnj 		pdp->p_fcn = dzxint;
1922395Swnj 		pdp++, tp++;
1932395Swnj 	}
1942567Swnj 	dzsoftCAR[ui->ui_unit] = ui->ui_flags;
1952627Swnj 	if (dz_timer == 0) {
1962627Swnj 		dz_timer++;
1972756Swnj 		timeout(dzscan, (caddr_t)0, hz);
1982627Swnj 	}
1992395Swnj }
2002395Swnj 
20117Sbill /*ARGSUSED*/
2022395Swnj dzopen(dev, flag)
2032395Swnj 	dev_t dev;
20417Sbill {
20517Sbill 	register struct tty *tp;
2062395Swnj 	register int unit;
20717Sbill 
2082395Swnj 	unit = minor(dev);
2092395Swnj 	if (unit >= dz_cnt || dzpdma[unit].p_addr == 0) {
21017Sbill 		u.u_error = ENXIO;
21117Sbill 		return;
21217Sbill 	}
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);
2235407Swnj 	} else if (tp->t_state&TS_XCLUDE && u.u_uid != 0) {
22417Sbill 		u.u_error = EBUSY;
22517Sbill 		return;
22617Sbill 	}
2276157Ssam 	(void) dzmctl(dev, DZ_ON, DMSET);
228114Sbill 	(void) spl5();
2295407Swnj 	while ((tp->t_state & TS_CARR_ON) == 0) {
2305407Swnj 		tp->t_state |= TS_WOPEN;
23117Sbill 		sleep((caddr_t)&tp->t_rawq, TTIPRI);
23217Sbill 	}
233114Sbill 	(void) spl0();
2342395Swnj 	(*linesw[tp->t_line].l_open)(dev, tp);
23517Sbill }
23617Sbill 
2372395Swnj /*ARGSUSED*/
2382395Swnj dzclose(dev, flag)
2392395Swnj 	dev_t dev;
24017Sbill {
24117Sbill 	register struct tty *tp;
2422395Swnj 	register int unit;
2435731Sroot 	register struct device *dzaddr;
2446150Ssam 	int dz;
24517Sbill 
2462395Swnj 	unit = minor(dev);
2472395Swnj 	dz = unit >> 3;
2482395Swnj 	tp = &dz_tty[unit];
24917Sbill 	(*linesw[tp->t_line].l_close)(tp);
2505731Sroot 	dzaddr = dzpdma[unit].p_addr;
2515731Sroot 	if (dzaddr->dzcsr&DZ_32)
2526157Ssam 		(void) dzmctl(dev, DZ_BRK, DMBIC);
2535731Sroot 	else
2545731Sroot 		dzaddr->dzbrk = (dz_brk[dz] &= ~(1 << (unit&07)));
2556842Swnj 	if ((tp->t_state&(TS_HUPCLS|TS_WOPEN)) || (tp->t_state&TS_ISOPEN) == 0)
2566157Ssam 		(void) dzmctl(dev, DZ_OFF, DMSET);
25717Sbill 	ttyclose(tp);
25817Sbill }
25917Sbill 
2602395Swnj dzread(dev)
2612395Swnj 	dev_t dev;
26217Sbill {
26317Sbill 	register struct tty *tp;
26417Sbill 
2652395Swnj 	tp = &dz_tty[minor(dev)];
26617Sbill 	(*linesw[tp->t_line].l_read)(tp);
26717Sbill }
26817Sbill 
2692395Swnj dzwrite(dev)
2702395Swnj 	dev_t dev;
27117Sbill {
27217Sbill 	register struct tty *tp;
27317Sbill 
2742395Swnj 	tp = &dz_tty[minor(dev)];
27517Sbill 	(*linesw[tp->t_line].l_write)(tp);
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*/
354*7631Ssam dzioctl(dev, cmd, data, flag)
3552395Swnj 	dev_t dev;
356*7631Ssam 	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;
36217Sbill 
3632395Swnj 	tp = &dz_tty[unit];
364*7631Ssam 	cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag);
365114Sbill 	if (cmd == 0)
366114Sbill 		return;
367*7631Ssam 	if (ttioctl(tp, cmd, data, flag)) {
368*7631Ssam 		if (cmd == TIOCSETP || cmd == TIOCSETN)
3692395Swnj 			dzparam(unit);
370170Sbill 	} else switch(cmd) {
3712395Swnj 
372170Sbill 	case TIOCSBRK:
3735731Sroot 		dzaddr = ((struct pdma *)(tp->t_addr))->p_addr;
3745731Sroot 		if (dzaddr->dzcsr&DZ_32)
3756157Ssam 			(void) dzmctl(dev, DZ_BRK, DMBIS);
3765731Sroot 		else
3775731Sroot 			dzaddr->dzbrk = (dz_brk[dz] |= 1 << (unit&07));
378170Sbill 		break;
379*7631Ssam 
380170Sbill 	case TIOCCBRK:
3815731Sroot 		dzaddr = ((struct pdma *)(tp->t_addr))->p_addr;
3825731Sroot 		if (dzaddr->dzcsr&DZ_32)
3836157Ssam 			(void) dzmctl(dev, DZ_BRK, DMBIC);
3845731Sroot 		else
3855731Sroot 			dzaddr->dzbrk = (dz_brk[dz] &= ~(1 << (unit&07)));
386170Sbill 		break;
387*7631Ssam 
388170Sbill 	case TIOCSDTR:
3896157Ssam 		(void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIS);
390170Sbill 		break;
391*7631Ssam 
392170Sbill 	case TIOCCDTR:
3936157Ssam 		(void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIC);
394170Sbill 		break;
395*7631Ssam 
3965731Sroot 	case TIOCMSET:
397*7631Ssam 		(void) dzmctl(dev, dmtodz(*(int *)data), DMSET);
3985731Sroot 		break;
399*7631Ssam 
4005731Sroot 	case TIOCMBIS:
401*7631Ssam 		(void) dzmctl(dev, dmtodz(*(int *)data), DMBIS);
4025731Sroot 		break;
403*7631Ssam 
4045731Sroot 	case TIOCMBIC:
405*7631Ssam 		(void) dzmctl(dev, dmtodz(*(int *)data), DMBIC);
4065731Sroot 		break;
407*7631Ssam 
4085731Sroot 	case TIOCMGET:
409*7631Ssam 		*(int *)data = dztodm(dzmctl(dev, 0, DMGET));
4105731Sroot 		break;
411*7631Ssam 
412170Sbill 	default:
41317Sbill 		u.u_error = ENOTTY;
414170Sbill 	}
41517Sbill }
4165731Sroot 
4175731Sroot dmtodz(bits)
4185731Sroot 	register int bits;
4195731Sroot {
4205731Sroot 	register int b;
4215731Sroot 
4225731Sroot 	b = (bits >>1) & 0370;
4235731Sroot 	if (bits & DML_ST) b |= DZ_ST;
4245731Sroot 	if (bits & DML_RTS) b |= DZ_RTS;
4255731Sroot 	if (bits & DML_DTR) b |= DZ_DTR;
4265731Sroot 	if (bits & DML_LE) b |= DZ_LE;
4275731Sroot 	return(b);
4285731Sroot }
4295731Sroot 
4305731Sroot dztodm(bits)
4315731Sroot 	register int bits;
4325731Sroot {
4335731Sroot 	register int b;
4345731Sroot 
4355731Sroot 	b = (bits << 1) & 0360;
4365731Sroot 	if (bits & DZ_DSR) b |= DML_DSR;
4375731Sroot 	if (bits & DZ_DTR) b |= DML_DTR;
4385731Sroot 	if (bits & DZ_ST) b |= DML_ST;
4395731Sroot 	if (bits & DZ_RTS) b |= DML_RTS;
4405731Sroot 	return(b);
4415731Sroot }
44217Sbill 
4432395Swnj dzparam(unit)
4442395Swnj 	register int unit;
44517Sbill {
44617Sbill 	register struct tty *tp;
44717Sbill 	register struct device *dzaddr;
4482395Swnj 	register int lpr;
44917Sbill 
4502395Swnj 	tp = &dz_tty[unit];
4512395Swnj 	dzaddr = dzpdma[unit].p_addr;
45217Sbill 	dzaddr->dzcsr = DZ_IEN;
4532395Swnj 	dzact |= (1<<(unit>>3));
45417Sbill 	if (tp->t_ispeed == 0) {
4556157Ssam 		(void) dzmctl(unit, DZ_OFF, DMSET);	/* hang up line */
45617Sbill 		return;
45717Sbill 	}
4582395Swnj 	lpr = (dz_speeds[tp->t_ispeed]<<8) | (unit & 07);
4592296Swnj 	if ((tp->t_local&LLITOUT) || (tp->t_flags&RAW))
46017Sbill 		lpr |= BITS8;
46117Sbill 	else
46217Sbill 		lpr |= (BITS7|PENABLE);
46317Sbill 	if ((tp->t_flags & EVENP) == 0)
46417Sbill 		lpr |= OPAR;
4652469Swnj 	if (tp->t_ispeed == B110)
4662469Swnj 		lpr |= TWOSB;
46717Sbill 	dzaddr->dzlpr = lpr;
46817Sbill }
46917Sbill 
47017Sbill dzxint(tp)
4712395Swnj 	register struct tty *tp;
47217Sbill {
47317Sbill 	register struct pdma *dp;
4745731Sroot 	register s, dz, unit;
47517Sbill 
4762469Swnj 	s = spl5();		/* block pdma interrupts */
4772395Swnj 	dp = (struct pdma *)tp->t_addr;
4785407Swnj 	tp->t_state &= ~TS_BUSY;
4795407Swnj 	if (tp->t_state & TS_FLUSH)
4805407Swnj 		tp->t_state &= ~TS_FLUSH;
4815731Sroot 	else {
482281Sbill 		ndflush(&tp->t_outq, dp->p_mem-tp->t_outq.c_cf);
4835731Sroot 		dp->p_end = dp->p_mem = tp->t_outq.c_cf;
4845731Sroot 	}
48517Sbill 	if (tp->t_line)
48617Sbill 		(*linesw[tp->t_line].l_start)(tp);
48717Sbill 	else
48817Sbill 		dzstart(tp);
4895731Sroot 	dz = minor(tp->t_dev) >> 3;
4905731Sroot 	unit = minor(tp->t_dev) & 7;
4915407Swnj 	if (tp->t_outq.c_cc == 0 || (tp->t_state&TS_BUSY)==0)
4925731Sroot 		if (dp->p_addr->dzcsr & DZ_32)
4935731Sroot 			dp->p_addr->dzlnen = (dz_lnen[dz] &= ~(1<<unit));
4945731Sroot 		else
4955731Sroot 			dp->p_addr->dztcr &= ~(1<<unit);
496145Sbill 	splx(s);
49717Sbill }
49817Sbill 
49917Sbill dzstart(tp)
5002395Swnj 	register struct tty *tp;
50117Sbill {
50217Sbill 	register struct pdma *dp;
50317Sbill 	register struct device *dzaddr;
5042395Swnj 	register int cc;
5055731Sroot 	int s, dz, unit;
50617Sbill 
5072395Swnj 	dp = (struct pdma *)tp->t_addr;
50817Sbill 	dzaddr = dp->p_addr;
5092395Swnj 	s = spl5();
5105407Swnj 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
51117Sbill 		goto out;
5125407Swnj 	if (tp->t_outq.c_cc <= TTLOWAT(tp)) {
5135407Swnj 		if (tp->t_state&TS_ASLEEP) {
5145407Swnj 			tp->t_state &= ~TS_ASLEEP;
5155407Swnj 			wakeup((caddr_t)&tp->t_outq);
5165407Swnj 		}
5175407Swnj 		if (tp->t_wsel) {
5185407Swnj 			selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
5195407Swnj 			tp->t_wsel = 0;
5205407Swnj 			tp->t_state &= ~TS_WCOLL;
5215407Swnj 		}
52217Sbill 	}
52317Sbill 	if (tp->t_outq.c_cc == 0)
52417Sbill 		goto out;
5255731Sroot 	if ((tp->t_flags&RAW) || (tp->t_local&LLITOUT))
52617Sbill 		cc = ndqb(&tp->t_outq, 0);
52717Sbill 	else {
52817Sbill 		cc = ndqb(&tp->t_outq, 0200);
52917Sbill 		if (cc == 0) {
53017Sbill 			cc = getc(&tp->t_outq);
5312469Swnj 			timeout(ttrstrt, (caddr_t)tp, (cc&0x7f) + 6);
5325407Swnj 			tp->t_state |= TS_TIMEOUT;
53317Sbill 			goto out;
53417Sbill 		}
53517Sbill 	}
5365407Swnj 	tp->t_state |= TS_BUSY;
53717Sbill 	dp->p_end = dp->p_mem = tp->t_outq.c_cf;
53817Sbill 	dp->p_end += cc;
5395731Sroot 	dz = minor(tp->t_dev) >> 3;
5405731Sroot 	unit = minor(tp->t_dev) & 7;
5415731Sroot 	if (dzaddr->dzcsr & DZ_32)
5425731Sroot 		dzaddr->dzlnen = (dz_lnen[dz] |= (1<<unit));
5435731Sroot 	else
5445731Sroot 		dzaddr->dztcr |= (1<<unit);
5452395Swnj out:
5462395Swnj 	splx(s);
54717Sbill }
54817Sbill 
54917Sbill /*
55017Sbill  * Stop output on a line.
55117Sbill  */
55217Sbill /*ARGSUSED*/
55317Sbill dzstop(tp, flag)
5542395Swnj 	register struct tty *tp;
55517Sbill {
55617Sbill 	register struct pdma *dp;
55717Sbill 	register int s;
55817Sbill 
5592395Swnj 	dp = (struct pdma *)tp->t_addr;
5602457Swnj 	s = spl5();
5615407Swnj 	if (tp->t_state & TS_BUSY) {
56217Sbill 		dp->p_end = dp->p_mem;
5635407Swnj 		if ((tp->t_state&TS_TTSTOP)==0)
5645407Swnj 			tp->t_state |= TS_FLUSH;
56517Sbill 	}
56617Sbill 	splx(s);
56717Sbill }
56817Sbill 
5695731Sroot dzmctl(dev, bits, how)
5705731Sroot 	dev_t dev;
5715731Sroot 	int bits, how;
57217Sbill {
57317Sbill 	register struct device *dzaddr;
5745731Sroot 	register int unit, mbits;
5755731Sroot 	int b, s;
5765731Sroot 
5775731Sroot 	unit = minor(dev);
5785731Sroot 	b = 1<<(unit&7);
5792395Swnj 	dzaddr = dzpdma[unit].p_addr;
5805731Sroot 	s = spl5();
5815731Sroot 	if (dzaddr->dzcsr & DZ_32) {
5825731Sroot 		dzwait(dzaddr)
5835731Sroot 		DELAY(100);		/* IS 100 TOO MUCH? */
5845731Sroot 		dzaddr->dzlcs = unit&7;
5855731Sroot 		DELAY(100);
5865731Sroot 		dzwait(dzaddr)
5875731Sroot 		DELAY(100);
5885731Sroot 		mbits = dzaddr->dzlcs;
5895731Sroot 		mbits &= 0177770;
5905731Sroot 	} else {
5915731Sroot 		mbits = (dzaddr->dzdtr & b) ? DZ_DTR : 0;
5925731Sroot 		mbits |= (dzaddr->dzmsr & b) ? DZ_CD : 0;
5935731Sroot 		mbits |= (dzaddr->dztbuf & b) ? DZ_RI : 0;
5945731Sroot 	}
5955731Sroot 	switch (how) {
5965731Sroot 	case DMSET:
5975731Sroot 		mbits = bits;
5985731Sroot 		break;
5995731Sroot 
6005731Sroot 	case DMBIS:
6015731Sroot 		mbits |= bits;
6025731Sroot 		break;
6035731Sroot 
6045731Sroot 	case DMBIC:
6055731Sroot 		mbits &= ~bits;
6065731Sroot 		break;
6075731Sroot 
6085731Sroot 	case DMGET:
6095731Sroot 		(void) splx(s);
6105731Sroot 		return(mbits);
6115731Sroot 	}
6125731Sroot 	if (dzaddr->dzcsr & DZ_32) {
6135731Sroot 		mbits |= DZ_ACK|(unit&7);
6145731Sroot 		dzaddr->dzlcs = mbits;
6155731Sroot 	} else {
6165731Sroot 		if (mbits & DZ_DTR)
6175731Sroot 			dzaddr->dzdtr |= b;
6185731Sroot 		else
6195731Sroot 			dzaddr->dzdtr &= ~b;
6205731Sroot 	}
6215731Sroot 	(void) splx(s);
6225731Sroot 	return(mbits);
62317Sbill }
62417Sbill 
62517Sbill dzscan()
62617Sbill {
62717Sbill 	register i;
62817Sbill 	register struct device *dzaddr;
62917Sbill 	register bit;
63017Sbill 	register struct tty *tp;
6315731Sroot 	register car;
63217Sbill 
63317Sbill 	for (i = 0; i < dz_cnt ; i++) {
63417Sbill 		dzaddr = dzpdma[i].p_addr;
6352627Swnj 		if (dzaddr == 0)
6362627Swnj 			continue;
63717Sbill 		tp = &dz_tty[i];
63817Sbill 		bit = 1<<(i&07);
6395731Sroot 		car = 0;
6405731Sroot 		if (dzsoftCAR[i>>3]&bit)
6415731Sroot 			car = 1;
6425731Sroot 		else if (dzaddr->dzcsr & DZ_32) {
6435731Sroot 			dzaddr->dzlcs = i&07;
6445731Sroot 			dzwait(dzaddr);
6455731Sroot 			car = dzaddr->dzlcs & DZ_CD;
6465731Sroot 		} else
6475731Sroot 			car = dzaddr->dzmsr&bit;
6485731Sroot 		if (car) {
64917Sbill 			/* carrier present */
6505407Swnj 			if ((tp->t_state & TS_CARR_ON) == 0) {
65117Sbill 				wakeup((caddr_t)&tp->t_rawq);
6525407Swnj 				tp->t_state |= TS_CARR_ON;
65317Sbill 			}
65417Sbill 		} else {
6555407Swnj 			if ((tp->t_state&TS_CARR_ON) &&
6562469Swnj 			    (tp->t_local&LNOHANG)==0) {
65717Sbill 				/* carrier lost */
6585407Swnj 				if (tp->t_state&TS_ISOPEN) {
659170Sbill 					gsignal(tp->t_pgrp, SIGHUP);
660205Sbill 					gsignal(tp->t_pgrp, SIGCONT);
661170Sbill 					dzaddr->dzdtr &= ~bit;
662871Sbill 					flushtty(tp, FREAD|FWRITE);
663170Sbill 				}
6645407Swnj 				tp->t_state &= ~TS_CARR_ON;
66517Sbill 			}
66617Sbill 		}
66717Sbill 	}
6682756Swnj 	timeout(dzscan, (caddr_t)0, 2*hz);
66917Sbill }
670119Sbill 
671119Sbill dztimer()
672119Sbill {
6732457Swnj 	int dz;
674119Sbill 
6752645Swnj 	for (dz = 0; dz < NDZ; dz++)
6762457Swnj 		dzrint(dz);
677119Sbill }
678281Sbill 
679281Sbill /*
680281Sbill  * Reset state of driver if UBA reset was necessary.
681301Sbill  * Reset parameters and restart transmission on open lines.
682281Sbill  */
6832395Swnj dzreset(uban)
6842422Skre 	int uban;
685281Sbill {
6862395Swnj 	register int unit;
687281Sbill 	register struct tty *tp;
6882976Swnj 	register struct uba_device *ui;
689281Sbill 
6902645Swnj 	for (unit = 0; unit < NDZLINE; unit++) {
6912422Skre 		ui = dzinfo[unit >> 3];
6922422Skre 		if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0)
6932422Skre 			continue;
6942923Swnj 		if (unit%8 == 0)
6952923Swnj 			printf(" dz%d", unit>>3);
6962395Swnj 		tp = &dz_tty[unit];
6975407Swnj 		if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) {
6982395Swnj 			dzparam(unit);
6996157Ssam 			(void) dzmctl(unit, DZ_ON, DMSET);
7005407Swnj 			tp->t_state &= ~TS_BUSY;
701301Sbill 			dzstart(tp);
702281Sbill 		}
703281Sbill 	}
704281Sbill 	dztimer();
705281Sbill }
7061562Sbill #endif
707