xref: /csrg-svn/sys/vax/uba/dz.c (revision 6616)
1*6616Ssam /*	dz.c	4.36	82/05/04	*/
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
1255731Sroot #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[] =
1482395Swnj 	{ 0,020,021,022,023,024,0,025,026,027,030,032,034,036,0,0 };
14917Sbill 
150*6616Ssam #ifndef PORTSELECTOR
151*6616Ssam #define	ISPEED	B300
152*6616Ssam #define	IFLAGS	(EVENP|ODDP|ECHO)
153*6616Ssam #else
154*6616Ssam #define	ISPEED	B4800
155*6616Ssam #define	IFLAGS	(EVENP|ODDP)
156*6616Ssam #endif
157*6616Ssam 
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;
1772457Swnj 	return (1);
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);
219*6616Ssam 		tp->t_ospeed = tp->t_ispeed = ISPEED;
220*6616Ssam 		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)));
2555731Sroot 	if ((tp->t_state&TS_HUPCLS) || (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);
325*6616Ssam #ifdef PORTSELECTOR
326*6616Ssam 			if ((tp->t_state&TS_WOPEN) == 0)
327*6616Ssam #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*/
35417Sbill dzioctl(dev, cmd, addr, flag)
3552395Swnj 	dev_t dev;
3562395Swnj 	caddr_t addr;
35717Sbill {
35817Sbill 	register struct tty *tp;
3592395Swnj 	register int unit = minor(dev);
3602395Swnj 	register int dz = unit >> 3;
3615731Sroot 	register struct device *dzaddr;
3625731Sroot 	int temp;
36317Sbill 
3642395Swnj 	tp = &dz_tty[unit];
365114Sbill 	cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr);
366114Sbill 	if (cmd == 0)
367114Sbill 		return;
3681896Swnj 	if (ttioctl(tp, cmd, addr, flag)) {
36917Sbill 		if (cmd==TIOCSETP || cmd==TIOCSETN)
3702395Swnj 			dzparam(unit);
371170Sbill 	} else switch(cmd) {
3722395Swnj 
373170Sbill 	case TIOCSBRK:
3745731Sroot 		dzaddr = ((struct pdma *)(tp->t_addr))->p_addr;
3755731Sroot 		if (dzaddr->dzcsr&DZ_32)
3766157Ssam 			(void) dzmctl(dev, DZ_BRK, DMBIS);
3775731Sroot 		else
3785731Sroot 			dzaddr->dzbrk = (dz_brk[dz] |= 1 << (unit&07));
379170Sbill 		break;
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;
387170Sbill 	case TIOCSDTR:
3886157Ssam 		(void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIS);
389170Sbill 		break;
390170Sbill 	case TIOCCDTR:
3916157Ssam 		(void) dzmctl(dev, DZ_DTR|DZ_RTS, DMBIC);
392170Sbill 		break;
3935731Sroot 	case TIOCMSET:
3945731Sroot 		if (copyin(addr, (caddr_t) &temp, sizeof(temp)))
3955731Sroot 			u.u_error = EFAULT;
3965731Sroot 		else
3976157Ssam 			(void) dzmctl(dev, dmtodz(temp), DMSET);
3985731Sroot 		break;
3995731Sroot 	case TIOCMBIS:
4005731Sroot 		if (copyin(addr, (caddr_t) &temp, sizeof(temp)))
4015731Sroot 			u.u_error = EFAULT;
4025731Sroot 		else
4036157Ssam 			(void) dzmctl(dev, dmtodz(temp), DMBIS);
4045731Sroot 		break;
4055731Sroot 	case TIOCMBIC:
4065731Sroot 		if (copyin(addr, (caddr_t) &temp, sizeof(temp)))
4075731Sroot 			u.u_error = EFAULT;
4085731Sroot 		else
4096157Ssam 			(void) dzmctl(dev, dmtodz(temp), DMBIC);
4105731Sroot 		break;
4115731Sroot 	case TIOCMGET:
4125731Sroot 		temp = dztodm(dzmctl(dev, 0, DMGET));
4135731Sroot 		if (copyout((caddr_t) &temp, addr, sizeof(temp)))
4145731Sroot 			u.u_error = EFAULT;
4155731Sroot 		break;
416170Sbill 	default:
41717Sbill 		u.u_error = ENOTTY;
418170Sbill 	}
41917Sbill }
4205731Sroot 
4215731Sroot dmtodz(bits)
4225731Sroot 	register int bits;
4235731Sroot {
4245731Sroot 	register int b;
4255731Sroot 
4265731Sroot 	b = (bits >>1) & 0370;
4275731Sroot 	if (bits & DML_ST) b |= DZ_ST;
4285731Sroot 	if (bits & DML_RTS) b |= DZ_RTS;
4295731Sroot 	if (bits & DML_DTR) b |= DZ_DTR;
4305731Sroot 	if (bits & DML_LE) b |= DZ_LE;
4315731Sroot 	return(b);
4325731Sroot }
4335731Sroot 
4345731Sroot dztodm(bits)
4355731Sroot 	register int bits;
4365731Sroot {
4375731Sroot 	register int b;
4385731Sroot 
4395731Sroot 	b = (bits << 1) & 0360;
4405731Sroot 	if (bits & DZ_DSR) b |= DML_DSR;
4415731Sroot 	if (bits & DZ_DTR) b |= DML_DTR;
4425731Sroot 	if (bits & DZ_ST) b |= DML_ST;
4435731Sroot 	if (bits & DZ_RTS) b |= DML_RTS;
4445731Sroot 	return(b);
4455731Sroot }
44617Sbill 
4472395Swnj dzparam(unit)
4482395Swnj 	register int unit;
44917Sbill {
45017Sbill 	register struct tty *tp;
45117Sbill 	register struct device *dzaddr;
4522395Swnj 	register int lpr;
45317Sbill 
4542395Swnj 	tp = &dz_tty[unit];
4552395Swnj 	dzaddr = dzpdma[unit].p_addr;
45617Sbill 	dzaddr->dzcsr = DZ_IEN;
4572395Swnj 	dzact |= (1<<(unit>>3));
45817Sbill 	if (tp->t_ispeed == 0) {
4596157Ssam 		(void) dzmctl(unit, DZ_OFF, DMSET);	/* hang up line */
46017Sbill 		return;
46117Sbill 	}
4622395Swnj 	lpr = (dz_speeds[tp->t_ispeed]<<8) | (unit & 07);
4632296Swnj 	if ((tp->t_local&LLITOUT) || (tp->t_flags&RAW))
46417Sbill 		lpr |= BITS8;
46517Sbill 	else
46617Sbill 		lpr |= (BITS7|PENABLE);
46717Sbill 	if ((tp->t_flags & EVENP) == 0)
46817Sbill 		lpr |= OPAR;
4692469Swnj 	if (tp->t_ispeed == B110)
4702469Swnj 		lpr |= TWOSB;
47117Sbill 	dzaddr->dzlpr = lpr;
47217Sbill }
47317Sbill 
47417Sbill dzxint(tp)
4752395Swnj 	register struct tty *tp;
47617Sbill {
47717Sbill 	register struct pdma *dp;
4785731Sroot 	register s, dz, unit;
47917Sbill 
4802469Swnj 	s = spl5();		/* block pdma interrupts */
4812395Swnj 	dp = (struct pdma *)tp->t_addr;
4825407Swnj 	tp->t_state &= ~TS_BUSY;
4835407Swnj 	if (tp->t_state & TS_FLUSH)
4845407Swnj 		tp->t_state &= ~TS_FLUSH;
4855731Sroot 	else {
486281Sbill 		ndflush(&tp->t_outq, dp->p_mem-tp->t_outq.c_cf);
4875731Sroot 		dp->p_end = dp->p_mem = tp->t_outq.c_cf;
4885731Sroot 	}
48917Sbill 	if (tp->t_line)
49017Sbill 		(*linesw[tp->t_line].l_start)(tp);
49117Sbill 	else
49217Sbill 		dzstart(tp);
4935731Sroot 	dz = minor(tp->t_dev) >> 3;
4945731Sroot 	unit = minor(tp->t_dev) & 7;
4955407Swnj 	if (tp->t_outq.c_cc == 0 || (tp->t_state&TS_BUSY)==0)
4965731Sroot 		if (dp->p_addr->dzcsr & DZ_32)
4975731Sroot 			dp->p_addr->dzlnen = (dz_lnen[dz] &= ~(1<<unit));
4985731Sroot 		else
4995731Sroot 			dp->p_addr->dztcr &= ~(1<<unit);
500145Sbill 	splx(s);
50117Sbill }
50217Sbill 
50317Sbill dzstart(tp)
5042395Swnj 	register struct tty *tp;
50517Sbill {
50617Sbill 	register struct pdma *dp;
50717Sbill 	register struct device *dzaddr;
5082395Swnj 	register int cc;
5095731Sroot 	int s, dz, unit;
51017Sbill 
5112395Swnj 	dp = (struct pdma *)tp->t_addr;
51217Sbill 	dzaddr = dp->p_addr;
5132395Swnj 	s = spl5();
5145407Swnj 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
51517Sbill 		goto out;
5165407Swnj 	if (tp->t_outq.c_cc <= TTLOWAT(tp)) {
5175407Swnj 		if (tp->t_state&TS_ASLEEP) {
5185407Swnj 			tp->t_state &= ~TS_ASLEEP;
5195407Swnj 			wakeup((caddr_t)&tp->t_outq);
5205407Swnj 		}
5215407Swnj 		if (tp->t_wsel) {
5225407Swnj 			selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
5235407Swnj 			tp->t_wsel = 0;
5245407Swnj 			tp->t_state &= ~TS_WCOLL;
5255407Swnj 		}
52617Sbill 	}
52717Sbill 	if (tp->t_outq.c_cc == 0)
52817Sbill 		goto out;
5295731Sroot 	if ((tp->t_flags&RAW) || (tp->t_local&LLITOUT))
53017Sbill 		cc = ndqb(&tp->t_outq, 0);
53117Sbill 	else {
53217Sbill 		cc = ndqb(&tp->t_outq, 0200);
53317Sbill 		if (cc == 0) {
53417Sbill 			cc = getc(&tp->t_outq);
5352469Swnj 			timeout(ttrstrt, (caddr_t)tp, (cc&0x7f) + 6);
5365407Swnj 			tp->t_state |= TS_TIMEOUT;
53717Sbill 			goto out;
53817Sbill 		}
53917Sbill 	}
5405407Swnj 	tp->t_state |= TS_BUSY;
54117Sbill 	dp->p_end = dp->p_mem = tp->t_outq.c_cf;
54217Sbill 	dp->p_end += cc;
5435731Sroot 	dz = minor(tp->t_dev) >> 3;
5445731Sroot 	unit = minor(tp->t_dev) & 7;
5455731Sroot 	if (dzaddr->dzcsr & DZ_32)
5465731Sroot 		dzaddr->dzlnen = (dz_lnen[dz] |= (1<<unit));
5475731Sroot 	else
5485731Sroot 		dzaddr->dztcr |= (1<<unit);
5492395Swnj out:
5502395Swnj 	splx(s);
55117Sbill }
55217Sbill 
55317Sbill /*
55417Sbill  * Stop output on a line.
55517Sbill  */
55617Sbill /*ARGSUSED*/
55717Sbill dzstop(tp, flag)
5582395Swnj 	register struct tty *tp;
55917Sbill {
56017Sbill 	register struct pdma *dp;
56117Sbill 	register int s;
56217Sbill 
5632395Swnj 	dp = (struct pdma *)tp->t_addr;
5642457Swnj 	s = spl5();
5655407Swnj 	if (tp->t_state & TS_BUSY) {
56617Sbill 		dp->p_end = dp->p_mem;
5675407Swnj 		if ((tp->t_state&TS_TTSTOP)==0)
5685407Swnj 			tp->t_state |= TS_FLUSH;
56917Sbill 	}
57017Sbill 	splx(s);
57117Sbill }
57217Sbill 
5735731Sroot dzmctl(dev, bits, how)
5745731Sroot 	dev_t dev;
5755731Sroot 	int bits, how;
57617Sbill {
57717Sbill 	register struct device *dzaddr;
5785731Sroot 	register int unit, mbits;
5795731Sroot 	int b, s;
5805731Sroot 
5815731Sroot 	unit = minor(dev);
5825731Sroot 	b = 1<<(unit&7);
5832395Swnj 	dzaddr = dzpdma[unit].p_addr;
5845731Sroot 	s = spl5();
5855731Sroot 	if (dzaddr->dzcsr & DZ_32) {
5865731Sroot 		dzwait(dzaddr)
5875731Sroot 		DELAY(100);		/* IS 100 TOO MUCH? */
5885731Sroot 		dzaddr->dzlcs = unit&7;
5895731Sroot 		DELAY(100);
5905731Sroot 		dzwait(dzaddr)
5915731Sroot 		DELAY(100);
5925731Sroot 		mbits = dzaddr->dzlcs;
5935731Sroot 		mbits &= 0177770;
5945731Sroot 	} else {
5955731Sroot 		mbits = (dzaddr->dzdtr & b) ? DZ_DTR : 0;
5965731Sroot 		mbits |= (dzaddr->dzmsr & b) ? DZ_CD : 0;
5975731Sroot 		mbits |= (dzaddr->dztbuf & b) ? DZ_RI : 0;
5985731Sroot 	}
5995731Sroot 	switch (how) {
6005731Sroot 	case DMSET:
6015731Sroot 		mbits = bits;
6025731Sroot 		break;
6035731Sroot 
6045731Sroot 	case DMBIS:
6055731Sroot 		mbits |= bits;
6065731Sroot 		break;
6075731Sroot 
6085731Sroot 	case DMBIC:
6095731Sroot 		mbits &= ~bits;
6105731Sroot 		break;
6115731Sroot 
6125731Sroot 	case DMGET:
6135731Sroot 		(void) splx(s);
6145731Sroot 		return(mbits);
6155731Sroot 	}
6165731Sroot 	if (dzaddr->dzcsr & DZ_32) {
6175731Sroot 		mbits |= DZ_ACK|(unit&7);
6185731Sroot 		dzaddr->dzlcs = mbits;
6195731Sroot 	} else {
6205731Sroot 		if (mbits & DZ_DTR)
6215731Sroot 			dzaddr->dzdtr |= b;
6225731Sroot 		else
6235731Sroot 			dzaddr->dzdtr &= ~b;
6245731Sroot 	}
6255731Sroot 	(void) splx(s);
6265731Sroot 	return(mbits);
62717Sbill }
62817Sbill 
62917Sbill dzscan()
63017Sbill {
63117Sbill 	register i;
63217Sbill 	register struct device *dzaddr;
63317Sbill 	register bit;
63417Sbill 	register struct tty *tp;
6355731Sroot 	register car;
63617Sbill 
63717Sbill 	for (i = 0; i < dz_cnt ; i++) {
63817Sbill 		dzaddr = dzpdma[i].p_addr;
6392627Swnj 		if (dzaddr == 0)
6402627Swnj 			continue;
64117Sbill 		tp = &dz_tty[i];
64217Sbill 		bit = 1<<(i&07);
6435731Sroot 		car = 0;
6445731Sroot 		if (dzsoftCAR[i>>3]&bit)
6455731Sroot 			car = 1;
6465731Sroot 		else if (dzaddr->dzcsr & DZ_32) {
6475731Sroot 			dzaddr->dzlcs = i&07;
6485731Sroot 			dzwait(dzaddr);
6495731Sroot 			car = dzaddr->dzlcs & DZ_CD;
6505731Sroot 		} else
6515731Sroot 			car = dzaddr->dzmsr&bit;
6525731Sroot 		if (car) {
65317Sbill 			/* carrier present */
6545407Swnj 			if ((tp->t_state & TS_CARR_ON) == 0) {
65517Sbill 				wakeup((caddr_t)&tp->t_rawq);
6565407Swnj 				tp->t_state |= TS_CARR_ON;
65717Sbill 			}
65817Sbill 		} else {
6595407Swnj 			if ((tp->t_state&TS_CARR_ON) &&
6602469Swnj 			    (tp->t_local&LNOHANG)==0) {
66117Sbill 				/* carrier lost */
6625407Swnj 				if (tp->t_state&TS_ISOPEN) {
663170Sbill 					gsignal(tp->t_pgrp, SIGHUP);
664205Sbill 					gsignal(tp->t_pgrp, SIGCONT);
665170Sbill 					dzaddr->dzdtr &= ~bit;
666871Sbill 					flushtty(tp, FREAD|FWRITE);
667170Sbill 				}
6685407Swnj 				tp->t_state &= ~TS_CARR_ON;
66917Sbill 			}
67017Sbill 		}
67117Sbill 	}
6722756Swnj 	timeout(dzscan, (caddr_t)0, 2*hz);
67317Sbill }
674119Sbill 
675119Sbill dztimer()
676119Sbill {
6772457Swnj 	int dz;
678119Sbill 
6792645Swnj 	for (dz = 0; dz < NDZ; dz++)
6802457Swnj 		dzrint(dz);
681119Sbill }
682281Sbill 
683281Sbill /*
684281Sbill  * Reset state of driver if UBA reset was necessary.
685301Sbill  * Reset parameters and restart transmission on open lines.
686281Sbill  */
6872395Swnj dzreset(uban)
6882422Skre 	int uban;
689281Sbill {
6902395Swnj 	register int unit;
691281Sbill 	register struct tty *tp;
6922976Swnj 	register struct uba_device *ui;
693281Sbill 
6942645Swnj 	for (unit = 0; unit < NDZLINE; unit++) {
6952422Skre 		ui = dzinfo[unit >> 3];
6962422Skre 		if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0)
6972422Skre 			continue;
6982923Swnj 		if (unit%8 == 0)
6992923Swnj 			printf(" dz%d", unit>>3);
7002395Swnj 		tp = &dz_tty[unit];
7015407Swnj 		if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) {
7022395Swnj 			dzparam(unit);
7036157Ssam 			(void) dzmctl(unit, DZ_ON, DMSET);
7045407Swnj 			tp->t_state &= ~TS_BUSY;
705301Sbill 			dzstart(tp);
706281Sbill 		}
707281Sbill 	}
708281Sbill 	dztimer();
709281Sbill }
7101562Sbill #endif
711