rc.c revision 9855
18471Sache/* 28471Sache * Copyright (C) 1995 by Pavel Antonov, Moscow, Russia. 38471Sache * Copyright (C) 1995 by Andrey A. Chernov, Moscow, Russia. 48471Sache * All rights reserved. 58471Sache * 68471Sache * Redistribution and use in source and binary forms, with or without 78471Sache * modification, are permitted provided that the following conditions 88471Sache * are met: 98471Sache * 1. Redistributions of source code must retain the above copyright 108471Sache * notice, this list of conditions and the following disclaimer. 118471Sache * 2. Redistributions in binary form must reproduce the above copyright 128471Sache * notice, this list of conditions and the following disclaimer in the 138471Sache * documentation and/or other materials provided with the distribution. 148471Sache * 158471Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND 168471Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 178471Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 188471Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 198471Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208471Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 218471Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 228471Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 238471Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 248471Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 258471Sache * SUCH DAMAGE. 268471Sache */ 278471Sache 288471Sache/* 298471Sache * SDL Communications Riscom/8 (based on Cirrus Logic CL-CD180) driver 308471Sache * 318471Sache */ 328471Sache 338471Sache#include "rc.h" 348471Sache#if NRC > 0 358471Sache 369232Sache/*#define RCDEBUG*/ 378471Sache 388471Sache#include <sys/param.h> 398471Sache#include <sys/systm.h> 408471Sache#include <sys/ioctl.h> 418471Sache#include <sys/tty.h> 428471Sache#include <sys/proc.h> 438471Sache#include <sys/user.h> 448471Sache#include <sys/conf.h> 458471Sache#include <sys/dkstat.h> 468471Sache#include <sys/file.h> 478471Sache#include <sys/uio.h> 488471Sache#include <sys/kernel.h> 498471Sache#include <sys/syslog.h> 508471Sache#include <sys/devconf.h> 518471Sache 528471Sache#include <machine/clock.h> 538471Sache 548471Sache#include <i386/isa/isa.h> 558471Sache#include <i386/isa/isa_device.h> 568471Sache#include <i386/isa/sioreg.h> 578471Sache 588471Sache#include <i386/isa/ic/cd180.h> 598471Sache#include <i386/isa/rcreg.h> 608471Sache 618471Sache/* Prototypes */ 628471Sacheint rcprobe __P((struct isa_device *)); 638471Sacheint rcattach __P((struct isa_device *)); 648471Sache 658471Sacheint rcopen __P((dev_t, int, int, struct proc *)); 668471Sacheint rcclose __P((dev_t, int, int, struct proc *)); 678471Sacheint rcread __P((dev_t, struct uio *, int)); 688471Sacheint rcwrite __P((dev_t, struct uio *, int)); 698471Sachevoid rcintr __P((int)); 708471Sachevoid rcpoll __P((void)); 718471Sachevoid rcstop __P((struct tty *, int)); 728471Sacheint rcioctl __P((dev_t, int, caddr_t, int, struct proc *)); 738471Sache 748471Sache#define rcin(port) RC_IN (nec, port) 758471Sache#define rcout(port,v) RC_OUT (nec, port, v) 768471Sache 779232Sache#define WAITFORCCR(u,c) rc_wait0(nec, (u), (c), __LINE__) 789232Sache#define CCRCMD(u,c,cmd) WAITFORCCR((u), (c)); rcout(CD180_CCR, (cmd)) 798471Sache 809232Sache#define RC_IBUFSIZE 256 819232Sache#define RB_I_HIGH_WATER (TTYHOG - 2 * RC_IBUFSIZE) 829232Sache#define RC_OBUFSIZE 512 838471Sache#define RC_IHIGHWATER (3 * RC_IBUFSIZE / 4) 848471Sache#define INPUT_FLAGS_SHIFT (2 * RC_IBUFSIZE) 858471Sache#define LOTS_OF_EVENTS 64 868471Sache 878471Sache#define RC_FAKEID 0x10 888471Sache 899232Sache#define RC_PROBED 1 909232Sache#define RC_ATTACHED 2 919232Sache 928471Sache#define GET_UNIT(dev) (minor(dev) & 0x3F) 938471Sache#define CALLOUT(dev) (minor(dev) & 0x80) 948471Sache 958471Sache/* For isa routines */ 968471Sachestruct isa_driver rcdriver = { 978471Sache rcprobe, rcattach, "rc" 988471Sache}; 998471Sache 1008471Sache/* Per-board structure */ 1018471Sachestatic struct rc_softc { 1029232Sache u_int rcb_probed; /* 1 - probed, 2 - attached */ 1038471Sache u_int rcb_addr; /* Base I/O addr */ 1048471Sache u_int rcb_unit; /* unit # */ 1058471Sache u_char rcb_dtr; /* DTR status */ 1068471Sache struct rc_chans *rcb_baserc; /* base rc ptr */ 1078471Sache} rc_softc[NRC]; 1088471Sache 1098471Sache/* Per-channel structure */ 1108471Sachestatic struct rc_chans { 1118471Sache struct rc_softc *rc_rcb; /* back ptr */ 1128471Sache u_short rc_flags; /* Misc. flags */ 1138471Sache int rc_chan; /* Channel # */ 1148471Sache u_char rc_ier; /* intr. enable reg */ 1158471Sache u_char rc_msvr; /* modem sig. status */ 1168471Sache u_char rc_cor2; /* options reg */ 1178471Sache u_char rc_pendcmd; /* special cmd pending */ 1188471Sache u_int rc_dtrwait; /* dtr timeout */ 1198471Sache u_int rc_dcdwaits; /* how many waits DCD in open */ 1208471Sache u_char rc_hotchar; /* end packed optimize */ 1218471Sache struct tty *rc_tp; /* tty struct */ 1228471Sache u_char *rc_iptr; /* Chars input buffer */ 1238471Sache u_char *rc_hiwat; /* hi-water mark */ 1248471Sache u_char *rc_bufend; /* end of buffer */ 1258471Sache u_char *rc_optr; /* ptr in output buf */ 1268471Sache u_char *rc_obufend; /* end of output buf */ 1278471Sache u_char rc_ibuf[4 * RC_IBUFSIZE]; /* input buffer */ 1288471Sache u_char rc_obuf[RC_OBUFSIZE]; /* output buffer */ 1298471Sache} rc_chans[NRC * CD180_NCHAN]; 1308471Sache 1318471Sachestatic int rc_scheduled_event = 0; 1328471Sache 1338471Sache/* for pstat -t */ 1348471Sachestruct tty rc_tty[NRC * CD180_NCHAN]; 1358471Sacheint nrc_tty = NRC * CD180_NCHAN; 1368471Sache 1378471Sache/* Flags */ 1389232Sache#define RC_DTR_OFF 0x0001 /* DTR wait, for close/open */ 1399232Sache#define RC_ACTOUT 0x0002 /* Dial-out port active */ 1409232Sache#define RC_RTSFLOW 0x0004 /* RTS flow ctl enabled */ 1419232Sache#define RC_CTSFLOW 0x0008 /* CTS flow ctl enabled */ 1429232Sache#define RC_DORXFER 0x0010 /* RXFER event planned */ 1439232Sache#define RC_DOXXFER 0x0020 /* XXFER event planned */ 1449232Sache#define RC_MODCHG 0x0040 /* Modem status changed */ 1459232Sache#define RC_OSUSP 0x0080 /* Output suspended */ 1469232Sache#define RC_OSBUSY 0x0100 /* start() routine in progress */ 1479232Sache#define RC_WAS_BUFOVFL 0x0200 /* low-level buffer ovferflow */ 1489232Sache#define RC_WAS_SILOVFL 0x0400 /* silo buffer overflow */ 1499232Sache#define RC_SEND_RDY 0x0800 /* ready to send */ 1508471Sache 1518471Sache/* Table for translation of RCSR status bits to internal form */ 1528471Sachestatic int rc_rcsrt[16] = { 1538471Sache 0, TTY_OE, TTY_FE, 1548471Sache TTY_FE|TTY_OE, TTY_PE, TTY_PE|TTY_OE, 1558471Sache TTY_PE|TTY_FE, TTY_PE|TTY_FE|TTY_OE, TTY_BI, 1568471Sache TTY_BI|TTY_OE, TTY_BI|TTY_FE, TTY_BI|TTY_FE|TTY_OE, 1578471Sache TTY_BI|TTY_PE, TTY_BI|TTY_PE|TTY_OE, TTY_BI|TTY_PE|TTY_FE, 1588471Sache TTY_BI|TTY_PE|TTY_FE|TTY_OE 1598471Sache}; 1608471Sache 1618471Sache/* Static prototypes */ 1629232Sachestatic void rc_hwreset __P((int, int, unsigned int)); 1638471Sachestatic int rc_test __P((int, int)); 1648471Sachestatic void rc_discard_output __P((struct rc_chans *)); 1658471Sachestatic void rc_hardclose __P((struct rc_chans *)); 1668471Sachestatic int rc_modctl __P((struct rc_chans *, int, int)); 1678471Sachestatic void rc_start __P((struct tty *)); 1688471Sachestatic int rc_param __P((struct tty *, struct termios *)); 1698471Sachestatic void rc_registerdev __P((struct isa_device *id)); 1709232Sachestatic void rc_reinit __P((struct rc_softc *)); 1719232Sache#ifdef RCDEBUG 1729232Sachestatic void printrcflags(); 1739232Sache#endif 1748471Sachestatic timeout_t rc_dtrwakeup; 1758471Sachestatic timeout_t rc_wakeup; 1768471Sachestatic void disc_optim __P((struct tty *tp, struct termios *t, struct rc_chans *)); 1779232Sachestatic void rc_wait0 __P((int nec, int unit, int chan, int line)); 1788471Sache 1798471Sache/**********************************************/ 1808471Sache 1818471Sache/* Quick device probing */ 1828471Sacheint rcprobe(dvp) 1838471Sache struct isa_device *dvp; 1848471Sache{ 1858471Sache int irq = ffs(dvp->id_irq) - 1; 1868471Sache register int nec = dvp->id_iobase; 1878471Sache 1888471Sache if (dvp->id_unit > NRC) 1898471Sache return 0; 1908471Sache if (!RC_VALIDADDR(nec)) { 1918471Sache printf("rc%d: illegal base address %x\n", nec); 1928471Sache return 0; 1938471Sache } 1948471Sache if (!RC_VALIDIRQ(irq)) { 1958471Sache printf("rc%d: illegal IRQ value %d\n", irq); 1968471Sache return 0; 1978471Sache } 1988471Sache rcout(CD180_PPRL, 0x22); /* Random values to Prescale reg. */ 1998471Sache rcout(CD180_PPRH, 0x11); 2008471Sache if (rcin(CD180_PPRL) != 0x22 || rcin(CD180_PPRH) != 0x11) 2018471Sache return 0; 2028471Sache /* Now, test the board more thoroughly, with diagnostic */ 2038471Sache if (rc_test(nec, dvp->id_unit)) 2048471Sache return 0; 2059232Sache rc_softc[dvp->id_unit].rcb_probed = RC_PROBED; 2069232Sache 2079232Sache return 0xF; 2088471Sache} 2098471Sache 2108471Sachestatic struct kern_devconf kdc_rc[NRC] = { { 2118471Sache 0, 0, 0, /* filled in by dev_attach */ 2128471Sache "rc", 0, { MDDT_ISA, 0, "tty" }, 2138471Sache isa_generic_externalize, 0, 0, ISA_EXTERNALLEN, 2148471Sache &kdc_isa0, /* parent */ 2158471Sache 0, /* parentdata */ 2168471Sache DC_UNCONFIGURED, /* state */ 2178471Sache "RISCom/8 multiport card", 2188471Sache DC_CLS_SERIAL /* class */ 2198471Sache} }; 2208471Sache 2218471Sachestatic void 2228471Sacherc_registerdev(id) 2238471Sache struct isa_device *id; 2248471Sache{ 2258471Sache int unit; 2268471Sache 2278471Sache unit = id->id_unit; 2288471Sache if (unit != 0) 2298471Sache kdc_rc[unit] = kdc_rc[0]; 2308471Sache kdc_rc[unit].kdc_unit = unit; 2318471Sache kdc_rc[unit].kdc_isa = id; 2328471Sache kdc_rc[unit].kdc_state = DC_UNKNOWN; 2338471Sache dev_attach(&kdc_rc[unit]); 2348471Sache} 2358471Sache 2368471Sacheint rcattach(dvp) 2378471Sache struct isa_device *dvp; 2388471Sache{ 2398471Sache register int i, chan, nec = dvp->id_iobase; 2408471Sache struct rc_softc *rcb = &rc_softc[dvp->id_unit]; 2418471Sache struct rc_chans *rc = &rc_chans[dvp->id_unit * CD180_NCHAN]; 2428471Sache static int rc_wakeup_started = 0; 2439232Sache struct tty *tp; 2448471Sache 2458471Sache /* Thorooughly test the device */ 2469232Sache if (rcb->rcb_probed != RC_PROBED) 2478471Sache return 0; 2488471Sache rcb->rcb_addr = nec; 2498471Sache rcb->rcb_dtr = 0; 2508471Sache rcb->rcb_baserc = rc; 2518471Sache /*rcb->rcb_chipid = 0x10 + dvp->id_unit;*/ 2528471Sache printf("rc%d: %d chans, firmware rev. %c\n", dvp->id_unit, 2538471Sache CD180_NCHAN, (rcin(CD180_GFRCR) & 0xF) + 'A'); 2548471Sache 2558471Sache rc_registerdev(dvp); 2568471Sache 2578471Sache for (chan = 0; chan < CD180_NCHAN; chan++, rc++) { 2588471Sache rc->rc_rcb = rcb; 2598471Sache rc->rc_chan = chan; 2608471Sache rc->rc_iptr = rc->rc_ibuf; 2618471Sache rc->rc_bufend = &rc->rc_ibuf[RC_IBUFSIZE]; 2628471Sache rc->rc_hiwat = &rc->rc_ibuf[RC_IHIGHWATER]; 2638471Sache rc->rc_flags = rc->rc_ier = rc->rc_msvr = 0; 2648471Sache rc->rc_cor2 = rc->rc_pendcmd = 0; 2658471Sache rc->rc_optr = rc->rc_obufend = rc->rc_obuf; 2668471Sache rc->rc_dtrwait = 3 * hz; 2678471Sache rc->rc_dcdwaits= 0; 2688471Sache rc->rc_hotchar = 0; 2699232Sache tp = rc->rc_tp = &rc_tty[chan]; 2709232Sache ttychars(tp); 2719232Sache tp->t_lflag = tp->t_iflag = tp->t_oflag = 0; 2729232Sache tp->t_cflag = TTYDEF_CFLAG; 2739232Sache tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 2748471Sache } 2759232Sache rcb->rcb_probed = RC_ATTACHED; 2768471Sache if (!rc_wakeup_started) { 2778471Sache rc_wakeup((void *)NULL); 2788471Sache rc_wakeup_started = 0; 2798471Sache } 2808471Sache return 1; 2818471Sache} 2828471Sache 2838471Sache/* RC interrupt handling */ 2848471Sachevoid rcintr(unit) 2858471Sache int unit; 2868471Sache{ 2878471Sache register struct rc_softc *rcb = &rc_softc[unit]; 2888471Sache register struct rc_chans *rc; 2899232Sache register int nec, resid; 2909232Sache register u_char val, iack, bsr, ucnt, *optr; 2919232Sache int good_data, t_state; 2928471Sache 2939232Sache if (rcb->rcb_probed != RC_ATTACHED) { 2949232Sache printf("rc%d: bogus interrupt\n", unit); 2959232Sache return; 2969232Sache } 2978471Sache nec = rcb->rcb_addr; 2988471Sache 2998471Sache bsr = ~(rcin(RC_BSR)); 3008471Sache 3019232Sache if (!(bsr & (RC_BSR_TOUT|RC_BSR_RXINT|RC_BSR_TXINT|RC_BSR_MOINT))) { 3029232Sache printf("rc%d: extra interrupt\n", unit); 3039232Sache rcout(CD180_EOIR, 0); 3049232Sache return; 3059232Sache } 3069232Sache 3079232Sache while (bsr & (RC_BSR_TOUT|RC_BSR_RXINT|RC_BSR_TXINT|RC_BSR_MOINT)) { 3089232Sache#ifdef RCDEBUG_DETAILED 3099232Sache printf("rc%d: intr (%02x) %s%s%s%s\n", unit, bsr, 3109232Sache (bsr & RC_BSR_TOUT)?"TOUT ":"", 3119232Sache (bsr & RC_BSR_RXINT)?"RXINT ":"", 3129232Sache (bsr & RC_BSR_TXINT)?"TXINT ":"", 3139232Sache (bsr & RC_BSR_MOINT)?"MOINT":""); 3148471Sache#endif 3159232Sache if (bsr & RC_BSR_TOUT) { 3169232Sache printf("rc%d: hardware failure, reset board\n", unit); 3179232Sache rcout(RC_CTOUT, 0); 3189232Sache rc_reinit(rcb); 3199232Sache return; 3208471Sache } 3219232Sache if (bsr & RC_BSR_RXINT) { 3229232Sache iack = rcin(RC_PILR_RX); 3239232Sache good_data = (iack == (GIVR_IT_RGDI | RC_FAKEID)); 3249232Sache if (!good_data && iack != (GIVR_IT_REI | RC_FAKEID)) { 3259232Sache printf("rc%d: fake rxint: %02x\n", unit, iack); 3269232Sache goto more_intrs; 3279232Sache } 3289232Sache rc = rcb->rcb_baserc + ((rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH); 3299232Sache t_state = rc->rc_tp->t_state; 3309232Sache /* Do RTS flow control stuff */ 3319232Sache if ( (rc->rc_flags & RC_RTSFLOW) 3329232Sache || !(t_state & TS_ISOPEN) 3339232Sache ) { 3349232Sache if ( ( !(t_state & TS_ISOPEN) 3359232Sache || (t_state & TS_TBLOCK) 3369232Sache ) 3379232Sache && (rc->rc_msvr & MSVR_RTS) 3389232Sache ) 3399232Sache rcout(CD180_MSVR, 3409232Sache rc->rc_msvr &= ~MSVR_RTS); 3419232Sache else if (!(rc->rc_msvr & MSVR_RTS)) 3429232Sache rcout(CD180_MSVR, 3439232Sache rc->rc_msvr |= MSVR_RTS); 3449232Sache } 3459232Sache ucnt = rcin(CD180_RDCR) & 0xF; 3469232Sache resid = 0; 3478471Sache 3489232Sache if (t_state & TS_ISOPEN) { 3499232Sache /* check for input buffer overflow */ 3509232Sache if ((rc->rc_iptr + ucnt) >= rc->rc_bufend) { 3519232Sache resid = ucnt; 3529232Sache ucnt = rc->rc_bufend - rc->rc_iptr; 3539232Sache resid -= ucnt; 3549232Sache if (!(rc->rc_flags & RC_WAS_BUFOVFL)) { 3559232Sache rc->rc_flags |= RC_WAS_BUFOVFL; 3569232Sache rc_scheduled_event++; 3579232Sache } 3588471Sache } 3599232Sache optr = rc->rc_iptr; 3609232Sache /* check foor good data */ 3619232Sache if (good_data) { 3629232Sache while (ucnt-- > 0) { 3639232Sache val = rcin(CD180_RDR); 3649232Sache optr[0] = val; 3659232Sache optr[INPUT_FLAGS_SHIFT] = 0; 3669232Sache optr++; 3678471Sache rc_scheduled_event++; 3689232Sache if (val != 0 && val == rc->rc_hotchar) 3698471Sache setsofttty(); 3708471Sache } 3719232Sache } else { 3729232Sache /* Store also status data */ 3739232Sache while (ucnt-- > 0) { 3749232Sache iack = rcin(CD180_RCSR); 3759232Sache if (iack & RCSR_Timeout) 3769232Sache break; 3779232Sache if ( (iack & RCSR_OE) 3789232Sache && !(rc->rc_flags & RC_WAS_SILOVFL)) { 3799232Sache rc->rc_flags |= RC_WAS_SILOVFL; 3809232Sache rc_scheduled_event++; 3819232Sache } 3829232Sache val = rcin(CD180_RDR); 3839232Sache /* 3849232Sache Don't store PE if IGNPAR and BREAK if IGNBRK, 3859232Sache this hack allows "raw" tty optimization 3869232Sache works even if IGN* is set. 3879232Sache */ 3889232Sache if ( !(iack & (RCSR_PE|RCSR_FE|RCSR_Break)) 3899232Sache || (!(iack & (RCSR_PE|RCSR_FE)) 3909232Sache || !(rc->rc_tp->t_iflag & IGNPAR)) 3919232Sache && (!(iack & RCSR_Break) 3929232Sache || !(rc->rc_tp->t_iflag & IGNBRK))) { 3939232Sache if ( (iack & (RCSR_PE|RCSR_FE)) 3949232Sache && (t_state & TS_CAN_BYPASS_L_RINT) 3959232Sache && ((iack & RCSR_FE) 3969232Sache || (iack & RCSR_PE) 3979232Sache && (rc->rc_tp->t_iflag & INPCK))) 3989232Sache val = 0; 3999232Sache else if (val != 0 && val == rc->rc_hotchar) 4009232Sache setsofttty(); 4019232Sache optr[0] = val; 4029232Sache optr[INPUT_FLAGS_SHIFT] = iack; 4039232Sache optr++; 4049232Sache rc_scheduled_event++; 4059232Sache } 4069232Sache } 4078471Sache } 4089232Sache rc->rc_iptr = optr; 4099232Sache rc->rc_flags |= RC_DORXFER; 4109232Sache } else 4119232Sache resid = ucnt; 4129232Sache /* Clear FIFO if necessary */ 4139232Sache while (resid-- > 0) { 4149232Sache if (!good_data) 4159232Sache iack = rcin(CD180_RCSR); 4169232Sache else 4179232Sache iack = 0; 4189232Sache if (iack & RCSR_Timeout) 4199232Sache break; 4209232Sache (void) rcin(CD180_RDR); 4218471Sache } 4229232Sache goto more_intrs; 4238471Sache } 4249232Sache if (bsr & RC_BSR_MOINT) { 4259232Sache iack = rcin(RC_PILR_MODEM); 4269232Sache if (iack != (GIVR_IT_MSCI | RC_FAKEID)) { 4279232Sache printf("rc%d: fake moint: %02x\n", unit, iack); 4289232Sache goto more_intrs; 4299232Sache } 4309232Sache rc = rcb->rcb_baserc + ((rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH); 4319232Sache iack = rcin(CD180_MCR); 4329232Sache rc->rc_msvr = rcin(CD180_MSVR); 4339232Sache rcout(CD180_MCR, 0); 4348471Sache#ifdef RCDEBUG 4359232Sache printrcflags(rc, "moint"); 4368471Sache#endif 4379232Sache if (rc->rc_flags & RC_CTSFLOW) { 4389232Sache if (rc->rc_msvr & MSVR_CTS) 4399232Sache rc->rc_flags |= RC_SEND_RDY; 4409232Sache else 4419232Sache rc->rc_flags &= ~RC_SEND_RDY; 4429232Sache } else 4438471Sache rc->rc_flags |= RC_SEND_RDY; 4449232Sache if ((iack & MCR_CDchg) && !(rc->rc_flags & RC_MODCHG)) { 4459232Sache rc_scheduled_event += LOTS_OF_EVENTS; 4469232Sache rc->rc_flags |= RC_MODCHG; 4479232Sache setsofttty(); 4489232Sache } 4499232Sache goto more_intrs; 4508471Sache } 4519232Sache if (bsr & RC_BSR_TXINT) { 4529232Sache iack = rcin(RC_PILR_TX); 4539232Sache if (iack != (GIVR_IT_TDI | RC_FAKEID)) { 4549232Sache printf("rc%d: fake txint: %02x\n", unit, iack); 4559232Sache goto more_intrs; 4569232Sache } 4579232Sache rc = rcb->rcb_baserc + ((rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH); 4589232Sache if ( (rc->rc_flags & RC_OSUSP) 4599232Sache || !(rc->rc_flags & RC_SEND_RDY) 4609232Sache ) 4619232Sache goto more_intrs; 4629232Sache /* Handle breaks and other stuff */ 4639232Sache if (rc->rc_pendcmd) { 4649232Sache rcout(CD180_COR2, rc->rc_cor2 |= COR2_ETC); 4659232Sache rcout(CD180_TDR, CD180_C_ESC); 4669232Sache rcout(CD180_TDR, rc->rc_pendcmd); 4679232Sache rcout(CD180_COR2, rc->rc_cor2 &= ~COR2_ETC); 4689232Sache rc->rc_pendcmd = 0; 4699232Sache goto more_intrs; 4709232Sache } 4719232Sache optr = rc->rc_optr; 4729232Sache resid = rc->rc_obufend - optr; 4739232Sache if (resid > CD180_NFIFO) 4749232Sache resid = CD180_NFIFO; 4759232Sache while (resid-- > 0) 4769232Sache rcout(CD180_TDR, *optr++); 4779232Sache rc->rc_optr = optr; 4788471Sache 4799232Sache /* output completed? */ 4809232Sache if (optr >= rc->rc_obufend) { 4819232Sache rcout(CD180_IER, rc->rc_ier &= ~IER_TxRdy); 4828471Sache#ifdef RCDEBUG 4839232Sache printf("rc%d/%d: output completed\n", unit, rc->rc_chan); 4848471Sache#endif 4859232Sache if (!(rc->rc_flags & RC_DOXXFER)) { 4869232Sache rc_scheduled_event += LOTS_OF_EVENTS; 4879232Sache rc->rc_flags |= RC_DOXXFER; 4889232Sache setsofttty(); 4899232Sache } 4909232Sache } 4918471Sache } 4929232Sache more_intrs: 4939232Sache rcout(CD180_EOIR, 0); /* end of interrupt */ 4949232Sache rcout(RC_CTOUT, 0); 4959232Sache bsr = ~(rcin(RC_BSR)); 4968471Sache } 4978471Sache} 4988471Sache 4998471Sache/* Feed characters to output buffer */ 5008471Sachestatic void rc_start(tp) 5018471Sacheregister struct tty *tp; 5028471Sache{ 5038471Sache register struct rc_chans *rc = &rc_chans[GET_UNIT(tp->t_dev)]; 5048471Sache register int nec = rc->rc_rcb->rcb_addr, s; 5058471Sache 5068471Sache if (rc->rc_flags & RC_OSBUSY) 5078471Sache return; 5088471Sache s = spltty(); 5098471Sache rc->rc_flags |= RC_OSBUSY; 5108471Sache disable_intr(); 5118471Sache if (tp->t_state & TS_TTSTOP) 5128471Sache rc->rc_flags |= RC_OSUSP; 5138471Sache else 5148471Sache rc->rc_flags &= ~RC_OSUSP; 5158471Sache /* Do RTS flow control stuff */ 5169232Sache if ( (rc->rc_flags & RC_RTSFLOW) 5179232Sache && (tp->t_state & TS_TBLOCK) 5189232Sache && (rc->rc_msvr & MSVR_RTS) 5199232Sache ) { 5209232Sache rcout(CD180_CAR, rc->rc_chan); 5219232Sache rcout(CD180_MSVR, rc->rc_msvr &= ~MSVR_RTS); 5229232Sache } else if (!(rc->rc_msvr & MSVR_RTS)) { 5239232Sache rcout(CD180_CAR, rc->rc_chan); 5249232Sache rcout(CD180_MSVR, rc->rc_msvr |= MSVR_RTS); 5258471Sache } 5268471Sache enable_intr(); 5278471Sache if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) 5288471Sache goto out; 5298471Sache#ifdef RCDEBUG 5308471Sache printrcflags(rc, "rcstart"); 5318471Sache#endif 5329626Sbde ttwwakeup(tp); 5338471Sache#ifdef RCDEBUG 5349232Sache printf("rcstart: outq = %d obuf = %d\n", 5358471Sache tp->t_outq.c_cc, rc->rc_obufend - rc->rc_optr); 5368471Sache#endif 5379232Sache if (tp->t_state & TS_BUSY) 5388471Sache goto out; /* output still in progress ... */ 5398471Sache 5408471Sache if (tp->t_outq.c_cc > 0) { 5418471Sache u_int ocnt; 5428471Sache 5438471Sache tp->t_state |= TS_BUSY; 5448471Sache ocnt = q_to_b(&tp->t_outq, rc->rc_obuf, sizeof rc->rc_obuf); 5458471Sache disable_intr(); 5468471Sache rc->rc_optr = rc->rc_obuf; 5479232Sache rc->rc_obufend = rc->rc_optr + ocnt; 5488471Sache enable_intr(); 5499232Sache if (!(rc->rc_ier & IER_TxRdy)) { 5508471Sache#ifdef RCDEBUG 5519232Sache printf("rc%d/%d: rcstart enable txint\n", rc->rc_rcb->rcb_unit, rc->rc_chan); 5528471Sache#endif 5538471Sache rcout(CD180_CAR, rc->rc_chan); 5549232Sache rcout(CD180_IER, rc->rc_ier |= IER_TxRdy); 5558471Sache } 5568471Sache } 5578471Sacheout: 5588471Sache rc->rc_flags &= ~RC_OSBUSY; 5598471Sache (void) splx(s); 5608471Sache} 5618471Sache 5628471Sache/* Handle delayed events. */ 5638471Sachevoid rcpoll() 5648471Sache{ 5658471Sache register struct rc_chans *rc; 5668471Sache register struct rc_softc *rcb; 5678471Sache register u_char *tptr, *eptr; 5688471Sache register int s; 5698471Sache register struct tty *tp; 5708471Sache register int chan, icnt, c, nec, unit; 5718471Sache 5728471Sache if (rc_scheduled_event == 0) 5738471Sache return; 5748471Sacherepeat: 5758471Sache for (unit = 0; unit < NRC; unit++) { 5768471Sache rcb = &rc_softc[unit]; 5778471Sache rc = rcb->rcb_baserc; 5788471Sache nec = rc->rc_rcb->rcb_addr; 5798471Sache for (chan = 0; chan < CD180_NCHAN; rc++, chan++) { 5808471Sache tp = rc->rc_tp; 5818471Sache#ifdef RCDEBUG 5828471Sache if (rc->rc_flags & (RC_DORXFER|RC_DOXXFER|RC_MODCHG| 5838471Sache RC_WAS_BUFOVFL|RC_WAS_SILOVFL)) 5848471Sache printrcflags(rc, "rcevent"); 5858471Sache#endif 5868471Sache if (rc->rc_flags & RC_WAS_BUFOVFL) { 5879232Sache disable_intr(); 5888471Sache rc->rc_flags &= ~RC_WAS_BUFOVFL; 5898471Sache rc_scheduled_event--; 5909232Sache enable_intr(); 5918471Sache printf("rc%d/%d: interrupt-level buffer overflow\n", 5928471Sache unit, chan); 5938471Sache } 5948471Sache if (rc->rc_flags & RC_WAS_SILOVFL) { 5959232Sache disable_intr(); 5968471Sache rc->rc_flags &= ~RC_WAS_SILOVFL; 5978471Sache rc_scheduled_event--; 5989232Sache enable_intr(); 5998471Sache printf("rc%d/%d: silo overflow\n", 6008471Sache unit, chan); 6018471Sache } 6028471Sache if (rc->rc_flags & RC_MODCHG) { 6039232Sache disable_intr(); 6048471Sache rc->rc_flags &= ~RC_MODCHG; 6058471Sache rc_scheduled_event -= LOTS_OF_EVENTS; 6069232Sache enable_intr(); 6079232Sache (*linesw[tp->t_line].l_modem)(tp, !!(rc->rc_msvr & MSVR_CD)); 6088471Sache } 6098471Sache if (rc->rc_flags & RC_DORXFER) { 6109232Sache disable_intr(); 6118471Sache rc->rc_flags &= ~RC_DORXFER; 6128471Sache eptr = rc->rc_iptr; 6138471Sache if (rc->rc_bufend == &rc->rc_ibuf[2 * RC_IBUFSIZE]) 6148471Sache tptr = &rc->rc_ibuf[RC_IBUFSIZE]; 6158471Sache else 6168471Sache tptr = rc->rc_ibuf; 6178471Sache icnt = eptr - tptr; 6188471Sache if (icnt > 0) { 6198471Sache if (rc->rc_bufend == &rc->rc_ibuf[2 * RC_IBUFSIZE]) { 6208471Sache rc->rc_iptr = rc->rc_ibuf; 6218471Sache rc->rc_bufend = &rc->rc_ibuf[RC_IBUFSIZE]; 6228471Sache rc->rc_hiwat = &rc->rc_ibuf[RC_IHIGHWATER]; 6238471Sache } else { 6248471Sache rc->rc_iptr = &rc->rc_ibuf[RC_IBUFSIZE]; 6258471Sache rc->rc_bufend = &rc->rc_ibuf[2 * RC_IBUFSIZE]; 6268471Sache rc->rc_hiwat = 6278471Sache &rc->rc_ibuf[RC_IBUFSIZE + RC_IHIGHWATER]; 6288471Sache } 6299232Sache if ( (rc->rc_flags & RC_RTSFLOW) 6309232Sache && (tp->t_state & TS_ISOPEN) 6319232Sache && !(tp->t_state & TS_TBLOCK) 6328471Sache && !(rc->rc_msvr & MSVR_RTS) 6339232Sache ) { 6348471Sache rcout(CD180_CAR, chan); 6358471Sache rcout(CD180_MSVR, 6368471Sache rc->rc_msvr |= MSVR_RTS); 6378471Sache } 6388471Sache rc_scheduled_event -= icnt; 6398471Sache } 6408471Sache enable_intr(); 6418471Sache 6429232Sache if (icnt <= 0 || !(tp->t_state & TS_ISOPEN)) 6438471Sache goto done1; 6448471Sache 6458471Sache if ( (tp->t_state & TS_CAN_BYPASS_L_RINT) 6468471Sache && !(tp->t_state & TS_LOCAL)) { 6479822Sbde if ((tp->t_rawq.c_cc + icnt) >= RB_I_HIGH_WATER 6489822Sbde && ((rc->rc_flags & RC_RTSFLOW) || (tp->t_iflag & IXOFF)) 6499822Sbde && !(tp->t_state & TS_TBLOCK)) 6509822Sbde ttyblock(tp); 6518471Sache tk_nin += icnt; 6528471Sache tk_rawcc += icnt; 6538471Sache tp->t_rawcc += icnt; 6548471Sache if (b_to_q(tptr, icnt, &tp->t_rawq)) 6558471Sache printf("rc%d/%d: tty-level buffer overflow\n", 6568471Sache unit, chan); 6578471Sache ttwakeup(tp); 6588471Sache if ((tp->t_state & TS_TTSTOP) && ((tp->t_iflag & IXANY) 6598471Sache || (tp->t_cc[VSTART] == tp->t_cc[VSTOP]))) { 6608471Sache tp->t_state &= ~TS_TTSTOP; 6618471Sache tp->t_lflag &= ~FLUSHO; 6629754Sbde rc_start(tp); 6638471Sache } 6648471Sache } else { 6658471Sache for (; tptr < eptr; tptr++) 6668471Sache (*linesw[tp->t_line].l_rint) 6678471Sache (tptr[0] | 6688471Sache rc_rcsrt[tptr[INPUT_FLAGS_SHIFT] & 0xF], tp); 6698471Sache } 6708471Sachedone1: 6718471Sache } 6728471Sache if (rc->rc_flags & RC_DOXXFER) { 6739232Sache disable_intr(); 6749232Sache rc_scheduled_event -= LOTS_OF_EVENTS; 6759232Sache rc->rc_flags &= ~RC_DOXXFER; 6769232Sache rc->rc_tp->t_state &= ~TS_BUSY; 6779232Sache enable_intr(); 6788471Sache (*linesw[tp->t_line].l_start)(tp); 6798471Sache } 6808471Sache } 6818471Sache if (rc_scheduled_event == 0) 6828471Sache break; 6838471Sache } 6848471Sache if (rc_scheduled_event >= LOTS_OF_EVENTS) 6858471Sache goto repeat; 6868471Sache} 6878471Sache 6888471Sachevoid rcstop(tp, rw) 6898471Sache register struct tty *tp; 6908471Sache int rw; 6918471Sache{ 6928471Sache register struct rc_chans *rc = &rc_chans[GET_UNIT(tp->t_dev)]; 6938471Sache u_char *tptr, *eptr; 6948471Sache 6958471Sache#ifdef RCDEBUG 6969232Sache printf("rc%d/%d: rcstop %s%s\n", rc->rc_rcb->rcb_unit, rc->rc_chan, 6978471Sache (rw & FWRITE)?"FWRITE ":"", (rw & FREAD)?"FREAD":""); 6988471Sache#endif 6998471Sache if (rw & FWRITE) 7008471Sache rc_discard_output(rc); 7018471Sache disable_intr(); 7028471Sache if (rw & FREAD) { 7039232Sache rc->rc_flags &= ~RC_DORXFER; 7048471Sache eptr = rc->rc_iptr; 7058471Sache if (rc->rc_bufend == &rc->rc_ibuf[2 * RC_IBUFSIZE]) { 7068471Sache tptr = &rc->rc_ibuf[RC_IBUFSIZE]; 7078471Sache rc->rc_iptr = &rc->rc_ibuf[RC_IBUFSIZE]; 7088471Sache } else { 7098471Sache tptr = rc->rc_ibuf; 7108471Sache rc->rc_iptr = rc->rc_ibuf; 7118471Sache } 7128471Sache rc_scheduled_event -= eptr - tptr; 7138471Sache } 7148471Sache if (tp->t_state & TS_TTSTOP) 7158471Sache rc->rc_flags |= RC_OSUSP; 7168471Sache else 7178471Sache rc->rc_flags &= ~RC_OSUSP; 7188471Sache enable_intr(); 7198471Sache} 7208471Sache 7218471Sacheint rcopen(dev, flag, mode, p) 7228471Sache dev_t dev; 7238471Sache int flag, mode; 7248471Sache struct proc *p; 7258471Sache{ 7268471Sache register struct rc_chans *rc; 7278471Sache register struct tty *tp; 7288471Sache int unit, nec, s, error = 0; 7298471Sache 7308471Sache unit = GET_UNIT(dev); 7318471Sache if (unit >= NRC * CD180_NCHAN) 7328471Sache return ENXIO; 7339232Sache if (rc_softc[unit / CD180_NCHAN].rcb_probed != RC_ATTACHED) 7349232Sache return ENXIO; 7358471Sache rc = &rc_chans[unit]; 7369232Sache tp = rc->rc_tp; 7378471Sache nec = rc->rc_rcb->rcb_addr; 7388471Sache#ifdef RCDEBUG 7399232Sache printf("rc%d/%d: rcopen: dev %x\n", rc->rc_rcb->rcb_unit, unit, dev); 7408471Sache#endif 7418471Sache s = spltty(); 7428471Sache 7438471Sacheagain: 7448471Sache while (rc->rc_flags & RC_DTR_OFF) { 7459232Sache error = tsleep(&(rc->rc_dtrwait), TTIPRI | PCATCH, "rcdtr", 0); 7468471Sache if (error != 0) 7478471Sache goto out; 7488471Sache } 7498471Sache if (tp->t_state & TS_ISOPEN) { 7508471Sache if (CALLOUT(dev)) { 7518471Sache if (!(rc->rc_flags & RC_ACTOUT)) { 7528471Sache error = EBUSY; 7538471Sache goto out; 7548471Sache } 7558471Sache } else { 7568471Sache if (rc->rc_flags & RC_ACTOUT) { 7578471Sache if (flag & O_NONBLOCK) { 7588471Sache error = EBUSY; 7598471Sache goto out; 7608471Sache } 7618471Sache if (error = tsleep(&rc->rc_rcb, 7628471Sache TTIPRI|PCATCH, "rcbi", 0)) 7638471Sache goto out; 7648471Sache goto again; 7658471Sache } 7668471Sache } 7678471Sache if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) { 7688471Sache error = EBUSY; 7698471Sache goto out; 7708471Sache } 7718471Sache } else { 7728471Sache tp->t_oproc = rc_start; 7738471Sache tp->t_param = rc_param; 7748471Sache tp->t_dev = dev; 7758471Sache 7768471Sache if (CALLOUT(dev)) 7778471Sache tp->t_cflag |= CLOCAL; 7788471Sache else 7798471Sache tp->t_cflag &= ~CLOCAL; 7808471Sache 7818471Sache error = rc_param(tp, &tp->t_termios); 7828471Sache if (error) 7838471Sache goto out; 7849232Sache (void) rc_modctl(rc, TIOCM_RTS|TIOCM_DTR, DMSET); 7858471Sache 7868471Sache ttsetwater(tp); 7878471Sache 7888471Sache if ((rc->rc_msvr & MSVR_CD) || CALLOUT(dev)) 7898471Sache (*linesw[tp->t_line].l_modem)(tp, 1); 7908471Sache } 7918471Sache if (!(tp->t_state & TS_CARR_ON) && !CALLOUT(dev) 7928471Sache && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) { 7938471Sache rc->rc_dcdwaits++; 7949639Sbde error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "rcdcd", 0); 7958471Sache rc->rc_dcdwaits--; 7968471Sache if (error != 0) 7978471Sache goto out; 7988471Sache goto again; 7998471Sache } 8008471Sache error = (*linesw[tp->t_line].l_open)(dev, tp); 8018471Sache if ((tp->t_state & TS_ISOPEN) && CALLOUT(dev)) 8028471Sache rc->rc_flags |= RC_ACTOUT; 8038471Sacheout: 8048471Sache (void) splx(s); 8058471Sache 8068471Sache if(rc->rc_dcdwaits == 0 && !(tp->t_state & TS_ISOPEN)) 8078471Sache rc_hardclose(rc); 8088471Sache 8098471Sache return error; 8108471Sache} 8118471Sache 8128471Sacheint rcclose(dev, flag, mode, p) 8138471Sache dev_t dev; 8148471Sache int flag, mode; 8158471Sache struct proc *p; 8168471Sache{ 8178471Sache register struct rc_chans *rc; 8188471Sache register struct tty *tp; 8198471Sache int s, unit = GET_UNIT(dev); 8208471Sache 8218471Sache if (unit >= NRC * CD180_NCHAN) 8228471Sache return ENXIO; 8238471Sache rc = &rc_chans[unit]; 8248471Sache tp = rc->rc_tp; 8259232Sache#ifdef RCDEBUG 8269232Sache printf("rc%d/%d: rcclose dev %x\n", rc->rc_rcb->rcb_unit, unit, dev); 8279232Sache#endif 8288471Sache s = spltty(); 8298471Sache (*linesw[tp->t_line].l_close)(tp, flag); 8308471Sache rcstop(tp, FREAD | FWRITE); 8318471Sache rc_hardclose(rc); 8328471Sache ttyclose(tp); 8338471Sache splx(s); 8348471Sache return 0; 8358471Sache} 8368471Sache 8378471Sachestatic void rc_hardclose(rc) 8388471Sacheregister struct rc_chans *rc; 8398471Sache{ 8408471Sache register int s, nec = rc->rc_rcb->rcb_addr; 8418471Sache register struct tty *tp = rc->rc_tp; 8428471Sache 8438471Sache s = spltty(); 8448471Sache rcout(CD180_CAR, rc->rc_chan); 8458471Sache 8469232Sache /* Disable rx/tx intrs */ 8478471Sache rcout(CD180_IER, rc->rc_ier = 0); 8489232Sache if ( (tp->t_cflag & HUPCL) 8498471Sache || !(rc->rc_flags & RC_ACTOUT) 8508471Sache && !(rc->rc_msvr & MSVR_CD) 8518471Sache && !(tp->t_cflag & CLOCAL) 8529232Sache || !(tp->t_state & TS_ISOPEN) 8539232Sache ) { 8549232Sache CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, CCR_ResetChan); 8559232Sache WAITFORCCR(rc->rc_rcb->rcb_unit, rc->rc_chan); 8568471Sache (void) rc_modctl(rc, TIOCM_RTS, DMSET); 8578471Sache if (rc->rc_dtrwait) { 8588471Sache timeout(rc_dtrwakeup, rc, rc->rc_dtrwait); 8598471Sache rc->rc_flags |= RC_DTR_OFF; 8608471Sache } 8618471Sache } 8628471Sache rc->rc_flags &= ~RC_ACTOUT; 8638471Sache wakeup((caddr_t) &rc->rc_rcb); /* wake bi */ 8649639Sbde wakeup(TSA_CARR_ON(tp)); 8658471Sache (void) splx(s); 8668471Sache} 8678471Sache 8688471Sache/* Read from line */ 8698471Sacheint rcread(dev, uio, flag) 8708471Sache dev_t dev; 8718471Sache struct uio *uio; 8728471Sache int flag; 8738471Sache{ 8748471Sache struct tty *tp = rc_chans[GET_UNIT(dev)].rc_tp; 8759232Sache 8768471Sache return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); 8778471Sache} 8788471Sache 8798471Sache/* Write to line */ 8808471Sacheint rcwrite(dev, uio, flag) 8818471Sache dev_t dev; 8828471Sache struct uio *uio; 8838471Sache int flag; 8848471Sache{ 8858471Sache struct tty *tp = rc_chans[GET_UNIT(dev)].rc_tp; 8869232Sache 8878471Sache return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); 8888471Sache} 8898471Sache 8908471Sache/* Reset the bastard */ 8919232Sachestatic void rc_hwreset(unit, nec, chipid) 8929232Sache register int unit, nec; 8938471Sache unsigned int chipid; 8948471Sache{ 8959232Sache CCRCMD(unit, -1, CCR_HWRESET); /* Hardware reset */ 8968471Sache DELAY(20000); 8979232Sache WAITFORCCR(unit, -1); 8989232Sache 8999232Sache rcout(RC_CTOUT, 0); /* Clear timeout */ 9008471Sache rcout(CD180_GIVR, chipid); 9018471Sache rcout(CD180_GICR, 0); 9028471Sache 9038471Sache /* Set Prescaler Registers (1 msec) */ 9049232Sache rcout(CD180_PPRL, ((RC_OSCFREQ + 999) / 1000) & 0xFF); 9059232Sache rcout(CD180_PPRH, ((RC_OSCFREQ + 999) / 1000) >> 8); 9068471Sache 9078471Sache /* Initialize Priority Interrupt Level Registers */ 9088471Sache rcout(CD180_PILR1, RC_PILR_MODEM); 9098471Sache rcout(CD180_PILR2, RC_PILR_TX); 9108471Sache rcout(CD180_PILR3, RC_PILR_RX); 9118471Sache 9128471Sache /* Reset DTR */ 9139232Sache rcout(RC_DTREG, ~0); 9148471Sache} 9158471Sache 9168471Sache/* Set channel parameters */ 9178471Sachestatic int rc_param(tp, ts) 9188471Sache register struct tty *tp; 9198471Sache struct termios *ts; 9208471Sache{ 9219232Sache register struct rc_chans *rc = &rc_chans[GET_UNIT(tp->t_dev)]; 9228471Sache register int nec = rc->rc_rcb->rcb_addr; 9239232Sache int idivs, odivs, s, val, cflag, iflag, lflag, inpflow; 9248471Sache 9259855Sache if ( ts->c_ospeed < 0 || ts->c_ospeed > 76800 9269855Sache || ts->c_ispeed < 0 || ts->c_ispeed > 76800 9279855Sache ) 9289855Sache return (EINVAL); 9298471Sache if (ts->c_ispeed == 0) 9308471Sache ts->c_ispeed = ts->c_ospeed; 9319855Sache odivs = RC_BRD(ts->c_ospeed); 9329855Sache idivs = RC_BRD(ts->c_ispeed); 9338471Sache 9348471Sache s = spltty(); 9358471Sache 9369232Sache /* Select channel */ 9379232Sache rcout(CD180_CAR, rc->rc_chan); 9389232Sache 9398471Sache /* If speed == 0, hangup line */ 9409232Sache if (ts->c_ospeed == 0) { 9419232Sache CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, CCR_ResetChan); 9429232Sache WAITFORCCR(rc->rc_rcb->rcb_unit, rc->rc_chan); 9439232Sache (void) rc_modctl(rc, TIOCM_DTR, DMBIC); 9449232Sache } 9458471Sache 9468471Sache tp->t_state &= ~TS_CAN_BYPASS_L_RINT; 9478471Sache cflag = ts->c_cflag; 9488471Sache iflag = ts->c_iflag; 9498471Sache lflag = ts->c_lflag; 9508471Sache 9518471Sache if (idivs > 0) { 9528471Sache rcout(CD180_RBPRL, idivs & 0xFF); 9538471Sache rcout(CD180_RBPRH, idivs >> 8); 9548471Sache } 9558471Sache if (odivs > 0) { 9568471Sache rcout(CD180_TBPRL, odivs & 0xFF); 9578471Sache rcout(CD180_TBPRH, odivs >> 8); 9588471Sache } 9598471Sache 9608471Sache /* set timeout value */ 9619232Sache if (ts->c_ispeed > 0) { 9629232Sache int itm = ts->c_ispeed > 2400 ? 5 : 10000 / ts->c_ispeed + 1; 9638471Sache 9649232Sache if ( !(lflag & ICANON) 9659232Sache && ts->c_cc[VMIN] != 0 && ts->c_cc[VTIME] != 0 9669232Sache && ts->c_cc[VTIME] * 10 > itm) 9679232Sache itm = ts->c_cc[VTIME] * 10; 9689232Sache 9699232Sache rcout(CD180_RTPR, itm <= 255 ? itm : 255); 9709232Sache } 9719232Sache 9728471Sache switch (cflag & CSIZE) { 9738471Sache case CS5: val = COR1_5BITS; break; 9748471Sache case CS6: val = COR1_6BITS; break; 9758471Sache case CS7: val = COR1_7BITS; break; 9768471Sache default: 9778471Sache case CS8: val = COR1_8BITS; break; 9788471Sache } 9798471Sache if (cflag & PARENB) { 9808471Sache val |= COR1_NORMPAR; 9818471Sache if (cflag & PARODD) 9828471Sache val |= COR1_ODDP; 9839232Sache if (!(cflag & INPCK)) 9849232Sache val |= COR1_Ignore; 9858471Sache } else 9869232Sache val |= COR1_Ignore; 9878471Sache if (cflag & CSTOPB) 9888471Sache val |= COR1_2SB; 9898471Sache rcout(CD180_COR1, val); 9908471Sache 9918471Sache /* Set FIFO threshold */ 9929232Sache val = ts->c_ospeed <= 4800 ? 1 : CD180_NFIFO / 2; 9939232Sache inpflow = 0; 9949232Sache if ( (iflag & IXOFF) 9959232Sache && ( ts->c_cc[VSTOP] != _POSIX_VDISABLE 9969232Sache && ( ts->c_cc[VSTART] != _POSIX_VDISABLE 9979232Sache || (iflag & IXANY) 9989232Sache ) 9999232Sache ) 10009232Sache ) { 10019232Sache inpflow = 1; 10029232Sache val |= COR3_SCDE|COR3_FCT; 10039232Sache } 10049232Sache rcout(CD180_COR3, val); 10058471Sache 10068471Sache /* Initialize on-chip automatic flow control */ 10078471Sache val = 0; 10089232Sache rc->rc_flags &= ~(RC_CTSFLOW|RC_SEND_RDY); 10098471Sache if (cflag & CCTS_OFLOW) { 10108471Sache rc->rc_flags |= RC_CTSFLOW; 10119232Sache val |= COR2_CtsAE; 10129232Sache } else 10139232Sache rc->rc_flags |= RC_SEND_RDY; 10149232Sache if (tp->t_state & TS_TTSTOP) 10159232Sache rc->rc_flags |= RC_OSUSP; 10168471Sache else 10179232Sache rc->rc_flags &= ~RC_OSUSP; 10188471Sache if (cflag & CRTS_IFLOW) 10198471Sache rc->rc_flags |= RC_RTSFLOW; 10209232Sache else 10219232Sache rc->rc_flags &= ~RC_RTSFLOW; 10228471Sache 10239232Sache if (inpflow) { 10249232Sache if (ts->c_cc[VSTART] != _POSIX_VDISABLE) 10259232Sache rcout(CD180_SCHR1, ts->c_cc[VSTART]); 10269232Sache rcout(CD180_SCHR2, ts->c_cc[VSTOP]); 10279232Sache val |= COR2_TxIBE; 10289232Sache if (iflag & IXANY) 10299232Sache val |= COR2_IXM; 10308471Sache } 10318471Sache 10329232Sache rcout(CD180_COR2, rc->rc_cor2 = val); 10338471Sache 10349232Sache CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, 10359232Sache CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); 10369232Sache 10378471Sache disc_optim(tp, ts, rc); 10388471Sache 10398471Sache /* modem ctl */ 10409232Sache val = cflag & CLOCAL ? 0 : MCOR1_CDzd; 10419232Sache if (cflag & CCTS_OFLOW) 10429232Sache val |= MCOR1_CTSzd; 10439232Sache rcout(CD180_MCOR1, val); 10448471Sache 10459232Sache val = cflag & CLOCAL ? 0 : MCOR2_CDod; 10469232Sache if (cflag & CCTS_OFLOW) 10479232Sache val |= MCOR2_CTSod; 10489232Sache rcout(CD180_MCOR2, val); 10499232Sache 10508471Sache /* enable i/o and interrupts */ 10519232Sache CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, 10529232Sache CCR_XMTREN | ((cflag & CREAD) ? CCR_RCVREN : CCR_RCVRDIS)); 10539232Sache WAITFORCCR(rc->rc_rcb->rcb_unit, rc->rc_chan); 10548471Sache 10559232Sache rc->rc_ier = cflag & CLOCAL ? 0 : IER_CD; 10569232Sache if (cflag & CCTS_OFLOW) 10579232Sache rc->rc_ier |= IER_CTS; 10589232Sache if (cflag & CREAD) 10599232Sache rc->rc_ier |= IER_RxData; 10609232Sache if (tp->t_state & TS_BUSY) 10619232Sache rc->rc_ier |= IER_TxRdy; 10629232Sache if (ts->c_ospeed != 0) 10639232Sache rc_modctl(rc, TIOCM_DTR, DMBIS); 10649232Sache if ((cflag & CCTS_OFLOW) && (rc->rc_msvr & MSVR_CTS)) 10659232Sache rc->rc_flags |= RC_SEND_RDY; 10669232Sache rcout(CD180_IER, rc->rc_ier); 10678471Sache (void) splx(s); 10688471Sache return 0; 10698471Sache} 10708471Sache 10719232Sache/* Re-initialize board after bogus interrupts */ 10729232Sachestatic void rc_reinit(rcb) 10739232Sachestruct rc_softc *rcb; 10749232Sache{ 10759232Sache register struct rc_chans *rc, *rce; 10769232Sache register int i, nec; 10779232Sache 10789232Sache nec = rcb->rcb_addr; 10799232Sache rc_hwreset(rcb->rcb_unit, nec, RC_FAKEID); 10809232Sache rc = &rc_chans[rcb->rcb_unit * CD180_NCHAN]; 10819232Sache rce = rc + CD180_NCHAN; 10829232Sache for (; rc < rce; rc++) 10839232Sache (void) rc_param(rc->rc_tp, &rc->rc_tp->t_termios); 10849232Sache} 10859232Sache 10868471Sacheint rcioctl(dev, cmd, data, flag, p) 10878471Sachedev_t dev; 10888471Sacheint cmd, flag; 10898471Sachecaddr_t data; 10908471Sachestruct proc *p; 10918471Sache{ 10928471Sache register struct rc_chans *rc = &rc_chans[GET_UNIT(dev)]; 10938471Sache register int s, error; 10948471Sache struct tty *tp = rc->rc_tp; 10958471Sache 10968471Sache error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); 10978471Sache if (error >= 0) 10988471Sache return (error); 10998471Sache error = ttioctl(tp, cmd, data, flag); 11008471Sache if (error >= 0) 11018471Sache return (error); 11028471Sache s = spltty(); 11038471Sache 11048471Sache switch (cmd) { 11058471Sache case TIOCSBRK: 11068471Sache rc->rc_pendcmd = CD180_C_SBRK; 11078471Sache break; 11088471Sache 11098471Sache case TIOCCBRK: 11108471Sache rc->rc_pendcmd = CD180_C_EBRK; 11118471Sache break; 11128471Sache 11138471Sache case TIOCSDTR: 11149232Sache (void) rc_modctl(rc, TIOCM_DTR, DMBIS); 11158471Sache break; 11168471Sache 11178471Sache case TIOCCDTR: 11188471Sache (void) rc_modctl(rc, TIOCM_DTR, DMBIC); 11198471Sache break; 11208471Sache 11218471Sache case TIOCMGET: 11228471Sache *(int *) data = rc_modctl(rc, 0, DMGET); 11238471Sache break; 11248471Sache 11258471Sache case TIOCMSET: 11268471Sache (void) rc_modctl(rc, *(int *) data, DMSET); 11278471Sache break; 11288471Sache 11298471Sache case TIOCMBIC: 11308471Sache (void) rc_modctl(rc, *(int *) data, DMBIC); 11318471Sache break; 11328471Sache 11338471Sache case TIOCMBIS: 11348471Sache (void) rc_modctl(rc, *(int *) data, DMBIS); 11358471Sache break; 11368471Sache 11378471Sache case TIOCMSDTRWAIT: 11388471Sache error = suser(p->p_ucred, &p->p_acflag); 11398471Sache if (error != 0) { 11408471Sache splx(s); 11418471Sache return (error); 11428471Sache } 11438471Sache rc->rc_dtrwait = *(int *)data * hz / 100; 11448471Sache break; 11458471Sache 11468471Sache case TIOCMGDTRWAIT: 11478471Sache *(int *)data = rc->rc_dtrwait * 100 / hz; 11488471Sache break; 11498471Sache 11508471Sache default: 11518471Sache (void) splx(s); 11528471Sache return ENOTTY; 11538471Sache } 11548471Sache (void) splx(s); 11558471Sache return 0; 11568471Sache} 11578471Sache 11588471Sache 11598471Sache/* Modem control routines */ 11608471Sache 11618471Sachestatic int rc_modctl(rc, bits, cmd) 11628471Sacheregister struct rc_chans *rc; 11638471Sacheint bits, cmd; 11648471Sache{ 11658471Sache register int nec = rc->rc_rcb->rcb_addr; 11669232Sache u_char *dtr = &rc->rc_rcb->rcb_dtr, msvr; 11678471Sache 11688471Sache rcout(CD180_CAR, rc->rc_chan); 11698471Sache 11708471Sache switch (cmd) { 11718471Sache case DMSET: 11729232Sache rcout(RC_DTREG, (bits & TIOCM_DTR) ? 11739232Sache ~(*dtr |= 1 << rc->rc_chan) : 11749232Sache ~(*dtr &= ~(1 << rc->rc_chan))); 11759232Sache msvr = rcin(CD180_MSVR); 11769232Sache if (bits & TIOCM_RTS) 11779232Sache msvr |= MSVR_RTS; 11789232Sache else 11799232Sache msvr &= ~MSVR_RTS; 11809232Sache if (bits & TIOCM_DTR) 11819232Sache msvr |= MSVR_DTR; 11829232Sache else 11839232Sache msvr &= ~MSVR_DTR; 11849232Sache rcout(CD180_MSVR, msvr); 11859232Sache break; 11868471Sache 11878471Sache case DMBIS: 11889232Sache if (bits & TIOCM_DTR) 11899232Sache rcout(RC_DTREG, ~(*dtr |= 1 << rc->rc_chan)); 11909232Sache msvr = rcin(CD180_MSVR); 11918471Sache if (bits & TIOCM_RTS) 11929232Sache msvr |= MSVR_RTS; 11938471Sache if (bits & TIOCM_DTR) 11949232Sache msvr |= MSVR_DTR; 11959232Sache rcout(CD180_MSVR, msvr); 11968471Sache break; 11978471Sache 11988471Sache case DMGET: 11998471Sache bits = TIOCM_LE; 12009232Sache msvr = rc->rc_msvr = rcin(CD180_MSVR); 12018471Sache 12028471Sache if (msvr & MSVR_RTS) 12038471Sache bits |= TIOCM_RTS; 12048471Sache if (msvr & MSVR_CTS) 12058471Sache bits |= TIOCM_CTS; 12068471Sache if (msvr & MSVR_DSR) 12078471Sache bits |= TIOCM_DSR; 12088471Sache if (msvr & MSVR_DTR) 12098471Sache bits |= TIOCM_DTR; 12109232Sache if (msvr & MSVR_CD) 12119232Sache bits |= TIOCM_CD; 12129232Sache if (~rcin(RC_RIREG) & (1 << rc->rc_chan)) 12139232Sache bits |= TIOCM_RI; 12148471Sache return bits; 12158471Sache 12168471Sache case DMBIC: 12178471Sache if (bits & TIOCM_DTR) 12189232Sache rcout(RC_DTREG, ~(*dtr &= ~(1 << rc->rc_chan))); 12199232Sache msvr = rcin(CD180_MSVR); 12208471Sache if (bits & TIOCM_RTS) 12219232Sache msvr &= ~MSVR_RTS; 12229232Sache if (bits & TIOCM_DTR) 12239232Sache msvr &= ~MSVR_DTR; 12249232Sache rcout(CD180_MSVR, msvr); 12258471Sache break; 12268471Sache } 12279232Sache rc->rc_msvr = rcin(CD180_MSVR); 12288471Sache return 0; 12298471Sache} 12308471Sache 12318471Sache/* Test the board. */ 12328471Sacheint rc_test(nec, unit) 12338471Sache register int nec; 12348471Sache int unit; 12358471Sache{ 12368471Sache int chan = 0, nopt = 0; 12378471Sache int i = 0, rcnt, old_level; 12388471Sache unsigned int iack, chipid; 12398471Sache unsigned short divs; 12408471Sache static u_char ctest[] = "\377\125\252\045\244\0\377"; 12418471Sache#define CTLEN 8 12428471Sache#define ERR(s) { \ 12438471Sache printf("rc%d: ", unit); printf s ; printf("\n"); \ 12448471Sache (void) splx(old_level); return 1; } 12458471Sache 12468471Sache struct rtest { 12478471Sache u_char txbuf[CD180_NFIFO]; /* TX buffer */ 12488471Sache u_char rxbuf[CD180_NFIFO]; /* RX buffer */ 12498471Sache int rxptr; /* RX pointer */ 12508471Sache int txptr; /* TX pointer */ 12518471Sache } tchans[CD180_NCHAN]; 12528471Sache 12539232Sache old_level = spltty(); 12548471Sache 12558471Sache chipid = RC_FAKEID; 12568471Sache 12578471Sache /* First, reset board to inital state */ 12589232Sache rc_hwreset(unit, nec, chipid); 12598471Sache 12609232Sache divs = RC_BRD(19200); 12619232Sache 12628471Sache /* Initialize channels */ 12638471Sache for (chan = 0; chan < CD180_NCHAN; chan++) { 12648471Sache 12658471Sache /* Select and reset channel */ 12668471Sache rcout(CD180_CAR, chan); 12679232Sache CCRCMD(unit, chan, CCR_ResetChan); 12689232Sache WAITFORCCR(unit, chan); 12698471Sache 12708471Sache /* Set speed */ 12718471Sache rcout(CD180_RBPRL, divs & 0xFF); 12728471Sache rcout(CD180_RBPRH, divs >> 8); 12738471Sache rcout(CD180_TBPRL, divs & 0xFF); 12748471Sache rcout(CD180_TBPRH, divs >> 8); 12758471Sache 12768471Sache /* set timeout value */ 12778471Sache rcout(CD180_RTPR, 0); 12788471Sache 12798471Sache /* Establish local loopback */ 12808471Sache rcout(CD180_COR1, COR1_NOPAR | COR1_8BITS | COR1_1SB); 12818471Sache rcout(CD180_COR2, COR2_LLM); 12828471Sache rcout(CD180_COR3, CD180_NFIFO); 12839232Sache CCRCMD(unit, chan, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); 12849232Sache CCRCMD(unit, chan, CCR_RCVREN | CCR_XMTREN); 12859232Sache WAITFORCCR(unit, chan); 12868471Sache rcout(CD180_MSVR, MSVR_RTS); 12878471Sache 12888471Sache /* Fill TXBUF with test data */ 12898471Sache for (i = 0; i < CD180_NFIFO; i++) { 12908471Sache tchans[chan].txbuf[i] = ctest[i]; 12918471Sache tchans[chan].rxbuf[i] = 0; 12928471Sache } 12938471Sache tchans[chan].txptr = tchans[chan].rxptr = 0; 12948471Sache 12958471Sache /* Now, start transmit */ 12969232Sache rcout(CD180_IER, IER_TxMpty|IER_RxData); 12978471Sache } 12988471Sache /* Pseudo-interrupt poll stuff */ 12998471Sache for (rcnt = 10000; rcnt-- > 0; rcnt--) { 13009232Sache i = ~(rcin(RC_BSR)); 13018471Sache if (i & RC_BSR_TOUT) 13028471Sache ERR(("BSR timeout bit set\n")) 13039232Sache else if (i & RC_BSR_TXINT) { 13048471Sache iack = rcin(RC_PILR_TX); 13058471Sache if (iack != (GIVR_IT_TDI | chipid)) 13068471Sache ERR(("Bad TX intr ack (%02x != %02x)\n", 13078471Sache iack, GIVR_IT_TDI | chipid)); 13089232Sache chan = (rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH; 13098471Sache /* If no more data to transmit, disable TX intr */ 13108471Sache if (tchans[chan].txptr >= CD180_NFIFO) { 13118471Sache iack = rcin(CD180_IER); 13129232Sache rcout(CD180_IER, iack & ~IER_TxMpty); 13138471Sache } else { 13148471Sache for (iack = tchans[chan].txptr; 13158471Sache iack < CD180_NFIFO; iack++) 13168471Sache rcout(CD180_TDR, 13178471Sache tchans[chan].txbuf[iack]); 13188471Sache tchans[chan].txptr = iack; 13198471Sache } 13209232Sache rcout(CD180_EOIR, 0); 13219232Sache } else if (i & RC_BSR_RXINT) { 13229232Sache u_char ucnt; 13238471Sache 13248471Sache iack = rcin(RC_PILR_RX); 13258471Sache if (iack != (GIVR_IT_RGDI | chipid) && 13268471Sache iack != (GIVR_IT_REI | chipid)) 13278471Sache ERR(("Bad RX intr ack (%02x != %02x)\n", 13288471Sache iack, GIVR_IT_RGDI | chipid)) 13299232Sache chan = (rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH; 13308471Sache ucnt = rcin(CD180_RDCR) & 0xF; 13318471Sache while (ucnt-- > 0) { 13328471Sache iack = rcin(CD180_RCSR); 13339232Sache if (iack & RCSR_Timeout) 13348471Sache break; 13358471Sache if (iack & 0xF) 13368471Sache ERR(("Bad char chan %d (RCSR = %02X)\n", 13378471Sache chan, iack)) 13388471Sache if (tchans[chan].rxptr > CD180_NFIFO) 13398471Sache ERR(("Got extra chars chan %d\n", 13408471Sache chan)) 13418471Sache tchans[chan].rxbuf[tchans[chan].rxptr++] = 13428471Sache rcin(CD180_RDR); 13438471Sache } 13448471Sache rcout(CD180_EOIR, 0); 13458471Sache } 13469232Sache rcout(RC_CTOUT, 0); 13478471Sache for (iack = chan = 0; chan < CD180_NCHAN; chan++) 13488471Sache if (tchans[chan].rxptr >= CD180_NFIFO) 13498471Sache iack++; 13508471Sache if (iack == CD180_NCHAN) 13518471Sache break; 13528471Sache } 13539232Sache for (chan = 0; chan < CD180_NCHAN; chan++) { 13549232Sache /* Select and reset channel */ 13559232Sache rcout(CD180_CAR, chan); 13569232Sache CCRCMD(unit, chan, CCR_ResetChan); 13579232Sache } 13589232Sache 13598471Sache if (!rcnt) 13608471Sache ERR(("looses characters during local loopback\n")) 13618471Sache /* Now, check data */ 13628471Sache for (chan = 0; chan < CD180_NCHAN; chan++) 13638471Sache for (i = 0; i < CD180_NFIFO; i++) 13648471Sache if (ctest[i] != tchans[chan].rxbuf[i]) 13658471Sache ERR(("data mismatch chan %d ptr %d (%d != %d)\n", 13668471Sache chan, i, ctest[i], tchans[chan].rxbuf[i])) 13678471Sache (void) splx(old_level); 13688471Sache return 0; 13698471Sache} 13708471Sache 13718471Sache#ifdef RCDEBUG 13729232Sachestatic void printrcflags(rc, comment) 13738471Sachestruct rc_chans *rc; 13748471Sachechar *comment; 13758471Sache{ 13768471Sache u_short f = rc->rc_flags; 13779232Sache register int nec = rc->rc_rcb->rcb_addr; 13788471Sache 13799232Sache printf("rc%d/%d: %s flags: %s%s%s%s%s%s%s%s%s%s%s%s\n", 13808471Sache rc->rc_rcb->rcb_unit, rc->rc_chan, comment, 13818471Sache (f & RC_DTR_OFF)?"DTR_OFF " :"", 13829232Sache (f & RC_ACTOUT) ?"ACTOUT " :"", 13839232Sache (f & RC_RTSFLOW)?"RTSFLOW " :"", 13849232Sache (f & RC_CTSFLOW)?"CTSFLOW " :"", 13859232Sache (f & RC_DORXFER)?"DORXFER " :"", 13869232Sache (f & RC_DOXXFER)?"DOXXFER " :"", 13879232Sache (f & RC_MODCHG) ?"MODCHG " :"", 13889232Sache (f & RC_OSUSP) ?"OSUSP " :"", 13899232Sache (f & RC_OSBUSY) ?"OSBUSY " :"", 13909232Sache (f & RC_WAS_BUFOVFL) ?"BUFOVFL " :"", 13919232Sache (f & RC_WAS_SILOVFL) ?"SILOVFL " :"", 13929232Sache (f & RC_SEND_RDY) ?"SEND_RDY":""); 13939232Sache 13949232Sache rcout(CD180_CAR, rc->rc_chan); 13959232Sache 13969232Sache printf("rc%d/%d: msvr %02x ier %02x ccsr %02x\n", 13979232Sache rc->rc_rcb->rcb_unit, rc->rc_chan, 13989232Sache rcin(CD180_MSVR), 13999232Sache rcin(CD180_IER), 14009232Sache rcin(CD180_CCSR)); 14018471Sache} 14028471Sache#endif /* RCDEBUG */ 14038471Sache 14048471Sachestruct tty * 14058471Sachercdevtotty(dev) 14068471Sache dev_t dev; 14078471Sache{ 14088471Sache int unit; 14098471Sache 14108471Sache unit = GET_UNIT(dev); 14118471Sache if (unit >= NRC * CD180_NCHAN) 14128471Sache return NULL; 14138471Sache return (&rc_tty[unit]); 14148471Sache} 14158471Sache 14168471Sachestatic void 14178471Sacherc_dtrwakeup(chan) 14188471Sache void *chan; 14198471Sache{ 14208471Sache struct rc_chans *rc; 14218471Sache 14228471Sache rc = (struct rc_chans *)chan; 14238471Sache rc->rc_flags &= ~RC_DTR_OFF; 14248471Sache wakeup(&rc->rc_dtrwait); 14258471Sache} 14268471Sache 14278471Sachestatic void 14288471Sacherc_discard_output(rc) 14298471Sache struct rc_chans *rc; 14308471Sache{ 14318471Sache disable_intr(); 14328471Sache if (rc->rc_flags & RC_DOXXFER) { 14338471Sache rc_scheduled_event -= LOTS_OF_EVENTS; 14348471Sache rc->rc_flags &= ~RC_DOXXFER; 14358471Sache } 14368471Sache rc->rc_optr = rc->rc_obufend; 14379232Sache rc->rc_tp->t_state &= ~TS_BUSY; 14388471Sache enable_intr(); 14399754Sbde ttwwakeup(rc->rc_tp); 14408471Sache} 14418471Sache 14428471Sachestatic void 14438471Sacherc_wakeup(chan) 14448471Sache void *chan; 14458471Sache{ 14468471Sache int unit; 14478471Sache 14488471Sache timeout(rc_wakeup, (caddr_t)NULL, 1); 14498471Sache 14508471Sache if (rc_scheduled_event != 0) { 14518471Sache int s; 14528471Sache 14538471Sache s = splsofttty(); 14548471Sache rcpoll(); 14558471Sache splx(s); 14568471Sache } 14578471Sache} 14588471Sache 14598471Sachestatic void 14608471Sachedisc_optim(tp, t, rc) 14618471Sache struct tty *tp; 14628471Sache struct termios *t; 14638471Sache struct rc_chans *rc; 14648471Sache{ 14658471Sache 14669757Sbde if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON)) 14678471Sache && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) 14689757Sbde && (!(t->c_iflag & PARMRK) 14699757Sbde || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) 14709757Sbde && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) 14718471Sache && linesw[tp->t_line].l_rint == ttyinput) 14728471Sache tp->t_state |= TS_CAN_BYPASS_L_RINT; 14738471Sache else 14748471Sache tp->t_state &= ~TS_CAN_BYPASS_L_RINT; 14758471Sache if (tp->t_line == SLIPDISC) 14768471Sache rc->rc_hotchar = 0xc0; 14778471Sache else if (tp->t_line == PPPDISC) 14788471Sache rc->rc_hotchar = 0x7e; 14798471Sache else 14808471Sache rc->rc_hotchar = 0; 14818471Sache} 14829232Sache 14839232Sachestatic void 14849232Sacherc_wait0(nec, unit, chan, line) 14859232Sache int nec, unit, chan, line; 14869232Sache{ 14879232Sache int rcnt; 14889232Sache 14899232Sache for (rcnt = 100; rcnt && rcin(CD180_CCR); rcnt--) 14909232Sache DELAY(15); 14919232Sache if (rcnt == 0) 14929232Sache printf("rc%d/%d: channel command timeout, rc.c line: %d\n", 14939232Sache unit, chan, line); 14949232Sache} 14958471Sache#endif /* NRC */ 1496