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