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