rc.c revision 24203
1/* 2 * Copyright (C) 1995 by Pavel Antonov, Moscow, Russia. 3 * Copyright (C) 1995 by Andrey A. Chernov, Moscow, Russia. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28/* 29 * SDL Communications Riscom/8 (based on Cirrus Logic CL-CD180) driver 30 * 31 */ 32 33#include "opt_comconsole.h" 34#include "rc.h" 35 36#if NRC > 0 37 38/*#define RCDEBUG*/ 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/tty.h> 43#include <sys/proc.h> 44#include <sys/conf.h> 45#include <sys/dkstat.h> 46#include <sys/fcntl.h> 47#include <sys/uio.h> 48#include <sys/kernel.h> 49#include <sys/syslog.h> 50#ifdef DEVFS 51#include <sys/devfsext.h> 52#endif /*DEVFS*/ 53 54#include <machine/clock.h> 55 56#include <i386/isa/isa_device.h> 57#include <i386/isa/sioreg.h> 58 59#include <i386/isa/ic/cd180.h> 60#include <i386/isa/rcreg.h> 61 62 63/* Prototypes */ 64static int rcprobe __P((struct isa_device *)); 65static int rcattach __P((struct isa_device *)); 66 67/*- 68 * This space intentionally left blank to stop __LINE__ from screwing up 69 * regression tests :-(. 70 * 71 * 72 * 73 */ 74void rcpoll __P((void)); 75 76#define rcin(port) RC_IN (nec, port) 77#define rcout(port,v) RC_OUT (nec, port, v) 78 79#define WAITFORCCR(u,c) rc_wait0(nec, (u), (c), __LINE__) 80#define CCRCMD(u,c,cmd) WAITFORCCR((u), (c)); rcout(CD180_CCR, (cmd)) 81 82#define RC_IBUFSIZE 256 83#define RB_I_HIGH_WATER (TTYHOG - 2 * RC_IBUFSIZE) 84#define RC_OBUFSIZE 512 85#define RC_IHIGHWATER (3 * RC_IBUFSIZE / 4) 86#define INPUT_FLAGS_SHIFT (2 * RC_IBUFSIZE) 87#define LOTS_OF_EVENTS 64 88 89#define RC_FAKEID 0x10 90 91#define RC_PROBED 1 92#define RC_ATTACHED 2 93 94#define GET_UNIT(dev) (minor(dev) & 0x3F) 95#define CALLOUT(dev) (minor(dev) & 0x80) 96 97/* For isa routines */ 98struct isa_driver rcdriver = { 99 rcprobe, rcattach, "rc" 100}; 101 102static d_open_t rcopen; 103static d_close_t rcclose; 104static d_read_t rcread; 105static d_write_t rcwrite; 106static d_ioctl_t rcioctl; 107static d_stop_t rcstop; 108static d_devtotty_t rcdevtotty; 109 110#define CDEV_MAJOR 63 111static struct cdevsw rc_cdevsw = 112 { rcopen, rcclose, rcread, rcwrite, /*63*/ 113 rcioctl, rcstop, noreset, rcdevtotty,/* rc */ 114 ttselect, nommap, NULL, "rc", NULL, -1 }; 115 116/* Per-board structure */ 117static struct rc_softc { 118 u_int rcb_probed; /* 1 - probed, 2 - attached */ 119 u_int rcb_addr; /* Base I/O addr */ 120 u_int rcb_unit; /* unit # */ 121 u_char rcb_dtr; /* DTR status */ 122 struct rc_chans *rcb_baserc; /* base rc ptr */ 123} rc_softc[NRC]; 124 125/* Per-channel structure */ 126static struct rc_chans { 127 struct rc_softc *rc_rcb; /* back ptr */ 128 u_short rc_flags; /* Misc. flags */ 129 int rc_chan; /* Channel # */ 130 u_char rc_ier; /* intr. enable reg */ 131 u_char rc_msvr; /* modem sig. status */ 132 u_char rc_cor2; /* options reg */ 133 u_char rc_pendcmd; /* special cmd pending */ 134 u_int rc_dtrwait; /* dtr timeout */ 135 u_int rc_dcdwaits; /* how many waits DCD in open */ 136 u_char rc_hotchar; /* end packed optimize */ 137 struct tty *rc_tp; /* tty struct */ 138 u_char *rc_iptr; /* Chars input buffer */ 139 u_char *rc_hiwat; /* hi-water mark */ 140 u_char *rc_bufend; /* end of buffer */ 141 u_char *rc_optr; /* ptr in output buf */ 142 u_char *rc_obufend; /* end of output buf */ 143 u_char rc_ibuf[4 * RC_IBUFSIZE]; /* input buffer */ 144 u_char rc_obuf[RC_OBUFSIZE]; /* output buffer */ 145#ifdef DEVFS 146 void *devfs_token; 147#endif 148} rc_chans[NRC * CD180_NCHAN]; 149 150static int rc_scheduled_event = 0; 151 152/* for pstat -t */ 153static struct tty rc_tty[NRC * CD180_NCHAN]; 154static const int nrc_tty = NRC * CD180_NCHAN; 155 156/* Flags */ 157#define RC_DTR_OFF 0x0001 /* DTR wait, for close/open */ 158#define RC_ACTOUT 0x0002 /* Dial-out port active */ 159#define RC_RTSFLOW 0x0004 /* RTS flow ctl enabled */ 160#define RC_CTSFLOW 0x0008 /* CTS flow ctl enabled */ 161#define RC_DORXFER 0x0010 /* RXFER event planned */ 162#define RC_DOXXFER 0x0020 /* XXFER event planned */ 163#define RC_MODCHG 0x0040 /* Modem status changed */ 164#define RC_OSUSP 0x0080 /* Output suspended */ 165#define RC_OSBUSY 0x0100 /* start() routine in progress */ 166#define RC_WAS_BUFOVFL 0x0200 /* low-level buffer ovferflow */ 167#define RC_WAS_SILOVFL 0x0400 /* silo buffer overflow */ 168#define RC_SEND_RDY 0x0800 /* ready to send */ 169 170/* Table for translation of RCSR status bits to internal form */ 171static int rc_rcsrt[16] = { 172 0, TTY_OE, TTY_FE, 173 TTY_FE|TTY_OE, TTY_PE, TTY_PE|TTY_OE, 174 TTY_PE|TTY_FE, TTY_PE|TTY_FE|TTY_OE, TTY_BI, 175 TTY_BI|TTY_OE, TTY_BI|TTY_FE, TTY_BI|TTY_FE|TTY_OE, 176 TTY_BI|TTY_PE, TTY_BI|TTY_PE|TTY_OE, TTY_BI|TTY_PE|TTY_FE, 177 TTY_BI|TTY_PE|TTY_FE|TTY_OE 178}; 179 180/* Static prototypes */ 181static void rc_hwreset __P((int, int, unsigned int)); 182static int rc_test __P((int, int)); 183static void rc_discard_output __P((struct rc_chans *)); 184static void rc_hardclose __P((struct rc_chans *)); 185static int rc_modctl __P((struct rc_chans *, int, int)); 186static void rc_start __P((struct tty *)); 187static int rc_param __P((struct tty *, struct termios *)); 188static void rc_reinit __P((struct rc_softc *)); 189#ifdef RCDEBUG 190static void printrcflags(); 191#endif 192static timeout_t rc_dtrwakeup; 193static timeout_t rc_wakeup; 194static void disc_optim __P((struct tty *tp, struct termios *t, struct rc_chans *)); 195static void rc_wait0 __P((int nec, int unit, int chan, int line)); 196 197/**********************************************/ 198 199/* Quick device probing */ 200static int 201rcprobe(dvp) 202 struct isa_device *dvp; 203{ 204 int irq = ffs(dvp->id_irq) - 1; 205 register int nec = dvp->id_iobase; 206 207 if (dvp->id_unit > NRC) 208 return 0; 209 if (!RC_VALIDADDR(nec)) { 210 printf("rc%d: illegal base address %x\n", nec); 211 return 0; 212 } 213 if (!RC_VALIDIRQ(irq)) { 214 printf("rc%d: illegal IRQ value %d\n", irq); 215 return 0; 216 } 217 rcout(CD180_PPRL, 0x22); /* Random values to Prescale reg. */ 218 rcout(CD180_PPRH, 0x11); 219 if (rcin(CD180_PPRL) != 0x22 || rcin(CD180_PPRH) != 0x11) 220 return 0; 221 /* Now, test the board more thoroughly, with diagnostic */ 222 if (rc_test(nec, dvp->id_unit)) 223 return 0; 224 rc_softc[dvp->id_unit].rcb_probed = RC_PROBED; 225 226 return 0xF; 227} 228 229static int 230rcattach(dvp) 231 struct isa_device *dvp; 232{ 233 register int chan, nec = dvp->id_iobase; 234 struct rc_softc *rcb = &rc_softc[dvp->id_unit]; 235 struct rc_chans *rc = &rc_chans[dvp->id_unit * CD180_NCHAN]; 236 static int rc_wakeup_started = 0; 237 struct tty *tp; 238 239 /* Thorooughly test the device */ 240 if (rcb->rcb_probed != RC_PROBED) 241 return 0; 242 rcb->rcb_addr = nec; 243 rcb->rcb_dtr = 0; 244 rcb->rcb_baserc = rc; 245 /*rcb->rcb_chipid = 0x10 + dvp->id_unit;*/ 246 printf("rc%d: %d chans, firmware rev. %c\n", dvp->id_unit, 247 CD180_NCHAN, (rcin(CD180_GFRCR) & 0xF) + 'A'); 248 249 for (chan = 0; chan < CD180_NCHAN; chan++, rc++) { 250 rc->rc_rcb = rcb; 251 rc->rc_chan = chan; 252 rc->rc_iptr = rc->rc_ibuf; 253 rc->rc_bufend = &rc->rc_ibuf[RC_IBUFSIZE]; 254 rc->rc_hiwat = &rc->rc_ibuf[RC_IHIGHWATER]; 255 rc->rc_flags = rc->rc_ier = rc->rc_msvr = 0; 256 rc->rc_cor2 = rc->rc_pendcmd = 0; 257 rc->rc_optr = rc->rc_obufend = rc->rc_obuf; 258 rc->rc_dtrwait = 3 * hz; 259 rc->rc_dcdwaits= 0; 260 rc->rc_hotchar = 0; 261 tp = rc->rc_tp = &rc_tty[chan]; 262 ttychars(tp); 263 tp->t_lflag = tp->t_iflag = tp->t_oflag = 0; 264 tp->t_cflag = TTYDEF_CFLAG; 265 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 266#ifdef DEVFS 267/* FIX THIS to reflect real devices */ 268 rc->devfs_token = 269 devfs_add_devswf(&rc_cdevsw, 270 (dvp->id_unit * CD180_NCHAN) + chan, 271 DV_CHR, 0, 0, 0600, "rc%d.%d", 272 dvp->id_unit, chan); 273#endif 274 } 275 rcb->rcb_probed = RC_ATTACHED; 276 if (!rc_wakeup_started) { 277 rc_wakeup((void *)NULL); 278 rc_wakeup_started = 0; 279 } 280 return 1; 281} 282 283/* RC interrupt handling */ 284void rcintr(unit) 285 int unit; 286{ 287 register struct rc_softc *rcb = &rc_softc[unit]; 288 register struct rc_chans *rc; 289 register int nec, resid; 290 register u_char val, iack, bsr, ucnt, *optr; 291 int good_data, t_state; 292 293 if (rcb->rcb_probed != RC_ATTACHED) { 294 printf("rc%d: bogus interrupt\n", unit); 295 return; 296 } 297 nec = rcb->rcb_addr; 298 299 bsr = ~(rcin(RC_BSR)); 300 301 if (!(bsr & (RC_BSR_TOUT|RC_BSR_RXINT|RC_BSR_TXINT|RC_BSR_MOINT))) { 302 printf("rc%d: extra interrupt\n", unit); 303 rcout(CD180_EOIR, 0); 304 return; 305 } 306 307 while (bsr & (RC_BSR_TOUT|RC_BSR_RXINT|RC_BSR_TXINT|RC_BSR_MOINT)) { 308#ifdef RCDEBUG_DETAILED 309 printf("rc%d: intr (%02x) %s%s%s%s\n", unit, bsr, 310 (bsr & RC_BSR_TOUT)?"TOUT ":"", 311 (bsr & RC_BSR_RXINT)?"RXINT ":"", 312 (bsr & RC_BSR_TXINT)?"TXINT ":"", 313 (bsr & RC_BSR_MOINT)?"MOINT":""); 314#endif 315 if (bsr & RC_BSR_TOUT) { 316 printf("rc%d: hardware failure, reset board\n", unit); 317 rcout(RC_CTOUT, 0); 318 rc_reinit(rcb); 319 return; 320 } 321 if (bsr & RC_BSR_RXINT) { 322 iack = rcin(RC_PILR_RX); 323 good_data = (iack == (GIVR_IT_RGDI | RC_FAKEID)); 324 if (!good_data && iack != (GIVR_IT_REI | RC_FAKEID)) { 325 printf("rc%d: fake rxint: %02x\n", unit, iack); 326 goto more_intrs; 327 } 328 rc = rcb->rcb_baserc + ((rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH); 329 t_state = rc->rc_tp->t_state; 330 /* Do RTS flow control stuff */ 331 if ( (rc->rc_flags & RC_RTSFLOW) 332 || !(t_state & TS_ISOPEN) 333 ) { 334 if ( ( !(t_state & TS_ISOPEN) 335 || (t_state & TS_TBLOCK) 336 ) 337 && (rc->rc_msvr & MSVR_RTS) 338 ) 339 rcout(CD180_MSVR, 340 rc->rc_msvr &= ~MSVR_RTS); 341 else if (!(rc->rc_msvr & MSVR_RTS)) 342 rcout(CD180_MSVR, 343 rc->rc_msvr |= MSVR_RTS); 344 } 345 ucnt = rcin(CD180_RDCR) & 0xF; 346 resid = 0; 347 348 if (t_state & TS_ISOPEN) { 349 /* check for input buffer overflow */ 350 if ((rc->rc_iptr + ucnt) >= rc->rc_bufend) { 351 resid = ucnt; 352 ucnt = rc->rc_bufend - rc->rc_iptr; 353 resid -= ucnt; 354 if (!(rc->rc_flags & RC_WAS_BUFOVFL)) { 355 rc->rc_flags |= RC_WAS_BUFOVFL; 356 rc_scheduled_event++; 357 } 358 } 359 optr = rc->rc_iptr; 360 /* check foor good data */ 361 if (good_data) { 362 while (ucnt-- > 0) { 363 val = rcin(CD180_RDR); 364 optr[0] = val; 365 optr[INPUT_FLAGS_SHIFT] = 0; 366 optr++; 367 rc_scheduled_event++; 368 if (val != 0 && val == rc->rc_hotchar) 369 setsofttty(); 370 } 371 } else { 372 /* Store also status data */ 373 while (ucnt-- > 0) { 374 iack = rcin(CD180_RCSR); 375 if (iack & RCSR_Timeout) 376 break; 377 if ( (iack & RCSR_OE) 378 && !(rc->rc_flags & RC_WAS_SILOVFL)) { 379 rc->rc_flags |= RC_WAS_SILOVFL; 380 rc_scheduled_event++; 381 } 382 val = rcin(CD180_RDR); 383 /* 384 Don't store PE if IGNPAR and BREAK if IGNBRK, 385 this hack allows "raw" tty optimization 386 works even if IGN* is set. 387 */ 388 if ( !(iack & (RCSR_PE|RCSR_FE|RCSR_Break)) 389 || (!(iack & (RCSR_PE|RCSR_FE)) 390 || !(rc->rc_tp->t_iflag & IGNPAR)) 391 && (!(iack & RCSR_Break) 392 || !(rc->rc_tp->t_iflag & IGNBRK))) { 393 if ( (iack & (RCSR_PE|RCSR_FE)) 394 && (t_state & TS_CAN_BYPASS_L_RINT) 395 && ((iack & RCSR_FE) 396 || (iack & RCSR_PE) 397 && (rc->rc_tp->t_iflag & INPCK))) 398 val = 0; 399 else if (val != 0 && val == rc->rc_hotchar) 400 setsofttty(); 401 optr[0] = val; 402 optr[INPUT_FLAGS_SHIFT] = iack; 403 optr++; 404 rc_scheduled_event++; 405 } 406 } 407 } 408 rc->rc_iptr = optr; 409 rc->rc_flags |= RC_DORXFER; 410 } else 411 resid = ucnt; 412 /* Clear FIFO if necessary */ 413 while (resid-- > 0) { 414 if (!good_data) 415 iack = rcin(CD180_RCSR); 416 else 417 iack = 0; 418 if (iack & RCSR_Timeout) 419 break; 420 (void) rcin(CD180_RDR); 421 } 422 goto more_intrs; 423 } 424 if (bsr & RC_BSR_MOINT) { 425 iack = rcin(RC_PILR_MODEM); 426 if (iack != (GIVR_IT_MSCI | RC_FAKEID)) { 427 printf("rc%d: fake moint: %02x\n", unit, iack); 428 goto more_intrs; 429 } 430 rc = rcb->rcb_baserc + ((rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH); 431 iack = rcin(CD180_MCR); 432 rc->rc_msvr = rcin(CD180_MSVR); 433 rcout(CD180_MCR, 0); 434#ifdef RCDEBUG 435 printrcflags(rc, "moint"); 436#endif 437 if (rc->rc_flags & RC_CTSFLOW) { 438 if (rc->rc_msvr & MSVR_CTS) 439 rc->rc_flags |= RC_SEND_RDY; 440 else 441 rc->rc_flags &= ~RC_SEND_RDY; 442 } else 443 rc->rc_flags |= RC_SEND_RDY; 444 if ((iack & MCR_CDchg) && !(rc->rc_flags & RC_MODCHG)) { 445 rc_scheduled_event += LOTS_OF_EVENTS; 446 rc->rc_flags |= RC_MODCHG; 447 setsofttty(); 448 } 449 goto more_intrs; 450 } 451 if (bsr & RC_BSR_TXINT) { 452 iack = rcin(RC_PILR_TX); 453 if (iack != (GIVR_IT_TDI | RC_FAKEID)) { 454 printf("rc%d: fake txint: %02x\n", unit, iack); 455 goto more_intrs; 456 } 457 rc = rcb->rcb_baserc + ((rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH); 458 if ( (rc->rc_flags & RC_OSUSP) 459 || !(rc->rc_flags & RC_SEND_RDY) 460 ) 461 goto more_intrs; 462 /* Handle breaks and other stuff */ 463 if (rc->rc_pendcmd) { 464 rcout(CD180_COR2, rc->rc_cor2 |= COR2_ETC); 465 rcout(CD180_TDR, CD180_C_ESC); 466 rcout(CD180_TDR, rc->rc_pendcmd); 467 rcout(CD180_COR2, rc->rc_cor2 &= ~COR2_ETC); 468 rc->rc_pendcmd = 0; 469 goto more_intrs; 470 } 471 optr = rc->rc_optr; 472 resid = rc->rc_obufend - optr; 473 if (resid > CD180_NFIFO) 474 resid = CD180_NFIFO; 475 while (resid-- > 0) 476 rcout(CD180_TDR, *optr++); 477 rc->rc_optr = optr; 478 479 /* output completed? */ 480 if (optr >= rc->rc_obufend) { 481 rcout(CD180_IER, rc->rc_ier &= ~IER_TxRdy); 482#ifdef RCDEBUG 483 printf("rc%d/%d: output completed\n", unit, rc->rc_chan); 484#endif 485 if (!(rc->rc_flags & RC_DOXXFER)) { 486 rc_scheduled_event += LOTS_OF_EVENTS; 487 rc->rc_flags |= RC_DOXXFER; 488 setsofttty(); 489 } 490 } 491 } 492 more_intrs: 493 rcout(CD180_EOIR, 0); /* end of interrupt */ 494 rcout(RC_CTOUT, 0); 495 bsr = ~(rcin(RC_BSR)); 496 } 497} 498 499/* Feed characters to output buffer */ 500static void rc_start(tp) 501register struct tty *tp; 502{ 503 register struct rc_chans *rc = &rc_chans[GET_UNIT(tp->t_dev)]; 504 register int nec = rc->rc_rcb->rcb_addr, s; 505 506 if (rc->rc_flags & RC_OSBUSY) 507 return; 508 s = spltty(); 509 rc->rc_flags |= RC_OSBUSY; 510 disable_intr(); 511 if (tp->t_state & TS_TTSTOP) 512 rc->rc_flags |= RC_OSUSP; 513 else 514 rc->rc_flags &= ~RC_OSUSP; 515 /* Do RTS flow control stuff */ 516 if ( (rc->rc_flags & RC_RTSFLOW) 517 && (tp->t_state & TS_TBLOCK) 518 && (rc->rc_msvr & MSVR_RTS) 519 ) { 520 rcout(CD180_CAR, rc->rc_chan); 521 rcout(CD180_MSVR, rc->rc_msvr &= ~MSVR_RTS); 522 } else if (!(rc->rc_msvr & MSVR_RTS)) { 523 rcout(CD180_CAR, rc->rc_chan); 524 rcout(CD180_MSVR, rc->rc_msvr |= MSVR_RTS); 525 } 526 enable_intr(); 527 if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) 528 goto out; 529#ifdef RCDEBUG 530 printrcflags(rc, "rcstart"); 531#endif 532 ttwwakeup(tp); 533#ifdef RCDEBUG 534 printf("rcstart: outq = %d obuf = %d\n", 535 tp->t_outq.c_cc, rc->rc_obufend - rc->rc_optr); 536#endif 537 if (tp->t_state & TS_BUSY) 538 goto out; /* output still in progress ... */ 539 540 if (tp->t_outq.c_cc > 0) { 541 u_int ocnt; 542 543 tp->t_state |= TS_BUSY; 544 ocnt = q_to_b(&tp->t_outq, rc->rc_obuf, sizeof rc->rc_obuf); 545 disable_intr(); 546 rc->rc_optr = rc->rc_obuf; 547 rc->rc_obufend = rc->rc_optr + ocnt; 548 enable_intr(); 549 if (!(rc->rc_ier & IER_TxRdy)) { 550#ifdef RCDEBUG 551 printf("rc%d/%d: rcstart enable txint\n", rc->rc_rcb->rcb_unit, rc->rc_chan); 552#endif 553 rcout(CD180_CAR, rc->rc_chan); 554 rcout(CD180_IER, rc->rc_ier |= IER_TxRdy); 555 } 556 } 557out: 558 rc->rc_flags &= ~RC_OSBUSY; 559 (void) splx(s); 560} 561 562/* Handle delayed events. */ 563void rcpoll() 564{ 565 register struct rc_chans *rc; 566 register struct rc_softc *rcb; 567 register u_char *tptr, *eptr; 568 register struct tty *tp; 569 register int chan, icnt, nec, unit; 570 571 if (rc_scheduled_event == 0) 572 return; 573repeat: 574 for (unit = 0; unit < NRC; unit++) { 575 rcb = &rc_softc[unit]; 576 rc = rcb->rcb_baserc; 577 nec = rc->rc_rcb->rcb_addr; 578 for (chan = 0; chan < CD180_NCHAN; rc++, chan++) { 579 tp = rc->rc_tp; 580#ifdef RCDEBUG 581 if (rc->rc_flags & (RC_DORXFER|RC_DOXXFER|RC_MODCHG| 582 RC_WAS_BUFOVFL|RC_WAS_SILOVFL)) 583 printrcflags(rc, "rcevent"); 584#endif 585 if (rc->rc_flags & RC_WAS_BUFOVFL) { 586 disable_intr(); 587 rc->rc_flags &= ~RC_WAS_BUFOVFL; 588 rc_scheduled_event--; 589 enable_intr(); 590 printf("rc%d/%d: interrupt-level buffer overflow\n", 591 unit, chan); 592 } 593 if (rc->rc_flags & RC_WAS_SILOVFL) { 594 disable_intr(); 595 rc->rc_flags &= ~RC_WAS_SILOVFL; 596 rc_scheduled_event--; 597 enable_intr(); 598 printf("rc%d/%d: silo overflow\n", 599 unit, chan); 600 } 601 if (rc->rc_flags & RC_MODCHG) { 602 disable_intr(); 603 rc->rc_flags &= ~RC_MODCHG; 604 rc_scheduled_event -= LOTS_OF_EVENTS; 605 enable_intr(); 606 (*linesw[tp->t_line].l_modem)(tp, !!(rc->rc_msvr & MSVR_CD)); 607 } 608 if (rc->rc_flags & RC_DORXFER) { 609 disable_intr(); 610 rc->rc_flags &= ~RC_DORXFER; 611 eptr = rc->rc_iptr; 612 if (rc->rc_bufend == &rc->rc_ibuf[2 * RC_IBUFSIZE]) 613 tptr = &rc->rc_ibuf[RC_IBUFSIZE]; 614 else 615 tptr = rc->rc_ibuf; 616 icnt = eptr - tptr; 617 if (icnt > 0) { 618 if (rc->rc_bufend == &rc->rc_ibuf[2 * RC_IBUFSIZE]) { 619 rc->rc_iptr = rc->rc_ibuf; 620 rc->rc_bufend = &rc->rc_ibuf[RC_IBUFSIZE]; 621 rc->rc_hiwat = &rc->rc_ibuf[RC_IHIGHWATER]; 622 } else { 623 rc->rc_iptr = &rc->rc_ibuf[RC_IBUFSIZE]; 624 rc->rc_bufend = &rc->rc_ibuf[2 * RC_IBUFSIZE]; 625 rc->rc_hiwat = 626 &rc->rc_ibuf[RC_IBUFSIZE + RC_IHIGHWATER]; 627 } 628 if ( (rc->rc_flags & RC_RTSFLOW) 629 && (tp->t_state & TS_ISOPEN) 630 && !(tp->t_state & TS_TBLOCK) 631 && !(rc->rc_msvr & MSVR_RTS) 632 ) { 633 rcout(CD180_CAR, chan); 634 rcout(CD180_MSVR, 635 rc->rc_msvr |= MSVR_RTS); 636 } 637 rc_scheduled_event -= icnt; 638 } 639 enable_intr(); 640 641 if (icnt <= 0 || !(tp->t_state & TS_ISOPEN)) 642 goto done1; 643 644 if ( (tp->t_state & TS_CAN_BYPASS_L_RINT) 645 && !(tp->t_state & TS_LOCAL)) { 646 if ((tp->t_rawq.c_cc + icnt) >= RB_I_HIGH_WATER 647 && ((rc->rc_flags & RC_RTSFLOW) || (tp->t_iflag & IXOFF)) 648 && !(tp->t_state & TS_TBLOCK)) 649 ttyblock(tp); 650 tk_nin += icnt; 651 tk_rawcc += icnt; 652 tp->t_rawcc += icnt; 653 if (b_to_q(tptr, icnt, &tp->t_rawq)) 654 printf("rc%d/%d: tty-level buffer overflow\n", 655 unit, chan); 656 ttwakeup(tp); 657 if ((tp->t_state & TS_TTSTOP) && ((tp->t_iflag & IXANY) 658 || (tp->t_cc[VSTART] == tp->t_cc[VSTOP]))) { 659 tp->t_state &= ~TS_TTSTOP; 660 tp->t_lflag &= ~FLUSHO; 661 rc_start(tp); 662 } 663 } else { 664 for (; tptr < eptr; tptr++) 665 (*linesw[tp->t_line].l_rint) 666 (tptr[0] | 667 rc_rcsrt[tptr[INPUT_FLAGS_SHIFT] & 0xF], tp); 668 } 669done1: 670 } 671 if (rc->rc_flags & RC_DOXXFER) { 672 disable_intr(); 673 rc_scheduled_event -= LOTS_OF_EVENTS; 674 rc->rc_flags &= ~RC_DOXXFER; 675 rc->rc_tp->t_state &= ~TS_BUSY; 676 enable_intr(); 677 (*linesw[tp->t_line].l_start)(tp); 678 } 679 } 680 if (rc_scheduled_event == 0) 681 break; 682 } 683 if (rc_scheduled_event >= LOTS_OF_EVENTS) 684 goto repeat; 685} 686 687static void 688rcstop(tp, rw) 689 register struct tty *tp; 690 int rw; 691{ 692 register struct rc_chans *rc = &rc_chans[GET_UNIT(tp->t_dev)]; 693 u_char *tptr, *eptr; 694 695#ifdef RCDEBUG 696 printf("rc%d/%d: rcstop %s%s\n", rc->rc_rcb->rcb_unit, rc->rc_chan, 697 (rw & FWRITE)?"FWRITE ":"", (rw & FREAD)?"FREAD":""); 698#endif 699 if (rw & FWRITE) 700 rc_discard_output(rc); 701 disable_intr(); 702 if (rw & FREAD) { 703 rc->rc_flags &= ~RC_DORXFER; 704 eptr = rc->rc_iptr; 705 if (rc->rc_bufend == &rc->rc_ibuf[2 * RC_IBUFSIZE]) { 706 tptr = &rc->rc_ibuf[RC_IBUFSIZE]; 707 rc->rc_iptr = &rc->rc_ibuf[RC_IBUFSIZE]; 708 } else { 709 tptr = rc->rc_ibuf; 710 rc->rc_iptr = rc->rc_ibuf; 711 } 712 rc_scheduled_event -= eptr - tptr; 713 } 714 if (tp->t_state & TS_TTSTOP) 715 rc->rc_flags |= RC_OSUSP; 716 else 717 rc->rc_flags &= ~RC_OSUSP; 718 enable_intr(); 719} 720 721static int 722rcopen(dev, flag, mode, p) 723 dev_t dev; 724 int flag, mode; 725 struct proc *p; 726{ 727 register struct rc_chans *rc; 728 register struct tty *tp; 729 int unit, nec, s, error = 0; 730 731 unit = GET_UNIT(dev); 732 if (unit >= NRC * CD180_NCHAN) 733 return ENXIO; 734 if (rc_softc[unit / CD180_NCHAN].rcb_probed != RC_ATTACHED) 735 return ENXIO; 736 rc = &rc_chans[unit]; 737 tp = rc->rc_tp; 738 nec = rc->rc_rcb->rcb_addr; 739#ifdef RCDEBUG 740 printf("rc%d/%d: rcopen: dev %x\n", rc->rc_rcb->rcb_unit, unit, dev); 741#endif 742 s = spltty(); 743 744again: 745 while (rc->rc_flags & RC_DTR_OFF) { 746 error = tsleep(&(rc->rc_dtrwait), TTIPRI | PCATCH, "rcdtr", 0); 747 if (error != 0) 748 goto out; 749 } 750 if (tp->t_state & TS_ISOPEN) { 751 if (CALLOUT(dev)) { 752 if (!(rc->rc_flags & RC_ACTOUT)) { 753 error = EBUSY; 754 goto out; 755 } 756 } else { 757 if (rc->rc_flags & RC_ACTOUT) { 758 if (flag & O_NONBLOCK) { 759 error = EBUSY; 760 goto out; 761 } 762 if (error = tsleep(&rc->rc_rcb, 763 TTIPRI|PCATCH, "rcbi", 0)) 764 goto out; 765 goto again; 766 } 767 } 768 if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) { 769 error = EBUSY; 770 goto out; 771 } 772 } else { 773 tp->t_oproc = rc_start; 774 tp->t_param = rc_param; 775 tp->t_dev = dev; 776 777 if (CALLOUT(dev)) 778 tp->t_cflag |= CLOCAL; 779 else 780 tp->t_cflag &= ~CLOCAL; 781 782 error = rc_param(tp, &tp->t_termios); 783 if (error) 784 goto out; 785 (void) rc_modctl(rc, TIOCM_RTS|TIOCM_DTR, DMSET); 786 787 ttsetwater(tp); 788 789 if ((rc->rc_msvr & MSVR_CD) || CALLOUT(dev)) 790 (*linesw[tp->t_line].l_modem)(tp, 1); 791 } 792 if (!(tp->t_state & TS_CARR_ON) && !CALLOUT(dev) 793 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) { 794 rc->rc_dcdwaits++; 795 error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "rcdcd", 0); 796 rc->rc_dcdwaits--; 797 if (error != 0) 798 goto out; 799 goto again; 800 } 801 error = (*linesw[tp->t_line].l_open)(dev, tp); 802 disc_optim(tp, &tp->t_termios, rc); 803 if ((tp->t_state & TS_ISOPEN) && CALLOUT(dev)) 804 rc->rc_flags |= RC_ACTOUT; 805out: 806 (void) splx(s); 807 808 if(rc->rc_dcdwaits == 0 && !(tp->t_state & TS_ISOPEN)) 809 rc_hardclose(rc); 810 811 return error; 812} 813 814static int 815rcclose(dev, flag, mode, p) 816 dev_t dev; 817 int flag, mode; 818 struct proc *p; 819{ 820 register struct rc_chans *rc; 821 register struct tty *tp; 822 int s, unit = GET_UNIT(dev); 823 824 if (unit >= NRC * CD180_NCHAN) 825 return ENXIO; 826 rc = &rc_chans[unit]; 827 tp = rc->rc_tp; 828#ifdef RCDEBUG 829 printf("rc%d/%d: rcclose dev %x\n", rc->rc_rcb->rcb_unit, unit, dev); 830#endif 831 s = spltty(); 832 (*linesw[tp->t_line].l_close)(tp, flag); 833 disc_optim(tp, &tp->t_termios, rc); 834 rcstop(tp, FREAD | FWRITE); 835 rc_hardclose(rc); 836 ttyclose(tp); 837 splx(s); 838 return 0; 839} 840 841static void rc_hardclose(rc) 842register struct rc_chans *rc; 843{ 844 register int s, nec = rc->rc_rcb->rcb_addr; 845 register struct tty *tp = rc->rc_tp; 846 847 s = spltty(); 848 rcout(CD180_CAR, rc->rc_chan); 849 850 /* Disable rx/tx intrs */ 851 rcout(CD180_IER, rc->rc_ier = 0); 852 if ( (tp->t_cflag & HUPCL) 853 || !(rc->rc_flags & RC_ACTOUT) 854 && !(rc->rc_msvr & MSVR_CD) 855 && !(tp->t_cflag & CLOCAL) 856 || !(tp->t_state & TS_ISOPEN) 857 ) { 858 CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, CCR_ResetChan); 859 WAITFORCCR(rc->rc_rcb->rcb_unit, rc->rc_chan); 860 (void) rc_modctl(rc, TIOCM_RTS, DMSET); 861 if (rc->rc_dtrwait) { 862 timeout(rc_dtrwakeup, rc, rc->rc_dtrwait); 863 rc->rc_flags |= RC_DTR_OFF; 864 } 865 } 866 rc->rc_flags &= ~RC_ACTOUT; 867 wakeup((caddr_t) &rc->rc_rcb); /* wake bi */ 868 wakeup(TSA_CARR_ON(tp)); 869 (void) splx(s); 870} 871 872/* Read from line */ 873static int 874rcread(dev, uio, flag) 875 dev_t dev; 876 struct uio *uio; 877 int flag; 878{ 879 struct tty *tp = rc_chans[GET_UNIT(dev)].rc_tp; 880 881 return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); 882} 883 884/* Write to line */ 885static int 886rcwrite(dev, uio, flag) 887 dev_t dev; 888 struct uio *uio; 889 int flag; 890{ 891 struct tty *tp = rc_chans[GET_UNIT(dev)].rc_tp; 892 893 return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); 894} 895 896/* Reset the bastard */ 897static void rc_hwreset(unit, nec, chipid) 898 register int unit, nec; 899 unsigned int chipid; 900{ 901 CCRCMD(unit, -1, CCR_HWRESET); /* Hardware reset */ 902 DELAY(20000); 903 WAITFORCCR(unit, -1); 904 905 rcout(RC_CTOUT, 0); /* Clear timeout */ 906 rcout(CD180_GIVR, chipid); 907 rcout(CD180_GICR, 0); 908 909 /* Set Prescaler Registers (1 msec) */ 910 rcout(CD180_PPRL, ((RC_OSCFREQ + 999) / 1000) & 0xFF); 911 rcout(CD180_PPRH, ((RC_OSCFREQ + 999) / 1000) >> 8); 912 913 /* Initialize Priority Interrupt Level Registers */ 914 rcout(CD180_PILR1, RC_PILR_MODEM); 915 rcout(CD180_PILR2, RC_PILR_TX); 916 rcout(CD180_PILR3, RC_PILR_RX); 917 918 /* Reset DTR */ 919 rcout(RC_DTREG, ~0); 920} 921 922/* Set channel parameters */ 923static int rc_param(tp, ts) 924 register struct tty *tp; 925 struct termios *ts; 926{ 927 register struct rc_chans *rc = &rc_chans[GET_UNIT(tp->t_dev)]; 928 register int nec = rc->rc_rcb->rcb_addr; 929 int idivs, odivs, s, val, cflag, iflag, lflag, inpflow; 930 931 if ( ts->c_ospeed < 0 || ts->c_ospeed > 76800 932 || ts->c_ispeed < 0 || ts->c_ispeed > 76800 933 ) 934 return (EINVAL); 935 if (ts->c_ispeed == 0) 936 ts->c_ispeed = ts->c_ospeed; 937 odivs = RC_BRD(ts->c_ospeed); 938 idivs = RC_BRD(ts->c_ispeed); 939 940 s = spltty(); 941 942 /* Select channel */ 943 rcout(CD180_CAR, rc->rc_chan); 944 945 /* If speed == 0, hangup line */ 946 if (ts->c_ospeed == 0) { 947 CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, CCR_ResetChan); 948 WAITFORCCR(rc->rc_rcb->rcb_unit, rc->rc_chan); 949 (void) rc_modctl(rc, TIOCM_DTR, DMBIC); 950 } 951 952 tp->t_state &= ~TS_CAN_BYPASS_L_RINT; 953 cflag = ts->c_cflag; 954 iflag = ts->c_iflag; 955 lflag = ts->c_lflag; 956 957 if (idivs > 0) { 958 rcout(CD180_RBPRL, idivs & 0xFF); 959 rcout(CD180_RBPRH, idivs >> 8); 960 } 961 if (odivs > 0) { 962 rcout(CD180_TBPRL, odivs & 0xFF); 963 rcout(CD180_TBPRH, odivs >> 8); 964 } 965 966 /* set timeout value */ 967 if (ts->c_ispeed > 0) { 968 int itm = ts->c_ispeed > 2400 ? 5 : 10000 / ts->c_ispeed + 1; 969 970 if ( !(lflag & ICANON) 971 && ts->c_cc[VMIN] != 0 && ts->c_cc[VTIME] != 0 972 && ts->c_cc[VTIME] * 10 > itm) 973 itm = ts->c_cc[VTIME] * 10; 974 975 rcout(CD180_RTPR, itm <= 255 ? itm : 255); 976 } 977 978 switch (cflag & CSIZE) { 979 case CS5: val = COR1_5BITS; break; 980 case CS6: val = COR1_6BITS; break; 981 case CS7: val = COR1_7BITS; break; 982 default: 983 case CS8: val = COR1_8BITS; break; 984 } 985 if (cflag & PARENB) { 986 val |= COR1_NORMPAR; 987 if (cflag & PARODD) 988 val |= COR1_ODDP; 989 if (!(cflag & INPCK)) 990 val |= COR1_Ignore; 991 } else 992 val |= COR1_Ignore; 993 if (cflag & CSTOPB) 994 val |= COR1_2SB; 995 rcout(CD180_COR1, val); 996 997 /* Set FIFO threshold */ 998 val = ts->c_ospeed <= 4800 ? 1 : CD180_NFIFO / 2; 999 inpflow = 0; 1000 if ( (iflag & IXOFF) 1001 && ( ts->c_cc[VSTOP] != _POSIX_VDISABLE 1002 && ( ts->c_cc[VSTART] != _POSIX_VDISABLE 1003 || (iflag & IXANY) 1004 ) 1005 ) 1006 ) { 1007 inpflow = 1; 1008 val |= COR3_SCDE|COR3_FCT; 1009 } 1010 rcout(CD180_COR3, val); 1011 1012 /* Initialize on-chip automatic flow control */ 1013 val = 0; 1014 rc->rc_flags &= ~(RC_CTSFLOW|RC_SEND_RDY); 1015 if (cflag & CCTS_OFLOW) { 1016 rc->rc_flags |= RC_CTSFLOW; 1017 val |= COR2_CtsAE; 1018 } else 1019 rc->rc_flags |= RC_SEND_RDY; 1020 if (tp->t_state & TS_TTSTOP) 1021 rc->rc_flags |= RC_OSUSP; 1022 else 1023 rc->rc_flags &= ~RC_OSUSP; 1024 if (cflag & CRTS_IFLOW) 1025 rc->rc_flags |= RC_RTSFLOW; 1026 else 1027 rc->rc_flags &= ~RC_RTSFLOW; 1028 1029 if (inpflow) { 1030 if (ts->c_cc[VSTART] != _POSIX_VDISABLE) 1031 rcout(CD180_SCHR1, ts->c_cc[VSTART]); 1032 rcout(CD180_SCHR2, ts->c_cc[VSTOP]); 1033 val |= COR2_TxIBE; 1034 if (iflag & IXANY) 1035 val |= COR2_IXM; 1036 } 1037 1038 rcout(CD180_COR2, rc->rc_cor2 = val); 1039 1040 CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, 1041 CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); 1042 1043 disc_optim(tp, ts, rc); 1044 1045 /* modem ctl */ 1046 val = cflag & CLOCAL ? 0 : MCOR1_CDzd; 1047 if (cflag & CCTS_OFLOW) 1048 val |= MCOR1_CTSzd; 1049 rcout(CD180_MCOR1, val); 1050 1051 val = cflag & CLOCAL ? 0 : MCOR2_CDod; 1052 if (cflag & CCTS_OFLOW) 1053 val |= MCOR2_CTSod; 1054 rcout(CD180_MCOR2, val); 1055 1056 /* enable i/o and interrupts */ 1057 CCRCMD(rc->rc_rcb->rcb_unit, rc->rc_chan, 1058 CCR_XMTREN | ((cflag & CREAD) ? CCR_RCVREN : CCR_RCVRDIS)); 1059 WAITFORCCR(rc->rc_rcb->rcb_unit, rc->rc_chan); 1060 1061 rc->rc_ier = cflag & CLOCAL ? 0 : IER_CD; 1062 if (cflag & CCTS_OFLOW) 1063 rc->rc_ier |= IER_CTS; 1064 if (cflag & CREAD) 1065 rc->rc_ier |= IER_RxData; 1066 if (tp->t_state & TS_BUSY) 1067 rc->rc_ier |= IER_TxRdy; 1068 if (ts->c_ospeed != 0) 1069 rc_modctl(rc, TIOCM_DTR, DMBIS); 1070 if ((cflag & CCTS_OFLOW) && (rc->rc_msvr & MSVR_CTS)) 1071 rc->rc_flags |= RC_SEND_RDY; 1072 rcout(CD180_IER, rc->rc_ier); 1073 (void) splx(s); 1074 return 0; 1075} 1076 1077/* Re-initialize board after bogus interrupts */ 1078static void rc_reinit(rcb) 1079struct rc_softc *rcb; 1080{ 1081 register struct rc_chans *rc, *rce; 1082 register int nec; 1083 1084 nec = rcb->rcb_addr; 1085 rc_hwreset(rcb->rcb_unit, nec, RC_FAKEID); 1086 rc = &rc_chans[rcb->rcb_unit * CD180_NCHAN]; 1087 rce = rc + CD180_NCHAN; 1088 for (; rc < rce; rc++) 1089 (void) rc_param(rc->rc_tp, &rc->rc_tp->t_termios); 1090} 1091 1092static int 1093rcioctl(dev, cmd, data, flag, p) 1094dev_t dev; 1095int cmd, flag; 1096caddr_t data; 1097struct proc *p; 1098{ 1099 register struct rc_chans *rc = &rc_chans[GET_UNIT(dev)]; 1100 register int s, error; 1101 struct tty *tp = rc->rc_tp; 1102 1103 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); 1104 if (error >= 0) 1105 return (error); 1106 error = ttioctl(tp, cmd, data, flag); 1107 disc_optim(tp, &tp->t_termios, rc); 1108 if (error >= 0) 1109 return (error); 1110 s = spltty(); 1111 1112 switch (cmd) { 1113 case TIOCSBRK: 1114 rc->rc_pendcmd = CD180_C_SBRK; 1115 break; 1116 1117 case TIOCCBRK: 1118 rc->rc_pendcmd = CD180_C_EBRK; 1119 break; 1120 1121 case TIOCSDTR: 1122 (void) rc_modctl(rc, TIOCM_DTR, DMBIS); 1123 break; 1124 1125 case TIOCCDTR: 1126 (void) rc_modctl(rc, TIOCM_DTR, DMBIC); 1127 break; 1128 1129 case TIOCMGET: 1130 *(int *) data = rc_modctl(rc, 0, DMGET); 1131 break; 1132 1133 case TIOCMSET: 1134 (void) rc_modctl(rc, *(int *) data, DMSET); 1135 break; 1136 1137 case TIOCMBIC: 1138 (void) rc_modctl(rc, *(int *) data, DMBIC); 1139 break; 1140 1141 case TIOCMBIS: 1142 (void) rc_modctl(rc, *(int *) data, DMBIS); 1143 break; 1144 1145 case TIOCMSDTRWAIT: 1146 error = suser(p->p_ucred, &p->p_acflag); 1147 if (error != 0) { 1148 splx(s); 1149 return (error); 1150 } 1151 rc->rc_dtrwait = *(int *)data * hz / 100; 1152 break; 1153 1154 case TIOCMGDTRWAIT: 1155 *(int *)data = rc->rc_dtrwait * 100 / hz; 1156 break; 1157 1158 default: 1159 (void) splx(s); 1160 return ENOTTY; 1161 } 1162 (void) splx(s); 1163 return 0; 1164} 1165 1166 1167/* Modem control routines */ 1168 1169static int rc_modctl(rc, bits, cmd) 1170register struct rc_chans *rc; 1171int bits, cmd; 1172{ 1173 register int nec = rc->rc_rcb->rcb_addr; 1174 u_char *dtr = &rc->rc_rcb->rcb_dtr, msvr; 1175 1176 rcout(CD180_CAR, rc->rc_chan); 1177 1178 switch (cmd) { 1179 case DMSET: 1180 rcout(RC_DTREG, (bits & TIOCM_DTR) ? 1181 ~(*dtr |= 1 << rc->rc_chan) : 1182 ~(*dtr &= ~(1 << rc->rc_chan))); 1183 msvr = rcin(CD180_MSVR); 1184 if (bits & TIOCM_RTS) 1185 msvr |= MSVR_RTS; 1186 else 1187 msvr &= ~MSVR_RTS; 1188 if (bits & TIOCM_DTR) 1189 msvr |= MSVR_DTR; 1190 else 1191 msvr &= ~MSVR_DTR; 1192 rcout(CD180_MSVR, msvr); 1193 break; 1194 1195 case DMBIS: 1196 if (bits & TIOCM_DTR) 1197 rcout(RC_DTREG, ~(*dtr |= 1 << rc->rc_chan)); 1198 msvr = rcin(CD180_MSVR); 1199 if (bits & TIOCM_RTS) 1200 msvr |= MSVR_RTS; 1201 if (bits & TIOCM_DTR) 1202 msvr |= MSVR_DTR; 1203 rcout(CD180_MSVR, msvr); 1204 break; 1205 1206 case DMGET: 1207 bits = TIOCM_LE; 1208 msvr = rc->rc_msvr = rcin(CD180_MSVR); 1209 1210 if (msvr & MSVR_RTS) 1211 bits |= TIOCM_RTS; 1212 if (msvr & MSVR_CTS) 1213 bits |= TIOCM_CTS; 1214 if (msvr & MSVR_DSR) 1215 bits |= TIOCM_DSR; 1216 if (msvr & MSVR_DTR) 1217 bits |= TIOCM_DTR; 1218 if (msvr & MSVR_CD) 1219 bits |= TIOCM_CD; 1220 if (~rcin(RC_RIREG) & (1 << rc->rc_chan)) 1221 bits |= TIOCM_RI; 1222 return bits; 1223 1224 case DMBIC: 1225 if (bits & TIOCM_DTR) 1226 rcout(RC_DTREG, ~(*dtr &= ~(1 << rc->rc_chan))); 1227 msvr = rcin(CD180_MSVR); 1228 if (bits & TIOCM_RTS) 1229 msvr &= ~MSVR_RTS; 1230 if (bits & TIOCM_DTR) 1231 msvr &= ~MSVR_DTR; 1232 rcout(CD180_MSVR, msvr); 1233 break; 1234 } 1235 rc->rc_msvr = rcin(CD180_MSVR); 1236 return 0; 1237} 1238 1239/* Test the board. */ 1240int rc_test(nec, unit) 1241 register int nec; 1242 int unit; 1243{ 1244 int chan = 0; 1245 int i = 0, rcnt, old_level; 1246 unsigned int iack, chipid; 1247 unsigned short divs; 1248 static u_char ctest[] = "\377\125\252\045\244\0\377"; 1249#define CTLEN 8 1250#define ERR(s) { \ 1251 printf("rc%d: ", unit); printf s ; printf("\n"); \ 1252 (void) splx(old_level); return 1; } 1253 1254 struct rtest { 1255 u_char txbuf[CD180_NFIFO]; /* TX buffer */ 1256 u_char rxbuf[CD180_NFIFO]; /* RX buffer */ 1257 int rxptr; /* RX pointer */ 1258 int txptr; /* TX pointer */ 1259 } tchans[CD180_NCHAN]; 1260 1261 old_level = spltty(); 1262 1263 chipid = RC_FAKEID; 1264 1265 /* First, reset board to inital state */ 1266 rc_hwreset(unit, nec, chipid); 1267 1268 divs = RC_BRD(19200); 1269 1270 /* Initialize channels */ 1271 for (chan = 0; chan < CD180_NCHAN; chan++) { 1272 1273 /* Select and reset channel */ 1274 rcout(CD180_CAR, chan); 1275 CCRCMD(unit, chan, CCR_ResetChan); 1276 WAITFORCCR(unit, chan); 1277 1278 /* Set speed */ 1279 rcout(CD180_RBPRL, divs & 0xFF); 1280 rcout(CD180_RBPRH, divs >> 8); 1281 rcout(CD180_TBPRL, divs & 0xFF); 1282 rcout(CD180_TBPRH, divs >> 8); 1283 1284 /* set timeout value */ 1285 rcout(CD180_RTPR, 0); 1286 1287 /* Establish local loopback */ 1288 rcout(CD180_COR1, COR1_NOPAR | COR1_8BITS | COR1_1SB); 1289 rcout(CD180_COR2, COR2_LLM); 1290 rcout(CD180_COR3, CD180_NFIFO); 1291 CCRCMD(unit, chan, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); 1292 CCRCMD(unit, chan, CCR_RCVREN | CCR_XMTREN); 1293 WAITFORCCR(unit, chan); 1294 rcout(CD180_MSVR, MSVR_RTS); 1295 1296 /* Fill TXBUF with test data */ 1297 for (i = 0; i < CD180_NFIFO; i++) { 1298 tchans[chan].txbuf[i] = ctest[i]; 1299 tchans[chan].rxbuf[i] = 0; 1300 } 1301 tchans[chan].txptr = tchans[chan].rxptr = 0; 1302 1303 /* Now, start transmit */ 1304 rcout(CD180_IER, IER_TxMpty|IER_RxData); 1305 } 1306 /* Pseudo-interrupt poll stuff */ 1307 for (rcnt = 10000; rcnt-- > 0; rcnt--) { 1308 i = ~(rcin(RC_BSR)); 1309 if (i & RC_BSR_TOUT) 1310 ERR(("BSR timeout bit set\n")) 1311 else if (i & RC_BSR_TXINT) { 1312 iack = rcin(RC_PILR_TX); 1313 if (iack != (GIVR_IT_TDI | chipid)) 1314 ERR(("Bad TX intr ack (%02x != %02x)\n", 1315 iack, GIVR_IT_TDI | chipid)); 1316 chan = (rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH; 1317 /* If no more data to transmit, disable TX intr */ 1318 if (tchans[chan].txptr >= CD180_NFIFO) { 1319 iack = rcin(CD180_IER); 1320 rcout(CD180_IER, iack & ~IER_TxMpty); 1321 } else { 1322 for (iack = tchans[chan].txptr; 1323 iack < CD180_NFIFO; iack++) 1324 rcout(CD180_TDR, 1325 tchans[chan].txbuf[iack]); 1326 tchans[chan].txptr = iack; 1327 } 1328 rcout(CD180_EOIR, 0); 1329 } else if (i & RC_BSR_RXINT) { 1330 u_char ucnt; 1331 1332 iack = rcin(RC_PILR_RX); 1333 if (iack != (GIVR_IT_RGDI | chipid) && 1334 iack != (GIVR_IT_REI | chipid)) 1335 ERR(("Bad RX intr ack (%02x != %02x)\n", 1336 iack, GIVR_IT_RGDI | chipid)) 1337 chan = (rcin(CD180_GICR) & GICR_CHAN) >> GICR_LSH; 1338 ucnt = rcin(CD180_RDCR) & 0xF; 1339 while (ucnt-- > 0) { 1340 iack = rcin(CD180_RCSR); 1341 if (iack & RCSR_Timeout) 1342 break; 1343 if (iack & 0xF) 1344 ERR(("Bad char chan %d (RCSR = %02X)\n", 1345 chan, iack)) 1346 if (tchans[chan].rxptr > CD180_NFIFO) 1347 ERR(("Got extra chars chan %d\n", 1348 chan)) 1349 tchans[chan].rxbuf[tchans[chan].rxptr++] = 1350 rcin(CD180_RDR); 1351 } 1352 rcout(CD180_EOIR, 0); 1353 } 1354 rcout(RC_CTOUT, 0); 1355 for (iack = chan = 0; chan < CD180_NCHAN; chan++) 1356 if (tchans[chan].rxptr >= CD180_NFIFO) 1357 iack++; 1358 if (iack == CD180_NCHAN) 1359 break; 1360 } 1361 for (chan = 0; chan < CD180_NCHAN; chan++) { 1362 /* Select and reset channel */ 1363 rcout(CD180_CAR, chan); 1364 CCRCMD(unit, chan, CCR_ResetChan); 1365 } 1366 1367 if (!rcnt) 1368 ERR(("looses characters during local loopback\n")) 1369 /* Now, check data */ 1370 for (chan = 0; chan < CD180_NCHAN; chan++) 1371 for (i = 0; i < CD180_NFIFO; i++) 1372 if (ctest[i] != tchans[chan].rxbuf[i]) 1373 ERR(("data mismatch chan %d ptr %d (%d != %d)\n", 1374 chan, i, ctest[i], tchans[chan].rxbuf[i])) 1375 (void) splx(old_level); 1376 return 0; 1377} 1378 1379#ifdef RCDEBUG 1380static void printrcflags(rc, comment) 1381struct rc_chans *rc; 1382char *comment; 1383{ 1384 u_short f = rc->rc_flags; 1385 register int nec = rc->rc_rcb->rcb_addr; 1386 1387 printf("rc%d/%d: %s flags: %s%s%s%s%s%s%s%s%s%s%s%s\n", 1388 rc->rc_rcb->rcb_unit, rc->rc_chan, comment, 1389 (f & RC_DTR_OFF)?"DTR_OFF " :"", 1390 (f & RC_ACTOUT) ?"ACTOUT " :"", 1391 (f & RC_RTSFLOW)?"RTSFLOW " :"", 1392 (f & RC_CTSFLOW)?"CTSFLOW " :"", 1393 (f & RC_DORXFER)?"DORXFER " :"", 1394 (f & RC_DOXXFER)?"DOXXFER " :"", 1395 (f & RC_MODCHG) ?"MODCHG " :"", 1396 (f & RC_OSUSP) ?"OSUSP " :"", 1397 (f & RC_OSBUSY) ?"OSBUSY " :"", 1398 (f & RC_WAS_BUFOVFL) ?"BUFOVFL " :"", 1399 (f & RC_WAS_SILOVFL) ?"SILOVFL " :"", 1400 (f & RC_SEND_RDY) ?"SEND_RDY":""); 1401 1402 rcout(CD180_CAR, rc->rc_chan); 1403 1404 printf("rc%d/%d: msvr %02x ier %02x ccsr %02x\n", 1405 rc->rc_rcb->rcb_unit, rc->rc_chan, 1406 rcin(CD180_MSVR), 1407 rcin(CD180_IER), 1408 rcin(CD180_CCSR)); 1409} 1410#endif /* RCDEBUG */ 1411 1412static struct tty * 1413rcdevtotty(dev) 1414 dev_t dev; 1415{ 1416 int unit; 1417 1418 unit = GET_UNIT(dev); 1419 if (unit >= NRC * CD180_NCHAN) 1420 return NULL; 1421 return (&rc_tty[unit]); 1422} 1423 1424static void 1425rc_dtrwakeup(chan) 1426 void *chan; 1427{ 1428 struct rc_chans *rc; 1429 1430 rc = (struct rc_chans *)chan; 1431 rc->rc_flags &= ~RC_DTR_OFF; 1432 wakeup(&rc->rc_dtrwait); 1433} 1434 1435static void 1436rc_discard_output(rc) 1437 struct rc_chans *rc; 1438{ 1439 disable_intr(); 1440 if (rc->rc_flags & RC_DOXXFER) { 1441 rc_scheduled_event -= LOTS_OF_EVENTS; 1442 rc->rc_flags &= ~RC_DOXXFER; 1443 } 1444 rc->rc_optr = rc->rc_obufend; 1445 rc->rc_tp->t_state &= ~TS_BUSY; 1446 enable_intr(); 1447 ttwwakeup(rc->rc_tp); 1448} 1449 1450static void 1451rc_wakeup(chan) 1452 void *chan; 1453{ 1454 timeout(rc_wakeup, (caddr_t)NULL, 1); 1455 1456 if (rc_scheduled_event != 0) { 1457 int s; 1458 1459 s = splsofttty(); 1460 rcpoll(); 1461 splx(s); 1462 } 1463} 1464 1465static void 1466disc_optim(tp, t, rc) 1467 struct tty *tp; 1468 struct termios *t; 1469 struct rc_chans *rc; 1470{ 1471 1472 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON)) 1473 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) 1474 && (!(t->c_iflag & PARMRK) 1475 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) 1476 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) 1477 && linesw[tp->t_line].l_rint == ttyinput) 1478 tp->t_state |= TS_CAN_BYPASS_L_RINT; 1479 else 1480 tp->t_state &= ~TS_CAN_BYPASS_L_RINT; 1481 if (tp->t_line == SLIPDISC) 1482 rc->rc_hotchar = 0xc0; 1483 else if (tp->t_line == PPPDISC) 1484 rc->rc_hotchar = 0x7e; 1485 else 1486 rc->rc_hotchar = 0; 1487} 1488 1489static void 1490rc_wait0(nec, unit, chan, line) 1491 int nec, unit, chan, line; 1492{ 1493 int rcnt; 1494 1495 for (rcnt = 50; rcnt && rcin(CD180_CCR); rcnt--) 1496 DELAY(30); 1497 if (rcnt == 0) 1498 printf("rc%d/%d: channel command timeout, rc.c line: %d\n", 1499 unit, chan, line); 1500} 1501 1502static rc_devsw_installed = 0; 1503 1504static void rc_drvinit(void *unused) 1505{ 1506 dev_t dev; 1507 1508 if( ! rc_devsw_installed ) { 1509 dev = makedev(CDEV_MAJOR, 0); 1510 cdevsw_add(&dev,&rc_cdevsw, NULL); 1511 rc_devsw_installed = 1; 1512 } 1513} 1514 1515SYSINIT(rcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,rc_drvinit,NULL) 1516 1517 1518#endif /* NRC */ 1519