xref: /csrg-svn/sys/vax/uba/dn.c (revision 7833)
1*7833Sroot /*	dn.c	4.6	82/08/22	*/
24737Swnj 
34737Swnj #include "dn.h"
44737Swnj #if NDN > 0
54737Swnj /*
64737Swnj  * DN-11 ACU interface
74737Swnj  */
84737Swnj 
94737Swnj #include "../h/param.h"
104737Swnj #include "../h/systm.h"
114737Swnj #include "../h/dir.h"
124737Swnj #include "../h/user.h"
134737Swnj #include "../h/buf.h"
144737Swnj #include "../h/map.h"
154737Swnj #include "../h/pte.h"
164737Swnj #include "../h/ubavar.h"
174737Swnj #include "../h/conf.h"
184737Swnj #include "../h/ioctl.h"
194737Swnj 
204737Swnj struct dndevice {
216593Ssam 	u_short	dn_reg[4];
224737Swnj };
234737Swnj 
244737Swnj struct uba_device *dninfo[NDN];
254737Swnj int dnprobe(), dnattach();
264737Swnj u_short dnstd[] = { 0175200 };
274737Swnj struct uba_driver dndriver =
284737Swnj 	{ dnprobe, 0, dnattach, 0, dnstd, "dn", dninfo };
294737Swnj 
306593Ssam #define	CRQ	0x001		/* call request */
316593Ssam #define	DPR	0x002		/* digit present */
326593Ssam #define	MENABLE	0x004		/* master enable */
336593Ssam #define MAINT	0x008		/* maintenance mode */
346593Ssam #define	PND	0x010		/* present next digit */
356593Ssam #define	DSS	0x020		/* data set status */
366593Ssam #define	IENABLE	0x040		/* interrupt enable */
376593Ssam #define	DONE	0x080		/* operation complete */
386593Ssam #define	DLO	0x1000		/* data line occupied */
396593Ssam #define	ACR	0x4000		/* abandon call and retry */
406593Ssam #define	PWI	0x8000		/* power indicate */
414737Swnj 
424737Swnj #define	DNPRI	(PZERO+5)
434737Swnj #define DNUNIT(dev)	(minor(dev)>>2)
444737Swnj #define DNREG(dev)	((dev)&03)
454737Swnj 
464737Swnj #define OBUFSIZ	40		/* largest phone # dialer can handle */
474737Swnj 
484737Swnj /*
494737Swnj  * There's no good way to determine the correct number of dialers attached
504933Swnj  * to a single device (especially when dialers such as Vadic-821 MACS
516593Ssam  * exist which can address four chassis, each with its own dialer).
524737Swnj  */
534737Swnj dnprobe(reg)
544737Swnj 	caddr_t reg;
554737Swnj {
566593Ssam 	register int br, cvec;	/* value-result, must be r11, r10 */
574737Swnj 	register struct dndevice *dnaddr = (struct dndevice *)reg;
584737Swnj 
594737Swnj 	/*
604737Swnj 	 * If there's at least one dialer out there it better be
616593Ssam 	 *  at chassis 0.
624737Swnj 	 */
634737Swnj 	dnaddr->dn_reg[0] = MENABLE|IENABLE|DONE;
644737Swnj 	DELAY(5);
654737Swnj 	dnaddr->dn_reg[0] = 0;
667409Skre 	return (sizeof (struct dndevice));
674737Swnj }
684737Swnj 
694737Swnj dnattach(ui)
704737Swnj 	struct uba_device *ui;
716593Ssam {}
724933Swnj 
734737Swnj /*ARGSUSED*/
744737Swnj dnopen(dev, flag)
754737Swnj 	dev_t dev;
764737Swnj {
774737Swnj 	register struct dndevice *dp;
786593Ssam 	register u_short unit, *dnreg;
794737Swnj 	register struct uba_device *ui;
804737Swnj 	register short dialer;
814737Swnj 
824737Swnj 	if ((unit = DNUNIT(dev)) >= NDN || (ui = dninfo[unit]) == 0 ||
836593Ssam 	    ui->ui_alive == 0) {
844737Swnj 		u.u_error = ENXIO;
854737Swnj 		return;
864737Swnj 	}
876593Ssam 	dialer = DNREG(dev);
886593Ssam 	dp = (struct dndevice *)ui->ui_addr;
896593Ssam 	if (dp->dn_reg[dialer] & PWI) {
906593Ssam 		u.u_error = ENXIO;
916593Ssam 		return;
926593Ssam 	}
934737Swnj 	dnreg = &(dp->dn_reg[dialer]);
944737Swnj 	if (*dnreg&(DLO|CRQ)) {
954737Swnj 		u.u_error = EBUSY;
964737Swnj 		return;
974737Swnj 	}
984737Swnj 	dp->dn_reg[0] |= MENABLE;
994737Swnj 	*dnreg = IENABLE|MENABLE|CRQ;
1004737Swnj }
1014737Swnj 
1024737Swnj /*ARGSUSED*/
1034737Swnj dnclose(dev, flag)
1044737Swnj 	dev_t dev;
1054737Swnj {
1064737Swnj 	register struct dndevice *dp;
1074737Swnj 
1084737Swnj 	dp = (struct dndevice *)dninfo[DNUNIT(dev)]->ui_addr;
1094737Swnj 	dp->dn_reg[DNREG(dev)] = MENABLE;
1104737Swnj }
1114737Swnj 
112*7833Sroot dnwrite(dev, uio)
1134737Swnj 	dev_t dev;
114*7833Sroot 	struct uio *uio;
1154737Swnj {
1166593Ssam 	register u_short *dnreg;
1176593Ssam 	register int cc;
1184737Swnj 	register struct dndevice *dp;
1196593Ssam 	char buf[OBUFSIZ];
1204737Swnj 	register char *cp;
1214737Swnj 	extern lbolt;
1224737Swnj 
1234737Swnj 	dp = (struct dndevice *)dninfo[DNUNIT(dev)]->ui_addr;
1244737Swnj 	dnreg = &(dp->dn_reg[DNREG(dev)]);
125*7833Sroot 	cc = MIN(uio->uio_resid, OBUFSIZ);
1266593Ssam 	cp = buf;
127*7833Sroot 	u.u_error = uiomove(cp, (unsigned)cc, UIO_WRITE, uio);
1284737Swnj 	if (u.u_error)
1294737Swnj 		return;
1304737Swnj 	while ((*dnreg & (PWI|ACR|DSS)) == 0 && cc >= 0) {
1316593Ssam 		spl4();
1326593Ssam 		if ((*dnreg & PND) == 0 || cc == 0)
1334737Swnj 			sleep((caddr_t)dnreg, DNPRI);
1344737Swnj 		else switch(*cp) {
1354737Swnj 
1364737Swnj 		case '-':
1374737Swnj 			sleep((caddr_t)&lbolt, DNPRI);
1384737Swnj 			sleep((caddr_t)&lbolt, DNPRI);
1394737Swnj 			break;
1404737Swnj 
1414737Swnj 		case 'f':
1424737Swnj 			*dnreg &= ~CRQ;
1434737Swnj 			sleep((caddr_t)&lbolt, DNPRI);
1444737Swnj 			*dnreg |= CRQ;
1454737Swnj 			break;
1464737Swnj 
1474737Swnj 		case '*': case ':':
1484737Swnj 			*cp = 012;
1494737Swnj 			goto dial;
1504737Swnj 
1514737Swnj 		case '#': case ';':
1524737Swnj 			*cp = 013;
1534737Swnj 			goto dial;
1544737Swnj 
1554737Swnj 		case 'e': case '<':
1564737Swnj 			*cp = 014;
1574737Swnj 			goto dial;
1584737Swnj 
1594737Swnj 		case 'w': case '=':
1604737Swnj 			*cp = 015;
1614737Swnj 			goto dial;
1624737Swnj 
1634737Swnj 		default:
1644737Swnj 			if (*cp < '0' || *cp > '9')
1654737Swnj 				break;
1664737Swnj 		dial:
1676593Ssam 			*dnreg = (*cp << 8) | (IENABLE|MENABLE|DPR|CRQ);
1684737Swnj 			sleep((caddr_t)dnreg, DNPRI);
1694737Swnj 		}
1704737Swnj 		cp++, cc--;
1714737Swnj 		spl0();
1724737Swnj 	}
1736593Ssam 	if (*dnreg & (PWI|ACR))
1744737Swnj 		u.u_error = EIO;
1754737Swnj }
1764737Swnj 
1774737Swnj dnintr(dev)
1784737Swnj 	dev_t dev;
1794737Swnj {
1806593Ssam 	register u_short *basereg, *dnreg;
1814737Swnj 
1826593Ssam 	basereg = (u_short *)dninfo[dev]->ui_addr;
1834737Swnj 	*basereg &= ~MENABLE;
1846593Ssam 	for (dnreg = basereg; dnreg < basereg + 4; dnreg++)
1856593Ssam 		if (*dnreg & DONE) {
1864737Swnj 			*dnreg &= ~(DONE|DPR);
1874737Swnj 			wakeup((caddr_t)dnreg);
1884737Swnj 		}
1894737Swnj 	*basereg |= MENABLE;
1904737Swnj }
1914737Swnj #endif
192