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
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/kernel.h>
29 #include <sys/fcntl.h>
33 #include <sys/socket.h>
38 # include <machine/pio.h>
39 # define RB_GETC(q) getc(q)
43 # include <sys/ttystats.h>
44 # include <machine/inline.h>
45 # define tsleep(tp,pri,msg,x) ((tp)->t_state |= TS_WOPEN,\
46 ttysleep (tp, (caddr_t)&tp->t_rawq, pri, msg, x))
48 #if !defined (__FreeBSD__) || __FreeBSD__ >= 2
50 # define RB_LEN(q) ((q).c_cc)
51 # define RB_GETC(q) getc(&q)
52 #ifndef TSA_CARR_ON /* FreeBSD 2.x before not long after 2.0.5 */
53 # define TSA_CARR_ON(tp) tp
54 # define TSA_OLOWAT(q) ((caddr_t)&(q)->t_out)
58 #include <machine/cronyx.h>
59 #include <i386/isa/cxreg.h>
61 /* XXX imported from if_cx.c. */
62 void cxswitch (cx_chan_t *c, cx_soft_opt_t new);
65 void cxmint (cx_chan_t *c);
66 int cxrinta (cx_chan_t *c);
67 void cxtinta (cx_chan_t *c);
71 # define print(s) printf s
73 # define print(s) {/*void*/}
76 #define DMABUFSZ (6*256) /* buffer size */
77 #define BYTE *(unsigned char*)&
78 #define UNIT(u) (minor(u) & 077)
81 extern cx_board_t cxboard [NCX]; /* adapter state structures */
82 extern cx_chan_t *cxchan [NCX*NCHAN]; /* unit to channel struct pointer */
84 static struct tty cx_tty [NCX*NCHAN]; /* tty data */
86 static d_open_t cxopen;
87 static d_close_t cxclose;
88 static d_ioctl_t cxioctl;
91 /* Don't make this static, since if_cx.c uses it. */
92 struct cdevsw cx_cdevsw = {
100 /* strategy */ nostrategy,
102 /* maj */ CDEV_MAJOR,
109 struct tty *cx_tty [NCX*NCHAN]; /* tty data */
112 static void cxoproc (struct tty *tp);
113 static void cxstop (struct tty *tp, int flag);
114 static int cxparam (struct tty *tp, struct termios *t);
116 int cxopen (dev_t dev, int flag, int mode, struct proc *p)
118 int unit = UNIT (dev);
119 cx_chan_t *c = cxchan[unit];
124 if (unit == UNIT_CTL) {
125 print (("cx: cxopen /dev/cronyx\n"));
128 if (unit >= NCX*NCHAN || !c || c->type==T_NONE)
130 port = c->chip->port;
131 print (("cx%d.%d: cxopen unit=%d\n", c->board->num, c->num, unit));
132 if (c->mode != M_ASYNC)
137 c->ttyp = &cx_tty[unit];
139 c->ttyp = cx_tty[unit] = ttymalloc (cx_tty[unit]);
142 MALLOC (cx_tty[unit], struct tty*, sizeof (struct tty), M_DEVBUF, M_WAITOK);
143 bzero (cx_tty[unit], sizeof (*cx_tty[unit]));
144 c->ttyp = cx_tty[unit];
146 c->ttyp->t_oproc = cxoproc;
147 c->ttyp->t_stop = cxstop;
148 c->ttyp->t_param = cxparam;
150 dev->si_tty = c->ttyp;
153 MALLOC (c->ttydev, struct ttydevice_tmp*,
154 sizeof (struct ttydevice_tmp), M_DEVBUF, M_WAITOK);
155 bzero (c->ttydev, sizeof (*c->ttydev));
156 strcpy (c->ttydev->tty_name, "cx");
157 c->ttydev->tty_unit = unit;
158 c->ttydev->tty_base = unit;
159 c->ttydev->tty_count = 1;
160 c->ttydev->tty_ttys = c->ttyp;
161 tty_attach (c->ttydev);
166 if ((tp->t_state & TS_ISOPEN) && (tp->t_state & TS_XCLUDE) &&
169 if (! (tp->t_state & TS_ISOPEN)) {
171 if (tp->t_ispeed == 0) {
173 tp->t_termios = deftermios;
178 tp->t_cflag = CREAD | CS8 | HUPCL;
179 tp->t_ispeed = c->rxbaud;
180 tp->t_ospeed = c->txbaud;
183 cxparam (tp, &tp->t_termios);
188 if (! (tp->t_state & TS_ISOPEN)) {
190 * Compute optimal receiver buffer length.
191 * The best choice is rxbaud/400.
192 * Make it even, to avoid byte-wide DMA transfers.
193 * --------------------------
194 * Baud rate Buffer length
195 * --------------------------
203 * --------------------------
205 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
208 else if (rbsz > DMABUFSZ)
211 /* Initialize channel, enable receiver. */
212 cx_cmd (port, CCR_INITCH | CCR_ENRX);
213 cx_cmd (port, CCR_INITCH | CCR_ENRX);
215 /* Start receiver. */
216 outw (ARBCNT(port), rbsz);
217 outw (BRBCNT(port), rbsz);
218 outw (ARBSTS(port), BSTS_OWN24);
219 outw (BRBSTS(port), BSTS_OWN24);
221 /* Enable interrupts. */
222 outb (IER(port), IER_RXD | IER_RET | IER_TXD | IER_MDM);
228 (*linesw[tp->t_line].l_modem)(tp, 1);
229 if (! (flag & O_NONBLOCK)) {
230 /* Lock the channel against cxconfig while we are
231 * waiting for carrier. */
233 while (!(tp->t_cflag & CLOCAL) && !(tp->t_state & TS_CARR_ON))
234 if ((error = tsleep (TSA_CARR_ON(tp), TTIPRI | PCATCH,
237 c->sopt.lock = 0; /* Unlock the channel. */
239 print (("cx%d.%d: cxopen done csr=%b\n", c->board->num, c->num,
240 inb(CSR(c->chip->port)), CSRA_BITS));
245 error = (*linesw[tp->t_line].l_open) (dev, tp);
247 error = (*linesw[tp->t_line].l_open) (dev, tp, 0);
252 int cxclose (dev_t dev, int flag, int mode, struct proc *p)
254 int unit = UNIT (dev);
255 cx_chan_t *c = cxchan[unit];
259 if (unit == UNIT_CTL)
262 (*linesw[tp->t_line].l_close) (tp, flag);
265 * Transmitter continues sending the queued data. */
267 outb (CAR(c->chip->port), c->num & 3);
268 outb (IER(c->chip->port), IER_TXD | IER_MDM);
269 cx_cmd (c->chip->port, CCR_DISRX);
271 /* Clear DTR and RTS. */
272 if ((tp->t_cflag & HUPCL) || ! (tp->t_state & TS_ISOPEN)) {
277 /* Stop sending break. */
278 if (c->brk == BRK_SEND) {
280 if (! (tp->t_state & TS_BUSY))
288 int cxioctl (dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
290 int unit = UNIT (dev);
296 struct ifnet *master;
298 if (unit == UNIT_CTL) {
299 /* Process an ioctl request on /dev/cronyx */
300 cx_options_t *o = (cx_options_t*) data;
302 if (o->board >= NCX || o->channel >= NCHAN)
304 c = &cxboard[o->board].chan[o->channel];
305 if (c->type == T_NONE)
312 print (("cx%d.%d: CXIOCSETMODE\n", o->board, o->channel));
313 if (c->type == T_NONE)
315 if (c->type == T_ASYNC && o->mode != M_ASYNC)
317 if (o->mode == M_ASYNC)
324 /* Somebody is waiting for carrier? */
327 /* /dev/ttyXX is already opened by someone? */
328 if (c->mode == M_ASYNC && c->ttyp &&
329 (c->ttyp->t_state & TS_ISOPEN))
331 /* Network interface is up? */
332 if (c->mode != M_ASYNC && (c->ifp->if_flags & IFF_UP))
335 /* Find the master interface. */
336 master = *o->master ? ifunit (o->master) : c->ifp;
339 m = cxchan[master->if_unit];
341 /* Leave the previous master queue. */
342 if (c->master != c->ifp) {
343 cx_chan_t *p = cxchan[c->master->if_unit];
345 for (; p; p=p->slaveq)
347 p->slaveq = c->slaveq;
350 /* Set up new master. */
354 /* Join the new master queue. */
355 if (c->master != c->ifp) {
356 c->slaveq = m->slaveq;
361 c->rxbaud = o->rxbaud;
362 c->txbaud = o->txbaud;
369 case 0: c->board->if0type = o->iftype; break;
370 case 8: c->board->if8type = o->iftype; break;
373 cxswitch (c, o->sopt);
375 outb (IER(c->chip->port), 0);
380 st = (cx_stat_t*) data;
381 st->rintr = c->stat->rintr;
382 st->tintr = c->stat->tintr;
383 st->mintr = c->stat->mintr;
384 st->ibytes = c->stat->ibytes;
385 st->ipkts = c->stat->ipkts;
386 st->ierrs = c->stat->ierrs;
387 st->obytes = c->stat->obytes;
388 st->opkts = c->stat->opkts;
389 st->oerrs = c->stat->oerrs;
393 print (("cx%d.%d: CXIOCGETMODE\n", o->board, o->channel));
396 o->rxbaud = c->rxbaud;
397 o->txbaud = c->txbaud;
405 case 0: o->iftype = c->board->if0type; break;
406 case 8: o->iftype = c->board->if8type; break;
408 if (c->master != c->ifp)
409 snprintf (o->master, sizeof(o->master),
410 "%s%d", c->master->if_name,
424 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag, p);
426 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag);
428 if (error != ENOIOCTL)
430 error = ttioctl (tp, cmd, data, flag);
431 if (error != ENOIOCTL)
439 case TIOCSBRK: /* Start sending line break */
441 if (! (tp->t_state & TS_BUSY))
444 case TIOCCBRK: /* Stop sending line break */
446 if (! (tp->t_state & TS_BUSY))
449 case TIOCSDTR: /* Set DTR */
452 case TIOCCDTR: /* Clear DTR */
455 case TIOCMSET: /* Set DTR/RTS */
456 cx_chan_dtr (c, (*(int*)data & TIOCM_DTR) ? 1 : 0);
457 cx_chan_rts (c, (*(int*)data & TIOCM_RTS) ? 1 : 0);
459 case TIOCMBIS: /* Add DTR/RTS */
460 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 1);
461 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 1);
463 case TIOCMBIC: /* Clear DTR/RTS */
464 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 0);
465 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 0);
467 case TIOCMGET: /* Get modem status */
468 msv = inb (MSVR(c->chip->port));
469 *(int*)data = TIOCM_LE; /* always enabled while open */
470 if (msv & MSV_DSR) *(int*)data |= TIOCM_DSR;
471 if (msv & MSV_CTS) *(int*)data |= TIOCM_CTS;
472 if (msv & MSV_CD) *(int*)data |= TIOCM_CD;
473 if (c->dtr) *(int*)data |= TIOCM_DTR;
474 if (c->rts) *(int*)data |= TIOCM_RTS;
482 * Fill transmitter buffer with data.
485 cxout (cx_chan_t *c, char b)
487 unsigned char *buf, *p, sym;
488 unsigned short port = c->chip->port, len = 0, cnt_port, sts_port;
489 struct tty *tp = c->ttyp;
494 /* Choose the buffer. */
497 cnt_port = ATBCNT(port);
498 sts_port = ATBSTS(port);
501 cnt_port = BTBCNT(port);
502 sts_port = BTBSTS(port);
506 if (inb (sts_port) & BSTS_OWN24) {
507 tp->t_state |= TS_BUSY;
513 *buf++ = 0; /* extended transmit command */
514 *buf++ = 0x81; /* send break */
515 *buf++ = 0; /* extended transmit command */
516 *buf++ = 0x82; /* insert delay */
517 *buf++ = 250; /* 1/4 of second */
518 *buf++ = 0; /* extended transmit command */
519 *buf++ = 0x82; /* insert delay */
520 *buf++ = 250; /* + 1/4 of second */
525 *buf++ = 0; /* extended transmit command */
526 *buf++ = 0x83; /* stop break */
532 if (tp->t_iflag & IXOFF)
533 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
534 sym = RB_GETC (tp->t_out);
535 /* Send XON/XOFF out of band. */
536 if (sym == tp->t_cc[VSTOP]) {
537 outb (STCR(port), STC_SNDSPC|STC_SSPC_2);
540 if (sym == tp->t_cc[VSTART]) {
541 outb (STCR(port), STC_SNDSPC|STC_SSPC_1);
544 /* Duplicate NULLs in ETC mode. */
550 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
551 sym = RB_GETC (tp->t_out);
552 /* Duplicate NULLs in ETC mode. */
561 /* Start transmitter. */
563 outw (cnt_port, len);
564 outb (sts_port, BSTS_INTR | BSTS_OWN24);
565 c->stat->obytes += len;
566 tp->t_state |= TS_BUSY;
567 print (("cx%d.%d: out %d bytes to %c\n",
568 c->board->num, c->num, len, b));
572 void cxoproc (struct tty *tp)
574 int unit = UNIT (tp->t_dev);
575 cx_chan_t *c = cxchan[unit];
576 unsigned short port = c->chip->port;
579 /* Set current channel number */
580 outb (CAR(port), c->num & 3);
582 if (! (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))) {
583 /* Start transmitter. */
584 if (! (inb (CSR(port)) & CSRA_TXEN))
585 cx_cmd (port, CCR_ENTX);
587 /* Determine the buffer order. */
588 if (inb (DMABSTS(port)) & DMABSTS_NTBUF) {
596 #ifndef TS_ASLEEP /* FreeBSD some time after 2.0.5 */
599 if (RB_LEN (tp->t_out) <= tp->t_lowat) {
600 if (tp->t_state & TS_ASLEEP) {
601 tp->t_state &= ~TS_ASLEEP;
602 wakeup(TSA_OLOWAT(tp));
604 selwakeup(&tp->t_wsel);
611 cxparam (struct tty *tp, struct termios *t)
613 int unit = UNIT (tp->t_dev);
614 cx_chan_t *c = cxchan[unit];
615 unsigned short port = c->chip->port;
616 int clock, period, s;
617 cx_cor1_async_t cor1;
619 if (t->c_ospeed == 0) {
620 /* Clear DTR and RTS. */
625 print (("cx%d.%d: cxparam (hangup)\n", c->board->num, c->num));
628 print (("cx%d.%d: cxparam\n", c->board->num, c->num));
630 /* Check requested parameters. */
631 if (t->c_ospeed < 300 || t->c_ospeed > 256*1024)
633 if (t->c_ispeed && (t->c_ispeed < 300 || t->c_ispeed > 256*1024))
637 /* CLOCAL flag set -- wakeup everybody who waits for CD. */
638 /* FreeBSD does this themselves. */
639 if (! (tp->t_cflag & CLOCAL) && (t->c_cflag & CLOCAL))
640 wakeup ((caddr_t) &tp->t_rawq);
642 /* And copy them to tty and channel structures. */
643 c->rxbaud = tp->t_ispeed = t->c_ispeed;
644 c->txbaud = tp->t_ospeed = t->c_ospeed;
645 tp->t_cflag = t->c_cflag;
647 /* Set character length and parity mode. */
649 switch (t->c_cflag & CSIZE) {
651 case CS8: cor1.charlen = 7; break;
652 case CS7: cor1.charlen = 6; break;
653 case CS6: cor1.charlen = 5; break;
654 case CS5: cor1.charlen = 4; break;
656 if (t->c_cflag & PARENB) {
657 cor1.parmode = PARM_NORMAL;
659 cor1.parity = (t->c_cflag & PARODD) ? PAR_ODD : PAR_EVEN;
661 cor1.parmode = PARM_NOPAR;
665 /* Enable/disable hardware CTS. */
666 c->aopt.cor2.ctsae = (t->c_cflag & CRTSCTS) ? 1 : 0;
667 /* Handle DSR as CTS. */
668 c->aopt.cor2.dsrae = (t->c_cflag & CRTSCTS) ? 1 : 0;
669 /* Enable extended transmit command mode.
670 * Unfortunately, there is no other method for sending break. */
671 c->aopt.cor2.etc = 1;
672 /* Enable/disable hardware XON/XOFF. */
673 c->aopt.cor2.ixon = (t->c_iflag & IXON) ? 1 : 0;
674 c->aopt.cor2.ixany = (t->c_iflag & IXANY) ? 1 : 0;
676 /* Set the number of stop bits. */
677 if (t->c_cflag & CSTOPB)
678 c->aopt.cor3.stopb = STOPB_2;
680 c->aopt.cor3.stopb = STOPB_1;
681 /* Disable/enable passing XON/XOFF chars to the host. */
682 c->aopt.cor3.scde = (t->c_iflag & IXON) ? 1 : 0;
683 c->aopt.cor3.flowct = (t->c_iflag & IXON) ? FLOWCC_NOTPASS : FLOWCC_PASS;
685 c->aopt.schr1 = t->c_cc[VSTART]; /* XON */
686 c->aopt.schr2 = t->c_cc[VSTOP]; /* XOFF */
688 /* Set current channel number. */
690 outb (CAR(port), c->num & 3);
692 /* Set up receiver clock values. */
693 cx_clock (c->chip->oscfreq, c->rxbaud, &clock, &period);
694 c->opt.rcor.clk = clock;
695 outb (RCOR(port), BYTE c->opt.rcor);
696 outb (RBPR(port), period);
698 /* Set up transmitter clock values. */
699 cx_clock (c->chip->oscfreq, c->txbaud, &clock, &period);
700 c->opt.tcor.clk = clock;
701 c->opt.tcor.ext1x = 0;
702 outb (TCOR(port), BYTE c->opt.tcor);
703 outb (TBPR(port), period);
705 outb (COR2(port), BYTE c->aopt.cor2);
706 outb (COR3(port), BYTE c->aopt.cor3);
707 outb (SCHR1(port), c->aopt.schr1);
708 outb (SCHR2(port), c->aopt.schr2);
710 if (BYTE c->aopt.cor1 != BYTE cor1) {
711 BYTE c->aopt.cor1 = BYTE cor1;
712 outb (COR1(port), BYTE c->aopt.cor1);
713 /* Any change to COR1 require reinitialization. */
714 /* Unfortunately, it may cause transmitter glitches... */
715 cx_cmd (port, CCR_INITCH);
722 * Stop output on a line
724 void cxstop (struct tty *tp, int flag)
726 cx_chan_t *c = cxchan[UNIT(tp->t_dev)];
727 unsigned short port = c->chip->port;
730 if (tp->t_state & TS_BUSY) {
731 print (("cx%d.%d: cxstop\n", c->board->num, c->num));
733 /* Set current channel number */
734 outb (CAR(port), c->num & 3);
736 /* Stop transmitter */
737 cx_cmd (port, CCR_DISTX);
743 * Handle receive interrupts, including receive errors and
744 * receive timeout interrupt.
746 int cxrinta (cx_chan_t *c)
748 unsigned short port = c->chip->port;
749 unsigned short len = 0, risr = inw (RISR(port)), reoir = 0;
750 struct tty *tp = c->ttyp;
752 /* Compute optimal receiver buffer length. */
753 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
756 else if (rbsz > DMABUFSZ)
759 if (risr & RISA_TIMEOUT) {
760 unsigned long rcbadr = (unsigned short) inw (RCBADRL(port)) |
761 (long) inw (RCBADRU(port)) << 16;
762 unsigned char *buf = 0;
763 unsigned short cnt_port = 0, sts_port = 0;
764 if (rcbadr >= c->brphys && rcbadr < c->brphys+DMABUFSZ) {
766 len = rcbadr - c->brphys;
767 cnt_port = BRBCNT(port);
768 sts_port = BRBSTS(port);
769 } else if (rcbadr >= c->arphys && rcbadr < c->arphys+DMABUFSZ) {
771 len = rcbadr - c->arphys;
772 cnt_port = ARBCNT(port);
773 sts_port = ARBSTS(port);
775 printf ("cx%d.%d: timeout: invalid buffer address\n",
776 c->board->num, c->num);
779 print (("cx%d.%d: async receive timeout (%d bytes), risr=%b, arbsts=%b, brbsts=%b\n",
780 c->board->num, c->num, len, risr, RISA_BITS,
781 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
782 c->stat->ibytes += len;
783 if (tp && (tp->t_state & TS_ISOPEN)) {
785 int (*rint)(int, struct tty *) =
786 linesw[tp->t_line].l_rint;
788 for (i=0; i<len; ++i)
789 (*rint) (buf[i], tp);
792 /* Restart receiver. */
793 outw (cnt_port, rbsz);
794 outb (sts_port, BSTS_OWN24);
796 return (REOI_TERMBUFF);
799 print (("cx%d.%d: async receive interrupt, risr=%b, arbsts=%b, brbsts=%b\n",
800 c->board->num, c->num, risr, RISA_BITS,
801 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
803 if (risr & RIS_BUSERR) {
804 printf ("cx%d.%d: receive bus error\n", c->board->num, c->num);
807 if (risr & (RIS_OVERRUN | RISA_PARERR | RISA_FRERR | RISA_BREAK)) {
810 if (risr & RISA_PARERR)
812 if (risr & RISA_FRERR)
815 if (risr & RIS_OVERRUN)
819 if (risr & RISA_BREAK)
822 print (("cx%d.%d: receive error %x\n", c->board->num, c->num, err));
823 if (tp && (tp->t_state & TS_ISOPEN))
824 (*linesw[tp->t_line].l_rint) (err, tp);
828 /* Discard exception characters. */
829 if ((risr & RISA_SCMASK) && tp && (tp->t_iflag & IXON))
830 reoir |= REOI_DISCEXC;
832 /* Handle received data. */
833 if ((risr & RIS_EOBUF) && tp && (tp->t_state & TS_ISOPEN)) {
834 int (*rint)(int, struct tty *) = linesw[tp->t_line].l_rint;
838 len = (risr & RIS_BB) ? inw(BRBCNT(port)) : inw(ARBCNT(port));
840 print (("cx%d.%d: async: %d bytes received\n",
841 c->board->num, c->num, len));
842 c->stat->ibytes += len;
844 buf = (risr & RIS_BB) ? c->brbuf : c->arbuf;
845 for (i=0; i<len; ++i)
846 (*rint) (buf[i], tp);
849 /* Restart receiver. */
850 if (! (inb (ARBSTS(port)) & BSTS_OWN24)) {
851 outw (ARBCNT(port), rbsz);
852 outb (ARBSTS(port), BSTS_OWN24);
854 if (! (inb (BRBSTS(port)) & BSTS_OWN24)) {
855 outw (BRBCNT(port), rbsz);
856 outb (BRBSTS(port), BSTS_OWN24);
862 * Handle transmit interrupt.
864 void cxtinta (cx_chan_t *c)
866 struct tty *tp = c->ttyp;
867 unsigned short port = c->chip->port;
868 unsigned char tisr = inb (TISR(port));
870 print (("cx%d.%d: async transmit interrupt, tisr=%b, atbsts=%b, btbsts=%b\n",
871 c->board->num, c->num, tisr, TIS_BITS,
872 inb (ATBSTS(port)), BSTS_BITS, inb (BTBSTS(port)), BSTS_BITS));
874 if (tisr & TIS_BUSERR) {
875 printf ("cx%d.%d: transmit bus error\n",
876 c->board->num, c->num);
878 } else if (tisr & TIS_UNDERRUN) {
879 printf ("cx%d.%d: transmit underrun error\n",
880 c->board->num, c->num);
884 tp->t_state &= ~(TS_BUSY | TS_FLUSH);
886 (*linesw[tp->t_line].l_start) (tp);
893 * Handle modem interrupt.
895 void cxmint (cx_chan_t *c)
897 unsigned short port = c->chip->port;
898 unsigned char misr = inb (MISR(port));
899 unsigned char msvr = inb (MSVR(port));
900 struct tty *tp = c->ttyp;
902 if (c->mode != M_ASYNC) {
903 printf ("cx%d.%d: unexpected modem interrupt, misr=%b, msvr=%b\n",
904 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS);
907 print (("cx%d.%d: modem interrupt, misr=%b, msvr=%b\n",
908 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS));
910 /* Ignore DSR events. */
911 /* Ignore RTC/CTS events, handled by hardware. */
912 /* Handle carrier detect/loss. */
913 if (tp && (misr & MIS_CCD))
914 (*linesw[tp->t_line].l_modem) (tp, (msvr & MSV_CD) != 0);
918 * Recover after lost transmit interrupts.
920 void cxtimeout (void *a)
927 for (b=cxboard; b<cxboard+NCX; ++b)
928 for (c=b->chan; c<b->chan+NCHAN; ++c) {
930 if (c->type==T_NONE || c->mode!=M_ASYNC || !tp)
933 if (tp->t_state & TS_BUSY) {
934 tp->t_state &= ~TS_BUSY;
936 (*linesw[tp->t_line].l_start) (tp);
942 timeout (cxtimeout, 0, hz*5);
946 #if defined(__FreeBSD__) && (__FreeBSD__ > 1 )
947 static void cx_drvinit(void *unused)
950 cdevsw_add(&cx_cdevsw);
953 SYSINIT(cxdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,cx_drvinit,NULL)