xref: /csrg-svn/sys/vax/uba/dn.c (revision 7409)
1*7409Skre /*	dn.c	4.5	82/07/15	*/
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;
66*7409Skre 	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 
1124737Swnj dnwrite(dev)
1134737Swnj 	dev_t dev;
1144737Swnj {
1156593Ssam 	register u_short *dnreg;
1166593Ssam 	register int cc;
1174737Swnj 	register struct dndevice *dp;
1186593Ssam 	char buf[OBUFSIZ];
1194737Swnj 	register char *cp;
1204737Swnj 	extern lbolt;
1214737Swnj 
1224737Swnj 	dp = (struct dndevice *)dninfo[DNUNIT(dev)]->ui_addr;
1234737Swnj 	dnreg = &(dp->dn_reg[DNREG(dev)]);
1244737Swnj 	cc = MIN(u.u_count, OBUFSIZ);
1256593Ssam 	cp = buf;
1264737Swnj 	iomove(cp, (unsigned)cc, B_WRITE);
1274737Swnj 	if (u.u_error)
1284737Swnj 		return;
1294737Swnj 	while ((*dnreg & (PWI|ACR|DSS)) == 0 && cc >= 0) {
1306593Ssam 		spl4();
1316593Ssam 		if ((*dnreg & PND) == 0 || cc == 0)
1324737Swnj 			sleep((caddr_t)dnreg, DNPRI);
1334737Swnj 		else switch(*cp) {
1344737Swnj 
1354737Swnj 		case '-':
1364737Swnj 			sleep((caddr_t)&lbolt, DNPRI);
1374737Swnj 			sleep((caddr_t)&lbolt, DNPRI);
1384737Swnj 			break;
1394737Swnj 
1404737Swnj 		case 'f':
1414737Swnj 			*dnreg &= ~CRQ;
1424737Swnj 			sleep((caddr_t)&lbolt, DNPRI);
1434737Swnj 			*dnreg |= CRQ;
1444737Swnj 			break;
1454737Swnj 
1464737Swnj 		case '*': case ':':
1474737Swnj 			*cp = 012;
1484737Swnj 			goto dial;
1494737Swnj 
1504737Swnj 		case '#': case ';':
1514737Swnj 			*cp = 013;
1524737Swnj 			goto dial;
1534737Swnj 
1544737Swnj 		case 'e': case '<':
1554737Swnj 			*cp = 014;
1564737Swnj 			goto dial;
1574737Swnj 
1584737Swnj 		case 'w': case '=':
1594737Swnj 			*cp = 015;
1604737Swnj 			goto dial;
1614737Swnj 
1624737Swnj 		default:
1634737Swnj 			if (*cp < '0' || *cp > '9')
1644737Swnj 				break;
1654737Swnj 		dial:
1666593Ssam 			*dnreg = (*cp << 8) | (IENABLE|MENABLE|DPR|CRQ);
1674737Swnj 			sleep((caddr_t)dnreg, DNPRI);
1684737Swnj 		}
1694737Swnj 		cp++, cc--;
1704737Swnj 		spl0();
1714737Swnj 	}
1726593Ssam 	if (*dnreg & (PWI|ACR))
1734737Swnj 		u.u_error = EIO;
1744737Swnj }
1754737Swnj 
1764737Swnj dnintr(dev)
1774737Swnj 	dev_t dev;
1784737Swnj {
1796593Ssam 	register u_short *basereg, *dnreg;
1804737Swnj 
1816593Ssam 	basereg = (u_short *)dninfo[dev]->ui_addr;
1824737Swnj 	*basereg &= ~MENABLE;
1836593Ssam 	for (dnreg = basereg; dnreg < basereg + 4; dnreg++)
1846593Ssam 		if (*dnreg & DONE) {
1854737Swnj 			*dnreg &= ~(DONE|DPR);
1864737Swnj 			wakeup((caddr_t)dnreg);
1874737Swnj 		}
1884737Swnj 	*basereg |= MENABLE;
1894737Swnj }
1904737Swnj #endif
191