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.20 2006/12/22 23:26:19 swildner 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>
34 #include <sys/thread2.h>
37 #if defined(__DragonFly__) || defined(__FreeBSD__)
38 # if defined(__FreeBSD__) && __FreeBSD__ < 2
39 # include <machine/pio.h>
40 # define RB_GETC(q) getc(q)
44 # include <sys/ttystats.h>
45 # include <machine/inline.h>
46 # define tsleep(tp,pri,msg,x) ((tp)->t_state |= TS_WOPEN,\
47 ttysleep (tp, (caddr_t)&tp->t_rawq, pri, msg, x))
49 #if defined(__DragonFly__) || !defined (__FreeBSD__) || __FreeBSD__ >= 2
51 # define RB_LEN(q) ((q).c_cc)
52 # define RB_GETC(q) clist_getc(&q)
53 #ifndef TSA_CARR_ON /* FreeBSD 2.x before not long after 2.0.5 */
54 # define TSA_CARR_ON(tp) tp
55 # define TSA_OLOWAT(q) ((caddr_t)&(q)->t_out)
59 #include <machine/cronyx.h>
62 /* XXX imported from if_cx.c. */
63 void cxswitch (cx_chan_t
*c
, cx_soft_opt_t
new);
66 void cxmint (cx_chan_t
*c
);
67 int cxrinta (cx_chan_t
*c
);
68 void cxtinta (cx_chan_t
*c
);
70 extern struct callout cxtimeout_ch
;
73 # define print(s) kprintf s
75 # define print(s) {/*void*/}
78 #define DMABUFSZ (6*256) /* buffer size */
79 #define BYTE *(unsigned char*)&
80 #define UNIT(u) (minor(u) & 077)
83 extern cx_board_t cxboard
[NCX
]; /* adapter state structures */
84 extern cx_chan_t
*cxchan
[NCX
*NCHAN
]; /* unit to channel struct pointer */
85 #if defined(__DragonFly__) || __FreeBSD__ >= 2
86 static struct tty cx_tty
[NCX
*NCHAN
]; /* tty data */
88 static d_open_t cxopen
;
89 static d_close_t cxclose
;
90 static d_ioctl_t cxioctl
;
93 /* Don't make this static, since if_cx.c uses it. */
94 struct dev_ops cx_ops
= {
95 { "cx", CDEV_MAJOR
, D_TTY
| D_KQFILTER
},
102 .d_kqfilter
= ttykqfilter
105 struct tty
*cx_tty
[NCX
*NCHAN
]; /* tty data */
108 static void cxoproc (struct tty
*tp
);
109 static void cxstop (struct tty
*tp
, int flag
);
110 static int cxparam (struct tty
*tp
, struct termios
*t
);
113 cxopen (struct dev_open_args
*ap
)
115 cdev_t dev
= ap
->a_head
.a_dev
;
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
)
133 #if defined(__DragonFly__) || defined(__FreeBSD__)
134 #if defined(__DragonFly__) || __FreeBSD__ >= 2
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
) &&
165 suser_cred(ap
->a_cred
, 0))
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 (! (ap
->a_oflags
& 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
), 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
));
242 #if defined(__DragonFly__) || __FreeBSD__ >= 2
243 error
= (*linesw
[tp
->t_line
].l_open
) (dev
, tp
);
245 error
= (*linesw
[tp
->t_line
].l_open
) (dev
, tp
, 0);
251 cxclose (struct dev_close_args
*ap
)
253 cdev_t dev
= ap
->a_head
.a_dev
;
254 int unit
= UNIT (dev
);
255 cx_chan_t
*c
= cxchan
[unit
];
258 if (unit
== UNIT_CTL
)
261 (*linesw
[tp
->t_line
].l_close
) (tp
, ap
->a_fflag
);
264 * 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
))
289 cxioctl (struct dev_ioctl_args
*ap
)
291 cdev_t dev
= ap
->a_head
.a_dev
;
292 caddr_t data
= ap
->a_data
;
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 error
= (*linesw
[tp
->t_line
].l_ioctl
) (tp
, ap
->a_cmd
, data
,
425 ap
->a_fflag
, ap
->a_cred
);
426 if (error
!= ENOIOCTL
)
428 error
= ttioctl (tp
, ap
->a_cmd
, data
, ap
->a_fflag
);
429 if (error
!= ENOIOCTL
)
438 case TIOCSBRK
: /* Start sending line break */
440 if (! (tp
->t_state
& TS_BUSY
))
443 case TIOCCBRK
: /* Stop sending line break */
445 if (! (tp
->t_state
& TS_BUSY
))
448 case TIOCSDTR
: /* Set DTR */
451 case TIOCCDTR
: /* Clear DTR */
454 case TIOCMSET
: /* Set DTR/RTS */
455 cx_chan_dtr (c
, (*(int*)data
& TIOCM_DTR
) ? 1 : 0);
456 cx_chan_rts (c
, (*(int*)data
& TIOCM_RTS
) ? 1 : 0);
458 case TIOCMBIS
: /* Add DTR/RTS */
459 if (*(int*)data
& TIOCM_DTR
) cx_chan_dtr (c
, 1);
460 if (*(int*)data
& TIOCM_RTS
) cx_chan_rts (c
, 1);
462 case TIOCMBIC
: /* Clear DTR/RTS */
463 if (*(int*)data
& TIOCM_DTR
) cx_chan_dtr (c
, 0);
464 if (*(int*)data
& TIOCM_RTS
) cx_chan_rts (c
, 0);
466 case TIOCMGET
: /* Get modem status */
467 msv
= inb (MSVR(c
->chip
->port
));
468 *(int*)data
= TIOCM_LE
; /* always enabled while open */
469 if (msv
& MSV_DSR
) *(int*)data
|= TIOCM_DSR
;
470 if (msv
& MSV_CTS
) *(int*)data
|= TIOCM_CTS
;
471 if (msv
& MSV_CD
) *(int*)data
|= TIOCM_CD
;
472 if (c
->dtr
) *(int*)data
|= TIOCM_DTR
;
473 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
));
573 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
;
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
;
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
);
725 * Stop output on a line
728 cxstop (struct tty
*tp
, int flag
)
732 if (tp
->t_state
& TS_BUSY
) {
733 cx_chan_t
*c
= cxchan
[UNIT(tp
->t_dev
)];
734 unsigned short port
= c
->chip
->port
;
736 print (("cx%d.%d: cxstop\n", c
->board
->num
, c
->num
));
738 /* Set current channel number */
739 outb (CAR(port
), c
->num
& 3);
741 /* Stop transmitter */
742 cx_cmd (port
, CCR_DISTX
);
749 * Handle receive interrupts, including receive errors and
750 * receive timeout interrupt.
753 cxrinta (cx_chan_t
*c
)
755 unsigned short port
= c
->chip
->port
;
756 unsigned short len
= 0, risr
= inw (RISR(port
)), reoir
= 0;
757 struct tty
*tp
= c
->ttyp
;
759 /* Compute optimal receiver buffer length. */
760 int rbsz
= (c
->rxbaud
+ 800 - 1) / 800 * 2;
763 else if (rbsz
> DMABUFSZ
)
766 if (risr
& RISA_TIMEOUT
) {
767 unsigned long rcbadr
= (unsigned short) inw (RCBADRL(port
)) |
768 (long) inw (RCBADRU(port
)) << 16;
769 unsigned char *buf
= 0;
770 unsigned short cnt_port
= 0, sts_port
= 0;
771 if (rcbadr
>= c
->brphys
&& rcbadr
< c
->brphys
+DMABUFSZ
) {
773 len
= rcbadr
- c
->brphys
;
774 cnt_port
= BRBCNT(port
);
775 sts_port
= BRBSTS(port
);
776 } else if (rcbadr
>= c
->arphys
&& rcbadr
< c
->arphys
+DMABUFSZ
) {
778 len
= rcbadr
- c
->arphys
;
779 cnt_port
= ARBCNT(port
);
780 sts_port
= ARBSTS(port
);
782 kprintf ("cx%d.%d: timeout: invalid buffer address\n",
783 c
->board
->num
, c
->num
);
786 print (("cx%d.%d: async receive timeout (%d bytes), risr=%b, arbsts=%b, brbsts=%b\n",
787 c
->board
->num
, c
->num
, len
, risr
, RISA_BITS
,
788 inb (ARBSTS(port
)), BSTS_BITS
, inb (BRBSTS(port
)), BSTS_BITS
));
789 c
->stat
->ibytes
+= len
;
790 if (tp
&& (tp
->t_state
& TS_ISOPEN
)) {
792 int (*rint
)(int, struct tty
*) =
793 linesw
[tp
->t_line
].l_rint
;
795 for (i
=0; i
<len
; ++i
)
796 (*rint
) (buf
[i
], tp
);
799 /* Restart receiver. */
800 outw (cnt_port
, rbsz
);
801 outb (sts_port
, BSTS_OWN24
);
803 return (REOI_TERMBUFF
);
806 print (("cx%d.%d: async receive interrupt, risr=%b, arbsts=%b, brbsts=%b\n",
807 c
->board
->num
, c
->num
, risr
, RISA_BITS
,
808 inb (ARBSTS(port
)), BSTS_BITS
, inb (BRBSTS(port
)), BSTS_BITS
));
810 if (risr
& RIS_BUSERR
) {
811 kprintf ("cx%d.%d: receive bus error\n", c
->board
->num
, c
->num
);
814 if (risr
& (RIS_OVERRUN
| RISA_PARERR
| RISA_FRERR
| RISA_BREAK
)) {
817 if (risr
& RISA_PARERR
)
819 if (risr
& RISA_FRERR
)
822 if (risr
& RIS_OVERRUN
)
826 if (risr
& RISA_BREAK
)
829 print (("cx%d.%d: receive error %x\n", c
->board
->num
, c
->num
, err
));
830 if (tp
&& (tp
->t_state
& TS_ISOPEN
))
831 (*linesw
[tp
->t_line
].l_rint
) (err
, tp
);
835 /* Discard exception characters. */
836 if ((risr
& RISA_SCMASK
) && tp
&& (tp
->t_iflag
& IXON
))
837 reoir
|= REOI_DISCEXC
;
839 /* Handle received data. */
840 if ((risr
& RIS_EOBUF
) && tp
&& (tp
->t_state
& TS_ISOPEN
)) {
841 int (*rint
)(int, struct tty
*) = linesw
[tp
->t_line
].l_rint
;
845 len
= (risr
& RIS_BB
) ? inw(BRBCNT(port
)) : inw(ARBCNT(port
));
847 print (("cx%d.%d: async: %d bytes received\n",
848 c
->board
->num
, c
->num
, len
));
849 c
->stat
->ibytes
+= len
;
851 buf
= (risr
& RIS_BB
) ? c
->brbuf
: c
->arbuf
;
852 for (i
=0; i
<len
; ++i
)
853 (*rint
) (buf
[i
], tp
);
856 /* Restart receiver. */
857 if (! (inb (ARBSTS(port
)) & BSTS_OWN24
)) {
858 outw (ARBCNT(port
), rbsz
);
859 outb (ARBSTS(port
), BSTS_OWN24
);
861 if (! (inb (BRBSTS(port
)) & BSTS_OWN24
)) {
862 outw (BRBCNT(port
), rbsz
);
863 outb (BRBSTS(port
), BSTS_OWN24
);
869 * Handle transmit interrupt.
871 void cxtinta (cx_chan_t
*c
)
873 struct tty
*tp
= c
->ttyp
;
874 unsigned short port
= c
->chip
->port
;
875 unsigned char tisr
= inb (TISR(port
));
877 print (("cx%d.%d: async transmit interrupt, tisr=%b, atbsts=%b, btbsts=%b\n",
878 c
->board
->num
, c
->num
, tisr
, TIS_BITS
,
879 inb (ATBSTS(port
)), BSTS_BITS
, inb (BTBSTS(port
)), BSTS_BITS
));
881 if (tisr
& TIS_BUSERR
) {
882 kprintf ("cx%d.%d: transmit bus error\n",
883 c
->board
->num
, c
->num
);
885 } else if (tisr
& TIS_UNDERRUN
) {
886 kprintf ("cx%d.%d: transmit underrun error\n",
887 c
->board
->num
, c
->num
);
891 tp
->t_state
&= ~(TS_BUSY
| TS_FLUSH
);
893 (*linesw
[tp
->t_line
].l_start
) (tp
);
900 * Handle modem interrupt.
903 cxmint (cx_chan_t
*c
)
905 unsigned short port
= c
->chip
->port
;
906 unsigned char misr
= inb (MISR(port
));
907 unsigned char msvr
= inb (MSVR(port
));
908 struct tty
*tp
= c
->ttyp
;
910 if (c
->mode
!= M_ASYNC
) {
911 kprintf ("cx%d.%d: unexpected modem interrupt, misr=%b, msvr=%b\n",
912 c
->board
->num
, c
->num
, misr
, MIS_BITS
, msvr
, MSV_BITS
);
915 print (("cx%d.%d: modem interrupt, misr=%b, msvr=%b\n",
916 c
->board
->num
, c
->num
, misr
, MIS_BITS
, msvr
, MSV_BITS
));
918 /* Ignore DSR events. */
919 /* Ignore RTC/CTS events, handled by hardware. */
920 /* Handle carrier detect/loss. */
921 if (tp
&& (misr
& MIS_CCD
))
922 (*linesw
[tp
->t_line
].l_modem
) (tp
, (msvr
& MSV_CD
) != 0);
926 * Recover after lost transmit interrupts.
935 for (b
= cxboard
; b
< cxboard
+ NCX
; ++b
) {
936 for (c
= b
->chan
; c
< b
->chan
+ NCHAN
; ++c
) {
938 if (c
->type
== T_NONE
|| c
->mode
!= M_ASYNC
|| !tp
)
941 if (tp
->t_state
& TS_BUSY
) {
942 tp
->t_state
&= ~TS_BUSY
;
944 (*linesw
[tp
->t_line
].l_start
) (tp
);
951 callout_reset (&cxtimeout_ch
, hz
* 5, cxtimeout
, NULL
);
955 #if defined(__DragonFly__) || (defined(__FreeBSD__) && (__FreeBSD__ > 1 ))
959 cx_drvinit(void *unused
)
963 SYSINIT(cxdev
,SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR
,cx_drvinit
,NULL
)