1*8491Sroot /* dn.c 4.8 82/10/10 */ 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/conf.h" 174737Swnj #include "../h/ioctl.h" 184737Swnj 198474Sroot #include "../vaxuba/ubavar.h" 208474Sroot 214737Swnj struct dndevice { 226593Ssam u_short dn_reg[4]; 234737Swnj }; 244737Swnj 254737Swnj struct uba_device *dninfo[NDN]; 264737Swnj int dnprobe(), dnattach(); 274737Swnj u_short dnstd[] = { 0175200 }; 284737Swnj struct uba_driver dndriver = 294737Swnj { dnprobe, 0, dnattach, 0, dnstd, "dn", dninfo }; 304737Swnj 316593Ssam #define CRQ 0x001 /* call request */ 326593Ssam #define DPR 0x002 /* digit present */ 336593Ssam #define MENABLE 0x004 /* master enable */ 346593Ssam #define MAINT 0x008 /* maintenance mode */ 356593Ssam #define PND 0x010 /* present next digit */ 366593Ssam #define DSS 0x020 /* data set status */ 376593Ssam #define IENABLE 0x040 /* interrupt enable */ 386593Ssam #define DONE 0x080 /* operation complete */ 396593Ssam #define DLO 0x1000 /* data line occupied */ 406593Ssam #define ACR 0x4000 /* abandon call and retry */ 416593Ssam #define PWI 0x8000 /* power indicate */ 424737Swnj 434737Swnj #define DNPRI (PZERO+5) 444737Swnj #define DNUNIT(dev) (minor(dev)>>2) 454737Swnj #define DNREG(dev) ((dev)&03) 464737Swnj 474737Swnj #define OBUFSIZ 40 /* largest phone # dialer can handle */ 484737Swnj 494737Swnj /* 504737Swnj * There's no good way to determine the correct number of dialers attached 514933Swnj * to a single device (especially when dialers such as Vadic-821 MACS 526593Ssam * exist which can address four chassis, each with its own dialer). 534737Swnj */ 544737Swnj dnprobe(reg) 554737Swnj caddr_t reg; 564737Swnj { 576593Ssam register int br, cvec; /* value-result, must be r11, r10 */ 584737Swnj register struct dndevice *dnaddr = (struct dndevice *)reg; 594737Swnj 604737Swnj /* 614737Swnj * If there's at least one dialer out there it better be 626593Ssam * at chassis 0. 634737Swnj */ 644737Swnj dnaddr->dn_reg[0] = MENABLE|IENABLE|DONE; 654737Swnj DELAY(5); 664737Swnj dnaddr->dn_reg[0] = 0; 677409Skre return (sizeof (struct dndevice)); 684737Swnj } 694737Swnj 704737Swnj dnattach(ui) 714737Swnj struct uba_device *ui; 726593Ssam {} 734933Swnj 744737Swnj /*ARGSUSED*/ 754737Swnj dnopen(dev, flag) 764737Swnj dev_t dev; 774737Swnj { 784737Swnj register struct dndevice *dp; 796593Ssam register u_short unit, *dnreg; 804737Swnj register struct uba_device *ui; 814737Swnj register short dialer; 824737Swnj 834737Swnj if ((unit = DNUNIT(dev)) >= NDN || (ui = dninfo[unit]) == 0 || 846593Ssam ui->ui_alive == 0) { 854737Swnj u.u_error = ENXIO; 864737Swnj return; 874737Swnj } 886593Ssam dialer = DNREG(dev); 896593Ssam dp = (struct dndevice *)ui->ui_addr; 906593Ssam if (dp->dn_reg[dialer] & PWI) { 916593Ssam u.u_error = ENXIO; 926593Ssam return; 936593Ssam } 944737Swnj dnreg = &(dp->dn_reg[dialer]); 954737Swnj if (*dnreg&(DLO|CRQ)) { 964737Swnj u.u_error = EBUSY; 974737Swnj return; 984737Swnj } 994737Swnj dp->dn_reg[0] |= MENABLE; 1004737Swnj *dnreg = IENABLE|MENABLE|CRQ; 1014737Swnj } 1024737Swnj 1034737Swnj /*ARGSUSED*/ 1044737Swnj dnclose(dev, flag) 1054737Swnj dev_t dev; 1064737Swnj { 1074737Swnj register struct dndevice *dp; 1084737Swnj 1094737Swnj dp = (struct dndevice *)dninfo[DNUNIT(dev)]->ui_addr; 1104737Swnj dp->dn_reg[DNREG(dev)] = MENABLE; 1114737Swnj } 1124737Swnj 1137833Sroot dnwrite(dev, uio) 1144737Swnj dev_t dev; 1157833Sroot struct uio *uio; 1164737Swnj { 1176593Ssam register u_short *dnreg; 1186593Ssam register int cc; 1194737Swnj register struct dndevice *dp; 1206593Ssam char buf[OBUFSIZ]; 1214737Swnj register char *cp; 1224737Swnj extern lbolt; 123*8491Sroot int error; 1244737Swnj 1254737Swnj dp = (struct dndevice *)dninfo[DNUNIT(dev)]->ui_addr; 1264737Swnj dnreg = &(dp->dn_reg[DNREG(dev)]); 1277833Sroot cc = MIN(uio->uio_resid, OBUFSIZ); 1286593Ssam cp = buf; 129*8491Sroot error = uiomove(cp, (unsigned)cc, UIO_WRITE, uio); 130*8491Sroot if (error) 131*8491Sroot return (error); 1324737Swnj while ((*dnreg & (PWI|ACR|DSS)) == 0 && cc >= 0) { 1336593Ssam spl4(); 1346593Ssam if ((*dnreg & PND) == 0 || cc == 0) 1354737Swnj sleep((caddr_t)dnreg, DNPRI); 1364737Swnj else switch(*cp) { 1374737Swnj 1384737Swnj case '-': 1394737Swnj sleep((caddr_t)&lbolt, DNPRI); 1404737Swnj sleep((caddr_t)&lbolt, DNPRI); 1414737Swnj break; 1424737Swnj 1434737Swnj case 'f': 1444737Swnj *dnreg &= ~CRQ; 1454737Swnj sleep((caddr_t)&lbolt, DNPRI); 1464737Swnj *dnreg |= CRQ; 1474737Swnj break; 1484737Swnj 1494737Swnj case '*': case ':': 1504737Swnj *cp = 012; 1514737Swnj goto dial; 1524737Swnj 1534737Swnj case '#': case ';': 1544737Swnj *cp = 013; 1554737Swnj goto dial; 1564737Swnj 1574737Swnj case 'e': case '<': 1584737Swnj *cp = 014; 1594737Swnj goto dial; 1604737Swnj 1614737Swnj case 'w': case '=': 1624737Swnj *cp = 015; 1634737Swnj goto dial; 1644737Swnj 1654737Swnj default: 1664737Swnj if (*cp < '0' || *cp > '9') 1674737Swnj break; 1684737Swnj dial: 1696593Ssam *dnreg = (*cp << 8) | (IENABLE|MENABLE|DPR|CRQ); 1704737Swnj sleep((caddr_t)dnreg, DNPRI); 1714737Swnj } 1724737Swnj cp++, cc--; 1734737Swnj spl0(); 1744737Swnj } 1756593Ssam if (*dnreg & (PWI|ACR)) 176*8491Sroot return (EIO); 177*8491Sroot return (0); 1784737Swnj } 1794737Swnj 1804737Swnj dnintr(dev) 1814737Swnj dev_t dev; 1824737Swnj { 1836593Ssam register u_short *basereg, *dnreg; 1844737Swnj 1856593Ssam basereg = (u_short *)dninfo[dev]->ui_addr; 1864737Swnj *basereg &= ~MENABLE; 1876593Ssam for (dnreg = basereg; dnreg < basereg + 4; dnreg++) 1886593Ssam if (*dnreg & DONE) { 1894737Swnj *dnreg &= ~(DONE|DPR); 1904737Swnj wakeup((caddr_t)dnreg); 1914737Swnj } 1924737Swnj *basereg |= MENABLE; 1934737Swnj } 1944737Swnj #endif 195