2 * Cronyx-Sigma adapter driver for FreeBSD.
3 * Supports PPP/HDLC protocol in synchronous mode,
4 * and asyncronous channels with full modem control.
6 * Copyright (C) 1994 Cronyx Ltd.
7 * Author: Serge Vakulenko, <vak@zebub.msk.su>
9 * This software is distributed with NO WARRANTIES, not even the implied
10 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Authors grant any other persons or organisations permission to use
13 * or modify this software as long as this message is kept with the software,
14 * all derivative works or modified versions.
16 * Version 1.9, Wed Oct 4 18:58:15 MSK 1995
25 #include <sys/param.h>
26 #include <sys/systm.h>
27 #include <sys/kernel.h>
28 #include <sys/fcntl.h>
31 #include <sys/socket.h>
36 # include <machine/pio.h>
37 # define RB_GETC(q) getc(q)
41 # include <sys/ttystats.h>
42 # include <machine/inline.h>
43 # define tsleep(tp,pri,msg,x) ((tp)->t_state |= TS_WOPEN,\
44 ttysleep (tp, (caddr_t)&tp->t_rawq, pri, msg, x))
46 #if !defined (__FreeBSD__) || __FreeBSD__ >= 2
48 # define RB_LEN(q) ((q).c_cc)
49 # define RB_GETC(q) getc(&q)
50 #ifndef TSA_CARR_ON /* FreeBSD 2.x before not long after 2.0.5 */
51 # define TSA_CARR_ON(tp) tp
52 # define TSA_OLOWAT(q) ((caddr_t)&(q)->t_out)
56 #include <machine/cronyx.h>
57 #include <i386/isa/cxreg.h>
59 /* XXX imported from if_cx.c. */
60 void cxswitch (cx_chan_t *c, cx_soft_opt_t new);
63 void cxmint (cx_chan_t *c);
64 int cxrinta (cx_chan_t *c);
65 void cxtinta (cx_chan_t *c);
69 # define print(s) printf s
71 # define print(s) {/*void*/}
74 #define DMABUFSZ (6*256) /* buffer size */
75 #define BYTE *(unsigned char*)&
76 #define UNIT(u) (minor(u) & 077)
79 extern cx_board_t cxboard [NCX]; /* adapter state structures */
80 extern cx_chan_t *cxchan [NCX*NCHAN]; /* unit to channel struct pointer */
82 static struct tty cx_tty [NCX*NCHAN]; /* tty data */
84 static d_open_t cxopen;
85 static d_close_t cxclose;
86 static d_ioctl_t cxioctl;
89 /* Don't make this static, since if_cx.c uses it. */
90 struct cdevsw cx_cdevsw = {
98 /* strategy */ nostrategy,
100 /* maj */ CDEV_MAJOR,
107 struct tty *cx_tty [NCX*NCHAN]; /* tty data */
110 static void cxoproc (struct tty *tp);
111 static void cxstop (struct tty *tp, int flag);
112 static int cxparam (struct tty *tp, struct termios *t);
114 int cxopen (dev_t dev, int flag, int mode, struct proc *p)
116 int unit = UNIT (dev);
117 cx_chan_t *c = cxchan[unit];
122 if (unit == UNIT_CTL) {
123 print (("cx: cxopen /dev/cronyx\n"));
126 if (unit >= NCX*NCHAN || !c || c->type==T_NONE)
128 port = c->chip->port;
129 print (("cx%d.%d: cxopen unit=%d\n", c->board->num, c->num, unit));
130 if (c->mode != M_ASYNC)
135 c->ttyp = &cx_tty[unit];
137 c->ttyp = cx_tty[unit] = ttymalloc (cx_tty[unit]);
140 MALLOC (cx_tty[unit], struct tty*, sizeof (struct tty), M_DEVBUF, M_WAITOK);
141 bzero (cx_tty[unit], sizeof (*cx_tty[unit]));
142 c->ttyp = cx_tty[unit];
144 c->ttyp->t_oproc = cxoproc;
145 c->ttyp->t_stop = cxstop;
146 c->ttyp->t_param = cxparam;
148 dev->si_tty = c->ttyp;
151 MALLOC (c->ttydev, struct ttydevice_tmp*,
152 sizeof (struct ttydevice_tmp), M_DEVBUF, M_WAITOK);
153 bzero (c->ttydev, sizeof (*c->ttydev));
154 strcpy (c->ttydev->tty_name, "cx");
155 c->ttydev->tty_unit = unit;
156 c->ttydev->tty_base = unit;
157 c->ttydev->tty_count = 1;
158 c->ttydev->tty_ttys = c->ttyp;
159 tty_attach (c->ttydev);
164 if ((tp->t_state & TS_ISOPEN) && (tp->t_state & TS_XCLUDE) &&
167 if (! (tp->t_state & TS_ISOPEN)) {
169 if (tp->t_ispeed == 0) {
171 tp->t_termios = deftermios;
176 tp->t_cflag = CREAD | CS8 | HUPCL;
177 tp->t_ispeed = c->rxbaud;
178 tp->t_ospeed = c->txbaud;
181 cxparam (tp, &tp->t_termios);
186 if (! (tp->t_state & TS_ISOPEN)) {
188 * Compute optimal receiver buffer length.
189 * The best choice is rxbaud/400.
190 * Make it even, to avoid byte-wide DMA transfers.
191 * --------------------------
192 * Baud rate Buffer length
193 * --------------------------
201 * --------------------------
203 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
206 else if (rbsz > DMABUFSZ)
209 /* Initialize channel, enable receiver. */
210 cx_cmd (port, CCR_INITCH | CCR_ENRX);
211 cx_cmd (port, CCR_INITCH | CCR_ENRX);
213 /* Start receiver. */
214 outw (ARBCNT(port), rbsz);
215 outw (BRBCNT(port), rbsz);
216 outw (ARBSTS(port), BSTS_OWN24);
217 outw (BRBSTS(port), BSTS_OWN24);
219 /* Enable interrupts. */
220 outb (IER(port), IER_RXD | IER_RET | IER_TXD | IER_MDM);
226 (*linesw[tp->t_line].l_modem)(tp, 1);
227 if (! (flag & O_NONBLOCK)) {
228 /* Lock the channel against cxconfig while we are
229 * waiting for carrier. */
231 while (!(tp->t_cflag & CLOCAL) && !(tp->t_state & TS_CARR_ON))
232 if ((error = tsleep (TSA_CARR_ON(tp), TTIPRI | PCATCH,
235 c->sopt.lock = 0; /* Unlock the channel. */
237 print (("cx%d.%d: cxopen done csr=%b\n", c->board->num, c->num,
238 inb(CSR(c->chip->port)), CSRA_BITS));
243 error = (*linesw[tp->t_line].l_open) (dev, tp);
245 error = (*linesw[tp->t_line].l_open) (dev, tp, 0);
250 int cxclose (dev_t dev, int flag, int mode, struct proc *p)
252 int unit = UNIT (dev);
253 cx_chan_t *c = cxchan[unit];
257 if (unit == UNIT_CTL)
260 (*linesw[tp->t_line].l_close) (tp, flag);
263 * Transmitter continues sending the queued data. */
265 outb (CAR(c->chip->port), c->num & 3);
266 outb (IER(c->chip->port), IER_TXD | IER_MDM);
267 cx_cmd (c->chip->port, CCR_DISRX);
269 /* Clear DTR and RTS. */
270 if ((tp->t_cflag & HUPCL) || ! (tp->t_state & TS_ISOPEN)) {
275 /* Stop sending break. */
276 if (c->brk == BRK_SEND) {
278 if (! (tp->t_state & TS_BUSY))
286 int cxioctl (dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
288 int unit = UNIT (dev);
294 struct ifnet *master;
296 if (unit == UNIT_CTL) {
297 /* Process an ioctl request on /dev/cronyx */
298 cx_options_t *o = (cx_options_t*) data;
300 if (o->board >= NCX || o->channel >= NCHAN)
302 c = &cxboard[o->board].chan[o->channel];
303 if (c->type == T_NONE)
310 print (("cx%d.%d: CXIOCSETMODE\n", o->board, o->channel));
311 if (c->type == T_NONE)
313 if (c->type == T_ASYNC && o->mode != M_ASYNC)
315 if (o->mode == M_ASYNC)
322 /* Somebody is waiting for carrier? */
325 /* /dev/ttyXX is already opened by someone? */
326 if (c->mode == M_ASYNC && c->ttyp &&
327 (c->ttyp->t_state & TS_ISOPEN))
329 /* Network interface is up? */
330 if (c->mode != M_ASYNC && (c->ifp->if_flags & IFF_UP))
333 /* Find the master interface. */
334 master = *o->master ? ifunit (o->master) : c->ifp;
337 m = cxchan[master->if_unit];
339 /* Leave the previous master queue. */
340 if (c->master != c->ifp) {
341 cx_chan_t *p = cxchan[c->master->if_unit];
343 for (; p; p=p->slaveq)
345 p->slaveq = c->slaveq;
348 /* Set up new master. */
352 /* Join the new master queue. */
353 if (c->master != c->ifp) {
354 c->slaveq = m->slaveq;
359 c->rxbaud = o->rxbaud;
360 c->txbaud = o->txbaud;
367 case 0: c->board->if0type = o->iftype; break;
368 case 8: c->board->if8type = o->iftype; break;
371 cxswitch (c, o->sopt);
373 outb (IER(c->chip->port), 0);
378 st = (cx_stat_t*) data;
379 st->rintr = c->stat->rintr;
380 st->tintr = c->stat->tintr;
381 st->mintr = c->stat->mintr;
382 st->ibytes = c->stat->ibytes;
383 st->ipkts = c->stat->ipkts;
384 st->ierrs = c->stat->ierrs;
385 st->obytes = c->stat->obytes;
386 st->opkts = c->stat->opkts;
387 st->oerrs = c->stat->oerrs;
391 print (("cx%d.%d: CXIOCGETMODE\n", o->board, o->channel));
394 o->rxbaud = c->rxbaud;
395 o->txbaud = c->txbaud;
403 case 0: o->iftype = c->board->if0type; break;
404 case 8: o->iftype = c->board->if8type; break;
406 if (c->master != c->ifp)
407 snprintf (o->master, sizeof(o->master),
408 "%s%d", c->master->if_name,
422 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag, p);
424 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag);
426 if (error != ENOIOCTL)
428 error = ttioctl (tp, cmd, data, flag);
429 if (error != ENOIOCTL)
437 case TIOCSBRK: /* Start sending line break */
439 if (! (tp->t_state & TS_BUSY))
442 case TIOCCBRK: /* Stop sending line break */
444 if (! (tp->t_state & TS_BUSY))
447 case TIOCSDTR: /* Set DTR */
450 case TIOCCDTR: /* Clear DTR */
453 case TIOCMSET: /* Set DTR/RTS */
454 cx_chan_dtr (c, (*(int*)data & TIOCM_DTR) ? 1 : 0);
455 cx_chan_rts (c, (*(int*)data & TIOCM_RTS) ? 1 : 0);
457 case TIOCMBIS: /* Add DTR/RTS */
458 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 1);
459 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 1);
461 case TIOCMBIC: /* Clear DTR/RTS */
462 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 0);
463 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 0);
465 case TIOCMGET: /* Get modem status */
466 msv = inb (MSVR(c->chip->port));
467 *(int*)data = TIOCM_LE; /* always enabled while open */
468 if (msv & MSV_DSR) *(int*)data |= TIOCM_DSR;
469 if (msv & MSV_CTS) *(int*)data |= TIOCM_CTS;
470 if (msv & MSV_CD) *(int*)data |= TIOCM_CD;
471 if (c->dtr) *(int*)data |= TIOCM_DTR;
472 if (c->rts) *(int*)data |= TIOCM_RTS;
480 * Fill transmitter buffer with data.
483 cxout (cx_chan_t *c, char b)
485 unsigned char *buf, *p, sym;
486 unsigned short port = c->chip->port, len = 0, cnt_port, sts_port;
487 struct tty *tp = c->ttyp;
492 /* Choose the buffer. */
495 cnt_port = ATBCNT(port);
496 sts_port = ATBSTS(port);
499 cnt_port = BTBCNT(port);
500 sts_port = BTBSTS(port);
504 if (inb (sts_port) & BSTS_OWN24) {
505 tp->t_state |= TS_BUSY;
511 *buf++ = 0; /* extended transmit command */
512 *buf++ = 0x81; /* send break */
513 *buf++ = 0; /* extended transmit command */
514 *buf++ = 0x82; /* insert delay */
515 *buf++ = 250; /* 1/4 of second */
516 *buf++ = 0; /* extended transmit command */
517 *buf++ = 0x82; /* insert delay */
518 *buf++ = 250; /* + 1/4 of second */
523 *buf++ = 0; /* extended transmit command */
524 *buf++ = 0x83; /* stop break */
530 if (tp->t_iflag & IXOFF)
531 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
532 sym = RB_GETC (tp->t_out);
533 /* Send XON/XOFF out of band. */
534 if (sym == tp->t_cc[VSTOP]) {
535 outb (STCR(port), STC_SNDSPC|STC_SSPC_2);
538 if (sym == tp->t_cc[VSTART]) {
539 outb (STCR(port), STC_SNDSPC|STC_SSPC_1);
542 /* Duplicate NULLs in ETC mode. */
548 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
549 sym = RB_GETC (tp->t_out);
550 /* Duplicate NULLs in ETC mode. */
559 /* Start transmitter. */
561 outw (cnt_port, len);
562 outb (sts_port, BSTS_INTR | BSTS_OWN24);
563 c->stat->obytes += len;
564 tp->t_state |= TS_BUSY;
565 print (("cx%d.%d: out %d bytes to %c\n",
566 c->board->num, c->num, len, b));
570 void cxoproc (struct tty *tp)
572 int unit = UNIT (tp->t_dev);
573 cx_chan_t *c = cxchan[unit];
574 unsigned short port = c->chip->port;
577 /* Set current channel number */
578 outb (CAR(port), c->num & 3);
580 if (! (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))) {
581 /* Start transmitter. */
582 if (! (inb (CSR(port)) & CSRA_TXEN))
583 cx_cmd (port, CCR_ENTX);
585 /* Determine the buffer order. */
586 if (inb (DMABSTS(port)) & DMABSTS_NTBUF) {
594 #ifndef TS_ASLEEP /* FreeBSD some time after 2.0.5 */
597 if (RB_LEN (tp->t_out) <= tp->t_lowat) {
598 if (tp->t_state & TS_ASLEEP) {
599 tp->t_state &= ~TS_ASLEEP;
600 wakeup(TSA_OLOWAT(tp));
602 selwakeup(&tp->t_wsel);
609 cxparam (struct tty *tp, struct termios *t)
611 int unit = UNIT (tp->t_dev);
612 cx_chan_t *c = cxchan[unit];
613 unsigned short port = c->chip->port;
614 int clock, period, s;
615 cx_cor1_async_t cor1;
617 if (t->c_ospeed == 0) {
618 /* Clear DTR and RTS. */
623 print (("cx%d.%d: cxparam (hangup)\n", c->board->num, c->num));
626 print (("cx%d.%d: cxparam\n", c->board->num, c->num));
628 /* Check requested parameters. */
629 if (t->c_ospeed < 300 || t->c_ospeed > 256*1024)
631 if (t->c_ispeed && (t->c_ispeed < 300 || t->c_ispeed > 256*1024))
635 /* CLOCAL flag set -- wakeup everybody who waits for CD. */
636 /* FreeBSD does this themselves. */
637 if (! (tp->t_cflag & CLOCAL) && (t->c_cflag & CLOCAL))
638 wakeup ((caddr_t) &tp->t_rawq);
640 /* And copy them to tty and channel structures. */
641 c->rxbaud = tp->t_ispeed = t->c_ispeed;
642 c->txbaud = tp->t_ospeed = t->c_ospeed;
643 tp->t_cflag = t->c_cflag;
645 /* Set character length and parity mode. */
647 switch (t->c_cflag & CSIZE) {
649 case CS8: cor1.charlen = 7; break;
650 case CS7: cor1.charlen = 6; break;
651 case CS6: cor1.charlen = 5; break;
652 case CS5: cor1.charlen = 4; break;
654 if (t->c_cflag & PARENB) {
655 cor1.parmode = PARM_NORMAL;
657 cor1.parity = (t->c_cflag & PARODD) ? PAR_ODD : PAR_EVEN;
659 cor1.parmode = PARM_NOPAR;
663 /* Enable/disable hardware CTS. */
664 c->aopt.cor2.ctsae = (t->c_cflag & CRTSCTS) ? 1 : 0;
665 /* Handle DSR as CTS. */
666 c->aopt.cor2.dsrae = (t->c_cflag & CRTSCTS) ? 1 : 0;
667 /* Enable extended transmit command mode.
668 * Unfortunately, there is no other method for sending break. */
669 c->aopt.cor2.etc = 1;
670 /* Enable/disable hardware XON/XOFF. */
671 c->aopt.cor2.ixon = (t->c_iflag & IXON) ? 1 : 0;
672 c->aopt.cor2.ixany = (t->c_iflag & IXANY) ? 1 : 0;
674 /* Set the number of stop bits. */
675 if (t->c_cflag & CSTOPB)
676 c->aopt.cor3.stopb = STOPB_2;
678 c->aopt.cor3.stopb = STOPB_1;
679 /* Disable/enable passing XON/XOFF chars to the host. */
680 c->aopt.cor3.scde = (t->c_iflag & IXON) ? 1 : 0;
681 c->aopt.cor3.flowct = (t->c_iflag & IXON) ? FLOWCC_NOTPASS : FLOWCC_PASS;
683 c->aopt.schr1 = t->c_cc[VSTART]; /* XON */
684 c->aopt.schr2 = t->c_cc[VSTOP]; /* XOFF */
686 /* Set current channel number. */
688 outb (CAR(port), c->num & 3);
690 /* Set up receiver clock values. */
691 cx_clock (c->chip->oscfreq, c->rxbaud, &clock, &period);
692 c->opt.rcor.clk = clock;
693 outb (RCOR(port), BYTE c->opt.rcor);
694 outb (RBPR(port), period);
696 /* Set up transmitter clock values. */
697 cx_clock (c->chip->oscfreq, c->txbaud, &clock, &period);
698 c->opt.tcor.clk = clock;
699 c->opt.tcor.ext1x = 0;
700 outb (TCOR(port), BYTE c->opt.tcor);
701 outb (TBPR(port), period);
703 outb (COR2(port), BYTE c->aopt.cor2);
704 outb (COR3(port), BYTE c->aopt.cor3);
705 outb (SCHR1(port), c->aopt.schr1);
706 outb (SCHR2(port), c->aopt.schr2);
708 if (BYTE c->aopt.cor1 != BYTE cor1) {
709 BYTE c->aopt.cor1 = BYTE cor1;
710 outb (COR1(port), BYTE c->aopt.cor1);
711 /* Any change to COR1 require reinitialization. */
712 /* Unfortunately, it may cause transmitter glitches... */
713 cx_cmd (port, CCR_INITCH);
720 * Stop output on a line
722 void cxstop (struct tty *tp, int flag)
724 cx_chan_t *c = cxchan[UNIT(tp->t_dev)];
725 unsigned short port = c->chip->port;
728 if (tp->t_state & TS_BUSY) {
729 print (("cx%d.%d: cxstop\n", c->board->num, c->num));
731 /* Set current channel number */
732 outb (CAR(port), c->num & 3);
734 /* Stop transmitter */
735 cx_cmd (port, CCR_DISTX);
741 * Handle receive interrupts, including receive errors and
742 * receive timeout interrupt.
744 int cxrinta (cx_chan_t *c)
746 unsigned short port = c->chip->port;
747 unsigned short len = 0, risr = inw (RISR(port)), reoir = 0;
748 struct tty *tp = c->ttyp;
750 /* Compute optimal receiver buffer length. */
751 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
754 else if (rbsz > DMABUFSZ)
757 if (risr & RISA_TIMEOUT) {
758 unsigned long rcbadr = (unsigned short) inw (RCBADRL(port)) |
759 (long) inw (RCBADRU(port)) << 16;
760 unsigned char *buf = 0;
761 unsigned short cnt_port = 0, sts_port = 0;
762 if (rcbadr >= c->brphys && rcbadr < c->brphys+DMABUFSZ) {
764 len = rcbadr - c->brphys;
765 cnt_port = BRBCNT(port);
766 sts_port = BRBSTS(port);
767 } else if (rcbadr >= c->arphys && rcbadr < c->arphys+DMABUFSZ) {
769 len = rcbadr - c->arphys;
770 cnt_port = ARBCNT(port);
771 sts_port = ARBSTS(port);
773 printf ("cx%d.%d: timeout: invalid buffer address\n",
774 c->board->num, c->num);
777 print (("cx%d.%d: async receive timeout (%d bytes), risr=%b, arbsts=%b, brbsts=%b\n",
778 c->board->num, c->num, len, risr, RISA_BITS,
779 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
780 c->stat->ibytes += len;
781 if (tp && (tp->t_state & TS_ISOPEN)) {
783 int (*rint)(int, struct tty *) =
784 linesw[tp->t_line].l_rint;
786 for (i=0; i<len; ++i)
787 (*rint) (buf[i], tp);
790 /* Restart receiver. */
791 outw (cnt_port, rbsz);
792 outb (sts_port, BSTS_OWN24);
794 return (REOI_TERMBUFF);
797 print (("cx%d.%d: async receive interrupt, risr=%b, arbsts=%b, brbsts=%b\n",
798 c->board->num, c->num, risr, RISA_BITS,
799 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
801 if (risr & RIS_BUSERR) {
802 printf ("cx%d.%d: receive bus error\n", c->board->num, c->num);
805 if (risr & (RIS_OVERRUN | RISA_PARERR | RISA_FRERR | RISA_BREAK)) {
808 if (risr & RISA_PARERR)
810 if (risr & RISA_FRERR)
813 if (risr & RIS_OVERRUN)
817 if (risr & RISA_BREAK)
820 print (("cx%d.%d: receive error %x\n", c->board->num, c->num, err));
821 if (tp && (tp->t_state & TS_ISOPEN))
822 (*linesw[tp->t_line].l_rint) (err, tp);
826 /* Discard exception characters. */
827 if ((risr & RISA_SCMASK) && tp && (tp->t_iflag & IXON))
828 reoir |= REOI_DISCEXC;
830 /* Handle received data. */
831 if ((risr & RIS_EOBUF) && tp && (tp->t_state & TS_ISOPEN)) {
832 int (*rint)(int, struct tty *) = linesw[tp->t_line].l_rint;
836 len = (risr & RIS_BB) ? inw(BRBCNT(port)) : inw(ARBCNT(port));
838 print (("cx%d.%d: async: %d bytes received\n",
839 c->board->num, c->num, len));
840 c->stat->ibytes += len;
842 buf = (risr & RIS_BB) ? c->brbuf : c->arbuf;
843 for (i=0; i<len; ++i)
844 (*rint) (buf[i], tp);
847 /* Restart receiver. */
848 if (! (inb (ARBSTS(port)) & BSTS_OWN24)) {
849 outw (ARBCNT(port), rbsz);
850 outb (ARBSTS(port), BSTS_OWN24);
852 if (! (inb (BRBSTS(port)) & BSTS_OWN24)) {
853 outw (BRBCNT(port), rbsz);
854 outb (BRBSTS(port), BSTS_OWN24);
860 * Handle transmit interrupt.
862 void cxtinta (cx_chan_t *c)
864 struct tty *tp = c->ttyp;
865 unsigned short port = c->chip->port;
866 unsigned char tisr = inb (TISR(port));
868 print (("cx%d.%d: async transmit interrupt, tisr=%b, atbsts=%b, btbsts=%b\n",
869 c->board->num, c->num, tisr, TIS_BITS,
870 inb (ATBSTS(port)), BSTS_BITS, inb (BTBSTS(port)), BSTS_BITS));
872 if (tisr & TIS_BUSERR) {
873 printf ("cx%d.%d: transmit bus error\n",
874 c->board->num, c->num);
876 } else if (tisr & TIS_UNDERRUN) {
877 printf ("cx%d.%d: transmit underrun error\n",
878 c->board->num, c->num);
882 tp->t_state &= ~(TS_BUSY | TS_FLUSH);
884 (*linesw[tp->t_line].l_start) (tp);
891 * Handle modem interrupt.
893 void cxmint (cx_chan_t *c)
895 unsigned short port = c->chip->port;
896 unsigned char misr = inb (MISR(port));
897 unsigned char msvr = inb (MSVR(port));
898 struct tty *tp = c->ttyp;
900 if (c->mode != M_ASYNC) {
901 printf ("cx%d.%d: unexpected modem interrupt, misr=%b, msvr=%b\n",
902 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS);
905 print (("cx%d.%d: modem interrupt, misr=%b, msvr=%b\n",
906 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS));
908 /* Ignore DSR events. */
909 /* Ignore RTC/CTS events, handled by hardware. */
910 /* Handle carrier detect/loss. */
911 if (tp && (misr & MIS_CCD))
912 (*linesw[tp->t_line].l_modem) (tp, (msvr & MSV_CD) != 0);
916 * Recover after lost transmit interrupts.
918 void cxtimeout (void *a)
925 for (b=cxboard; b<cxboard+NCX; ++b)
926 for (c=b->chan; c<b->chan+NCHAN; ++c) {
928 if (c->type==T_NONE || c->mode!=M_ASYNC || !tp)
931 if (tp->t_state & TS_BUSY) {
932 tp->t_state &= ~TS_BUSY;
934 (*linesw[tp->t_line].l_start) (tp);
940 timeout (cxtimeout, 0, hz*5);
944 #if defined(__FreeBSD__) && (__FreeBSD__ > 1 )
945 static void cx_drvinit(void *unused)
948 cdevsw_add(&cx_cdevsw);
951 SYSINIT(cxdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,cx_drvinit,NULL)