xref: /csrg-svn/sys/tahoe/vba/vx.c (revision 25877)
1*25877Ssam /*	vx.c	1.5	86/01/12	*/
224003Ssam 
324003Ssam #include "vx.h"
424003Ssam #if NVX > 0
524003Ssam /*
625857Ssam  * VIOC-X driver
724003Ssam  */
8*25877Ssam #ifdef VXPERF
9*25877Ssam #define	DOSCOPE
10*25877Ssam #endif
11*25877Ssam 
1225675Ssam #include "../tahoe/pte.h"
1324003Ssam 
14*25877Ssam #include "param.h"
15*25877Ssam #include "ioctl.h"
16*25877Ssam #include "tty.h"
17*25877Ssam #include "dir.h"
18*25877Ssam #include "user.h"
19*25877Ssam #include "map.h"
20*25877Ssam #include "buf.h"
21*25877Ssam #include "conf.h"
22*25877Ssam #include "file.h"
23*25877Ssam #include "uio.h"
24*25877Ssam #include "proc.h"
25*25877Ssam #include "vm.h"
2625675Ssam 
2725675Ssam #include "../tahoevba/vbavar.h"
2825675Ssam #include "../tahoevba/vioc.h"
2925675Ssam #include "../tahoevba/scope.h"
3024003Ssam #include "vbsc.h"
3124003Ssam #if NVBSC > 0
3225861Ssam #include "../tahoebsc/bscio.h"
3325861Ssam #include "../tahoebsc/bsc.h"
3424003Ssam char bscport[NVXPORTS];
3524003Ssam #endif
3624003Ssam 
3724003Ssam #ifdef BSC_DEBUG
3825861Ssam #include "../tahoebsc/bscdebug.h"
3924003Ssam #endif
4024003Ssam 
4124003Ssam #ifdef	VX_DEBUG
4224003Ssam long vxintr4 = 0;
4324003Ssam long vxdebug = 0;
4425861Ssam #include "../tahoevba/vxdebug.h"
4524003Ssam #endif
4624003Ssam 
4724003Ssam #define RSPquals	1
4824003Ssam 
4925857Ssam struct	vcx vcx[NVIOCX] ;
5025857Ssam struct	tty vx_tty[NVXPORTS];
5125857Ssam extern	struct vcmds v_cmds[];
5225857Ssam extern	long reinit;
5324003Ssam 
5424003Ssam int	vxstart() ;
5524003Ssam int	ttrstrt() ;
5625857Ssam struct	vxcmd *vobtain() ;
5725857Ssam struct	vxcmd *nextcmd() ;
5824003Ssam 
5924003Ssam /*
6024003Ssam  * Driver information for auto-configuration stuff.
6124003Ssam  * (not tested and probably should be changed)
6224003Ssam  */
6324003Ssam int	vxprobe(), vxattach(), vxrint();
6424003Ssam struct	vba_device *vxinfo[NVIOCX];
6524003Ssam long	vxstd[] = { 0 };
6624003Ssam struct	vba_driver vxdriver =
6725857Ssam     { vxprobe, 0, vxattach, 0, vxstd, "vx", vxinfo };
6824003Ssam 
6925857Ssam char	vxtype[NVIOCX];	/* 0: viox-x/vioc-b; 1: vioc-bop */
7025857Ssam char	vxbbno = -1;
7125857Ssam char	vxbopno[NVIOCX];	/* BOP board no. if indicated by vxtype[] */
7225857Ssam int	vxivec[NVIOCX];		/* interrupt vector base */
7325857Ssam extern	vbrall();
7424003Ssam 
7525857Ssam vxprobe(reg, vi)
7624003Ssam 	caddr_t reg;
7725857Ssam 	struct vba_device *vi;
7824003Ssam {
7925857Ssam 	register int br, cvec;			/* must be r12, r11 */
8024003Ssam 	register struct vblok *vp = (struct vblok *)reg;
8124003Ssam 
8224003Ssam #ifdef lint
8324003Ssam 	br = 0; cvec = br; br = cvec;
8425675Ssam 	vackint(0); vunsol(0); vcmdrsp(0); vxfreset(0);
8524003Ssam #endif
8625675Ssam 	if (badaddr((caddr_t)vp, 1))
8725675Ssam 		return (0);
8825675Ssam 	vp->v_fault = 0;
8925675Ssam 	vp->v_vioc = V_BSY;
9025675Ssam 	vp->v_hdwre = V_RESET;		/* reset interrupt */
9124003Ssam 	DELAY(4000000);
9225675Ssam 	if (vp->v_fault != VREADY)
9325675Ssam 		return (0);
9425857Ssam #ifdef notdef
9525857Ssam 	/*
9625857Ssam 	 * Align vioc interrupt vector base to 4 vector
9725857Ssam 	 * boundary and fitting in 8 bits (is this necessary,
9825857Ssam 	 * wish we had documentation).
9925857Ssam 	 */
10025857Ssam 	if ((vi->ui_hd->vh_lastiv -= 3) > 0xff)
10125857Ssam 		vi->ui_hd->vh_lastiv = 0xff;
10225857Ssam 	vxivec[vi->ui_unit] = vi->ui_hd->vh_lastiv =
10325857Ssam 	    vi->ui_hd->vh_lastiv &~ 0x3;
10425857Ssam #else
10525857Ssam 	vxivec[vi->ui_unit] = 0x40+vi->ui_unit*4;
10625857Ssam #endif
10725857Ssam 	br = 0x18, cvec = vxivec[vi->ui_unit];	/* XXX */
10825675Ssam 	return (sizeof (*vp));
10924003Ssam }
11024003Ssam 
11125857Ssam vxattach(vi)
11225857Ssam 	register struct vba_device *vi;
11324003Ssam {
11425675Ssam 
11525857Ssam 	VIOCBAS[vi->ui_unit] = vi->ui_addr;
11625857Ssam 	vxinit(vi->ui_unit, (long)1);
11724003Ssam }
11824003Ssam 
11924003Ssam /*
12024003Ssam  * Open a VX line.
12124003Ssam  */
12225675Ssam /*ARGSUSED*/
12324003Ssam vxopen(dev, flag)
12424003Ssam {
12524003Ssam 	register struct tty *tp;	/* pointer to tty struct for port */
12624003Ssam 	register struct vcx *xp;	/* pointer to VIOC-X info/cmd buffer */
12724003Ssam 	register d;			/* minor device number */
12824003Ssam 	register long jj;
12924003Ssam 
13024003Ssam 
13124003Ssam 	d = minor(dev);			/* get minor device number */
13224003Ssam 	if (d >= NVXPORTS)		/* validate minor device number */
13324003Ssam 		return ENXIO;		/* set errno to indicate bad port # */
13424003Ssam 	tp = &vx_tty[d];		/* index the tty structure for port */
13524003Ssam 
13624003Ssam 	xp = &vcx[d>>4];			/* index VIOC-X info/cmd area */
13724003Ssam 	d &= 017;
13824003Ssam 
13924003Ssam 	/* If we did not find a board with the correct port number on
14024003Ssam 	   it, or the entry for the VIOC-X had no ports on it, inform the
14124003Ssam 	   caller that the port does not exist. */
14224003Ssam 	if(!( xp->v_loport <= d && d <= xp->v_hiport )	/* home? */
14324003Ssam 	 || (xp->v_hiport - xp->v_loport)==0)
14424003Ssam 		return ENXIO;	/* bad minor device number */
14524003Ssam 	tp->t_addr = (caddr_t)xp;	/* store address of VIOC-X info */
14624003Ssam 	tp->t_oproc = vxstart;		/* store address of startup routine */
14724003Ssam 	tp->t_dev = dev;		/* store major/minor device numbers */
14824003Ssam 	d = spl8();
14924003Ssam 	tp->t_state |= TS_WOPEN;	/* mark device as waiting for open */
15024003Ssam 	if ((tp->t_state&TS_ISOPEN) == 0)	/* is device already open? */
15124003Ssam 	{				/*  no, open it */
15224003Ssam 		ttychars(tp);		/* set default control chars */
15324003Ssam 		if (tp->t_ispeed == 0)	/* if no default speeds set them */
15424003Ssam 		{
15524003Ssam 			tp->t_ispeed = SSPEED;	/* default input baud */
15624003Ssam 			tp->t_ospeed = SSPEED;	/* default output baud */
15724003Ssam 			tp->t_flags |= (ODDP|EVENP|ECHO); /* default modes */
15824003Ssam 		}
15924003Ssam 		vxparam(dev);		/* set parameters for this port */
16024003Ssam 	}
16124003Ssam 	splx(d);
16224003Ssam 	/* ? if already open for exclusive use open fails unless caller is
16324003Ssam 	     root. */
16424003Ssam 	if (tp->t_state&TS_XCLUDE && u.u_uid!=0)
16524003Ssam 		return EBUSY;	/* device is busy, sorry */
16624003Ssam 
16724003Ssam 	/* wait for data carrier detect to go high */
16824003Ssam 	d = spl8();
16924003Ssam 	if( !vcmodem(dev,VMOD_ON) )
17024003Ssam 		while( (tp->t_state&TS_CARR_ON) == 0 )
17125675Ssam 			sleep((caddr_t)&tp->t_canq,TTIPRI);
17224003Ssam 	jj= (*linesw[tp->t_line].l_open)(dev,tp); /*let tty.c finish the open */
17324003Ssam 	splx(d);	/* 1/2/85 : assures open complete */
17424003Ssam 	return (jj);
17524003Ssam }
17624003Ssam 
17724003Ssam /*
17824003Ssam  * Close a VX line.
17924003Ssam  */
18025675Ssam /*ARGSUSED*/
18124003Ssam vxclose(dev, flag)
18224003Ssam dev_t dev;
18324003Ssam int  flag;
18424003Ssam {
18524003Ssam 	register struct tty *tp;
18624003Ssam 	register d;
18724003Ssam 
18824003Ssam 	d = minor(dev) & 0377;
18924003Ssam 	tp = &vx_tty[d];
19024003Ssam 	d = spl8();
19124003Ssam 	(*linesw[tp->t_line].l_close)(tp);
19224003Ssam 	if ((tp->t_state&TS_ISOPEN) && (tp->t_state&TS_HUPCLS))
19324003Ssam 		if( !vcmodem(dev,VMOD_OFF) )
19424003Ssam 			tp->t_state &= ~TS_CARR_ON;
19524003Ssam 	/* wait for the last response */
19624003Ssam 	while(tp->t_state & TS_FLUSH)
19724003Ssam 		sleep( (caddr_t)&tp->t_state, TTOPRI ) ;
19824003Ssam 	ttyclose(tp);	/* let tty.c finish the close */
19924003Ssam 	splx(d);
20024003Ssam }
20124003Ssam 
20224003Ssam /*
20324003Ssam  * Read from a VX line.
20424003Ssam  */
20524003Ssam vxread(dev, uio)
20624003Ssam 	dev_t dev;
20724003Ssam 	struct uio *uio;
20824003Ssam {
20924003Ssam 	register struct tty *tp = &vx_tty[minor(dev) & 0377];
21024003Ssam 	return (*linesw[tp->t_line].l_read)(tp, uio);
21124003Ssam }
21224003Ssam 
21324003Ssam /*
21424003Ssam  * write on a VX line
21524003Ssam  */
21624003Ssam vxwrite(dev, uio)
21724003Ssam 	dev_t dev;
21824003Ssam 	struct uio *uio;
21924003Ssam {
22024003Ssam 	register struct tty *tp = &vx_tty[minor(dev) & 0377];
22124003Ssam 	return (*linesw[tp->t_line].l_write)(tp, uio);
22224003Ssam }
22324003Ssam 
22424003Ssam /*
22524003Ssam  * VIOCX unsolicited interrupt.
22624003Ssam  */
22724003Ssam vxrint(n)
22824003Ssam register n;				/* mux number */
22924003Ssam {
23024003Ssam 	register struct tty *tp;
23124003Ssam 	register struct vcx *xp;
23224003Ssam 	register short *sp;
23324003Ssam 	register struct vblok *kp;
23424003Ssam 	register int i, c;
23524003Ssam 	short *savsilo;
23624003Ssam 	struct silo {
23724003Ssam 		char	data;
23824003Ssam 		char	port;
23924003Ssam 	};
24024003Ssam 
24124003Ssam 	kp = VBAS(n);
24224003Ssam 	xp = &vcx[n];
24324003Ssam 	switch(kp->v_uqual&037) {
24424003Ssam 	case 0:
24524003Ssam 		break;
24624003Ssam 	case 2:
24724003Ssam 		printf(" ERR NBR %x\n",kp->v_ustat);
24824003Ssam 		vpanic("vc: VC PROC ERR");
24924003Ssam 		vxstreset(n);
25024003Ssam 		return(0);
25124003Ssam 	case 3:
25224003Ssam 		vcmintr(n);
25324003Ssam 		return(1);
25424003Ssam 	case 4:
25524003Ssam 		return(1);
25624003Ssam 	default:
25724003Ssam 		printf(" ERR NBR %x\n",kp->v_uqual);
25824003Ssam 		vpanic("vc: VC UQUAL ERR");
25924003Ssam 		vxstreset(n);
26024003Ssam 		return(0);
26124003Ssam 	}
26224003Ssam 	if(xp->v_vers == V_NEW) {
26324003Ssam 		register short *aa ;
26424003Ssam 		aa = (short *)kp->v_usdata;
26524003Ssam 		sp = (short *)(*aa  + (char *)kp) ;
26624003Ssam 	} else {
26724003Ssam 		c = kp->v_usdata[0] << 6;
26824003Ssam 		sp = (short *)((char *)kp + SILOBAS + c);
26924003Ssam 	}
27024003Ssam 	i = *(savsilo = sp);
27124003Ssam 	if (i == 0) return(1);
27224003Ssam 	if(xp->v_vers == V_NEW)
27324003Ssam 		if( i > xp->v_silosiz ) {
27424003Ssam 			printf("vx: %d exceeds silo size\n",i) ;
27524003Ssam 			i = xp->v_silosiz;
27624003Ssam 		}
27724003Ssam 	for(sp++;i > 0;i--,sp++) {
27824003Ssam 		c = ((struct silo *)sp)->port & 017;
27924003Ssam 		tp = &vx_tty[c+n*16];
28024003Ssam 		if(xp->v_loport > c || c > xp->v_hiport)
28124003Ssam 			continue;	/* port out of bounds */
28224003Ssam 		if( (tp->t_state & TS_ISOPEN) == 0) {
28324003Ssam 			wakeup((caddr_t)&tp->t_rawq);
28424003Ssam 			continue;
28524003Ssam 		}
28624003Ssam 		c = ((struct silo *)sp)->data;
28724003Ssam 		switch(((struct silo *)sp)->port&(PERROR|FERROR)) {
28824003Ssam 		case PERROR:
28924003Ssam 		case PERROR|FERROR:
29024003Ssam 			if( (tp->t_flags&(EVENP|ODDP)) == EVENP
29124003Ssam 			|| (tp->t_flags & (EVENP|ODDP)) == ODDP )
29224003Ssam 				continue;
29324003Ssam 			if(!(((struct silo *)sp)->port&FERROR))
29424003Ssam 				break;
29524003Ssam 		case FERROR:
29624003Ssam 			if(tp->t_flags & RAW) c = 0;
29724003Ssam 			else c = tp->t_intrc;
29824003Ssam 		}
29924003Ssam 		(*linesw[tp->t_line].l_rint)(c, tp);
30024003Ssam 	}
30124003Ssam 	*savsilo = 0;
30224003Ssam 	return(1);
30324003Ssam }
30424003Ssam 
30524003Ssam /*
30624003Ssam  * stty/gtty for VX
30724003Ssam  */
30824003Ssam vxioctl(dev, cmd, data, flag)
30924003Ssam int	dev;			/* major, minor device numbers */
31024003Ssam int	cmd;			/* command */
31124003Ssam caddr_t	data;
31224003Ssam int	flag;
31324003Ssam {
31424003Ssam 	register struct tty	*tp;
31524003Ssam 	register error;
31624003Ssam 
31724003Ssam 	tp = &vx_tty[minor(dev) & 0377];
31824003Ssam 	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag);
31924003Ssam 	if (error == 0)
32024003Ssam 		return error;
32124003Ssam 	if((error = ttioctl(tp, cmd, data, flag)) >= 0)
32224003Ssam 	{
32324003Ssam 		if (cmd==TIOCSETP||cmd==TIOCSETN)
32424003Ssam 			vxparam(dev);
32524003Ssam 		return error;
32624003Ssam 	} else
32724003Ssam 		return ENOTTY;
32824003Ssam }
32924003Ssam 
33024003Ssam 
33124003Ssam vxparam(dev)
33224003Ssam dev_t	dev;
33324003Ssam {
33424003Ssam 	vxcparam(dev, 1);
33524003Ssam }
33624003Ssam 
33724003Ssam /*
33824003Ssam  * Set parameters from open or stty into the VX hardware
33924003Ssam  * registers.
34024003Ssam  */
34124003Ssam vxcparam(dev, wait)
34224003Ssam dev_t	dev;			/* major, minor device numbers */
34324003Ssam int wait;			/* nonzero if we should wait for finish */
34424003Ssam {
34524003Ssam 	register struct tty	*tp;
34624003Ssam 	register struct vcx	*xp;
34724003Ssam 	register struct vxcmd	*cp;
34824003Ssam 	register s;
34924003Ssam 
35024003Ssam 	tp = &vx_tty[minor(dev)];	/* pointer to tty structure for port */
35124003Ssam 	xp = (struct vcx *)tp->t_addr;	/* pointer to VIOCX info/cmd buffer */
35224003Ssam 	cp = vobtain(xp);
35324003Ssam 	s = spl8();
35424003Ssam 	cp->cmd = LPARAX;		/* set command to "load parameters" */
35524003Ssam 	cp->par[1] = minor(dev)&017;	/* port number */
35624003Ssam 
35724003Ssam 	cp->par[2] = (tp->t_flags&RAW)? 0 : tp->t_startc;	/* XON char */
35824003Ssam 	cp->par[3] = (tp->t_flags&RAW)? 0 : tp->t_stopc;	/* XOFF char */
35924003Ssam 
36024003Ssam 	if(tp->t_flags&(RAW|LITOUT) ||
36124003Ssam 	  (tp->t_flags&(EVENP|ODDP)) == (EVENP|ODDP)) {
36224003Ssam 		cp->par[4] = 0xc0;	/* 8 bits of data */
36324003Ssam 		cp->par[7] = 0;		/* no parity */
36424003Ssam 	} else {
36524003Ssam 		cp->par[4] = 0x40;	/* 7 bits of data */
36624003Ssam 		if((tp->t_flags&(EVENP|ODDP)) == ODDP)
36724003Ssam 			cp->par[7] = 1;		/* odd parity */
36824003Ssam 		else if((tp->t_flags&(EVENP|ODDP)) == EVENP)
36924003Ssam 			cp->par[7] = 3;		/* even parity */
37024003Ssam 		else
37124003Ssam 			cp->par[7] = 0;		/* no parity */
37224003Ssam 	}
37324003Ssam 	cp->par[5] = 0x4;			/* 1 stop bit */
37424003Ssam 	cp->par[6] = tp->t_ospeed;
37524003Ssam 
37625675Ssam 	if (vcmd(xp->v_nbr, (caddr_t)&cp->cmd) && wait)
37725675Ssam 		sleep((caddr_t)cp,TTIPRI);
37824003Ssam 	splx(s);
37924003Ssam }
38024003Ssam 
38124003Ssam /*
38224003Ssam  * VIOCX command response interrupt.
38324003Ssam  * For transmission, restart output to any active port.
38424003Ssam  * For all other commands, just clean up.
38524003Ssam  */
38624003Ssam vxxint(n,cp)
38724003Ssam register int n;			/* VIOC number */
38824003Ssam register struct vxcmd	*cp;	/* command structure */
38924003Ssam {
39024003Ssam 	register struct	vxmit	*vp, *pvp;
39124003Ssam 	register struct	tty	*tp;
39224003Ssam 	register struct	vcx	*xp;
39324003Ssam 	register struct tty	*hp;
39424003Ssam 
39524003Ssam 	xp = &vcx[n];
39624003Ssam 	cp = (struct vxcmd *)( (long *)cp - 1);
39724003Ssam #if NVBSC > 0
39824003Ssam 	switch(cp->cmd) {
39924003Ssam 	case MDMCTL1: case HUNTMD1: case LPARAX1:
40024003Ssam 		vrelease(xp, cp);
40124003Ssam 		wakeup(cp);
40224003Ssam 		return;
40324003Ssam 	}
40424003Ssam #endif
40524003Ssam 	switch(cp->cmd&0xff00) {
40624003Ssam 	case LIDENT:	/* initialization complete */
40724003Ssam 		if (xp->v_state & V_RESETTING) {
40824003Ssam 			vxfnreset(n,cp);
40924003Ssam 			vinthandl(n,((V_BSY | RSPquals) << 8) | V_INTR);
41024003Ssam 		}
41124003Ssam 		cp->cmd++;
41224003Ssam 		return;
41324003Ssam 	case XMITDTA: case XMITIMM:
41424003Ssam 		break;
41524003Ssam 	case LPARAX:
41625675Ssam 		wakeup((caddr_t)cp);
41724003Ssam 	default:	/* MDMCTL or FDTATOX */
41824003Ssam 		vrelease(xp, cp);
41924003Ssam 		if (xp->v_state & V_RESETTING) {
42024003Ssam 			vinthandl(n,((V_BSY | RSPquals) << 8) | V_INTR);
42124003Ssam 		}
42224003Ssam 		return;
42324003Ssam 	}
42424003Ssam 	for(vp = (struct vxmit *)(cp->par + (cp->cmd & 07)*sizvxmit);
42524003Ssam 	    vp >= (struct vxmit *)cp->par;
42624003Ssam 	    vp = (struct vxmit *) ((char *)vp - sizvxmit) )
42724003Ssam 	{
42824003Ssam 		tp = &vx_tty[(vp->line & 017)+n*16];
42924003Ssam /* cjk buffer bug */
43024003Ssam #if NVBSC > 0
43124003Ssam 					/* bsc change */
43224003Ssam 		if (tp->t_line == LDISP) {
43324003Ssam 			vrelease(xp, cp);
43424003Ssam 			bsctxd((vp->line & 017));
43524003Ssam 			return ;
43624003Ssam 		}
43724003Ssam 					/* End of bsc change */
43824003Ssam #endif
43924003Ssam /* cjk */
44024003Ssam 		pvp = vp;
44124003Ssam 		tp->t_state &= ~TS_BUSY;
44224003Ssam 		if(tp->t_state & TS_FLUSH) {
44324003Ssam 			tp->t_state &= ~TS_FLUSH;
44424003Ssam 			wakeup( (caddr_t)&tp->t_state ) ;
44524003Ssam 		}
44624003Ssam 		else
44724003Ssam 		 	ndflush(&tp->t_outq, vp->bcount+1);
44824003Ssam 	}
44924003Ssam 	xp->v_xmtcnt--;
45024003Ssam 	vrelease(xp,cp);
45124003Ssam 	if(xp->v_vers == V_NEW) {
45224003Ssam 		vp = pvp;
45324003Ssam 		xp->v_actport[(vp->line & 017) - xp->v_loport] |= 1 ;
45424003Ssam 		if(vxstart(tp) && (cp = nextcmd(xp)) != NULL)
45524003Ssam 		{
45624003Ssam 			xp->v_xmtcnt++;
45725675Ssam 			vcmd(n, (caddr_t)&cp->cmd);
45824003Ssam 			return ;
45924003Ssam 		}
46024003Ssam 		xp->v_actport[(vp->line & 017) - xp->v_loport] = 0 ;
46124003Ssam 		return ;
46224003Ssam 	}
46324003Ssam 	xp->v_actflg = 1;
46424003Ssam 	hp = &vx_tty[xp->v_hiport+n*16];
46524003Ssam 	for(tp = &vx_tty[xp->v_loport+n*16];tp <= hp;tp++)
46624003Ssam 		if(vxstart(tp) && (cp = nextcmd(xp)) != NULL)
46724003Ssam 		{
46824003Ssam 			xp->v_xmtcnt++;
46925675Ssam 			vcmd(n, (caddr_t)&cp->cmd);
47024003Ssam 		}
47124003Ssam 	if( (cp = nextcmd(xp)) != NULL )		/* command to send ? */
47224003Ssam 	{
47324003Ssam 		xp->v_xmtcnt++;
47425675Ssam 		vcmd(n, (caddr_t)&cp->cmd);
47524003Ssam 	}
47624003Ssam 	xp->v_actflg = 0;
47724003Ssam }
47824003Ssam 
47924003Ssam /*
48024003Ssam  * Force out partial XMIT command after timeout
48124003Ssam  */
48224003Ssam vxforce(xp)
48324003Ssam register struct vcx	*xp;
48424003Ssam {
48524003Ssam 	register struct vxcmd	*cp;
48624003Ssam 	register int s;
48724003Ssam 
48824003Ssam 	s = spl8();
48924003Ssam 	if((cp = nextcmd(xp)) != NULL) {
49024003Ssam 		xp->v_xmtcnt++;
49125675Ssam 		vcmd(xp->v_nbr, (caddr_t)&cp->cmd);
49224003Ssam 	}
49324003Ssam 	splx(s);
49424003Ssam }
49524003Ssam 
49624003Ssam /*
49724003Ssam  * Start (restart) transmission on the given VX line.
49824003Ssam  */
49924003Ssam vxstart(tp)
50024003Ssam register struct tty *tp;
50124003Ssam {
50225675Ssam 	register short n;
50324003Ssam 	register struct	vcx	*xp;
50424003Ssam 	register char *outb;
50524003Ssam 	register full = 0;
50624003Ssam 	int k, s, port;
50724003Ssam 
50824003Ssam 	s = spl8();
50924003Ssam 	port = minor(tp->t_dev) & 017;
51024003Ssam 	xp = (struct vcx *)tp->t_addr;
51124003Ssam 	if (!(tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) {
51224003Ssam 		if (tp->t_outq.c_cc<=TTLOWAT(tp)) {
51324003Ssam 			if (tp->t_state&TS_ASLEEP) {
51424003Ssam 				tp->t_state &= ~TS_ASLEEP;
51524003Ssam 				wakeup((caddr_t)&tp->t_outq);
51624003Ssam 			}
51724003Ssam 			if (tp->t_wsel) {
51824003Ssam 				selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
51924003Ssam 				tp->t_wsel = 0;
52024003Ssam 				tp->t_state &= ~TS_WCOLL;
52124003Ssam 			}
52224003Ssam 		}
52324003Ssam 		if(tp->t_outq.c_cc == 0) {
52424003Ssam 			splx(s);
52524003Ssam 			return(0);
52624003Ssam 		}
527*25877Ssam 		scope_out(3);
52824003Ssam 		if(!(tp->t_flags&(RAW|LITOUT)))
52924003Ssam 			full = 0200;
53025675Ssam 		if((n = ndqb(&tp->t_outq, full)) == 0)   {
53124003Ssam 			if(full) {
53225675Ssam 				n = getc(&tp->t_outq);
53325675Ssam 				timeout(ttrstrt, (caddr_t)tp, (n&0177) +6);
53424003Ssam 				tp->t_state |= TS_TIMEOUT;
53524003Ssam 				full = 0;
53624003Ssam 			}
53724003Ssam 		} else {
53824003Ssam 			outb = (char *)tp->t_outq.c_cf;
53924003Ssam 			tp->t_state |= TS_BUSY;
54024003Ssam 			if(xp->v_vers == V_NEW)
54124003Ssam 				k = xp->v_actport[port - xp->v_loport] ;
54224003Ssam 			else
54324003Ssam 				k = xp->v_actflg ;
54424003Ssam 
54525675Ssam 			full = vsetq(xp, port, outb, n);
54624003Ssam 
54724003Ssam 			if( (k&1) == 0 ) {	/* not called from vxxint */
54824003Ssam 				if(full || xp->v_xmtcnt == 0) {
54924003Ssam 					outb = (char *)(&nextcmd(xp)->cmd);
55024003Ssam 					xp->v_xmtcnt++;
55124003Ssam 					vcmd(xp->v_nbr, outb );
55224003Ssam 				} else
55325675Ssam 					timeout(vxforce,(caddr_t)xp,3);
55424003Ssam 			}
55524003Ssam 		}
55624003Ssam 	}
55724003Ssam 	splx(s);
55824003Ssam 	return(full);	/* indicate if max commands or not */
55924003Ssam }
56024003Ssam 
56124003Ssam /*
56224003Ssam  * Stop output on a line.
56324003Ssam  */
56424003Ssam vxstop(tp)
56524003Ssam register struct tty *tp;
56624003Ssam {
56724003Ssam 	register  s;
56824003Ssam 
56924003Ssam 	s = spl8();
57024003Ssam 	if (tp->t_state & TS_BUSY) {
57124003Ssam 		if ((tp->t_state&TS_TTSTOP)==0) {
57224003Ssam 			tp->t_state |= TS_FLUSH;
57324003Ssam 		}
57424003Ssam 	}
57524003Ssam 	splx(s);
57624003Ssam }
57724003Ssam 
57824003Ssam /*
57924003Ssam  * VIOCX Initialization.  Makes free lists of command buffers.
58024003Ssam  * Resets all viocx's.  Issues a LIDENT command to each
58124003Ssam  * viocx which establishes interrupt vectors and logical
58224003Ssam  * port numbers
58324003Ssam  */
58424003Ssam vxinit(i,wait)
58524003Ssam register int	i;
58624003Ssam long wait;
58724003Ssam {
58824003Ssam 	register struct	vcx	*xp;	/* ptr to VIOC-X info/cmd buffer */
58924003Ssam 	register struct	vblok	*kp;	/* pointer to VIOC-X control block */
59024003Ssam 	register struct	vxcmd	*cp;	/* pointer to a command buffer */
59124003Ssam 	register char	*resp;		/* pointer to response buffer */
59224003Ssam 	register int	j;
59324003Ssam 	char type;
59425675Ssam #if NVBSC > 0
59524003Ssam 	register struct	bsc	*bp;	/* bsc change */
59624003Ssam 	extern	 struct	bsc	bsc[];
59725675Ssam #endif
59824003Ssam 
59924003Ssam 
60024003Ssam 	kp = VBAS(i);		/* get base adr of cntl blok for VIOC */
60124003Ssam 
60224003Ssam 	xp = &vcx[i];		/* index info/command buffers */
60324003Ssam 	type = kp->v_ident;
60424003Ssam 	vxtype[i] =  0;		/* Type is Viox-x */
60524003Ssam 	switch(type) {
60624003Ssam 	case VIOCX:
60724003Ssam 		{
60824003Ssam 		xp->v_vers = V_OLD ;
60924003Ssam 		/* set DCD for printer ports */
61024003Ssam 		for(j = 0;j < 16;j++)
61124003Ssam 			if (kp->v_portyp[j] == 4 )
61224003Ssam 				kp->v_dcd |= 1 << j ;
61324003Ssam 		}
61424003Ssam 		break ;
61524003Ssam 	case NWVIOCX:
61624003Ssam 		{
61724003Ssam 		xp->v_vers = V_NEW ;
61824003Ssam 		xp->v_silosiz = kp->v_maxsilo ;
61924003Ssam 		/* set DCD for printer ports */
62024003Ssam 		for(j = 0;j < 16;j++)
62124003Ssam 			if (kp->v_portyp[j] == 4 )
62224003Ssam 				kp->v_dcd |= 1 << j ;
62324003Ssam 		}
62424003Ssam 		break ;
62524003Ssam 	case PVIOCX:
62624003Ssam 		xp->v_vers = V_OLD ;
62724003Ssam 		break ;
62824003Ssam 	case NPVIOCX:
62924003Ssam 		xp->v_vers = V_NEW ;
63024003Ssam 		xp->v_silosiz = kp->v_maxsilo ;
63124003Ssam 		break ;
63224003Ssam #if NVBSC > 0
63324003Ssam 	case VIOCB:	/* old f/w, Bisync board */
63424003Ssam 		printf("%X: %x%x OLD VIOC-B, ",
63524003Ssam 					(long)kp, (int)kp->v_ident,
63624003Ssam 					(int)kp->v_fault);
63724003Ssam 		xp->v_vers = V_OLD ;
63824003Ssam 		/* save device specific info */
63924003Ssam 		for(bp = &bsc[0]; bp <= &bsc[NBSC]; bp++)
64024003Ssam 			bp->b_devregs = (caddr_t)xp ;
64124003Ssam 		printf("%d BSC Ports initialized.\n",NBSC);
64224003Ssam 		break ;
64324003Ssam 
64424003Ssam 	case NWVIOCB:	/* new f/w, Bisync board */
64524003Ssam 		printf("%X: %x%x 16K VIOC-B, ",
64624003Ssam 					(long)kp, (int)kp->v_ident,
64724003Ssam 					(int)kp->v_fault);
64824003Ssam 		xp->v_vers = V_NEW ;
64924003Ssam 		xp->v_silosiz = kp->v_maxsilo ;
65024003Ssam 		/* save device specific info */
65124003Ssam 		for(bp = &bsc[0]; bp <= &bsc[NBSC]; bp++)
65224003Ssam 			bp->b_devregs = (caddr_t)xp ;
65324003Ssam 		printf("%d BSC Ports initialized.\n",NBSC);
65424003Ssam 		if(CBSIZE > kp->v_maxxmt)
65524003Ssam 			printf("vxinit: Warning CBSIZE > maxxmt\n") ;
65624003Ssam 		break ;
65724003Ssam #endif
65824003Ssam 	case VBOPID:		/* VIOC-BOP */
65924003Ssam 		vxbbno++;
66024003Ssam 		vxtype[i] = 1;
66124003Ssam 		vxbopno[i] = vxbbno;
66224003Ssam 		printf("VIOC-BOP no. %d at %lx\n",vxbopno[i],VIOCBAS[i]);
66324003Ssam 	default:
66424003Ssam 		return ;	/* Not a viocx type */
66524003Ssam 	}
66624003Ssam 	xp->v_nbr = -1;		/* no number for it yet */
66724003Ssam 	xp->v_maxcmd = xp->v_vers == V_NEW ? 24 : 4;
66824003Ssam 
66924003Ssam 	for(j=0; j<NVCXBUFS; j++)	/* init all cmd buffers */
67024003Ssam 	{
67124003Ssam 		cp = &xp->vx_lst[j];	/* index a buffer */
67224003Ssam 		cp->c_fwd = &xp->vx_lst[j+1];	/* point to next buf */
67324003Ssam 	}
67424003Ssam 	xp->vx_avail = &xp->vx_lst[0];	/* set idx to 1st free buf */
67524003Ssam 	cp->c_fwd = (struct vxcmd *)0;	/* mark last buf in free list */
67624003Ssam 
67724003Ssam 	cp = vobtain(xp);	/* grap the control block */
67824003Ssam 	cp->cmd = LIDENT;	/* set command type */
67925857Ssam 	cp->par[0] = vxivec[i]; 	/* ack vector */
68025857Ssam 	cp->par[1] = cp->par[0]+1;	/* cmd resp vector */
68125857Ssam 	cp->par[3] = cp->par[0]+2;	/* unsol intr vector */
68224003Ssam 	cp->par[4] = 15;	/* max ports, no longer used */
68324003Ssam 	cp->par[5] = 0;		/* set 1st port number */
68425675Ssam 	vcmd(i, (caddr_t)&cp->cmd);	/* initialize the VIOC-X */
68524003Ssam 
68624003Ssam 	if (!wait) return;
68725857Ssam 	for (j = 0; cp->cmd == LIDENT && j < 4000000; j++)
68825857Ssam 		;
68925857Ssam 	if (j >= 4000000)
69025857Ssam 		printf("vx%d: didn't respond to LIDENT\n", i);
69124003Ssam 
69224003Ssam  	/* calculate address of response buffer */
69324003Ssam  	resp = (char *)kp;
69424003Ssam  	resp += kp->v_rspoff & 0x3FFF;
69524003Ssam 
69624003Ssam 	if(resp[0] != 0 && (resp[0]&0177) != 3)	/* did init work? */
69724003Ssam 	{
69824003Ssam 		vrelease(xp,cp);	/* init failed */
69924003Ssam 		return;			/* try next VIOC-X */
70024003Ssam 	}
70124003Ssam 
70224003Ssam 	xp->v_loport = cp->par[5];	/* save low port number */
70324003Ssam 	xp->v_hiport = cp->par[7];/* VIOC knows high port numbr */
70424003Ssam 	vrelease(xp,cp);	/* done with this control block */
70524003Ssam 	xp->v_nbr = i;		/* assign VIOC-X board number */
70624003Ssam }
70724003Ssam 
70824003Ssam /*
70924003Ssam  * Obtain a command buffer
71024003Ssam  */
71124003Ssam struct	vxcmd *
71224003Ssam vobtain(xp)
71324003Ssam register struct	vcx	*xp;
71424003Ssam {
71524003Ssam 
71624003Ssam 	register struct	vxcmd	*p;
71724003Ssam 	register s;
71824003Ssam 
71924003Ssam 	s = spl8();
72024003Ssam 	p = xp->vx_avail;
72124003Ssam 	if(p == (struct vxcmd *)0) {
72224003Ssam #ifdef VX_DEBUG
72324003Ssam 		if (vxintr4 & VXNOBUF) vxintr4 &= ~VXNOBUF;
72424003Ssam #endif
72524003Ssam 		vpanic("vx: no buffs");
72624003Ssam 		vxstreset(xp - vcx);
72724003Ssam 		splx(s);
72824003Ssam 		return(vobtain(xp));
72924003Ssam 	}
73024003Ssam 	xp->vx_avail = (xp->vx_avail)->c_fwd;
73124003Ssam 	splx(s);
73224003Ssam 	return( (struct vxcmd *)p);
73324003Ssam }
73424003Ssam 
73524003Ssam /*
73624003Ssam  * Release a command buffer
73724003Ssam  */
73824003Ssam vrelease(xp,cp)
73924003Ssam register struct	vcx	*xp;
74024003Ssam register struct	vxcmd	*cp;
74124003Ssam {
74224003Ssam 
74324003Ssam 	register s;
74424003Ssam 
74524003Ssam #ifdef VX_DEBUG
74624003Ssam 	if (vxintr4 & VXNOBUF) return;
74724003Ssam #endif
74824003Ssam 	s = spl8();
74924003Ssam 	cp->c_fwd = xp->vx_avail;
75024003Ssam 	xp->vx_avail = cp;
75124003Ssam 	splx(s);
75224003Ssam }
75324003Ssam 
75424003Ssam /*
75524003Ssam  * vxcmd -
75624003Ssam  *
75724003Ssam  */
75824003Ssam struct vxcmd 	*
75924003Ssam nextcmd(xp)
76024003Ssam register struct	vcx	*xp;
76124003Ssam {
76224003Ssam 	register struct	vxcmd	*cp;
76324003Ssam 	register int	s;
76424003Ssam 
76524003Ssam 	s = spl8();
76624003Ssam 	cp = xp->vx_build;
76724003Ssam 	xp->vx_build = (struct vxcmd *)0;
76824003Ssam 	splx(s);
76924003Ssam 	return(cp);
77024003Ssam }
77124003Ssam 
77224003Ssam /*
77324003Ssam  * assemble transmits into a multiple command.
77424003Ssam  * up to 8 transmits to 8 lines can be assembled together
77524003Ssam  */
77625675Ssam vsetq(xp ,d ,addr, n)
77724003Ssam register struct	vcx	*xp;
77824003Ssam caddr_t	addr;
77924003Ssam {
78024003Ssam 
78124003Ssam 	register struct	vxcmd	*cp;
78224003Ssam 	register struct	vxmit	*mp;
78324003Ssam 	register char	*p;
78424003Ssam 	register i;
78524003Ssam 
78624003Ssam 	cp = xp->vx_build;
78724003Ssam 	if(cp == (struct vxcmd *)0) {
78824003Ssam 		cp = vobtain(xp);
78924003Ssam 		xp->vx_build = cp;
79024003Ssam 		cp->cmd = XMITDTA;
79124003Ssam 	} else {
79224003Ssam 		if((cp->cmd & 07) == 07) {
79324003Ssam 			vpanic("vx: vsetq overflow");
79424003Ssam 			vxstreset(xp->v_nbr);
79524003Ssam 			return(0);
79624003Ssam 		}
79724003Ssam 		cp->cmd++;
79824003Ssam 	}
79924003Ssam 
80024003Ssam 	mp = (struct vxmit *)(cp->par + (cp->cmd & 07)*sizvxmit);
80125675Ssam 	mp->bcount = n-1;
80224003Ssam 
80324003Ssam 	mp->line = d;
80425675Ssam 	if((xp->v_vers == V_NEW) && (n <= 6)) {
80524003Ssam 		cp->cmd = XMITIMM ;
80624003Ssam 		p = addr;
80725675Ssam 		/* bcopy(addr, &(char *)mp->ostream, n) ; */
80824003Ssam 	} else {
80925675Ssam 		addr = (caddr_t)vtoph((struct proc *)0, (unsigned)addr);
81025675Ssam 				/* should be a sys address */
81124003Ssam 		p = (char *)&addr;
81225675Ssam 		n = sizeof addr;
81324003Ssam 		/* mp->ostream = addr ; */
81424003Ssam 	}
81525675Ssam 	for(i=0; i<n; i++)
81624003Ssam 		mp->ostream[i] = *p++;
81724003Ssam 	if(xp->v_vers == V_NEW)
81824003Ssam 		return(1) ;
81924003Ssam 	else
82024003Ssam 		return((cp->cmd&07) == 7) ;	/* Indicate if full */
82124003Ssam }
82224003Ssam #endif
823