1*8808Sroot /* dmf.c 4.14 82/10/22 */ 26940Ssam 36940Ssam #include "dmf.h" 46940Ssam #if NDMF > 0 56940Ssam /* 66940Ssam * DMF32 driver 76940Ssam * 86940Ssam * TODO: 96940Ssam * test with modem 106940Ssam * load as much as possible into silo 116940Ssam * get correct numbers for receive silo parameter timeout 126940Ssam * use auto XON/XOFF 136940Ssam * test reset code 146940Ssam * test with more than one unit 156940Ssam * optimize for efficient DMA and dynamically 166940Ssam * decide between silo and DMA mode 176940Ssam */ 186940Ssam #include "bk.h" 196940Ssam #include "../h/param.h" 206940Ssam #include "../h/conf.h" 216940Ssam #include "../h/dir.h" 226940Ssam #include "../h/user.h" 236940Ssam #include "../h/tty.h" 246940Ssam #include "../h/map.h" 256940Ssam #include "../h/pte.h" 266940Ssam #include "../h/buf.h" 276940Ssam #include "../h/vm.h" 286940Ssam #include "../h/bk.h" 296940Ssam #include "../h/clist.h" 306940Ssam #include "../h/file.h" 317726Sroot #include "../h/uio.h" 326940Ssam 338473Sroot #include "../vaxuba/ubareg.h" 348473Sroot #include "../vaxuba/ubavar.h" 358473Sroot 366940Ssam /* 376940Ssam * Definition of the driver for the auto-configuration program. 386940Ssam */ 396940Ssam int dmfprobe(), dmfattach(), dmfrint(), dmfxint(); 406940Ssam struct uba_device *dmfinfo[NDMF]; 416940Ssam u_short dmfstd[] = { 0 }; 426940Ssam struct uba_driver dmfdriver = 436940Ssam { dmfprobe, 0, dmfattach, 0, dmfstd, "dmf", dmfinfo }; 446940Ssam 456940Ssam /* 466940Ssam * In this driver, "dmf" (unqualified) refers to the async portion 476940Ssam * of the dmf32, "dmfc" to the combo portion, "dmfs" to the sync 486940Ssam * portion, "dmfl" to the lp portion, and "dmfd" to the dr portion. 496940Ssam */ 506940Ssam struct dmfdevice 516940Ssam { 526940Ssam short dmfccsr0; /* combo csr 0 */ 536940Ssam short dmfccsr1; /* combo csr 1 */ 546940Ssam short dmfs[4]; 556940Ssam short dmfcsr; /* control-status register */ 566940Ssam short dmflpr; /* line parameter register */ 576940Ssam short dmfrbuf; /* receiver buffer (ro) */ 586940Ssam union { 596940Ssam u_short dmfirw; /* indirect register word */ 606940Ssam u_char dmfirc[2]; /* " " bytes */ 616940Ssam } dmfun; 626940Ssam short dmfl[2]; 636940Ssam short dmfd[4]; 646940Ssam }; 656940Ssam 666940Ssam #define dmfrsp dmfrbuf /* receive silo parameter register (wo) */ 676940Ssam #define dmftbuf dmfun.dmfirc[0] /* transmit buffer */ 686940Ssam #define dmftsc dmfun.dmfirc[0] /* transmit silo count */ 696940Ssam #define dmfrms dmfun.dmfirc[1] /* receive modem status */ 706940Ssam #define dmflcr dmfun.dmfirc[0] /* line control register */ 716940Ssam #define dmftms dmfun.dmfirc[1] /* transmit modem status */ 726940Ssam #define dmftba dmfun.dmfirw /* transmit buffer address */ 736940Ssam #define dmftcc dmfun.dmfirw /* transmit character count */ 746940Ssam 756940Ssam /* bits in dmfcsr */ 766940Ssam #define DMF_TI 0100000 /* transmit interrupt */ 776940Ssam #define DMF_TIE 0040000 /* transmit interrupt enable */ 786940Ssam #define DMF_NXM 0020000 /* non-existant memory */ 796940Ssam #define DMF_LIN 0003400 /* transmit line number */ 806940Ssam #define DMF_RI 0000200 /* receiver interrupt */ 816940Ssam #define DMF_RIE 0000100 /* receiver interrupt enable */ 826940Ssam #define DMF_CLR 0000040 /* master reset */ 836940Ssam #define DMF_IAD 0000037 /* indirect address register */ 846940Ssam 856940Ssam #define DMFIR_TBUF 000 /* select tbuf indirect register */ 866940Ssam #define DMFIR_LCR 010 /* select lcr indirect register */ 876940Ssam #define DMFIR_TBA 020 /* select tba indirect register */ 886940Ssam #define DMFIR_TCC 030 /* select tcc indirect register */ 896940Ssam 906940Ssam /* bits in dmflpr */ 916940Ssam #define BITS6 (01<<3) 926940Ssam #define BITS7 (02<<3) 936940Ssam #define BITS8 (03<<3) 946940Ssam #define TWOSB 0200 956940Ssam #define PENABLE 040 966940Ssam /* DEC manuals incorrectly say this bit causes generation of even parity. */ 976940Ssam #define OPAR 0100 986940Ssam 996940Ssam #define DMF_IE (DMF_TIE|DMF_RIE) 1006940Ssam 1016940Ssam #define DMF_SILOCNT 32 /* size of DMF output silo (per line) */ 1026940Ssam 1036940Ssam /* bits in dmfrbuf */ 1046940Ssam #define DMF_DSC 0004000 /* data set change */ 1056940Ssam #define DMF_PE 0010000 /* parity error */ 1066940Ssam #define DMF_FE 0020000 /* framing error */ 1076940Ssam #define DMF_DO 0040000 /* data overrun */ 1086940Ssam 1096940Ssam /* bits in dmfrms */ 1106940Ssam #define DMF_USRR 0004 /* user modem signal (pin 25) */ 1116940Ssam #define DMF_SR 0010 /* secondary receive */ 1126940Ssam #define DMF_CTS 0020 /* clear to send */ 1136940Ssam #define DMF_CAR 0040 /* carrier detect */ 1146940Ssam #define DMF_RNG 0100 /* ring */ 1156940Ssam #define DMF_DSR 0200 /* data set ready */ 1166940Ssam 1176940Ssam /* bits in dmftms */ 1186940Ssam #define DMF_USRW 0001 /* user modem signal (pin 18) */ 1196940Ssam #define DMF_DTR 0002 /* data terminal ready */ 1206940Ssam #define DMF_RATE 0004 /* data signal rate select */ 1216940Ssam #define DMF_ST 0010 /* secondary transmit */ 1226940Ssam #define DMF_RTS 0020 /* request to send */ 1236940Ssam #define DMF_BRK 0040 /* pseudo break bit */ 1246940Ssam #define DMF_PREEMPT 0200 /* preempt output */ 1256940Ssam 1266940Ssam /* flags for modem control */ 1276940Ssam #define DMF_ON (DMF_DTR|DMF_RTS) 1286940Ssam #define DMF_OFF 0 1296940Ssam 1306940Ssam /* bits in dmflcr */ 1316940Ssam #define DMF_MIE 0040 /* modem interrupt enable */ 1326940Ssam #define DMF_FLUSH 0020 /* flush transmit silo */ 1336940Ssam #define DMF_RBRK 0010 /* real break bit */ 1346940Ssam #define DMF_RE 0004 /* receive enable */ 1356940Ssam #define DMF_AUTOX 0002 /* auto XON/XOFF */ 1366940Ssam #define DMF_TE 0001 /* transmit enable */ 1376940Ssam 1386940Ssam #define DMFLCR_ENA (DMF_MIE|DMF_RE|DMF_TE) 1396940Ssam 1406940Ssam /* bits in dm lsr, copied from dh.c */ 1416940Ssam #define DML_USR 0001000 /* usr modem sig, not a real DM bit */ 1426940Ssam #define DML_DSR 0000400 /* data set ready, not a real DM bit */ 1436940Ssam #define DML_RNG 0000200 /* ring */ 1446940Ssam #define DML_CAR 0000100 /* carrier detect */ 1456940Ssam #define DML_CTS 0000040 /* clear to send */ 1466940Ssam #define DML_SR 0000020 /* secondary receive */ 1476940Ssam #define DML_ST 0000010 /* secondary transmit */ 1486940Ssam #define DML_RTS 0000004 /* request to send */ 1496940Ssam #define DML_DTR 0000002 /* data terminal ready */ 1506940Ssam #define DML_LE 0000001 /* line enable */ 1516940Ssam 1526940Ssam /* 1536940Ssam * Local variables for the driver 1546940Ssam */ 1556940Ssam char dmf_speeds[] = 1566940Ssam { 0, 0, 1, 2, 3, 4, 0, 5, 6, 7, 010, 012, 014, 016, 017, 0 }; 1576940Ssam 1586940Ssam struct tty dmf_tty[NDMF*8]; 1596940Ssam char dmfsoftCAR[NDMF]; 1608778Sroot #ifndef lint 1618778Sroot int ndmf = NDMF*8; /* used by iostat */ 1628778Sroot #endif 1636940Ssam int dmfact; /* mask of active dmf's */ 1646940Ssam int dmfstart(), ttrstrt(); 1656940Ssam 1666940Ssam #ifdef DMFDMA 1676940Ssam /* 1686940Ssam * The clist space is mapped by the driver onto each UNIBUS. 1696940Ssam * The UBACVT macro converts a clist space address for unibus uban 1706940Ssam * into an i/o space address for the DMA routine. 1716940Ssam */ 1726940Ssam int dmf_ubinfo[MAXNUBA]; /* info about allocated unibus map */ 1736940Ssam static int cbase[MAXNUBA]; /* base address in unibus map */ 1746940Ssam #define UBACVT(x, uban) (cbase[uban] + ((x)-(char *)cfree)) 1756940Ssam #endif 1766940Ssam 1776940Ssam /* 1786940Ssam * Routine for configuration to set dmf interrupt. 1796940Ssam */ 1806940Ssam /*ARGSUSED*/ 1816940Ssam dmfprobe(reg, ctlr) 1826940Ssam caddr_t reg; 1836940Ssam int ctlr; 1846940Ssam { 1856940Ssam register int br, cvec; /* these are ``value-result'' */ 1866940Ssam register struct dmfdevice *dmfaddr = (struct dmfdevice *)reg; 1876940Ssam 1886940Ssam #ifdef lint 1896940Ssam br = 0; cvec = br; br = cvec; 190*8808Sroot dmfxint(0); dmfrint(0); 191*8808Sroot dmfsrint(); dmfsxint(); dmfdaint(); dmfdbint(); dmflint(); 1926940Ssam #endif 1936940Ssam br = 0x15; 1946940Ssam cvec = (uba_hd[numuba].uh_lastiv -= 4*8); 1956940Ssam dmfaddr->dmfccsr0 = cvec >> 2; 1966940Ssam /* NEED TO SAVE IT SOMEWHERE FOR OTHER DEVICES */ 1977412Skre return (sizeof (struct dmfdevice)); 1986940Ssam } 1996940Ssam 2006940Ssam /* 2016940Ssam * Routine called to attach a dmf. 2026940Ssam */ 2036940Ssam dmfattach(ui) 2046940Ssam struct uba_device *ui; 2056940Ssam { 2066940Ssam 2076940Ssam dmfsoftCAR[ui->ui_unit] = ui->ui_flags; 2086940Ssam } 2096940Ssam 2106940Ssam 2116940Ssam /* 2126940Ssam * Open a DMF32 line, mapping the clist onto the uba if this 2136940Ssam * is the first dmf on this uba. Turn on this dmf if this is 2146940Ssam * the first use of it. 2156940Ssam */ 2166940Ssam /*ARGSUSED*/ 2176940Ssam dmfopen(dev, flag) 2186940Ssam dev_t dev; 2196940Ssam { 2206940Ssam register struct tty *tp; 2216940Ssam register int unit, dmf; 2226940Ssam register struct dmfdevice *addr; 2236940Ssam register struct uba_device *ui; 2246940Ssam int s; 2256940Ssam 2266940Ssam unit = minor(dev); 2276940Ssam dmf = unit >> 3; 2288567Sroot if (unit >= NDMF*8 || (ui = dmfinfo[dmf])== 0 || ui->ui_alive == 0) 2298567Sroot return (ENXIO); 2306940Ssam tp = &dmf_tty[unit]; 2318567Sroot if (tp->t_state&TS_XCLUDE && u.u_uid!=0) 2328567Sroot return (EBUSY); 2336940Ssam addr = (struct dmfdevice *)ui->ui_addr; 2346940Ssam tp->t_addr = (caddr_t)addr; 2356940Ssam tp->t_oproc = dmfstart; 2366971Ssam tp->t_state |= TS_WOPEN; 2376940Ssam /* 2386940Ssam * While setting up state for this uba and this dmf, 2396940Ssam * block uba resets which can clear the state. 2406940Ssam */ 2416940Ssam s = spl5(); 2426940Ssam #ifdef DMFDMA 2436940Ssam if (dmf_ubinfo[ui->ui_ubanum] == 0) { 2446940Ssam dmf_ubinfo[ui->ui_ubanum] = 2456940Ssam uballoc(ui->ui_ubanum, (caddr_t)cfree, 2466940Ssam nclist*sizeof(struct cblock), 0); 2476940Ssam cbase[ui->ui_ubanum] = dmf_ubinfo[ui->ui_ubanum]&0x3ffff; 2486940Ssam } 2496940Ssam #endif 2506940Ssam if ((dmfact&(1<<dmf)) == 0) { 2516940Ssam addr->dmfcsr |= DMF_IE; 2526940Ssam dmfact |= (1<<dmf); 2536940Ssam addr->dmfrsp = 1; /* DON'T KNOW WHAT TO SET IT TO YET */ 2546940Ssam } 2556940Ssam splx(s); 2566940Ssam /* 2576940Ssam * If this is first open, initialze tty state to default. 2586940Ssam */ 2596971Ssam if ((tp->t_state&TS_ISOPEN) == 0) { 2606940Ssam ttychars(tp); 2616940Ssam if (tp->t_ispeed == 0) { 2626940Ssam tp->t_ispeed = B300; 2636940Ssam tp->t_ospeed = B300; 2646940Ssam tp->t_flags = ODDP|EVENP|ECHO; 2656940Ssam } 2666940Ssam dmfparam(unit); 2676940Ssam } 2686940Ssam /* 2696940Ssam * Wait for carrier, then process line discipline specific open. 2706940Ssam */ 2716940Ssam if ((dmfmctl(dev, DMF_ON, DMSET) & (DMF_CAR<<8)) || 2726940Ssam (dmfsoftCAR[dmf] & (1<<(unit&07)))) 2736971Ssam tp->t_state |= TS_CARR_ON; 2746940Ssam s = spl5(); 2756971Ssam while ((tp->t_state & TS_CARR_ON) == 0) { 2766971Ssam tp->t_state |= TS_WOPEN; 2776940Ssam sleep((caddr_t)&tp->t_rawq, TTIPRI); 2786940Ssam } 2796940Ssam splx(s); 2808567Sroot return ((*linesw[tp->t_line].l_open)(dev, tp)); 2816940Ssam } 2826940Ssam 2836940Ssam /* 2846940Ssam * Close a DMF32 line. 2856940Ssam */ 2866940Ssam /*ARGSUSED*/ 2876940Ssam dmfclose(dev, flag) 2886940Ssam dev_t dev; 2896940Ssam int flag; 2906940Ssam { 2916940Ssam register struct tty *tp; 2926940Ssam register unit; 2936940Ssam 2946940Ssam unit = minor(dev); 2956940Ssam tp = &dmf_tty[unit]; 2966940Ssam (*linesw[tp->t_line].l_close)(tp); 2978702Sroot (void) dmfmctl(unit, DMF_BRK, DMBIC); 2986971Ssam if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) 2998702Sroot (void) dmfmctl(unit, DMF_OFF, DMSET); 3006940Ssam ttyclose(tp); 3016940Ssam } 3026940Ssam 3037726Sroot dmfread(dev, uio) 3046940Ssam dev_t dev; 3057726Sroot struct uio *uio; 3066940Ssam { 3076940Ssam register struct tty *tp; 3086940Ssam 3096940Ssam tp = &dmf_tty[minor(dev)]; 3107726Sroot return ((*linesw[tp->t_line].l_read)(tp, uio)); 3116940Ssam } 3126940Ssam 3137832Sroot dmfwrite(dev, uio) 3146940Ssam dev_t dev; 3157832Sroot struct uio *uio; 3166940Ssam { 3176940Ssam register struct tty *tp; 3186940Ssam 3196940Ssam tp = &dmf_tty[minor(dev)]; 3208530Sroot return ((*linesw[tp->t_line].l_write)(tp, uio)); 3216940Ssam } 3226940Ssam 3236940Ssam /* 3246940Ssam * DMF32 receiver interrupt. 3256940Ssam */ 3266940Ssam dmfrint(dmf) 3276940Ssam int dmf; 3286940Ssam { 3296940Ssam register struct tty *tp; 3306940Ssam register c; 3316940Ssam register struct dmfdevice *addr; 3326940Ssam register struct tty *tp0; 3336940Ssam register struct uba_device *ui; 3346940Ssam int overrun = 0; 3356940Ssam 3366940Ssam ui = dmfinfo[dmf]; 3376940Ssam if (ui == 0 || ui->ui_alive == 0) 3386940Ssam return; 3396940Ssam addr = (struct dmfdevice *)ui->ui_addr; 3406940Ssam tp0 = &dmf_tty[dmf<<3]; 3416940Ssam /* 3426940Ssam * Loop fetching characters from the silo for this 3436940Ssam * dmf until there are no more in the silo. 3446940Ssam */ 3456940Ssam while ((c = addr->dmfrbuf) < 0) { 3466940Ssam tp = tp0 + ((c>>8)&07); 3476940Ssam if (c & DMF_DSC) { 3486940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBUF | ((c>>8)&07); 3496940Ssam if (addr->dmfrms & DMF_CAR) { 3506971Ssam if ((tp->t_state & TS_CARR_ON) == 0) { 3516940Ssam wakeup((caddr_t)&tp->t_rawq); 3526971Ssam tp->t_state |= TS_CARR_ON; 3536940Ssam } 3546940Ssam } else { 3556971Ssam if (tp->t_state & TS_CARR_ON) { 3566940Ssam gsignal(tp->t_pgrp, SIGHUP); 3576940Ssam gsignal(tp->t_pgrp, SIGCONT); 3586940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | 3596940Ssam ((c>>8)&07); 3606940Ssam addr->dmftms = 0; 3616940Ssam flushtty(tp, FREAD|FWRITE); 3626940Ssam } 3636971Ssam tp->t_state &= ~TS_CARR_ON; 3646940Ssam } 3656940Ssam continue; 3666940Ssam } 3676971Ssam if ((tp->t_state&TS_ISOPEN)==0) { 3686940Ssam wakeup((caddr_t)tp); 3696940Ssam continue; 3706940Ssam } 3716940Ssam if (c & DMF_PE) 3726940Ssam if ((tp->t_flags&(EVENP|ODDP))==EVENP 3736940Ssam || (tp->t_flags&(EVENP|ODDP))==ODDP ) 3746940Ssam continue; 3756940Ssam if ((c & DMF_DO) && overrun == 0) { 3766940Ssam printf("dmf%d: silo overflow\n", dmf); 3776940Ssam overrun = 1; 3786940Ssam } 3796940Ssam if (c & DMF_FE) 3806940Ssam /* 3816940Ssam * At framing error (break) generate 3826940Ssam * a null (in raw mode, for getty), or a 3836940Ssam * interrupt (in cooked/cbreak mode). 3846940Ssam */ 3856940Ssam if (tp->t_flags&RAW) 3866940Ssam c = 0; 3876940Ssam else 3886940Ssam c = tun.t_intrc; 3896940Ssam #if NBK > 0 3906940Ssam if (tp->t_line == NETLDISC) { 3916940Ssam c &= 0177; 3926940Ssam BKINPUT(c, tp); 3936940Ssam } else 3946940Ssam #endif 3956940Ssam (*linesw[tp->t_line].l_rint)(c, tp); 3966940Ssam } 3976940Ssam } 3986940Ssam 3996940Ssam /* 4006940Ssam * Ioctl for DMF32. 4016940Ssam */ 4026940Ssam /*ARGSUSED*/ 4037630Ssam dmfioctl(dev, cmd, data, flag) 4046940Ssam dev_t dev; 4057630Ssam caddr_t data; 4066940Ssam { 4076940Ssam register struct tty *tp; 4086940Ssam register int unit = minor(dev); 4098567Sroot int error; 4106940Ssam 4116940Ssam tp = &dmf_tty[unit]; 4128567Sroot error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); 4138567Sroot if (error >= 0) 4148567Sroot return (error); 4158567Sroot error = ttioctl(tp, cmd, data, flag); 4168567Sroot if (error >= 0) { 4177630Ssam if (cmd == TIOCSETP || cmd == TIOCSETN) 4186940Ssam dmfparam(unit); 4198567Sroot return (error); 4208567Sroot } 4218567Sroot switch (cmd) { 4226940Ssam 4236940Ssam case TIOCSBRK: 4248702Sroot (void) dmfmctl(dev, DMF_BRK, DMBIS); 4256940Ssam break; 4267630Ssam 4276940Ssam case TIOCCBRK: 4288702Sroot (void) dmfmctl(dev, DMF_BRK, DMBIC); 4296940Ssam break; 4307630Ssam 4316940Ssam case TIOCSDTR: 4328702Sroot (void) dmfmctl(dev, DMF_DTR|DMF_RTS, DMBIS); 4336940Ssam break; 4347630Ssam 4356940Ssam case TIOCCDTR: 4368702Sroot (void) dmfmctl(dev, DMF_DTR|DMF_RTS, DMBIC); 4376940Ssam break; 4387630Ssam 4396940Ssam case TIOCMSET: 4408702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMSET); 4416940Ssam break; 4427630Ssam 4436940Ssam case TIOCMBIS: 4448702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMBIS); 4456940Ssam break; 4467630Ssam 4476940Ssam case TIOCMBIC: 4488702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMBIC); 4496940Ssam break; 4507630Ssam 4516940Ssam case TIOCMGET: 4527630Ssam *(int *)data = dmftodm(dmfmctl(dev, 0, DMGET)); 4536940Ssam break; 4547630Ssam 4556940Ssam default: 4568567Sroot return (ENOTTY); 4576940Ssam } 4588567Sroot return (0); 4596940Ssam } 4606940Ssam 4616940Ssam dmtodmf(bits) 4626940Ssam register int bits; 4636940Ssam { 4646940Ssam register int b; 4656940Ssam 4666940Ssam b = bits & 012; 4676940Ssam if (bits & DML_ST) b |= DMF_RATE; 4686940Ssam if (bits & DML_RTS) b |= DMF_RTS; 4696940Ssam if (bits & DML_USR) b |= DMF_USRW; 4706940Ssam return(b); 4716940Ssam } 4726940Ssam 4736940Ssam dmftodm(bits) 4746940Ssam register int bits; 4756940Ssam { 4766940Ssam register int b; 4776940Ssam 4786940Ssam b = (bits & 012) | ((bits >> 7) & 0760) | DML_LE; 4796940Ssam if (bits & DMF_USRR) b |= DML_USR; 4806940Ssam if (bits & DMF_RTS) b |= DML_RTS; 4816940Ssam return(b); 4826940Ssam } 4836940Ssam 4846940Ssam 4856940Ssam /* 4866940Ssam * Set parameters from open or stty into the DMF hardware 4876940Ssam * registers. 4886940Ssam */ 4896940Ssam dmfparam(unit) 4906940Ssam register int unit; 4916940Ssam { 4926940Ssam register struct tty *tp; 4936940Ssam register struct dmfdevice *addr; 4946940Ssam register int lpar, lcr; 4956940Ssam int s; 4966940Ssam 4976940Ssam tp = &dmf_tty[unit]; 4986940Ssam addr = (struct dmfdevice *)tp->t_addr; 4996940Ssam /* 5006940Ssam * Block interrupts so parameters will be set 5016940Ssam * before the line interrupts. 5026940Ssam */ 5036940Ssam s = spl5(); 5046940Ssam addr->dmfcsr = (unit&07) | DMFIR_LCR | DMF_IE; 5056940Ssam if ((tp->t_ispeed)==0) { 5066971Ssam tp->t_state |= TS_HUPCLS; 5078702Sroot (void) dmfmctl(unit, DMF_OFF, DMSET); 5086940Ssam return; 5096940Ssam } 5106940Ssam lpar = (dmf_speeds[tp->t_ospeed]<<12) | (dmf_speeds[tp->t_ispeed]<<8); 5116940Ssam lcr = DMFLCR_ENA; 5126940Ssam if ((tp->t_ispeed) == B134) 5136940Ssam lpar |= BITS6|PENABLE; 5146940Ssam else if ((tp->t_flags&RAW) || (tp->t_local&LLITOUT)) 5156940Ssam lpar |= BITS8; 5166940Ssam else { 5176940Ssam lpar |= BITS7|PENABLE; 5186940Ssam /* CHECK FOR XON/XOFF AND SET lcr |= DMF_AUTOX; */ 5196940Ssam } 5206940Ssam if ((tp->t_flags&EVENP) == 0) 5216940Ssam lpar |= OPAR; 5226940Ssam if ((tp->t_ospeed) == B110) 5236940Ssam lpar |= TWOSB; 5246940Ssam lpar |= (unit&07); 5256940Ssam addr->dmflpr = lpar; 5266940Ssam addr->dmflcr = lcr; 5276940Ssam splx(s); 5286940Ssam } 5296940Ssam 5306940Ssam /* 5316940Ssam * DMF32 transmitter interrupt. 5326940Ssam * Restart the idle line. 5336940Ssam */ 5346940Ssam dmfxint(dmf) 5356940Ssam int dmf; 5366940Ssam { 5376940Ssam register struct tty *tp; 5386940Ssam register struct dmfdevice *addr; 5396940Ssam register struct uba_device *ui; 5406940Ssam register int unit, t; 5416940Ssam #ifdef DMFDMA 5426940Ssam short cntr; 5436940Ssam #endif 5446940Ssam 5456940Ssam ui = dmfinfo[dmf]; 5466940Ssam addr = (struct dmfdevice *)ui->ui_addr; 5476940Ssam while ((t = addr->dmfcsr) & DMF_TI) { 5486940Ssam unit = dmf*8 + ((t>>8)&07); 5496940Ssam tp = &dmf_tty[unit]; 5506971Ssam tp->t_state &= ~TS_BUSY; 5516940Ssam if (t & DMF_NXM) { 5526940Ssam printf("dmf%d: NXM line %d\n", dmf, unit&7); 5536940Ssam /* SHOULD RESTART OR SOMETHING... */ 5546940Ssam } 5556971Ssam if (tp->t_state&TS_FLUSH) 5566971Ssam tp->t_state &= ~TS_FLUSH; 5576940Ssam #ifdef DMFDMA 5586940Ssam else { 5596940Ssam addr->dmfcsr = DMFIR_TBUF | DMF_IE | (unit&07); 5606940Ssam if (addr->dmftsc == 0) { 5616940Ssam /* 5626940Ssam * Do arithmetic in a short to make up 5636940Ssam * for lost 16&17 bits. 5646940Ssam */ 5656940Ssam addr->dmfcsr = DMFIR_TBA | DMF_IE | (unit&07); 5666940Ssam cntr = addr->dmftba - 5676940Ssam UBACVT(tp->t_outq.c_cf, ui->ui_ubanum); 5686940Ssam ndflush(&tp->t_outq, (int)cntr); 5696940Ssam } 5706940Ssam } 5716940Ssam #endif 5726940Ssam if (tp->t_line) 5736940Ssam (*linesw[tp->t_line].l_start)(tp); 5746940Ssam else 5756940Ssam dmfstart(tp); 5766940Ssam } 5776940Ssam } 5786940Ssam 5796940Ssam /* 5806940Ssam * Start (restart) transmission on the given DMF32 line. 5816940Ssam */ 5826940Ssam dmfstart(tp) 5836940Ssam register struct tty *tp; 5846940Ssam { 5856940Ssam register struct dmfdevice *addr; 5868607Sroot register int unit, nch; 5876940Ssam int s; 5886940Ssam 5896940Ssam unit = minor(tp->t_dev); 5906940Ssam unit &= 07; 5916940Ssam addr = (struct dmfdevice *)tp->t_addr; 5926940Ssam 5936940Ssam /* 5946940Ssam * Must hold interrupts in following code to prevent 5956940Ssam * state of the tp from changing. 5966940Ssam */ 5976940Ssam s = spl5(); 5986940Ssam /* 5996940Ssam * If it's currently active, or delaying, no need to do anything. 6006940Ssam */ 6016971Ssam if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 6026940Ssam goto out; 6036940Ssam /* 6046940Ssam * If there are still characters in the silo, 6056940Ssam * just reenable the transmitter. 6066940Ssam */ 6076940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 6086940Ssam if (addr->dmftsc) { 6096940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 6106940Ssam addr->dmflcr |= DMF_TE; 6116971Ssam tp->t_state |= TS_BUSY; 6126940Ssam goto out; 6136940Ssam } 6146940Ssam /* 6156940Ssam * If there are sleepers, and output has drained below low 6166940Ssam * water mark, wake up the sleepers. 6176940Ssam */ 6186971Ssam if ((tp->t_state&TS_ASLEEP) && tp->t_outq.c_cc<=TTLOWAT(tp)) { 6196971Ssam tp->t_state &= ~TS_ASLEEP; 6206963Ssam wakeup((caddr_t)&tp->t_outq); 6216940Ssam } 6226940Ssam /* 6236940Ssam * Now restart transmission unless the output queue is 6246940Ssam * empty. 6256940Ssam */ 6266940Ssam if (tp->t_outq.c_cc == 0) 6276940Ssam goto out; 6286940Ssam if (tp->t_flags&RAW || tp->t_local&LLITOUT) 6296940Ssam nch = ndqb(&tp->t_outq, 0); 6306940Ssam else { 6316940Ssam nch = ndqb(&tp->t_outq, 0200); 6326940Ssam /* 6336940Ssam * If first thing on queue is a delay process it. 6346940Ssam */ 6356940Ssam if (nch == 0) { 6366940Ssam nch = getc(&tp->t_outq); 6376940Ssam timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6); 6386971Ssam tp->t_state |= TS_TIMEOUT; 6396940Ssam goto out; 6406940Ssam } 6416940Ssam } 6426940Ssam /* 6436940Ssam * If characters to transmit, restart transmission. 6446940Ssam */ 6456940Ssam if (nch) { 6466940Ssam #ifdef DMFDMA 6476940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 6486940Ssam addr->dmflcr |= DMF_TE; 6496940Ssam car = UBACVT(tp->t_outq.c_cf, dmfinfo[dmf]->ui_ubanum); 6506940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBA | unit; 6516940Ssam addr->dmftba = car; 6526940Ssam addr->dmftcc = ((car>>2)&0xc000) | nch; 6536940Ssam #else 6546940Ssam register char *cp = tp->t_outq.c_cf; 6556940Ssam register int i; 6566940Ssam 6576940Ssam nch = MIN(nch, DMF_SILOCNT); 6586940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 6596940Ssam addr->dmflcr |= DMF_TE; 6606940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 6616940Ssam for (i = 0; i < nch; i++) 6626940Ssam addr->dmftbuf = *cp++; 6636940Ssam ndflush(&tp->t_outq, nch); 6646940Ssam #endif 6656971Ssam tp->t_state |= TS_BUSY; 6666940Ssam } 6676940Ssam out: 6686940Ssam splx(s); 6696940Ssam } 6706940Ssam 6716940Ssam /* 6726940Ssam * Stop output on a line, e.g. for ^S/^Q or output flush. 6736940Ssam */ 6746940Ssam /*ARGSUSED*/ 6756940Ssam dmfstop(tp, flag) 6766940Ssam register struct tty *tp; 6776940Ssam { 6786940Ssam register struct dmfdevice *addr; 6796940Ssam register int unit, s; 6806940Ssam 6816940Ssam addr = (struct dmfdevice *)tp->t_addr; 6826940Ssam /* 6836940Ssam * Block input/output interrupts while messing with state. 6846940Ssam */ 6856940Ssam s = spl5(); 6866971Ssam if (tp->t_state & TS_BUSY) { 6876940Ssam /* 6886940Ssam * Device is transmitting; stop output 6896940Ssam * by selecting the line and disabling 6906940Ssam * the transmitter. If this is a flush 6916940Ssam * request then flush the output silo, 6926940Ssam * otherwise we will pick up where we 6936940Ssam * left off by enabling the transmitter. 6946940Ssam */ 6956940Ssam unit = minor(tp->t_dev); 6966940Ssam addr->dmfcsr = DMFIR_LCR | (unit&07) | DMF_IE; 6976940Ssam addr->dmflcr &= ~DMF_TE; 6986971Ssam if ((tp->t_state&TS_TTSTOP)==0) { 6996971Ssam tp->t_state |= TS_FLUSH; 7006940Ssam addr->dmflcr |= DMF_FLUSH; 7016940Ssam } else 7026971Ssam tp->t_state &= ~TS_BUSY; 7036940Ssam } 7046940Ssam splx(s); 7056940Ssam } 7066940Ssam 7076940Ssam /* 7086940Ssam * DMF32 modem control 7096940Ssam */ 7106940Ssam dmfmctl(dev, bits, how) 7116940Ssam dev_t dev; 7126940Ssam int bits, how; 7136940Ssam { 7146940Ssam register struct dmfdevice *dmfaddr; 7156940Ssam register int unit, mbits, lcr; 7166940Ssam int s; 7176940Ssam 7186940Ssam unit = minor(dev); 7196940Ssam dmfaddr = (struct dmfdevice *)(dmf_tty[unit].t_addr); 7206940Ssam unit &= 07; 7216940Ssam s = spl5(); 7226940Ssam dmfaddr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 7236940Ssam mbits = dmfaddr->dmfrms << 8; 7246940Ssam dmfaddr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 7256940Ssam mbits |= dmfaddr->dmftms; 7266940Ssam lcr = dmfaddr->dmflcr; 7276940Ssam switch (how) { 7286940Ssam case DMSET: 7296940Ssam mbits = bits; 7306940Ssam break; 7316940Ssam 7326940Ssam case DMBIS: 7336940Ssam mbits |= bits; 7346940Ssam break; 7356940Ssam 7366940Ssam case DMBIC: 7376940Ssam mbits &= ~bits; 7386940Ssam break; 7396940Ssam 7406940Ssam case DMGET: 7416940Ssam (void) splx(s); 7426940Ssam return(mbits); 7436940Ssam } 7446940Ssam dmfaddr->dmftms = mbits&037; 7456940Ssam if (mbits & DMF_BRK) 7466940Ssam lcr |= DMF_RBRK; 7476940Ssam else 7486940Ssam lcr &= ~DMF_RBRK; 7496940Ssam dmfaddr->dmflcr = lcr; 7506940Ssam (void) splx(s); 7516940Ssam return(mbits); 7526940Ssam } 7536940Ssam 7546940Ssam /* 7556940Ssam * Reset state of driver if UBA reset was necessary. 7566940Ssam * Reset the csr, lpr, and lcr registers on open lines, and 7576940Ssam * restart transmitters. 7586940Ssam */ 7596940Ssam dmfreset(uban) 7606940Ssam int uban; 7616940Ssam { 7626940Ssam register int dmf, unit; 7636940Ssam register struct tty *tp; 7646940Ssam register struct uba_device *ui; 7656940Ssam register struct dmfdevice *addr; 7666940Ssam int i; 7676940Ssam 7686940Ssam #ifdef DMFDMA 7696940Ssam if (dmf_ubinfo[uban] == 0) 7706940Ssam return; 7716940Ssam dmf_ubinfo[uban] = uballoc(uban, (caddr_t)cfree, 7726940Ssam nclist*sizeof (struct cblock), 0); 7736940Ssam cbase[uban] = dmf_ubinfo[uban]&0x3ffff; 7746940Ssam #endif 7756940Ssam for (dmf = 0; dmf < NDMF; dmf++) { 7766940Ssam ui = dmfinfo[dmf]; 7776940Ssam if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban) 7786940Ssam continue; 7796940Ssam printf(" dmf%d", dmf); 7806940Ssam addr = (struct dmfdevice *)ui->ui_addr; 7816940Ssam addr->dmfcsr = DMF_IE; 7826940Ssam addr->dmfrsp = 1; 7836940Ssam unit = dmf * 8; 7846940Ssam for (i = 0; i < 8; i++) { 7856940Ssam tp = &dmf_tty[unit]; 7866971Ssam if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { 7876940Ssam dmfparam(unit); 7888702Sroot (void) dmfmctl(unit, DMF_ON, DMSET); 7896971Ssam tp->t_state &= ~TS_BUSY; 7906940Ssam dmfstart(tp); 7916940Ssam } 7926940Ssam unit++; 7936940Ssam } 7946940Ssam } 7956940Ssam } 7966940Ssam 7976940Ssam /* stubs for interrupt routines for devices not yet supported */ 7986940Ssam 7996940Ssam dmfsrint() { printf("dmfsrint\n"); } 8006940Ssam 8016940Ssam dmfsxint() { printf("dmfsxint\n"); } 8026940Ssam 8036940Ssam dmfdaint() { printf("dmfdaint\n"); } 8046940Ssam 8056940Ssam dmfdbint() { printf("dmfdbint\n"); } 8066940Ssam 8076940Ssam dmflint() { printf("dmflint\n"); } 8086940Ssam #endif 809