123324Smckusick /* 223324Smckusick * Copyright (c) 1982 Regents of the University of California. 323324Smckusick * All rights reserved. The Berkeley software License Agreement 423324Smckusick * specifies the terms and conditions for redistribution. 523324Smckusick * 6*26221Skarels * @(#)dmf.c 6.13 (Berkeley) 02/17/86 723324Smckusick */ 86940Ssam 96940Ssam #include "dmf.h" 106940Ssam #if NDMF > 0 116940Ssam /* 126940Ssam * DMF32 driver 136940Ssam * 1421955Sbloom * 156940Ssam * TODO: 166940Ssam * test with modem 176940Ssam * load as much as possible into silo 186940Ssam * use auto XON/XOFF 196940Ssam * test reset code 2021955Sbloom **************************** 2121955Sbloom * DMF32 line printer driver 2221955Sbloom * 2321955Sbloom * the line printer on dmfx is indicated by a minor device code of 128+x 2421955Sbloom * 2521955Sbloom * the flags field of the config file is interpreted like so: 2621955Sbloom * bits meaning 2721955Sbloom * ---- ------- 2821955Sbloom * 0-7 soft carrier bits for ttys part of dmf32 2921955Sbloom * 8-15 number of cols/line on the line printer 3021955Sbloom * if 0, 132 will be used. 3121955Sbloom * 16-23 number of lines/page on the line printer 3221955Sbloom * if 0, 66 will be used. 3321955Sbloom * 346940Ssam */ 359772Ssam #include "../machine/pte.h" 369772Ssam 376940Ssam #include "bk.h" 3816063Skarels #include "uba.h" 3917124Sbloom #include "param.h" 4017124Sbloom #include "conf.h" 4117124Sbloom #include "dir.h" 4217124Sbloom #include "user.h" 4317124Sbloom #include "ioctl.h" 4417124Sbloom #include "tty.h" 4517124Sbloom #include "map.h" 4617124Sbloom #include "buf.h" 4717124Sbloom #include "vm.h" 4817124Sbloom #include "bkmac.h" 4917124Sbloom #include "clist.h" 5017124Sbloom #include "file.h" 5117124Sbloom #include "uio.h" 5221955Sbloom #include "kernel.h" 5318312Sralph #include "syslog.h" 546940Ssam 5517124Sbloom #include "ubareg.h" 5617124Sbloom #include "ubavar.h" 5717124Sbloom #include "dmfreg.h" 588473Sroot 596940Ssam /* 606940Ssam * Definition of the driver for the auto-configuration program. 616940Ssam */ 626940Ssam int dmfprobe(), dmfattach(), dmfrint(), dmfxint(); 6321955Sbloom int dmflint(); 646940Ssam struct uba_device *dmfinfo[NDMF]; 656940Ssam u_short dmfstd[] = { 0 }; 666940Ssam struct uba_driver dmfdriver = 676940Ssam { dmfprobe, 0, dmfattach, 0, dmfstd, "dmf", dmfinfo }; 686940Ssam 6925449Skarels int dmf_timeout = 10; /* silo timeout, in ms */ 7021955Sbloom int dmf_mindma = 4; /* don't dma below this point */ 7121955Sbloom 726940Ssam /* 736940Ssam * Local variables for the driver 746940Ssam */ 756940Ssam char dmf_speeds[] = 766940Ssam { 0, 0, 1, 2, 3, 4, 0, 5, 6, 7, 010, 012, 014, 016, 017, 0 }; 776940Ssam 7825449Skarels #ifndef PORTSELECTOR 7925449Skarels #define ISPEED B9600 8025449Skarels #define IFLAGS (EVENP|ODDP|ECHO) 8125449Skarels #else 8225449Skarels #define ISPEED B4800 8325449Skarels #define IFLAGS (EVENP|ODDP) 8425449Skarels #endif 8525449Skarels 866940Ssam struct tty dmf_tty[NDMF*8]; 876940Ssam char dmfsoftCAR[NDMF]; 8821955Sbloom 8921955Sbloom struct dmfl_softc 9021955Sbloom { 9121955Sbloom unsigned dmfl_state; /* soft state bits */ 9221955Sbloom unsigned dmfl_info; /* uba info */ 9321955Sbloom unsigned short dmfl_lines; /* lines per page (66 def.) */ 9421955Sbloom unsigned short dmfl_cols; /* cols per line (132 def.) */ 9521955Sbloom char dmfl_buf[DMFL_BUFSIZ]; 9621955Sbloom } dmfl_softc[NDMF]; 9721955Sbloom 9821955Sbloom /* 9921955Sbloom * convert device number into DMF line printer unit number 10021955Sbloom */ 10121955Sbloom #define DMFL_UNIT(d) (minor(d)&0xF) /* up to 16 DMFs */ 10221955Sbloom 10321955Sbloom #define ASLP 1 /* waiting for interrupt from dmf */ 10421955Sbloom #define OPEN 2 /* line printer is open */ 10521955Sbloom #define ERROR 4 /* error while printing, driver 10621955Sbloom refuses to do anything till closed */ 10721955Sbloom 1088778Sroot #ifndef lint 1098778Sroot int ndmf = NDMF*8; /* used by iostat */ 1108778Sroot #endif 1116940Ssam int dmfact; /* mask of active dmf's */ 1126940Ssam int dmfstart(), ttrstrt(); 1136940Ssam 1146940Ssam /* 1156940Ssam * The clist space is mapped by the driver onto each UNIBUS. 1166940Ssam * The UBACVT macro converts a clist space address for unibus uban 1176940Ssam * into an i/o space address for the DMA routine. 1186940Ssam */ 11916063Skarels int dmf_ubinfo[NUBA]; /* info about allocated unibus map */ 12025449Skarels int cbase[NUBA]; /* base address in unibus map */ 1216940Ssam #define UBACVT(x, uban) (cbase[uban] + ((x)-(char *)cfree)) 12221955Sbloom char dmf_dma[NDMF*8]; 1236940Ssam 1246940Ssam /* 1256940Ssam * Routine for configuration to set dmf interrupt. 1266940Ssam */ 1276940Ssam /*ARGSUSED*/ 1286940Ssam dmfprobe(reg, ctlr) 1296940Ssam caddr_t reg; 13021955Sbloom struct uba_device *ctlr; 1316940Ssam { 1326940Ssam register int br, cvec; /* these are ``value-result'' */ 1336940Ssam register struct dmfdevice *dmfaddr = (struct dmfdevice *)reg; 13421955Sbloom register int i; 13521955Sbloom register unsigned int a; 13621955Sbloom static char *dmfdevs[]= 13721955Sbloom {"parallel","printer","synch","asynch"}; 13821955Sbloom unsigned int dmfoptions; 13925449Skarels static int (*intrv[3])() = { (int (*)())0, (int (*)())0, (int (*)())0 }; 1406940Ssam 1416940Ssam #ifdef lint 1426940Ssam br = 0; cvec = br; br = cvec; 1438808Sroot dmfxint(0); dmfrint(0); 1448808Sroot dmfsrint(); dmfsxint(); dmfdaint(); dmfdbint(); dmflint(); 1456940Ssam #endif 14621955Sbloom /* 14721955Sbloom * Pick the usual size DMF vector here (don't decrement it here). 14821955Sbloom * grab configuration; note that the DMF32 14921955Sbloom * doesn't seem to put the right bits in this 15021955Sbloom * register until AFTER the interrupt vector is set. 15121955Sbloom */ 1526940Ssam br = 0x15; 15321955Sbloom cvec = (uba_hd[numuba].uh_lastiv - 4*8); 15425449Skarels dmfaddr->dmfccsr0 = (cvec >> 2); 15521955Sbloom dmfoptions = dmfaddr->dmfccsr0 & DMFC_CONFMASK; 15621955Sbloom 15721955Sbloom /* catch a couple of special cases: Able vmz/32n and vmz/lp */ 15821955Sbloom if (dmfoptions == DMFC_ASYNC) { 15925449Skarels /* Async portion only */ 16025449Skarels 16125449Skarels cvec = (uba_hd[numuba].uh_lastiv -= 8); 16225449Skarels dmfaddr->dmfccsr0 = (cvec - 2*8) >> 2; 16325449Skarels intrv[0] = ctlr->ui_intr[4]; 16425449Skarels intrv[1] = ctlr->ui_intr[5]; 16525449Skarels ctlr->ui_intr = intrv; 16621955Sbloom } 16721955Sbloom else if (dmfoptions == DMFC_LP) { 16825449Skarels /* LP portion only */ 16921955Sbloom 17025449Skarels cvec = (uba_hd[numuba].uh_lastiv -= 8); 17125449Skarels ctlr->ui_intr = &ctlr->ui_intr[6]; 17221955Sbloom } 17325449Skarels else if (dmfoptions == (DMFC_LP|DMFC_ASYNC)) { 17425449Skarels /* LP ans Async portions only */ 17525449Skarels 17625449Skarels cvec = (uba_hd[numuba].uh_lastiv -= 2*8); 17725449Skarels ctlr->ui_intr = &ctlr->ui_intr[4]; 17825449Skarels } 17921955Sbloom else { 18025449Skarels /* All other configurations get everything */ 18121955Sbloom 18221955Sbloom cvec = (uba_hd[numuba].uh_lastiv -= 4*8); 18321955Sbloom } 18425449Skarels a = (dmfoptions >> 12) & 0xf; 18525449Skarels printf("dmf%d:", ctlr->ui_unit); 18625449Skarels for(i=0;a != 0;++i,a >>= 1) { 18725449Skarels if(a&1) 18825449Skarels printf(" %s",dmfdevs[i]); 18925449Skarels } 19025449Skarels printf(".\n"); 19121955Sbloom 19221955Sbloom if (dmfoptions & DMFC_LP) 19321955Sbloom dmfaddr->dmfl[0] = DMFL_RESET; 1946940Ssam /* NEED TO SAVE IT SOMEWHERE FOR OTHER DEVICES */ 1957412Skre return (sizeof (struct dmfdevice)); 1966940Ssam } 1976940Ssam 1986940Ssam /* 1996940Ssam * Routine called to attach a dmf. 2006940Ssam */ 2016940Ssam dmfattach(ui) 2026940Ssam struct uba_device *ui; 2036940Ssam { 20421955Sbloom register int cols = (ui->ui_flags>>8) & 0xff; 20521955Sbloom register int lines = (ui->ui_flags>>16) & 0xff; 2066940Ssam 20721955Sbloom dmfsoftCAR[ui->ui_unit] = ui->ui_flags & 0xff; 20821955Sbloom dmfl_softc[ui->ui_unit].dmfl_cols = cols==0?DMFL_DEFCOLS:cols; 20921955Sbloom dmfl_softc[ui->ui_unit].dmfl_lines = lines==0?DMFL_DEFLINES:lines; 210*26221Skarels cbase[ui->ui_ubanum] = -1; 2116940Ssam } 2126940Ssam 2136940Ssam 2146940Ssam /* 2156940Ssam * Open a DMF32 line, mapping the clist onto the uba if this 2166940Ssam * is the first dmf on this uba. Turn on this dmf if this is 2176940Ssam * the first use of it. 2186940Ssam */ 2196940Ssam /*ARGSUSED*/ 2206940Ssam dmfopen(dev, flag) 2216940Ssam dev_t dev; 2226940Ssam { 2236940Ssam register struct tty *tp; 2246940Ssam register int unit, dmf; 2256940Ssam register struct dmfdevice *addr; 2266940Ssam register struct uba_device *ui; 2276940Ssam int s; 2286940Ssam 2296940Ssam unit = minor(dev); 23021955Sbloom if(unit & 0200) 23121955Sbloom return(dmflopen(dev,flag)); 2326940Ssam dmf = unit >> 3; 2338567Sroot if (unit >= NDMF*8 || (ui = dmfinfo[dmf])== 0 || ui->ui_alive == 0) 2348567Sroot return (ENXIO); 2356940Ssam tp = &dmf_tty[unit]; 2368567Sroot if (tp->t_state&TS_XCLUDE && u.u_uid!=0) 2378567Sroot return (EBUSY); 2386940Ssam addr = (struct dmfdevice *)ui->ui_addr; 2396940Ssam tp->t_addr = (caddr_t)addr; 2406940Ssam tp->t_oproc = dmfstart; 2416971Ssam tp->t_state |= TS_WOPEN; 2426940Ssam /* 2436940Ssam * While setting up state for this uba and this dmf, 2446940Ssam * block uba resets which can clear the state. 2456940Ssam */ 24621955Sbloom s = spltty(); 247*26221Skarels if (cbase[ui->ui_ubanum] == -1) { 2486940Ssam dmf_ubinfo[ui->ui_ubanum] = 2496940Ssam uballoc(ui->ui_ubanum, (caddr_t)cfree, 2506940Ssam nclist*sizeof(struct cblock), 0); 251*26221Skarels cbase[ui->ui_ubanum] = UBAI_ADDR(dmf_ubinfo[ui->ui_ubanum]); 2526940Ssam } 2536940Ssam if ((dmfact&(1<<dmf)) == 0) { 2546940Ssam addr->dmfcsr |= DMF_IE; 2556940Ssam dmfact |= (1<<dmf); 25621955Sbloom addr->dmfrsp = dmf_timeout; 2576940Ssam } 2586940Ssam splx(s); 2596940Ssam /* 2606940Ssam * If this is first open, initialze tty state to default. 2616940Ssam */ 2626971Ssam if ((tp->t_state&TS_ISOPEN) == 0) { 2636940Ssam ttychars(tp); 26425449Skarels tp->t_ispeed = ISPEED; 26525449Skarels tp->t_ospeed = ISPEED; 26625449Skarels tp->t_flags = IFLAGS; 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; 27521955Sbloom s = spltty(); 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); 29621955Sbloom if(unit & 0200) 29721955Sbloom return(dmflclose(dev,flag)); 29821955Sbloom 2996940Ssam tp = &dmf_tty[unit]; 3006940Ssam (*linesw[tp->t_line].l_close)(tp); 3018702Sroot (void) dmfmctl(unit, DMF_BRK, DMBIC); 3026971Ssam if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) 3038702Sroot (void) dmfmctl(unit, DMF_OFF, DMSET); 3046940Ssam ttyclose(tp); 3056940Ssam } 3066940Ssam 3077726Sroot dmfread(dev, uio) 3086940Ssam dev_t dev; 3097726Sroot struct uio *uio; 3106940Ssam { 3116940Ssam register struct tty *tp; 3126940Ssam 31321955Sbloom if(minor(dev)&0200) 31421955Sbloom return(ENXIO); 3156940Ssam tp = &dmf_tty[minor(dev)]; 3167726Sroot return ((*linesw[tp->t_line].l_read)(tp, uio)); 3176940Ssam } 3186940Ssam 3197832Sroot dmfwrite(dev, uio) 3206940Ssam dev_t dev; 3217832Sroot struct uio *uio; 3226940Ssam { 3236940Ssam register struct tty *tp; 3246940Ssam 32521955Sbloom if(minor(dev)&0200) 32621955Sbloom return(dmflwrite(dev,uio)); 3276940Ssam tp = &dmf_tty[minor(dev)]; 3288530Sroot return ((*linesw[tp->t_line].l_write)(tp, uio)); 3296940Ssam } 3306940Ssam 3316940Ssam /* 3326940Ssam * DMF32 receiver interrupt. 3336940Ssam */ 3346940Ssam dmfrint(dmf) 3356940Ssam int dmf; 3366940Ssam { 3376940Ssam register c; 3386940Ssam register struct dmfdevice *addr; 3396940Ssam register struct tty *tp0; 34021955Sbloom register dev; 34121955Sbloom int unit; 34225449Skarels int overrun = 0; 3436940Ssam 34421955Sbloom { 34521955Sbloom register struct uba_device *ui; 34621955Sbloom 34721955Sbloom ui = dmfinfo[dmf]; 34821955Sbloom if (ui == 0 || ui->ui_alive == 0) 34921955Sbloom return; 35021955Sbloom addr = (struct dmfdevice *)ui->ui_addr; 35121955Sbloom } 35221955Sbloom tp0 = &dmf_tty[dmf * 8]; 3536940Ssam /* 3546940Ssam * Loop fetching characters from the silo for this 3556940Ssam * dmf until there are no more in the silo. 3566940Ssam */ 3576940Ssam while ((c = addr->dmfrbuf) < 0) { 35821955Sbloom register struct tty *tp; 35921955Sbloom 36021955Sbloom unit = (c >> 8) & 07; 36121955Sbloom tp = tp0 + unit; 36221955Sbloom dev = unit + dmf * 8; 3636940Ssam if (c & DMF_DSC) { 36421955Sbloom addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 36525449Skarels if (addr->dmfrms & DMF_CAR) 36625449Skarels (void)(*linesw[tp->t_line].l_modem)(tp, 1); 36725449Skarels else if ((dmfsoftCAR[dmf] & (1<<unit)) == 0 && 36825449Skarels (*linesw[tp->t_line].l_modem)(tp, 0) == 0) { 36925449Skarels addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 37025449Skarels addr->dmflctms = DMFLCR_ENA; 3716940Ssam } 3726940Ssam continue; 3736940Ssam } 3746971Ssam if ((tp->t_state&TS_ISOPEN)==0) { 37525449Skarels wakeup((caddr_t)&tp->t_rawq); 37625449Skarels #ifdef PORTSELECTOR 37725449Skarels if ((tp->t_state&TS_WOPEN) == 0) 37825449Skarels #endif 37925449Skarels continue; 3806940Ssam } 38121956Sbloom if (c & (DMF_PE|DMF_DO|DMF_FE)) { 38221955Sbloom if (c & DMF_PE) 38321955Sbloom if ((tp->t_flags&(EVENP|ODDP))==EVENP 38421955Sbloom || (tp->t_flags&(EVENP|ODDP))==ODDP ) 38521955Sbloom continue; 38621955Sbloom if ((c & DMF_DO) && overrun == 0) { 38724842Seric log(LOG_WARNING, "dmf%d: silo overflow\n", dmf); 38821955Sbloom overrun = 1; 38921955Sbloom } 39021955Sbloom if (c & DMF_FE) 39121955Sbloom /* 39221955Sbloom * At framing error (break) generate 39321955Sbloom * a null (in raw mode, for getty), or a 39421955Sbloom * interrupt (in cooked/cbreak mode). 39521955Sbloom */ 39621955Sbloom if (tp->t_flags&RAW) 39721955Sbloom c = 0; 39821955Sbloom else 39921955Sbloom c = tp->t_intrc; 4006940Ssam } 4016940Ssam #if NBK > 0 4026940Ssam if (tp->t_line == NETLDISC) { 4036940Ssam c &= 0177; 4046940Ssam BKINPUT(c, tp); 4056940Ssam } else 4066940Ssam #endif 4076940Ssam (*linesw[tp->t_line].l_rint)(c, tp); 4086940Ssam } 4096940Ssam } 4106940Ssam 4116940Ssam /* 4126940Ssam * Ioctl for DMF32. 4136940Ssam */ 4146940Ssam /*ARGSUSED*/ 4157630Ssam dmfioctl(dev, cmd, data, flag) 4166940Ssam dev_t dev; 4177630Ssam caddr_t data; 4186940Ssam { 4196940Ssam register struct tty *tp; 4206940Ssam register int unit = minor(dev); 4218567Sroot int error; 4226940Ssam 42321955Sbloom if(unit & 0200) 42421955Sbloom return (ENOTTY); 4256940Ssam tp = &dmf_tty[unit]; 4268567Sroot error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); 4278567Sroot if (error >= 0) 4288567Sroot return (error); 4298567Sroot error = ttioctl(tp, cmd, data, flag); 4308567Sroot if (error >= 0) { 43117562Sbloom if (cmd == TIOCSETP || cmd == TIOCSETN || cmd == TIOCLBIS || 43217562Sbloom cmd == TIOCLBIC || cmd == TIOCLSET) 4336940Ssam dmfparam(unit); 4348567Sroot return (error); 4358567Sroot } 4368567Sroot switch (cmd) { 4376940Ssam 4386940Ssam case TIOCSBRK: 4398702Sroot (void) dmfmctl(dev, DMF_BRK, DMBIS); 4406940Ssam break; 4417630Ssam 4426940Ssam case TIOCCBRK: 4438702Sroot (void) dmfmctl(dev, DMF_BRK, DMBIC); 4446940Ssam break; 4457630Ssam 4466940Ssam case TIOCSDTR: 4478702Sroot (void) dmfmctl(dev, DMF_DTR|DMF_RTS, DMBIS); 4486940Ssam break; 4497630Ssam 4506940Ssam case TIOCCDTR: 4518702Sroot (void) dmfmctl(dev, DMF_DTR|DMF_RTS, DMBIC); 4526940Ssam break; 4537630Ssam 4546940Ssam case TIOCMSET: 4558702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMSET); 4566940Ssam break; 4577630Ssam 4586940Ssam case TIOCMBIS: 4598702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMBIS); 4606940Ssam break; 4617630Ssam 4626940Ssam case TIOCMBIC: 4638702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMBIC); 4646940Ssam break; 4657630Ssam 4666940Ssam case TIOCMGET: 4677630Ssam *(int *)data = dmftodm(dmfmctl(dev, 0, DMGET)); 4686940Ssam break; 4697630Ssam 4706940Ssam default: 4718567Sroot return (ENOTTY); 4726940Ssam } 4738567Sroot return (0); 4746940Ssam } 4756940Ssam 4766940Ssam dmtodmf(bits) 4776940Ssam register int bits; 4786940Ssam { 4796940Ssam register int b; 4806940Ssam 4816940Ssam b = bits & 012; 4826940Ssam if (bits & DML_ST) b |= DMF_RATE; 4836940Ssam if (bits & DML_RTS) b |= DMF_RTS; 4846940Ssam if (bits & DML_USR) b |= DMF_USRW; 4856940Ssam return(b); 4866940Ssam } 4876940Ssam 4886940Ssam dmftodm(bits) 4896940Ssam register int bits; 4906940Ssam { 4916940Ssam register int b; 4926940Ssam 4936940Ssam b = (bits & 012) | ((bits >> 7) & 0760) | DML_LE; 4946940Ssam if (bits & DMF_USRR) b |= DML_USR; 4956940Ssam if (bits & DMF_RTS) b |= DML_RTS; 4966940Ssam return(b); 4976940Ssam } 4986940Ssam 4996940Ssam 5006940Ssam /* 5016940Ssam * Set parameters from open or stty into the DMF hardware 5026940Ssam * registers. 5036940Ssam */ 5046940Ssam dmfparam(unit) 5056940Ssam register int unit; 5066940Ssam { 5076940Ssam register struct tty *tp; 5086940Ssam register struct dmfdevice *addr; 5096940Ssam register int lpar, lcr; 5106940Ssam int s; 5116940Ssam 5126940Ssam tp = &dmf_tty[unit]; 5136940Ssam addr = (struct dmfdevice *)tp->t_addr; 5146940Ssam /* 5156940Ssam * Block interrupts so parameters will be set 5166940Ssam * before the line interrupts. 5176940Ssam */ 51821955Sbloom s = spltty(); 5196940Ssam addr->dmfcsr = (unit&07) | DMFIR_LCR | DMF_IE; 5206940Ssam if ((tp->t_ispeed)==0) { 5216971Ssam tp->t_state |= TS_HUPCLS; 5228702Sroot (void) dmfmctl(unit, DMF_OFF, DMSET); 52325449Skarels splx(s); 5246940Ssam return; 5256940Ssam } 5266940Ssam lpar = (dmf_speeds[tp->t_ospeed]<<12) | (dmf_speeds[tp->t_ispeed]<<8); 5276940Ssam lcr = DMFLCR_ENA; 5286940Ssam if ((tp->t_ispeed) == B134) 5296940Ssam lpar |= BITS6|PENABLE; 53024270Slepreau else if (tp->t_flags & (RAW|LITOUT|PASS8)) 5316940Ssam lpar |= BITS8; 5326940Ssam else { 5336940Ssam lpar |= BITS7|PENABLE; 5346940Ssam /* CHECK FOR XON/XOFF AND SET lcr |= DMF_AUTOX; */ 5356940Ssam } 53612450Ssam if (tp->t_flags&EVENP) 53712450Ssam lpar |= EPAR; 5386940Ssam if ((tp->t_ospeed) == B110) 5396940Ssam lpar |= TWOSB; 5406940Ssam lpar |= (unit&07); 5416940Ssam addr->dmflpr = lpar; 54225654Skarels addr->dmflctms = (addr->dmflctms &~ 0xff) | lcr; 5436940Ssam splx(s); 5446940Ssam } 5456940Ssam 5466940Ssam /* 5476940Ssam * DMF32 transmitter interrupt. 5486940Ssam * Restart the idle line. 5496940Ssam */ 5506940Ssam dmfxint(dmf) 5516940Ssam int dmf; 5526940Ssam { 55321955Sbloom int u = dmf * 8; 55421955Sbloom struct tty *tp0 = &dmf_tty[u]; 5556940Ssam register struct tty *tp; 5566940Ssam register struct dmfdevice *addr; 5576940Ssam register struct uba_device *ui; 55821955Sbloom register int t; 5596940Ssam short cntr; 5606940Ssam 5616940Ssam ui = dmfinfo[dmf]; 5626940Ssam addr = (struct dmfdevice *)ui->ui_addr; 5636940Ssam while ((t = addr->dmfcsr) & DMF_TI) { 56421955Sbloom if (t & DMF_NXM) 56521955Sbloom /* SHOULD RESTART OR SOMETHING... */ 56621955Sbloom printf("dmf%d: NXM line %d\n", dmf, t >> 8 & 7); 56721955Sbloom t = t >> 8 & 7; 56821955Sbloom tp = tp0 + t; 5696971Ssam tp->t_state &= ~TS_BUSY; 5706971Ssam if (tp->t_state&TS_FLUSH) 5716971Ssam tp->t_state &= ~TS_FLUSH; 57221955Sbloom else if (dmf_dma[u + t]) { 57321955Sbloom /* 57421955Sbloom * Do arithmetic in a short to make up 57521955Sbloom * for lost 16&17 bits. 57621955Sbloom */ 57721955Sbloom addr->dmfcsr = DMFIR_TBA | DMF_IE | t; 57821955Sbloom cntr = addr->dmftba - 57921955Sbloom UBACVT(tp->t_outq.c_cf, ui->ui_ubanum); 58021955Sbloom ndflush(&tp->t_outq, (int)cntr); 5816940Ssam } 5826940Ssam if (tp->t_line) 5836940Ssam (*linesw[tp->t_line].l_start)(tp); 5846940Ssam else 5856940Ssam dmfstart(tp); 5866940Ssam } 5876940Ssam } 5886940Ssam 5896940Ssam /* 5906940Ssam * Start (restart) transmission on the given DMF32 line. 5916940Ssam */ 5926940Ssam dmfstart(tp) 5936940Ssam register struct tty *tp; 5946940Ssam { 5956940Ssam register struct dmfdevice *addr; 5968607Sroot register int unit, nch; 5976940Ssam int s; 59821955Sbloom register int dmf; 5996940Ssam 6006940Ssam unit = minor(tp->t_dev); 60121955Sbloom dmf = unit >> 3; 6026940Ssam unit &= 07; 6036940Ssam addr = (struct dmfdevice *)tp->t_addr; 6046940Ssam 6056940Ssam /* 6066940Ssam * Must hold interrupts in following code to prevent 6076940Ssam * state of the tp from changing. 6086940Ssam */ 60921955Sbloom s = spltty(); 6106940Ssam /* 6116940Ssam * If it's currently active, or delaying, no need to do anything. 6126940Ssam */ 6136971Ssam if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 6146940Ssam goto out; 6156940Ssam /* 6166940Ssam * If there are still characters in the silo, 6176940Ssam * just reenable the transmitter. 6186940Ssam */ 6196940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 6206940Ssam if (addr->dmftsc) { 6216940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 62225449Skarels addr->dmflctms = addr->dmflctms | DMF_TE; 6236971Ssam tp->t_state |= TS_BUSY; 6246940Ssam goto out; 6256940Ssam } 6266940Ssam /* 6276940Ssam * If there are sleepers, and output has drained below low 6286940Ssam * water mark, wake up the sleepers. 6296940Ssam */ 63021955Sbloom if (tp->t_outq.c_cc<=TTLOWAT(tp)) { 63121955Sbloom if (tp->t_state&TS_ASLEEP) { 63221955Sbloom tp->t_state &= ~TS_ASLEEP; 63321955Sbloom wakeup((caddr_t)&tp->t_outq); 63421955Sbloom } 63521955Sbloom if (tp->t_wsel) { 63621955Sbloom selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); 63721955Sbloom tp->t_wsel = 0; 63821955Sbloom tp->t_state &= ~TS_WCOLL; 63921955Sbloom } 6406940Ssam } 6416940Ssam /* 6426940Ssam * Now restart transmission unless the output queue is 6436940Ssam * empty. 6446940Ssam */ 6456940Ssam if (tp->t_outq.c_cc == 0) 6466940Ssam goto out; 6479550Ssam if (tp->t_flags & (RAW|LITOUT)) 6486940Ssam nch = ndqb(&tp->t_outq, 0); 6496940Ssam else { 65021955Sbloom if ((nch = ndqb(&tp->t_outq, 0200)) == 0) { 65121955Sbloom /* 65221955Sbloom * If first thing on queue is a delay process it. 65321955Sbloom */ 6546940Ssam nch = getc(&tp->t_outq); 6556940Ssam timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6); 6566971Ssam tp->t_state |= TS_TIMEOUT; 6576940Ssam goto out; 6586940Ssam } 6596940Ssam } 6606940Ssam /* 6616940Ssam * If characters to transmit, restart transmission. 6626940Ssam */ 66321955Sbloom if (nch >= dmf_mindma) { 66421955Sbloom register car; 66521955Sbloom 66621955Sbloom dmf_dma[minor(tp->t_dev)] = 1; 6676940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 66825449Skarels addr->dmflctms = addr->dmflctms | DMF_TE; 6696940Ssam car = UBACVT(tp->t_outq.c_cf, dmfinfo[dmf]->ui_ubanum); 6706940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBA | unit; 6716940Ssam addr->dmftba = car; 67221955Sbloom addr->dmftcc = ((car >> 2) & 0xc000) | nch; 67321955Sbloom tp->t_state |= TS_BUSY; 67421955Sbloom } else if (nch) { 6756940Ssam register char *cp = tp->t_outq.c_cf; 6766940Ssam register int i; 6776940Ssam 67821955Sbloom dmf_dma[minor(tp->t_dev)] = 0; 6796940Ssam nch = MIN(nch, DMF_SILOCNT); 6806940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 68125449Skarels addr->dmflctms = addr->dmflctms | DMF_TE; 6826940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 6836940Ssam for (i = 0; i < nch; i++) 6846940Ssam addr->dmftbuf = *cp++; 6856940Ssam ndflush(&tp->t_outq, nch); 6866971Ssam tp->t_state |= TS_BUSY; 6876940Ssam } 6886940Ssam out: 6896940Ssam splx(s); 6906940Ssam } 6916940Ssam 6926940Ssam /* 6936940Ssam * Stop output on a line, e.g. for ^S/^Q or output flush. 6946940Ssam */ 6956940Ssam /*ARGSUSED*/ 6966940Ssam dmfstop(tp, flag) 6976940Ssam register struct tty *tp; 6986940Ssam { 6996940Ssam register struct dmfdevice *addr; 70021955Sbloom register unit = minor(tp->t_dev) & 7; 70121955Sbloom int s; 7026940Ssam 7036940Ssam addr = (struct dmfdevice *)tp->t_addr; 7046940Ssam /* 7056940Ssam * Block input/output interrupts while messing with state. 7066940Ssam */ 70721955Sbloom s = spltty(); 70821955Sbloom if (flag) { 70921955Sbloom addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 71021955Sbloom if (addr->dmftsc) { 71121955Sbloom /* 71221955Sbloom * Flush regardless of whether we're transmitting 71321955Sbloom * (TS_BUSY), if the silo contains untransmitted 71421955Sbloom * characters. 71521955Sbloom */ 71621955Sbloom addr->dmfcsr = DMFIR_LCR | unit | DMF_IE; 71725449Skarels addr->dmflctms = addr->dmflctms | DMF_TE | DMF_FLUSH; 71821955Sbloom /* this will interrupt so let dmfxint handle the rest */ 71921955Sbloom tp->t_state |= TS_FLUSH|TS_BUSY; 72021955Sbloom } 72121955Sbloom } else { 72221955Sbloom if (tp->t_state & TS_BUSY) { 72321955Sbloom /* 72421955Sbloom * Stop transmission by disabling 72521955Sbloom * the transmitter. We'll pick up where we 72621955Sbloom * left off by reenabling in dmfstart. 72721955Sbloom */ 72821955Sbloom addr->dmfcsr = DMFIR_LCR | unit | DMF_IE; 72925449Skarels addr->dmflctms = addr->dmflctms &~ DMF_TE; 73021955Sbloom /* no interrupt here */ 7316971Ssam tp->t_state &= ~TS_BUSY; 73221955Sbloom } 7336940Ssam } 7346940Ssam splx(s); 7356940Ssam } 7366940Ssam 7376940Ssam /* 7386940Ssam * DMF32 modem control 7396940Ssam */ 7406940Ssam dmfmctl(dev, bits, how) 7416940Ssam dev_t dev; 7426940Ssam int bits, how; 7436940Ssam { 7446940Ssam register struct dmfdevice *dmfaddr; 7456940Ssam register int unit, mbits, lcr; 7466940Ssam int s; 7476940Ssam 7486940Ssam unit = minor(dev); 7496940Ssam dmfaddr = (struct dmfdevice *)(dmf_tty[unit].t_addr); 7506940Ssam unit &= 07; 75121955Sbloom s = spltty(); 7526940Ssam dmfaddr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 7536940Ssam mbits = dmfaddr->dmfrms << 8; 7546940Ssam dmfaddr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 75525654Skarels lcr = dmfaddr->dmflctms; 75625449Skarels mbits |= (lcr & 0xff00) >> 8; 7576940Ssam switch (how) { 7586940Ssam case DMSET: 75912449Ssam mbits = (mbits &0xff00) | bits; 7606940Ssam break; 7616940Ssam 7626940Ssam case DMBIS: 7636940Ssam mbits |= bits; 7646940Ssam break; 7656940Ssam 7666940Ssam case DMBIC: 7676940Ssam mbits &= ~bits; 7686940Ssam break; 7696940Ssam 7706940Ssam case DMGET: 7716940Ssam (void) splx(s); 7726940Ssam return(mbits); 7736940Ssam } 7746940Ssam if (mbits & DMF_BRK) 7756940Ssam lcr |= DMF_RBRK; 7766940Ssam else 7776940Ssam lcr &= ~DMF_RBRK; 77825449Skarels dmfaddr->dmflctms = ((mbits & 037) << 8) | (lcr & 0xff); 7796940Ssam (void) splx(s); 7806940Ssam return(mbits); 7816940Ssam } 7826940Ssam 7836940Ssam /* 7846940Ssam * Reset state of driver if UBA reset was necessary. 7856940Ssam * Reset the csr, lpr, and lcr registers on open lines, and 7866940Ssam * restart transmitters. 7876940Ssam */ 7886940Ssam dmfreset(uban) 7896940Ssam int uban; 7906940Ssam { 7916940Ssam register int dmf, unit; 7926940Ssam register struct tty *tp; 7936940Ssam register struct uba_device *ui; 7946940Ssam register struct dmfdevice *addr; 7956940Ssam int i; 7966940Ssam 7976940Ssam for (dmf = 0; dmf < NDMF; dmf++) { 7986940Ssam ui = dmfinfo[dmf]; 7996940Ssam if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban) 8006940Ssam continue; 8016940Ssam printf(" dmf%d", dmf); 802*26221Skarels if (dmf_ubinfo[uban]) { 80325449Skarels dmf_ubinfo[uban] = uballoc(uban, (caddr_t)cfree, 80425449Skarels nclist*sizeof (struct cblock), 0); 805*26221Skarels cbase[uban] = UBAI_ADDR(dmf_ubinfo[uban]); 80625449Skarels } 8076940Ssam addr = (struct dmfdevice *)ui->ui_addr; 8086940Ssam addr->dmfcsr = DMF_IE; 80921955Sbloom addr->dmfrsp = dmf_timeout; 8106940Ssam unit = dmf * 8; 8116940Ssam for (i = 0; i < 8; i++) { 8126940Ssam tp = &dmf_tty[unit]; 8136971Ssam if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { 8146940Ssam dmfparam(unit); 8158702Sroot (void) dmfmctl(unit, DMF_ON, DMSET); 8166971Ssam tp->t_state &= ~TS_BUSY; 8176940Ssam dmfstart(tp); 8186940Ssam } 8196940Ssam unit++; 8206940Ssam } 8216940Ssam } 8226940Ssam } 8236940Ssam 82421955Sbloom /* dmflopen -- open the line printer port on a dmf32 82521955Sbloom * 82621955Sbloom */ 82721955Sbloom dmflopen(dev,flag) 82821955Sbloom dev_t dev; 82921955Sbloom int flag; 83021955Sbloom { 83121955Sbloom register int dmf; 83221955Sbloom register struct dmfl_softc *sc; 83321955Sbloom register struct uba_device *ui; 83421955Sbloom register struct dmfdevice *addr; 83521955Sbloom 83621955Sbloom 83721955Sbloom dmf = DMFL_UNIT(dev) ; 83821955Sbloom if(((sc= &dmfl_softc[dmf])->dmfl_state & OPEN) || 83921955Sbloom ((ui=dmfinfo[dmf]) == 0) || ui->ui_alive == 0) 84021955Sbloom return(ENXIO); 84121955Sbloom addr = (struct dmfdevice *)ui->ui_addr; 84221955Sbloom if((addr->dmfl[0] & DMFL_OFFLINE)) 84321955Sbloom { 84421955Sbloom /*printf("dmf: line printer offline/jammed\n");*/ 84521955Sbloom return(EIO); 84621955Sbloom } 84721955Sbloom if((addr->dmfl[0]&DMFL_CONV)) 84821955Sbloom { 84921955Sbloom printf("dmf:line printer disconnected\n"); 85021955Sbloom return(EIO); 85121955Sbloom } 85221955Sbloom 85321955Sbloom addr->dmfl[0] = 0; 85421955Sbloom sc->dmfl_state |= OPEN; 85521955Sbloom return 0; 85621955Sbloom } 85721955Sbloom 85821955Sbloom dmflclose(dev,flag) 85921955Sbloom dev_t dev; 86021955Sbloom int flag; 86121955Sbloom { 86221955Sbloom register int dmf= DMFL_UNIT(dev); 86321955Sbloom register struct dmfl_softc *sc = &dmfl_softc[dmf]; 86421955Sbloom 86521955Sbloom dmflout(dev,"\f",1); 86621955Sbloom sc->dmfl_state = 0; 86721955Sbloom if(sc->dmfl_info != 0) 86821955Sbloom ubarelse((struct dmfdevice *)(dmfinfo[dmf])->ui_ubanum, 86921955Sbloom &(sc->dmfl_info)); 87021955Sbloom 87121955Sbloom ((struct dmfdevice *)(dmfinfo[dmf]->ui_addr))->dmfl[0]=0; 87221955Sbloom return 0; 87321955Sbloom } 87421955Sbloom 87521955Sbloom dmflwrite(dev,uio) 87621955Sbloom dev_t dev; 87721955Sbloom struct uio *uio; 87821955Sbloom { 87921955Sbloom register unsigned int n; 88021955Sbloom register int error; 88121955Sbloom register struct dmfl_softc *sc; 88221955Sbloom 88321955Sbloom sc = &dmfl_softc[DMFL_UNIT(dev)]; 88421955Sbloom if(sc->dmfl_state&ERROR) return(EIO); 88521955Sbloom while(n=min(DMFL_BUFSIZ,(unsigned)uio->uio_resid)) 88621955Sbloom { 88721955Sbloom if(error=uiomove(&sc->dmfl_buf[0],(int)n, 88821955Sbloom UIO_WRITE,uio)) 88921955Sbloom { 89021955Sbloom printf("uio move error\n"); 89121955Sbloom return(error); 89221955Sbloom } 89321955Sbloom if(error=dmflout(dev,&sc->dmfl_buf[0],n)) 89421955Sbloom { 89521955Sbloom return(error); 89621955Sbloom } 89721955Sbloom } 89821955Sbloom return 0; 89921955Sbloom } 90021955Sbloom 90121955Sbloom 90221955Sbloom /* dmflout -- start io operation to dmf line printer 90321955Sbloom * cp is addr of buf of n chars to be sent. 90421955Sbloom * 90521955Sbloom * -- dmf will be put in formatted output mode, this will 90621955Sbloom * be selectable from an ioctl if the 90721955Sbloom * need ever arises. 90821955Sbloom */ 90921955Sbloom dmflout(dev,cp,n) 91021955Sbloom dev_t dev; 91121955Sbloom char *cp; 91221955Sbloom int n; 91321955Sbloom { 91421955Sbloom register struct dmfl_softc *sc; 91521955Sbloom register int dmf; 91621955Sbloom register struct uba_device *ui; 91721955Sbloom register struct dmfdevice *d; 91821955Sbloom register unsigned info; 91921955Sbloom register unsigned i; 92021955Sbloom 92121955Sbloom dmf = DMFL_UNIT(dev) ; 92221955Sbloom sc= &dmfl_softc[dmf]; 92321955Sbloom if(sc->dmfl_state&ERROR) return(EIO); 92421955Sbloom ui= dmfinfo[dmf]; 92521955Sbloom /* allocate unibus resources, will be released when io 92621955Sbloom * operation is done 92721955Sbloom */ 92821955Sbloom sc->dmfl_info= 92921955Sbloom info= 93021955Sbloom uballoc(ui->ui_ubanum,cp,n,0); 93121955Sbloom d= (struct dmfdevice *)ui->ui_addr; 93221955Sbloom d->dmfl[0] = (2<<8) | DMFL_FORMAT; /* indir reg 2 */ 93321955Sbloom /* indir reg auto increments on r/w */ 93421955Sbloom /* SO DON'T CHANGE THE ORDER OF THIS CODE */ 93521955Sbloom d->dmfl[1] = 0; /* prefix chars & num */ 93621955Sbloom d->dmfl[1] = 0; /* suffix chars & num */ 93721955Sbloom d->dmfl[1] = info; /* dma lo 16 bits addr */ 93821955Sbloom 93921955Sbloom /* NOT DOCUMENTED !! */ 94021955Sbloom d->dmfl[1] = -n; /* number of chars */ 94121955Sbloom /* ----------^-------- */ 94221955Sbloom 94321955Sbloom d->dmfl[1] = ((info>>16)&3) /* dma hi 2 bits addr */ 94421955Sbloom | (1<<8) /* auto cr insert */ 94521955Sbloom | (1<<9) /* use real ff */ 94621955Sbloom | (1<<15); /* no u/l conversion */ 94721955Sbloom d->dmfl[1] = sc->dmfl_lines /* lines per page */ 94821955Sbloom | (sc->dmfl_cols<<8); /* carriage width */ 94921955Sbloom sc->dmfl_state |= ASLP; 95021955Sbloom i=spltty(); 95121955Sbloom d->dmfl[0] |= DMFL_PEN|DMFL_IE; 95221955Sbloom while(sc->dmfl_state & ASLP) 95321955Sbloom { 95421955Sbloom sleep(&sc->dmfl_buf[0],(PZERO+8)); 95521955Sbloom while(sc->dmfl_state&ERROR) 95621955Sbloom { 95721955Sbloom timeout(dmflint,dmf,10*hz); 95821955Sbloom sleep(&sc->dmfl_state,(PZERO+8)); 95921955Sbloom } 96021955Sbloom /*if(sc->dmfl_state&ERROR) return (EIO);*/ 96121955Sbloom } 96221955Sbloom splx(i); 96321955Sbloom return(0); 96421955Sbloom } 96521955Sbloom /* dmflint -- handle an interrupt from the line printer part of the dmf32 96621955Sbloom * 96721955Sbloom */ 96821955Sbloom 96921955Sbloom dmflint(dmf) 97021955Sbloom int dmf; 97121955Sbloom { 97221955Sbloom 97321955Sbloom register struct uba_device *ui; 97421955Sbloom register struct dmfl_softc *sc; 97521955Sbloom register struct dmfdevice *d; 97621955Sbloom 97721955Sbloom ui= dmfinfo[dmf]; 97821955Sbloom sc= &dmfl_softc[dmf]; 97921955Sbloom d= (struct dmfdevice *)ui->ui_addr; 98021955Sbloom 98121955Sbloom d->dmfl[0] &= ~DMFL_IE; 98221955Sbloom 98321955Sbloom if(sc->dmfl_state&ERROR) 98421955Sbloom { 98521955Sbloom printf("dmfl: intr while in error state \n"); 98621955Sbloom if((d->dmfl[0]&DMFL_OFFLINE) == 0) 98721955Sbloom sc->dmfl_state &= ~ERROR; 98821955Sbloom wakeup(&sc->dmfl_state); 98921955Sbloom return; 99021955Sbloom } 99121955Sbloom if(d->dmfl[0]&DMFL_DMAERR) 99221955Sbloom { 99321955Sbloom printf("dmf:NXM\n"); 99421955Sbloom } 99521955Sbloom if(d->dmfl[0]&DMFL_OFFLINE) 99621955Sbloom { 99721955Sbloom printf("dmf:printer error\n"); 99821955Sbloom sc->dmfl_state |= ERROR; 99921955Sbloom } 100021955Sbloom if(d->dmfl[0]&DMFL_PDONE) 100121955Sbloom { 100221955Sbloom #ifdef notdef 100321955Sbloom printf("bytes= %d\n",d->dmfl[1]); 100421955Sbloom printf("lines= %d\n",d->dmfl[1]); 100521955Sbloom #endif 100621955Sbloom } 100721955Sbloom sc->dmfl_state &= ~ASLP; 100821955Sbloom wakeup(&sc->dmfl_buf[0]); 100921955Sbloom if(sc->dmfl_info != 0) 101021955Sbloom ubarelse(ui->ui_ubanum,&sc->dmfl_info); 101121955Sbloom sc->dmfl_info = 0; 101221955Sbloom 101321955Sbloom } 101421955Sbloom 10156940Ssam /* stubs for interrupt routines for devices not yet supported */ 10166940Ssam 10176940Ssam dmfsrint() { printf("dmfsrint\n"); } 10186940Ssam 10196940Ssam dmfsxint() { printf("dmfsxint\n"); } 10206940Ssam 10216940Ssam dmfdaint() { printf("dmfdaint\n"); } 10226940Ssam 10236940Ssam dmfdbint() { printf("dmfdbint\n"); } 10246940Ssam 102521955Sbloom 10266940Ssam #endif 1027