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.14 2004/09/19 01:28:54 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);
69 extern struct callout cxtimeout_ch;
72 # define print(s) printf s
74 # define print(s) {/*void*/}
77 #define DMABUFSZ (6*256) /* buffer size */
78 #define BYTE *(unsigned char*)&
79 #define UNIT(u) (minor(u) & 077)
82 extern cx_board_t cxboard [NCX]; /* adapter state structures */
83 extern cx_chan_t *cxchan [NCX*NCHAN]; /* unit to channel struct pointer */
84 #if defined(__DragonFly__) || __FreeBSD__ >= 2
85 static struct tty cx_tty [NCX*NCHAN]; /* tty data */
87 static d_open_t cxopen;
88 static d_close_t cxclose;
89 static d_ioctl_t cxioctl;
92 /* Don't make this static, since if_cx.c uses it. */
93 struct cdevsw cx_cdevsw = {
96 /* flags */ D_TTY | D_KQFILTER,
103 /* write */ ttywrite,
107 /* strategy */ nostrategy,
110 /* kqfilter */ ttykqfilter
113 struct tty *cx_tty [NCX*NCHAN]; /* tty data */
116 static void cxoproc (struct tty *tp);
117 static void cxstop (struct tty *tp, int flag);
118 static int cxparam (struct tty *tp, struct termios *t);
120 int cxopen (dev_t dev, int flag, int mode, struct thread *td)
122 int unit = UNIT (dev);
123 cx_chan_t *c = cxchan[unit];
128 if (unit == UNIT_CTL) {
129 print (("cx: cxopen /dev/cronyx\n"));
132 if (unit >= NCX*NCHAN || !c || c->type==T_NONE)
134 port = c->chip->port;
135 print (("cx%d.%d: cxopen unit=%d\n", c->board->num, c->num, unit));
136 if (c->mode != M_ASYNC)
139 #if defined(__DragonFly__) || defined(__FreeBSD__)
140 #if defined(__DragonFly__) || __FreeBSD__ >= 2
141 c->ttyp = &cx_tty[unit];
143 c->ttyp = cx_tty[unit] = ttymalloc (cx_tty[unit]);
146 MALLOC (cx_tty[unit], struct tty*, sizeof (struct tty), M_DEVBUF, M_WAITOK);
147 bzero (cx_tty[unit], sizeof (*cx_tty[unit]));
148 c->ttyp = cx_tty[unit];
150 c->ttyp->t_oproc = cxoproc;
151 c->ttyp->t_stop = cxstop;
152 c->ttyp->t_param = cxparam;
154 dev->si_tty = c->ttyp;
157 MALLOC (c->ttydev, struct ttydevice_tmp*,
158 sizeof (struct ttydevice_tmp), M_DEVBUF, M_WAITOK);
159 bzero (c->ttydev, sizeof (*c->ttydev));
160 strcpy (c->ttydev->tty_name, "cx");
161 c->ttydev->tty_unit = unit;
162 c->ttydev->tty_base = unit;
163 c->ttydev->tty_count = 1;
164 c->ttydev->tty_ttys = c->ttyp;
165 tty_attach (c->ttydev);
170 if ((tp->t_state & TS_ISOPEN) && (tp->t_state & TS_XCLUDE) &&
173 if (! (tp->t_state & TS_ISOPEN)) {
175 if (tp->t_ispeed == 0) {
177 tp->t_termios = deftermios;
182 tp->t_cflag = CREAD | CS8 | HUPCL;
183 tp->t_ispeed = c->rxbaud;
184 tp->t_ospeed = c->txbaud;
187 cxparam (tp, &tp->t_termios);
192 if (! (tp->t_state & TS_ISOPEN)) {
194 * Compute optimal receiver buffer length.
195 * The best choice is rxbaud/400.
196 * Make it even, to avoid byte-wide DMA transfers.
197 * --------------------------
198 * Baud rate Buffer length
199 * --------------------------
207 * --------------------------
209 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
212 else if (rbsz > DMABUFSZ)
215 /* Initialize channel, enable receiver. */
216 cx_cmd (port, CCR_INITCH | CCR_ENRX);
217 cx_cmd (port, CCR_INITCH | CCR_ENRX);
219 /* Start receiver. */
220 outw (ARBCNT(port), rbsz);
221 outw (BRBCNT(port), rbsz);
222 outw (ARBSTS(port), BSTS_OWN24);
223 outw (BRBSTS(port), BSTS_OWN24);
225 /* Enable interrupts. */
226 outb (IER(port), IER_RXD | IER_RET | IER_TXD | IER_MDM);
232 (*linesw[tp->t_line].l_modem)(tp, 1);
233 if (! (flag & O_NONBLOCK)) {
234 /* Lock the channel against cxconfig while we are
235 * waiting for carrier. */
237 while (!(tp->t_cflag & CLOCAL) && !(tp->t_state & TS_CARR_ON))
238 if ((error = tsleep (TSA_CARR_ON(tp), PCATCH,
241 c->sopt.lock = 0; /* Unlock the channel. */
243 print (("cx%d.%d: cxopen done csr=%b\n", c->board->num, c->num,
244 inb(CSR(c->chip->port)), CSRA_BITS));
248 #if defined(__DragonFly__) || __FreeBSD__ >= 2
249 error = (*linesw[tp->t_line].l_open) (dev, tp);
251 error = (*linesw[tp->t_line].l_open) (dev, tp, 0);
256 int cxclose (dev_t dev, int flag, int mode, struct thread *td)
258 int unit = UNIT (dev);
259 cx_chan_t *c = cxchan[unit];
263 if (unit == UNIT_CTL)
266 (*linesw[tp->t_line].l_close) (tp, flag);
269 * Transmitter continues sending the queued data. */
271 outb (CAR(c->chip->port), c->num & 3);
272 outb (IER(c->chip->port), IER_TXD | IER_MDM);
273 cx_cmd (c->chip->port, CCR_DISRX);
275 /* Clear DTR and RTS. */
276 if ((tp->t_cflag & HUPCL) || ! (tp->t_state & TS_ISOPEN)) {
281 /* Stop sending break. */
282 if (c->brk == BRK_SEND) {
284 if (! (tp->t_state & TS_BUSY))
292 int cxioctl (dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
294 int unit = UNIT (dev);
300 struct ifnet *master;
302 if (unit == UNIT_CTL) {
303 /* Process an ioctl request on /dev/cronyx */
304 cx_options_t *o = (cx_options_t*) data;
306 if (o->board >= NCX || o->channel >= NCHAN)
308 c = &cxboard[o->board].chan[o->channel];
309 if (c->type == T_NONE)
316 print (("cx%d.%d: CXIOCSETMODE\n", o->board, o->channel));
317 if (c->type == T_NONE)
319 if (c->type == T_ASYNC && o->mode != M_ASYNC)
321 if (o->mode == M_ASYNC)
328 /* Somebody is waiting for carrier? */
331 /* /dev/ttyXX is already opened by someone? */
332 if (c->mode == M_ASYNC && c->ttyp &&
333 (c->ttyp->t_state & TS_ISOPEN))
335 /* Network interface is up? */
336 if (c->mode != M_ASYNC && (c->ifp->if_flags & IFF_UP))
339 /* Find the master interface. */
340 master = *o->master ? ifunit (o->master) : c->ifp;
343 m = cxchan[master->if_dunit];
345 /* Leave the previous master queue. */
346 if (c->master != c->ifp) {
347 cx_chan_t *p = cxchan[c->master->if_dunit];
349 for (; p; p=p->slaveq)
351 p->slaveq = c->slaveq;
354 /* Set up new master. */
358 /* Join the new master queue. */
359 if (c->master != c->ifp) {
360 c->slaveq = m->slaveq;
365 c->rxbaud = o->rxbaud;
366 c->txbaud = o->txbaud;
373 case 0: c->board->if0type = o->iftype; break;
374 case 8: c->board->if8type = o->iftype; break;
377 cxswitch (c, o->sopt);
379 outb (IER(c->chip->port), 0);
384 st = (cx_stat_t*) data;
385 st->rintr = c->stat->rintr;
386 st->tintr = c->stat->tintr;
387 st->mintr = c->stat->mintr;
388 st->ibytes = c->stat->ibytes;
389 st->ipkts = c->stat->ipkts;
390 st->ierrs = c->stat->ierrs;
391 st->obytes = c->stat->obytes;
392 st->opkts = c->stat->opkts;
393 st->oerrs = c->stat->oerrs;
397 print (("cx%d.%d: CXIOCGETMODE\n", o->board, o->channel));
400 o->rxbaud = c->rxbaud;
401 o->txbaud = c->txbaud;
409 case 0: o->iftype = c->board->if0type; break;
410 case 8: o->iftype = c->board->if8type; break;
412 if (c->master != c->ifp)
413 strlcpy(o->master, c->master->if_xname, sizeof(o->master));
425 #if defined(__DragonFly__) || __FreeBSD__ >= 2
426 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag, td);
428 error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag);
430 if (error != ENOIOCTL)
432 error = ttioctl (tp, cmd, data, flag);
433 if (error != ENOIOCTL)
441 case TIOCSBRK: /* Start sending line break */
443 if (! (tp->t_state & TS_BUSY))
446 case TIOCCBRK: /* Stop sending line break */
448 if (! (tp->t_state & TS_BUSY))
451 case TIOCSDTR: /* Set DTR */
454 case TIOCCDTR: /* Clear DTR */
457 case TIOCMSET: /* Set DTR/RTS */
458 cx_chan_dtr (c, (*(int*)data & TIOCM_DTR) ? 1 : 0);
459 cx_chan_rts (c, (*(int*)data & TIOCM_RTS) ? 1 : 0);
461 case TIOCMBIS: /* Add DTR/RTS */
462 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 1);
463 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 1);
465 case TIOCMBIC: /* Clear DTR/RTS */
466 if (*(int*)data & TIOCM_DTR) cx_chan_dtr (c, 0);
467 if (*(int*)data & TIOCM_RTS) cx_chan_rts (c, 0);
469 case TIOCMGET: /* Get modem status */
470 msv = inb (MSVR(c->chip->port));
471 *(int*)data = TIOCM_LE; /* always enabled while open */
472 if (msv & MSV_DSR) *(int*)data |= TIOCM_DSR;
473 if (msv & MSV_CTS) *(int*)data |= TIOCM_CTS;
474 if (msv & MSV_CD) *(int*)data |= TIOCM_CD;
475 if (c->dtr) *(int*)data |= TIOCM_DTR;
476 if (c->rts) *(int*)data |= TIOCM_RTS;
484 * Fill transmitter buffer with data.
487 cxout (cx_chan_t *c, char b)
489 unsigned char *buf, *p, sym;
490 unsigned short port = c->chip->port, len = 0, cnt_port, sts_port;
491 struct tty *tp = c->ttyp;
496 /* Choose the buffer. */
499 cnt_port = ATBCNT(port);
500 sts_port = ATBSTS(port);
503 cnt_port = BTBCNT(port);
504 sts_port = BTBSTS(port);
508 if (inb (sts_port) & BSTS_OWN24) {
509 tp->t_state |= TS_BUSY;
515 *buf++ = 0; /* extended transmit command */
516 *buf++ = 0x81; /* send break */
517 *buf++ = 0; /* extended transmit command */
518 *buf++ = 0x82; /* insert delay */
519 *buf++ = 250; /* 1/4 of second */
520 *buf++ = 0; /* extended transmit command */
521 *buf++ = 0x82; /* insert delay */
522 *buf++ = 250; /* + 1/4 of second */
527 *buf++ = 0; /* extended transmit command */
528 *buf++ = 0x83; /* stop break */
534 if (tp->t_iflag & IXOFF)
535 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
536 sym = RB_GETC (tp->t_out);
537 /* Send XON/XOFF out of band. */
538 if (sym == tp->t_cc[VSTOP]) {
539 outb (STCR(port), STC_SNDSPC|STC_SSPC_2);
542 if (sym == tp->t_cc[VSTART]) {
543 outb (STCR(port), STC_SNDSPC|STC_SSPC_1);
546 /* Duplicate NULLs in ETC mode. */
552 while (RB_LEN (tp->t_out) && p<buf+DMABUFSZ-1) {
553 sym = RB_GETC (tp->t_out);
554 /* Duplicate NULLs in ETC mode. */
563 /* Start transmitter. */
565 outw (cnt_port, len);
566 outb (sts_port, BSTS_INTR | BSTS_OWN24);
567 c->stat->obytes += len;
568 tp->t_state |= TS_BUSY;
569 print (("cx%d.%d: out %d bytes to %c\n",
570 c->board->num, c->num, len, b));
574 void cxoproc (struct tty *tp)
576 int unit = UNIT (tp->t_dev);
577 cx_chan_t *c = cxchan[unit];
578 unsigned short port = c->chip->port;
581 /* Set current channel number */
582 outb (CAR(port), c->num & 3);
584 if (! (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))) {
585 /* Start transmitter. */
586 if (! (inb (CSR(port)) & CSRA_TXEN))
587 cx_cmd (port, CCR_ENTX);
589 /* Determine the buffer order. */
590 if (inb (DMABSTS(port)) & DMABSTS_NTBUF) {
598 #ifndef TS_ASLEEP /* FreeBSD some time after 2.0.5 */
601 if (RB_LEN (tp->t_out) <= tp->t_lowat) {
602 if (tp->t_state & TS_ASLEEP) {
603 tp->t_state &= ~TS_ASLEEP;
604 wakeup(TSA_OLOWAT(tp));
606 selwakeup(&tp->t_wsel);
613 cxparam (struct tty *tp, struct termios *t)
615 int unit = UNIT (tp->t_dev);
616 cx_chan_t *c = cxchan[unit];
617 unsigned short port = c->chip->port;
618 int clock, period, s;
619 cx_cor1_async_t cor1;
621 if (t->c_ospeed == 0) {
622 /* Clear DTR and RTS. */
627 print (("cx%d.%d: cxparam (hangup)\n", c->board->num, c->num));
630 print (("cx%d.%d: cxparam\n", c->board->num, c->num));
632 /* Check requested parameters. */
633 if (t->c_ospeed < 300 || t->c_ospeed > 256*1024)
635 if (t->c_ispeed && (t->c_ispeed < 300 || t->c_ispeed > 256*1024))
639 /* CLOCAL flag set -- wakeup everybody who waits for CD. */
640 /* FreeBSD does this themselves. */
641 if (! (tp->t_cflag & CLOCAL) && (t->c_cflag & CLOCAL))
642 wakeup ((caddr_t) &tp->t_rawq);
644 /* And copy them to tty and channel structures. */
645 c->rxbaud = tp->t_ispeed = t->c_ispeed;
646 c->txbaud = tp->t_ospeed = t->c_ospeed;
647 tp->t_cflag = t->c_cflag;
649 /* Set character length and parity mode. */
651 switch (t->c_cflag & CSIZE) {
653 case CS8: cor1.charlen = 7; break;
654 case CS7: cor1.charlen = 6; break;
655 case CS6: cor1.charlen = 5; break;
656 case CS5: cor1.charlen = 4; break;
658 if (t->c_cflag & PARENB) {
659 cor1.parmode = PARM_NORMAL;
661 cor1.parity = (t->c_cflag & PARODD) ? PAR_ODD : PAR_EVEN;
663 cor1.parmode = PARM_NOPAR;
667 /* Enable/disable hardware CTS. */
668 c->aopt.cor2.ctsae = (t->c_cflag & CRTSCTS) ? 1 : 0;
669 /* Handle DSR as CTS. */
670 c->aopt.cor2.dsrae = (t->c_cflag & CRTSCTS) ? 1 : 0;
671 /* Enable extended transmit command mode.
672 * Unfortunately, there is no other method for sending break. */
673 c->aopt.cor2.etc = 1;
674 /* Enable/disable hardware XON/XOFF. */
675 c->aopt.cor2.ixon = (t->c_iflag & IXON) ? 1 : 0;
676 c->aopt.cor2.ixany = (t->c_iflag & IXANY) ? 1 : 0;
678 /* Set the number of stop bits. */
679 if (t->c_cflag & CSTOPB)
680 c->aopt.cor3.stopb = STOPB_2;
682 c->aopt.cor3.stopb = STOPB_1;
683 /* Disable/enable passing XON/XOFF chars to the host. */
684 c->aopt.cor3.scde = (t->c_iflag & IXON) ? 1 : 0;
685 c->aopt.cor3.flowct = (t->c_iflag & IXON) ? FLOWCC_NOTPASS : FLOWCC_PASS;
687 c->aopt.schr1 = t->c_cc[VSTART]; /* XON */
688 c->aopt.schr2 = t->c_cc[VSTOP]; /* XOFF */
690 /* Set current channel number. */
692 outb (CAR(port), c->num & 3);
694 /* Set up receiver clock values. */
695 cx_clock (c->chip->oscfreq, c->rxbaud, &clock, &period);
696 c->opt.rcor.clk = clock;
697 outb (RCOR(port), BYTE c->opt.rcor);
698 outb (RBPR(port), period);
700 /* Set up transmitter clock values. */
701 cx_clock (c->chip->oscfreq, c->txbaud, &clock, &period);
702 c->opt.tcor.clk = clock;
703 c->opt.tcor.ext1x = 0;
704 outb (TCOR(port), BYTE c->opt.tcor);
705 outb (TBPR(port), period);
707 outb (COR2(port), BYTE c->aopt.cor2);
708 outb (COR3(port), BYTE c->aopt.cor3);
709 outb (SCHR1(port), c->aopt.schr1);
710 outb (SCHR2(port), c->aopt.schr2);
712 if (BYTE c->aopt.cor1 != BYTE cor1) {
713 BYTE c->aopt.cor1 = BYTE cor1;
714 outb (COR1(port), BYTE c->aopt.cor1);
715 /* Any change to COR1 require reinitialization. */
716 /* Unfortunately, it may cause transmitter glitches... */
717 cx_cmd (port, CCR_INITCH);
724 * Stop output on a line
726 void cxstop (struct tty *tp, int flag)
728 cx_chan_t *c = cxchan[UNIT(tp->t_dev)];
729 unsigned short port = c->chip->port;
732 if (tp->t_state & TS_BUSY) {
733 print (("cx%d.%d: cxstop\n", c->board->num, c->num));
735 /* Set current channel number */
736 outb (CAR(port), c->num & 3);
738 /* Stop transmitter */
739 cx_cmd (port, CCR_DISTX);
745 * Handle receive interrupts, including receive errors and
746 * receive timeout interrupt.
748 int cxrinta (cx_chan_t *c)
750 unsigned short port = c->chip->port;
751 unsigned short len = 0, risr = inw (RISR(port)), reoir = 0;
752 struct tty *tp = c->ttyp;
754 /* Compute optimal receiver buffer length. */
755 int rbsz = (c->rxbaud + 800 - 1) / 800 * 2;
758 else if (rbsz > DMABUFSZ)
761 if (risr & RISA_TIMEOUT) {
762 unsigned long rcbadr = (unsigned short) inw (RCBADRL(port)) |
763 (long) inw (RCBADRU(port)) << 16;
764 unsigned char *buf = 0;
765 unsigned short cnt_port = 0, sts_port = 0;
766 if (rcbadr >= c->brphys && rcbadr < c->brphys+DMABUFSZ) {
768 len = rcbadr - c->brphys;
769 cnt_port = BRBCNT(port);
770 sts_port = BRBSTS(port);
771 } else if (rcbadr >= c->arphys && rcbadr < c->arphys+DMABUFSZ) {
773 len = rcbadr - c->arphys;
774 cnt_port = ARBCNT(port);
775 sts_port = ARBSTS(port);
777 printf ("cx%d.%d: timeout: invalid buffer address\n",
778 c->board->num, c->num);
781 print (("cx%d.%d: async receive timeout (%d bytes), risr=%b, arbsts=%b, brbsts=%b\n",
782 c->board->num, c->num, len, risr, RISA_BITS,
783 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
784 c->stat->ibytes += len;
785 if (tp && (tp->t_state & TS_ISOPEN)) {
787 int (*rint)(int, struct tty *) =
788 linesw[tp->t_line].l_rint;
790 for (i=0; i<len; ++i)
791 (*rint) (buf[i], tp);
794 /* Restart receiver. */
795 outw (cnt_port, rbsz);
796 outb (sts_port, BSTS_OWN24);
798 return (REOI_TERMBUFF);
801 print (("cx%d.%d: async receive interrupt, risr=%b, arbsts=%b, brbsts=%b\n",
802 c->board->num, c->num, risr, RISA_BITS,
803 inb (ARBSTS(port)), BSTS_BITS, inb (BRBSTS(port)), BSTS_BITS));
805 if (risr & RIS_BUSERR) {
806 printf ("cx%d.%d: receive bus error\n", c->board->num, c->num);
809 if (risr & (RIS_OVERRUN | RISA_PARERR | RISA_FRERR | RISA_BREAK)) {
812 if (risr & RISA_PARERR)
814 if (risr & RISA_FRERR)
817 if (risr & RIS_OVERRUN)
821 if (risr & RISA_BREAK)
824 print (("cx%d.%d: receive error %x\n", c->board->num, c->num, err));
825 if (tp && (tp->t_state & TS_ISOPEN))
826 (*linesw[tp->t_line].l_rint) (err, tp);
830 /* Discard exception characters. */
831 if ((risr & RISA_SCMASK) && tp && (tp->t_iflag & IXON))
832 reoir |= REOI_DISCEXC;
834 /* Handle received data. */
835 if ((risr & RIS_EOBUF) && tp && (tp->t_state & TS_ISOPEN)) {
836 int (*rint)(int, struct tty *) = linesw[tp->t_line].l_rint;
840 len = (risr & RIS_BB) ? inw(BRBCNT(port)) : inw(ARBCNT(port));
842 print (("cx%d.%d: async: %d bytes received\n",
843 c->board->num, c->num, len));
844 c->stat->ibytes += len;
846 buf = (risr & RIS_BB) ? c->brbuf : c->arbuf;
847 for (i=0; i<len; ++i)
848 (*rint) (buf[i], tp);
851 /* Restart receiver. */
852 if (! (inb (ARBSTS(port)) & BSTS_OWN24)) {
853 outw (ARBCNT(port), rbsz);
854 outb (ARBSTS(port), BSTS_OWN24);
856 if (! (inb (BRBSTS(port)) & BSTS_OWN24)) {
857 outw (BRBCNT(port), rbsz);
858 outb (BRBSTS(port), BSTS_OWN24);
864 * Handle transmit interrupt.
866 void cxtinta (cx_chan_t *c)
868 struct tty *tp = c->ttyp;
869 unsigned short port = c->chip->port;
870 unsigned char tisr = inb (TISR(port));
872 print (("cx%d.%d: async transmit interrupt, tisr=%b, atbsts=%b, btbsts=%b\n",
873 c->board->num, c->num, tisr, TIS_BITS,
874 inb (ATBSTS(port)), BSTS_BITS, inb (BTBSTS(port)), BSTS_BITS));
876 if (tisr & TIS_BUSERR) {
877 printf ("cx%d.%d: transmit bus error\n",
878 c->board->num, c->num);
880 } else if (tisr & TIS_UNDERRUN) {
881 printf ("cx%d.%d: transmit underrun error\n",
882 c->board->num, c->num);
886 tp->t_state &= ~(TS_BUSY | TS_FLUSH);
888 (*linesw[tp->t_line].l_start) (tp);
895 * Handle modem interrupt.
897 void cxmint (cx_chan_t *c)
899 unsigned short port = c->chip->port;
900 unsigned char misr = inb (MISR(port));
901 unsigned char msvr = inb (MSVR(port));
902 struct tty *tp = c->ttyp;
904 if (c->mode != M_ASYNC) {
905 printf ("cx%d.%d: unexpected modem interrupt, misr=%b, msvr=%b\n",
906 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS);
909 print (("cx%d.%d: modem interrupt, misr=%b, msvr=%b\n",
910 c->board->num, c->num, misr, MIS_BITS, msvr, MSV_BITS));
912 /* Ignore DSR events. */
913 /* Ignore RTC/CTS events, handled by hardware. */
914 /* Handle carrier detect/loss. */
915 if (tp && (misr & MIS_CCD))
916 (*linesw[tp->t_line].l_modem) (tp, (msvr & MSV_CD) != 0);
920 * Recover after lost transmit interrupts.
930 for (b = cxboard; b < cxboard + NCX; ++b) {
931 for (c = b->chan; c < b->chan + NCHAN; ++c) {
933 if (c->type == T_NONE || c->mode != M_ASYNC || !tp)
936 if (tp->t_state & TS_BUSY) {
937 tp->t_state &= ~TS_BUSY;
939 (*linesw[tp->t_line].l_start) (tp);
946 callout_reset (&cxtimeout_ch, hz * 5, cxtimeout, NULL);
950 #if defined(__DragonFly__) || (defined(__FreeBSD__) && (__FreeBSD__ > 1 ))
954 cx_drvinit(void *unused)
958 SYSINIT(cxdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,cx_drvinit,NULL)