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
18 * $FreeBSD: src/sys/i386/isa/cx.c,v 1.45.2.1 2001/02/26 04:23:09 jlemon Exp $
19 * $DragonFly: src/sys/dev/netif/cx/cx.c,v 1.11 2004/05/13 23:49:18 dillon Exp $
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>
36 #if defined(__DragonFly__) || defined(__FreeBSD__)
37 # if defined(__FreeBSD__) && __FreeBSD__ < 2
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(__DragonFly__) || !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>
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 */
83 #if defined(__DragonFly__) || __FreeBSD__ >= 2
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 = {
95 /* flags */ D_TTY | D_KQFILTER,
102 /* write */ ttywrite,
106 /* strategy */ nostrategy,
109 /* kqfilter */ ttykqfilter
112 struct tty *cx_tty [NCX*NCHAN]; /* tty data */
115 static void cxoproc (struct tty *tp);
116 static void cxstop (struct tty *tp, int flag);
117 static int cxparam (struct tty *tp, struct termios *t);
119 int cxopen (dev_t dev, int flag, int mode, struct thread *td)
121 int unit = UNIT (dev);
122 cx_chan_t *c = cxchan[unit];
127 if (unit == UNIT_CTL) {
128 print (("cx: cxopen /dev/cronyx\n"));
131 if (unit >= NCX*NCHAN || !c || c->type==T_NONE)
133 port = c->chip->port;
134 print (("cx%d.%d: cxopen unit=%d\n", c->board->num, c->num, unit));
135 if (c->mode != M_ASYNC)
138 #if defined(__DragonFly__) || defined(__FreeBSD__)
139 #if defined(__DragonFly__) || __FreeBSD__ >= 2
140 c->ttyp = &cx_tty[unit];
142 c->ttyp = cx_tty[unit] = ttymalloc (cx_tty[unit]);
145 MALLOC (cx_tty[unit], struct tty*, sizeof (struct tty), M_DEVBUF, M_WAITOK);
146 bzero (cx_tty[unit], sizeof (*cx_tty[unit]));
147 c->ttyp = cx_tty[unit];
149 c->ttyp->t_oproc = cxoproc;
150 c->ttyp->t_stop = cxstop;
151 c->ttyp->t_param = cxparam;
153 dev->si_tty = c->ttyp;
156 MALLOC (c->ttydev, struct ttydevice_tmp*,
157 sizeof (struct ttydevice_tmp), M_DEVBUF, M_WAITOK);
158 bzero (c->ttydev, sizeof (*c->ttydev));
159 strcpy (c->ttydev->tty_name, "cx");
160 c->ttydev->tty_unit = unit;
161 c->ttydev->tty_base = unit;
162 c->ttydev->tty_count = 1;
163 c->ttydev->tty_ttys = c->ttyp;
164 tty_attach (c->ttydev);
169 if ((tp->t_state & TS_ISOPEN) && (tp->t_state & TS_XCLUDE) &&
172 if (! (tp->t_state & TS_ISOPEN)) {
174 if (tp->t_ispeed == 0) {
176 tp->t_termios = deftermios;
181 tp->t_cflag = CREAD | CS8 | HUPCL;
182 tp->t_ispeed = c->rxbaud;
183 tp->t_ospeed = c->txbaud;
186 cxparam (tp, &tp->t_termios);
191 if (! (tp->t_state & TS_ISOPEN)) {
193 * Compute optimal receiver buffer length.
194 * The best choice is rxbaud/400.
195 * Make it even, to avoid byte-wide DMA transfers.
196 * --------------------------
197 * Baud rate Buffer length
198 * --------------------------
206 * --------------------------
208 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
211 else if (rbsz > DMABUFSZ)
214 /* Initialize channel, enable receiver. */
215 cx_cmd (port, CCR_INITCH | CCR_ENRX);
216 cx_cmd (port, CCR_INITCH | CCR_ENRX);
218 /* Start receiver. */
219 outw (ARBCNT(port), rbsz);
220 outw (BRBCNT(port), rbsz);
221 outw (ARBSTS(port), BSTS_OWN24);
222 outw (BRBSTS(port), BSTS_OWN24);
224 /* Enable interrupts. */
225 outb (IER(port), IER_RXD | IER_RET | IER_TXD | IER_MDM);
231 (*linesw[tp->t_line].l_modem)(tp, 1);
232 if (! (flag & O_NONBLOCK)) {
233 /* Lock the channel against cxconfig while we are
234 * waiting for carrier. */
236 while (!(tp->t_cflag & CLOCAL) && !(tp->t_state & TS_CARR_ON))
237 if ((error = tsleep (TSA_CARR_ON(tp), PCATCH,
240 c->sopt.lock = 0; /* Unlock the channel. */
242 print (("cx%d.%d: cxopen done csr=%b\n", c->board->num, c->num,
243 inb(CSR(c->chip->port)), CSRA_BITS));
247 #if defined(__DragonFly__) || __FreeBSD__ >= 2
248 error = (*linesw[tp->t_line].l_open) (dev, tp);
250 error = (*linesw[tp->t_line].l_open) (dev, tp, 0);
255 int cxclose (dev_t dev, int flag, int mode, struct thread *td)
257 int unit = UNIT (dev);
258 cx_chan_t *c = cxchan[unit];
262 if (unit == UNIT_CTL)
265 (*linesw[tp->t_line].l_close) (tp, flag);
268 * Transmitter continues sending the queued data. */
270 outb (CAR(c->chip->port), c->num & 3);
271 outb (IER(c->chip->port), IER_TXD | IER_MDM);
272 cx_cmd (c->chip->port, CCR_DISRX);
274 /* Clear DTR and RTS. */
275 if ((tp->t_cflag & HUPCL) || ! (tp->t_state & TS_ISOPEN)) {
280 /* Stop sending break. */
281 if (c->brk == BRK_SEND) {
283 if (! (tp->t_state & TS_BUSY))
291 int cxioctl (dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
293 int unit = UNIT (dev);
299 struct ifnet *master;
301 if (unit == UNIT_CTL) {
302 /* Process an ioctl request on /dev/cronyx */
303 cx_options_t *o = (cx_options_t*) data;
305 if (o->board >= NCX || o->channel >= NCHAN)
307 c = &cxboard[o->board].chan[o->channel];
308 if (c->type == T_NONE)
315 print (("cx%d.%d: CXIOCSETMODE\n", o->board, o->channel));
316 if (c->type == T_NONE)
318 if (c->type == T_ASYNC && o->mode != M_ASYNC)
320 if (o->mode == M_ASYNC)
327 /* Somebody is waiting for carrier? */
330 /* /dev/ttyXX is already opened by someone? */
331 if (c->mode == M_ASYNC && c->ttyp &&
332 (c->ttyp->t_state & TS_ISOPEN))
334 /* Network interface is up? */
335 if (c->mode != M_ASYNC && (c->ifp->if_flags & IFF_UP))
338 /* Find the master interface. */
339 master = *o->master ? ifunit (o->master) : c->ifp;
342 m = cxchan[master->if_dunit];
344 /* Leave the previous master queue. */
345 if (c->master != c->ifp) {
346 cx_chan_t *p = cxchan[c->master->if_dunit];
348 for (; p; p=p->slaveq)
350 p->slaveq = c->slaveq;
353 /* Set up new master. */
357 /* Join the new master queue. */
358 if (c->master != c->ifp) {
359 c->slaveq = m->slaveq;
364 c->rxbaud = o->rxbaud;
365 c->txbaud = o->txbaud;
372 case 0: c->board->if0type = o->iftype; break;
373 case 8: c->board->if8type = o->iftype; break;
376 cxswitch (c, o->sopt);
378 outb (IER(c->chip->port), 0);
383 st = (cx_stat_t*) data;
384 st->rintr = c->stat->rintr;
385 st->tintr = c->stat->tintr;
386 st->mintr = c->stat->mintr;
387 st->ibytes = c->stat->ibytes;
388 st->ipkts = c->stat->ipkts;
389 st->ierrs = c->stat->ierrs;
390 st->obytes = c->stat->obytes;
391 st->opkts = c->stat->opkts;
392 st->oerrs = c->stat->oerrs;
396 print (("cx%d.%d: CXIOCGETMODE\n", o->board, o->channel));
399 o->rxbaud = c->rxbaud;
400 o->txbaud = c->txbaud;
408 case 0: o->iftype = c->board->if0type; break;
409 case 8: o->iftype = c->board->if8type; break;
411 if (c->master != c->ifp)
412 strlcpy(o->master, c->master->if_xname, sizeof(o->master));
424 #if defined(__DragonFly__) || __FreeBSD__ >= 2
425 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag, td);
427 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag);
429 if (error != ENOIOCTL)
431 error = ttioctl (tp, cmd, data, flag);
432 if (error != ENOIOCTL)
440 case TIOCSBRK: /* Start sending line break */
442 if (! (tp->t_state & TS_BUSY))
445 case TIOCCBRK: /* Stop sending line break */
447 if (! (tp->t_state & TS_BUSY))
450 case TIOCSDTR: /* Set DTR */
453 case TIOCCDTR: /* Clear DTR */
456 case TIOCMSET: /* Set DTR/RTS */
457 cx_chan_dtr (c, (*(int*)data & TIOCM_DTR) ? 1 : 0);
458 cx_chan_rts (c, (*(int*)data & TIOCM_RTS) ? 1 : 0);
460 case TIOCMBIS: /* Add DTR/RTS */
461 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 1);
462 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 1);
464 case TIOCMBIC: /* Clear DTR/RTS */
465 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 0);
466 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 0);
468 case TIOCMGET: /* Get modem status */
469 msv = inb (MSVR(c->chip->port));
470 *(int*)data = TIOCM_LE; /* always enabled while open */
471 if (msv & MSV_DSR) *(int*)data |= TIOCM_DSR;
472 if (msv & MSV_CTS) *(int*)data |= TIOCM_CTS;
473 if (msv & MSV_CD) *(int*)data |= TIOCM_CD;
474 if (c->dtr) *(int*)data |= TIOCM_DTR;
475 if (c->rts) *(int*)data |= TIOCM_RTS;
483 * Fill transmitter buffer with data.
486 cxout (cx_chan_t *c, char b)
488 unsigned char *buf, *p, sym;
489 unsigned short port = c->chip->port, len = 0, cnt_port, sts_port;
490 struct tty *tp = c->ttyp;
495 /* Choose the buffer. */
498 cnt_port = ATBCNT(port);
499 sts_port = ATBSTS(port);
502 cnt_port = BTBCNT(port);
503 sts_port = BTBSTS(port);
507 if (inb (sts_port) & BSTS_OWN24) {
508 tp->t_state |= TS_BUSY;
514 *buf++ = 0; /* extended transmit command */
515 *buf++ = 0x81; /* send break */
516 *buf++ = 0; /* extended transmit command */
517 *buf++ = 0x82; /* insert delay */
518 *buf++ = 250; /* 1/4 of second */
519 *buf++ = 0; /* extended transmit command */
520 *buf++ = 0x82; /* insert delay */
521 *buf++ = 250; /* + 1/4 of second */
526 *buf++ = 0; /* extended transmit command */
527 *buf++ = 0x83; /* stop break */
533 if (tp->t_iflag & IXOFF)
534 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
535 sym = RB_GETC (tp->t_out);
536 /* Send XON/XOFF out of band. */
537 if (sym == tp->t_cc[VSTOP]) {
538 outb (STCR(port), STC_SNDSPC|STC_SSPC_2);
541 if (sym == tp->t_cc[VSTART]) {
542 outb (STCR(port), STC_SNDSPC|STC_SSPC_1);
545 /* Duplicate NULLs in ETC mode. */
551 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
552 sym = RB_GETC (tp->t_out);
553 /* Duplicate NULLs in ETC mode. */
562 /* Start transmitter. */
564 outw (cnt_port, len);
565 outb (sts_port, BSTS_INTR | BSTS_OWN24);
566 c->stat->obytes += len;
567 tp->t_state |= TS_BUSY;
568 print (("cx%d.%d: out %d bytes to %c\n",
569 c->board->num, c->num, len, b));
573 void cxoproc (struct tty *tp)
575 int unit = UNIT (tp->t_dev);
576 cx_chan_t *c = cxchan[unit];
577 unsigned short port = c->chip->port;
580 /* Set current channel number */
581 outb (CAR(port), c->num & 3);
583 if (! (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))) {
584 /* Start transmitter. */
585 if (! (inb (CSR(port)) & CSRA_TXEN))
586 cx_cmd (port, CCR_ENTX);
588 /* Determine the buffer order. */
589 if (inb (DMABSTS(port)) & DMABSTS_NTBUF) {
597 #ifndef TS_ASLEEP /* FreeBSD some time after 2.0.5 */
600 if (RB_LEN (tp->t_out) <= tp->t_lowat) {
601 if (tp->t_state & TS_ASLEEP) {
602 tp->t_state &= ~TS_ASLEEP;
603 wakeup(TSA_OLOWAT(tp));
605 selwakeup(&tp->t_wsel);
612 cxparam (struct tty *tp, struct termios *t)
614 int unit = UNIT (tp->t_dev);
615 cx_chan_t *c = cxchan[unit];
616 unsigned short port = c->chip->port;
617 int clock, period, s;
618 cx_cor1_async_t cor1;
620 if (t->c_ospeed == 0) {
621 /* Clear DTR and RTS. */
626 print (("cx%d.%d: cxparam (hangup)\n", c->board->num, c->num));
629 print (("cx%d.%d: cxparam\n", c->board->num, c->num));
631 /* Check requested parameters. */
632 if (t->c_ospeed < 300 || t->c_ospeed > 256*1024)
634 if (t->c_ispeed && (t->c_ispeed < 300 || t->c_ispeed > 256*1024))
638 /* CLOCAL flag set -- wakeup everybody who waits for CD. */
639 /* FreeBSD does this themselves. */
640 if (! (tp->t_cflag & CLOCAL) && (t->c_cflag & CLOCAL))
641 wakeup ((caddr_t) &tp->t_rawq);
643 /* And copy them to tty and channel structures. */
644 c->rxbaud = tp->t_ispeed = t->c_ispeed;
645 c->txbaud = tp->t_ospeed = t->c_ospeed;
646 tp->t_cflag = t->c_cflag;
648 /* Set character length and parity mode. */
650 switch (t->c_cflag & CSIZE) {
652 case CS8: cor1.charlen = 7; break;
653 case CS7: cor1.charlen = 6; break;
654 case CS6: cor1.charlen = 5; break;
655 case CS5: cor1.charlen = 4; break;
657 if (t->c_cflag & PARENB) {
658 cor1.parmode = PARM_NORMAL;
660 cor1.parity = (t->c_cflag & PARODD) ? PAR_ODD : PAR_EVEN;
662 cor1.parmode = PARM_NOPAR;
666 /* Enable/disable hardware CTS. */
667 c->aopt.cor2.ctsae = (t->c_cflag & CRTSCTS) ? 1 : 0;
668 /* Handle DSR as CTS. */
669 c->aopt.cor2.dsrae = (t->c_cflag & CRTSCTS) ? 1 : 0;
670 /* Enable extended transmit command mode.
671 * Unfortunately, there is no other method for sending break. */
672 c->aopt.cor2.etc = 1;
673 /* Enable/disable hardware XON/XOFF. */
674 c->aopt.cor2.ixon = (t->c_iflag & IXON) ? 1 : 0;
675 c->aopt.cor2.ixany = (t->c_iflag & IXANY) ? 1 : 0;
677 /* Set the number of stop bits. */
678 if (t->c_cflag & CSTOPB)
679 c->aopt.cor3.stopb = STOPB_2;
681 c->aopt.cor3.stopb = STOPB_1;
682 /* Disable/enable passing XON/XOFF chars to the host. */
683 c->aopt.cor3.scde = (t->c_iflag & IXON) ? 1 : 0;
684 c->aopt.cor3.flowct = (t->c_iflag & IXON) ? FLOWCC_NOTPASS : FLOWCC_PASS;
686 c->aopt.schr1 = t->c_cc[VSTART]; /* XON */
687 c->aopt.schr2 = t->c_cc[VSTOP]; /* XOFF */
689 /* Set current channel number. */
691 outb (CAR(port), c->num & 3);
693 /* Set up receiver clock values. */
694 cx_clock (c->chip->oscfreq, c->rxbaud, &clock, &period);
695 c->opt.rcor.clk = clock;
696 outb (RCOR(port), BYTE c->opt.rcor);
697 outb (RBPR(port), period);
699 /* Set up transmitter clock values. */
700 cx_clock (c->chip->oscfreq, c->txbaud, &clock, &period);
701 c->opt.tcor.clk = clock;
702 c->opt.tcor.ext1x = 0;
703 outb (TCOR(port), BYTE c->opt.tcor);
704 outb (TBPR(port), period);
706 outb (COR2(port), BYTE c->aopt.cor2);
707 outb (COR3(port), BYTE c->aopt.cor3);
708 outb (SCHR1(port), c->aopt.schr1);
709 outb (SCHR2(port), c->aopt.schr2);
711 if (BYTE c->aopt.cor1 != BYTE cor1) {
712 BYTE c->aopt.cor1 = BYTE cor1;
713 outb (COR1(port), BYTE c->aopt.cor1);
714 /* Any change to COR1 require reinitialization. */
715 /* Unfortunately, it may cause transmitter glitches... */
716 cx_cmd (port, CCR_INITCH);
723 * Stop output on a line
725 void cxstop (struct tty *tp, int flag)
727 cx_chan_t *c = cxchan[UNIT(tp->t_dev)];
728 unsigned short port = c->chip->port;
731 if (tp->t_state & TS_BUSY) {
732 print (("cx%d.%d: cxstop\n", c->board->num, c->num));
734 /* Set current channel number */
735 outb (CAR(port), c->num & 3);
737 /* Stop transmitter */
738 cx_cmd (port, CCR_DISTX);
744 * Handle receive interrupts, including receive errors and
745 * receive timeout interrupt.
747 int cxrinta (cx_chan_t *c)
749 unsigned short port = c->chip->port;
750 unsigned short len = 0, risr = inw (RISR(port)), reoir = 0;
751 struct tty *tp = c->ttyp;
753 /* Compute optimal receiver buffer length. */
754 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
757 else if (rbsz > DMABUFSZ)
760 if (risr & RISA_TIMEOUT) {
761 unsigned long rcbadr = (unsigned short) inw (RCBADRL(port)) |
762 (long) inw (RCBADRU(port)) << 16;
763 unsigned char *buf = 0;
764 unsigned short cnt_port = 0, sts_port = 0;
765 if (rcbadr >= c->brphys && rcbadr < c->brphys+DMABUFSZ) {
767 len = rcbadr - c->brphys;
768 cnt_port = BRBCNT(port);
769 sts_port = BRBSTS(port);
770 } else if (rcbadr >= c->arphys && rcbadr < c->arphys+DMABUFSZ) {
772 len = rcbadr - c->arphys;
773 cnt_port = ARBCNT(port);
774 sts_port = ARBSTS(port);
776 printf ("cx%d.%d: timeout: invalid buffer address\n",
777 c->board->num, c->num);
780 print (("cx%d.%d: async receive timeout (%d bytes), risr=%b, arbsts=%b, brbsts=%b\n",
781 c->board->num, c->num, len, risr, RISA_BITS,
782 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
783 c->stat->ibytes += len;
784 if (tp && (tp->t_state & TS_ISOPEN)) {
786 int (*rint)(int, struct tty *) =
787 linesw[tp->t_line].l_rint;
789 for (i=0; i<len; ++i)
790 (*rint) (buf[i], tp);
793 /* Restart receiver. */
794 outw (cnt_port, rbsz);
795 outb (sts_port, BSTS_OWN24);
797 return (REOI_TERMBUFF);
800 print (("cx%d.%d: async receive interrupt, risr=%b, arbsts=%b, brbsts=%b\n",
801 c->board->num, c->num, risr, RISA_BITS,
802 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
804 if (risr & RIS_BUSERR) {
805 printf ("cx%d.%d: receive bus error\n", c->board->num, c->num);
808 if (risr & (RIS_OVERRUN | RISA_PARERR | RISA_FRERR | RISA_BREAK)) {
811 if (risr & RISA_PARERR)
813 if (risr & RISA_FRERR)
816 if (risr & RIS_OVERRUN)
820 if (risr & RISA_BREAK)
823 print (("cx%d.%d: receive error %x\n", c->board->num, c->num, err));
824 if (tp && (tp->t_state & TS_ISOPEN))
825 (*linesw[tp->t_line].l_rint) (err, tp);
829 /* Discard exception characters. */
830 if ((risr & RISA_SCMASK) && tp && (tp->t_iflag & IXON))
831 reoir |= REOI_DISCEXC;
833 /* Handle received data. */
834 if ((risr & RIS_EOBUF) && tp && (tp->t_state & TS_ISOPEN)) {
835 int (*rint)(int, struct tty *) = linesw[tp->t_line].l_rint;
839 len = (risr & RIS_BB) ? inw(BRBCNT(port)) : inw(ARBCNT(port));
841 print (("cx%d.%d: async: %d bytes received\n",
842 c->board->num, c->num, len));
843 c->stat->ibytes += len;
845 buf = (risr & RIS_BB) ? c->brbuf : c->arbuf;
846 for (i=0; i<len; ++i)
847 (*rint) (buf[i], tp);
850 /* Restart receiver. */
851 if (! (inb (ARBSTS(port)) & BSTS_OWN24)) {
852 outw (ARBCNT(port), rbsz);
853 outb (ARBSTS(port), BSTS_OWN24);
855 if (! (inb (BRBSTS(port)) & BSTS_OWN24)) {
856 outw (BRBCNT(port), rbsz);
857 outb (BRBSTS(port), BSTS_OWN24);
863 * Handle transmit interrupt.
865 void cxtinta (cx_chan_t *c)
867 struct tty *tp = c->ttyp;
868 unsigned short port = c->chip->port;
869 unsigned char tisr = inb (TISR(port));
871 print (("cx%d.%d: async transmit interrupt, tisr=%b, atbsts=%b, btbsts=%b\n",
872 c->board->num, c->num, tisr, TIS_BITS,
873 inb (ATBSTS(port)), BSTS_BITS, inb (BTBSTS(port)), BSTS_BITS));
875 if (tisr & TIS_BUSERR) {
876 printf ("cx%d.%d: transmit bus error\n",
877 c->board->num, c->num);
879 } else if (tisr & TIS_UNDERRUN) {
880 printf ("cx%d.%d: transmit underrun error\n",
881 c->board->num, c->num);
885 tp->t_state &= ~(TS_BUSY | TS_FLUSH);
887 (*linesw[tp->t_line].l_start) (tp);
894 * Handle modem interrupt.
896 void cxmint (cx_chan_t *c)
898 unsigned short port = c->chip->port;
899 unsigned char misr = inb (MISR(port));
900 unsigned char msvr = inb (MSVR(port));
901 struct tty *tp = c->ttyp;
903 if (c->mode != M_ASYNC) {
904 printf ("cx%d.%d: unexpected modem interrupt, misr=%b, msvr=%b\n",
905 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS);
908 print (("cx%d.%d: modem interrupt, misr=%b, msvr=%b\n",
909 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS));
911 /* Ignore DSR events. */
912 /* Ignore RTC/CTS events, handled by hardware. */
913 /* Handle carrier detect/loss. */
914 if (tp && (misr & MIS_CCD))
915 (*linesw[tp->t_line].l_modem) (tp, (msvr & MSV_CD) != 0);
919 * Recover after lost transmit interrupts.
921 void cxtimeout (void *a)
928 for (b=cxboard; b<cxboard+NCX; ++b)
929 for (c=b->chan; c<b->chan+NCHAN; ++c) {
931 if (c->type==T_NONE || c->mode!=M_ASYNC || !tp)
934 if (tp->t_state & TS_BUSY) {
935 tp->t_state &= ~TS_BUSY;
937 (*linesw[tp->t_line].l_start) (tp);
943 timeout (cxtimeout, 0, hz*5);
947 #if defined(__DragonFly__) || (defined(__FreeBSD__) && (__FreeBSD__ > 1 ))
948 static void cx_drvinit(void *unused)
951 cdevsw_add(&cx_cdevsw);
954 SYSINIT(cxdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,cx_drvinit,NULL)