2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b_rbch.c - device driver for raw B channel data
28 * ---------------------------------------------------
30 * $FreeBSD: src/sys/i4b/driver/i4b_rbch.c,v 1.10.2.3 2001/08/12 16:22:48 hm Exp $
31 * $DragonFly: src/sys/net/i4b/driver/i4b_rbch.c,v 1.14 2005/06/03 16:49:57 dillon Exp $
33 * last edit-date: [Sat Aug 11 18:06:57 2001]
35 *---------------------------------------------------------------------------*/
37 #include "use_i4brbch.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
46 #include <sys/kernel.h>
48 #include <sys/socket.h>
51 #include <sys/thread2.h>
53 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
54 #include <sys/callout.h>
57 #if defined (__NetBSD__) || defined (__OpenBSD__)
58 extern cc_t ttydefchars;
59 #define termioschars(t) memcpy((t)->c_cc, &ttydefchars, sizeof((t)->c_cc))
62 #if defined(__DragonFly__) || defined(__FreeBSD__)
65 #include <sys/devfsext.h>
68 #endif /* __FreeBSD__ */
71 #include <sys/filio.h>
74 #if defined(__DragonFly__) || defined(__FreeBSD__)
75 #include <net/i4b/include/machine/i4b_ioctl.h>
76 #include <net/i4b/include/machine/i4b_rbch_ioctl.h>
77 #include <net/i4b/include/machine/i4b_debug.h>
79 #include <i4b/i4b_ioctl.h>
80 #include <i4b/i4b_rbch_ioctl.h>
81 #include <i4b/i4b_debug.h>
84 #include "../include/i4b_global.h"
85 #include "../include/i4b_mbuf.h"
86 #include "../include/i4b_l3l4.h"
87 #include "../layer4/i4b_l4.h"
90 #include <sys/device.h>
94 #include <sys/ioccom.h>
97 #include <sys/fcntl.h>
98 #include <sys/ioctl.h>
101 #if defined(__DragonFly__) || defined(__FreeBSD__)
102 #include <sys/filio.h>
105 static drvr_link_t rbch_drvr_linktab[NI4BRBCH];
106 static isdn_link_t *isdn_linktab[NI4BRBCH];
108 #define I4BRBCHACCT 1 /* enable accounting messages */
109 #define I4BRBCHACCTINTVL 2 /* accounting msg interval in secs */
111 static struct rbch_softc {
113 int sc_unit; /* unit number */
115 int sc_devstate; /* state of driver */
117 #define ST_CONNECTED 0x01
118 #define ST_ISOPEN 0x02
119 #define ST_RDWAITDATA 0x04
120 #define ST_WRWAITEMPTY 0x08
121 #define ST_NOBLOCK 0x10
123 int sc_bprot; /* B-ch protocol used */
125 call_desc_t *sc_cd; /* Call Descriptor */
127 struct termios it_in;
129 struct ifqueue sc_hdlcq; /* hdlc read queue */
130 #define I4BRBCHMAXQLEN 10
132 struct selinfo selp; /* select / poll */
135 struct callout sc_timeout;
137 int sc_iinb; /* isdn driver # of inbytes */
138 int sc_ioutb; /* isdn driver # of outbytes */
139 int sc_linb; /* last # of bytes rx'd */
140 int sc_loutb; /* last # of bytes tx'd */
141 int sc_fn; /* flag, first null acct */
143 } rbch_softc[NI4BRBCH];
145 static void rbch_rx_data_rdy(int unit);
146 static void rbch_tx_queue_empty(int unit);
147 static void rbch_connect(int unit, void *cdp);
148 static void rbch_disconnect(int unit, void *cdp);
149 static void rbch_init_linktab(int unit);
150 static void rbch_clrq(int unit);
152 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
153 #define PDEVSTATIC /* - not static - */
154 #define IOCTL_CMD_T u_long
155 void i4brbchattach (void);
156 int i4brbchopen (dev_t dev, int flag, int fmt, struct proc *p);
157 int i4brbchclose (dev_t dev, int flag, int fmt, struct proc *p);
158 int i4brbchread (dev_t dev, struct uio *uio, int ioflag);
159 int i4brbchwrite (dev_t dev, struct uio *uio, int ioflag);
160 int i4brbchioctl (dev_t dev, IOCTL_CMD_T cmd, caddr_t arg, int flag, struct proc* pr);
162 int i4brbchpoll (dev_t dev, int events, struct proc *p);
164 PDEVSTATIC int i4brbchselect (dev_t dev, int rw, struct proc *p);
168 #if defined(__DragonFly__) || (BSD > 199306 && defined(__FreeBSD__))
169 #define PDEVSTATIC static
170 #define IOCTL_CMD_T u_long
172 PDEVSTATIC d_open_t i4brbchopen;
173 PDEVSTATIC d_close_t i4brbchclose;
174 PDEVSTATIC d_read_t i4brbchread;
175 PDEVSTATIC d_read_t i4brbchwrite;
176 PDEVSTATIC d_ioctl_t i4brbchioctl;
179 PDEVSTATIC d_poll_t i4brbchpoll;
180 #define POLLFIELD i4brbchpoll
182 PDEVSTATIC d_select_t i4brbchselect;
183 #define POLLFIELD i4brbchselect
186 #define CDEV_MAJOR 57
188 static struct cdevsw i4brbch_cdevsw = {
189 /* name */ "i4brbch",
190 /* maj */ CDEV_MAJOR,
195 /* open */ i4brbchopen,
196 /* close */ i4brbchclose,
197 /* read */ i4brbchread,
198 /* write */ i4brbchwrite,
199 /* ioctl */ i4brbchioctl,
200 /* poll */ POLLFIELD,
202 /* strategy */ nostrategy,
207 static void i4brbchattach(void *);
208 PSEUDO_SET(i4brbchattach, i4b_rbch);
210 /*===========================================================================*
211 * DEVICE DRIVER ROUTINES
212 *===========================================================================*/
214 /*---------------------------------------------------------------------------*
215 * initialization at kernel load time
216 *---------------------------------------------------------------------------*/
218 i4brbchinit(void *unused)
220 cdevsw_add(&i4brbch_cdevsw, 0, 0);
223 SYSINIT(i4brbchdev, SI_SUB_DRIVERS,
224 SI_ORDER_MIDDLE+CDEV_MAJOR, &i4brbchinit, NULL);
226 #endif /* BSD > 199306 && defined(__FreeBSD__) */
229 int i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux);
230 void dummy_i4brbchattach(struct device*, struct device *, void *);
232 #define CDEV_MAJOR 61
234 static struct cfdriver i4brbchcd =
235 { NULL, "i4brbch", i4brbchmatch, dummy_i4brbchattach, DV_DULL,
236 sizeof(struct cfdriver) };
237 struct devsw i4brbchsw =
239 i4brbchopen, i4brbchclose, i4brbchread, i4brbchwrite,
240 i4brbchioctl, seltrue, nommap, nostrat,
241 nodump, nopsize, 0, nostop
245 i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux)
247 printf("i4brbchmatch: aux=0x%x\n", aux);
251 dummy_i4brbchattach(struct device *parent, struct device *self, void *aux)
253 printf("dummy_i4brbchattach: aux=0x%x\n", aux);
255 #endif /* __bsdi__ */
257 /*---------------------------------------------------------------------------*
258 * interface attach routine
259 *---------------------------------------------------------------------------*/
261 #if defined(__DragonFly__) || defined(__FreeBSD__)
262 i4brbchattach(void *dummy)
269 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
270 printf("i4brbch: %d raw B channel access device(s) attached\n", NI4BRBCH);
273 for(i=0; i < NI4BRBCH; i++)
275 #if defined(__DragonFly__) || defined(__FreeBSD__)
276 make_dev(&i4brbch_cdevsw, i,
277 UID_ROOT, GID_WHEEL, 0600, "i4brbch%d", i);
281 callout_init(&rbch_softc[i].sc_timeout);
282 rbch_softc[i].sc_fn = 1;
284 rbch_softc[i].sc_unit = i;
285 rbch_softc[i].sc_devstate = ST_IDLE;
286 rbch_softc[i].sc_hdlcq.ifq_maxlen = I4BRBCHMAXQLEN;
287 #if defined(__FreeBSD__) && __FreeBSD__ > 4
288 mtx_init(&rbch_softc[i].sc_hdlcq.ifq_mtx, "i4b_rbch", MTX_DEF);
290 rbch_softc[i].it_in.c_ispeed = rbch_softc[i].it_in.c_ospeed = 64000;
291 termioschars(&rbch_softc[i].it_in);
292 rbch_init_linktab(i);
296 /*---------------------------------------------------------------------------*
298 *---------------------------------------------------------------------------*/
300 i4brbchopen(dev_t dev, int flag, int fmt, struct thread *td)
302 int unit = minor(dev);
307 if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
314 rbch_softc[unit].sc_devstate |= ST_ISOPEN;
316 NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
321 /*---------------------------------------------------------------------------*
323 *---------------------------------------------------------------------------*/
325 i4brbchclose(dev_t dev, int flag, int fmt, struct thread *td)
327 int unit = minor(dev);
328 struct rbch_softc *sc = &rbch_softc[unit];
330 if(sc->sc_devstate & ST_CONNECTED)
331 i4b_l4_drvrdisc(BDRV_RBCH, unit);
333 sc->sc_devstate &= ~ST_ISOPEN;
337 NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
342 /*---------------------------------------------------------------------------*
343 * read from rbch device
344 *---------------------------------------------------------------------------*/
346 i4brbchread(dev_t dev, struct uio *uio, int ioflag)
350 int unit = minor(dev);
352 struct rbch_softc *sc = &rbch_softc[unit];
356 NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
359 if(!(sc->sc_devstate & ST_ISOPEN))
362 NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
366 if((sc->sc_devstate & ST_NOBLOCK))
368 if(!(sc->sc_devstate & ST_CONNECTED)) {
373 if(sc->sc_bprot == BPROT_RHDLC)
376 iqp = isdn_linktab[unit]->rx_queue;
378 if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
385 while(!(sc->sc_devstate & ST_CONNECTED))
387 NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
389 if((error = tsleep((caddr_t) &rbch_softc[unit],
390 PCATCH, "rrrbch", 0 )) != 0)
393 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep", unit, error);
398 if(sc->sc_bprot == BPROT_RHDLC)
401 iqp = isdn_linktab[unit]->rx_queue;
403 while(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
405 sc->sc_devstate |= ST_RDWAITDATA;
407 NDBGL4(L4_RBCHDBG, "unit %d, wait read data", unit);
409 if((error = tsleep((caddr_t) &isdn_linktab[unit]->rx_queue,
410 PCATCH, "rrbch", 0 )) != 0)
413 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep read", unit, error);
414 sc->sc_devstate &= ~ST_RDWAITDATA;
422 NDBGL4(L4_RBCHDBG, "unit %d, read %d bytes", unit, m->m_len);
426 error = uiomove(m->m_data, m->m_len, uio);
430 NDBGL4(L4_RBCHDBG, "unit %d, error %d uiomove", unit, error);
442 /*---------------------------------------------------------------------------*
443 * write to rbch device
444 *---------------------------------------------------------------------------*/
446 i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
450 int unit = minor(dev);
451 struct rbch_softc *sc = &rbch_softc[unit];
455 NDBGL4(L4_RBCHDBG, "unit %d, write", unit);
458 if(!(sc->sc_devstate & ST_ISOPEN))
460 NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit);
465 if((sc->sc_devstate & ST_NOBLOCK))
467 if(!(sc->sc_devstate & ST_CONNECTED)) {
471 if(IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) {
478 while(!(sc->sc_devstate & ST_CONNECTED))
480 NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit);
482 error = tsleep((caddr_t) &rbch_softc[unit],
483 PCATCH, "wrrbch", 0 );
484 if(error == ERESTART) {
488 else if(error == EINTR)
491 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit);
497 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error);
500 tsleep((caddr_t) &rbch_softc[unit], PCATCH, "xrbch", (hz*1));
503 while(IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
505 sc->sc_devstate |= ST_WRWAITEMPTY;
507 NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit);
509 if ((error = tsleep((caddr_t) &isdn_linktab[unit]->tx_queue,
510 PCATCH, "wrbch", 0)) != 0) {
511 sc->sc_devstate &= ~ST_WRWAITEMPTY;
512 if(error == ERESTART)
517 else if(error == EINTR)
520 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
526 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
533 if(!(sc->sc_devstate & ST_ISOPEN))
535 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
540 if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
542 m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
544 NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
546 error = uiomove(m->m_data, m->m_len, uio);
548 #if defined (__FreeBSD__) && __FreeBSD__ > 4
549 (void) IF_HANDOFF(isdn_linktab[unit]->tx_queue, m, NULL);
551 if(IF_QFULL(isdn_linktab[unit]->tx_queue))
554 IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
556 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
564 /*---------------------------------------------------------------------------*
565 * rbch device ioctl handlibg
566 *---------------------------------------------------------------------------*/
568 i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct thread *td)
571 int unit = minor(dev);
572 struct rbch_softc *sc = &rbch_softc[unit];
576 case FIOASYNC: /* Set async mode */
579 NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
583 NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
590 NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
591 sc->sc_devstate |= ST_NOBLOCK;
595 NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
596 sc->sc_devstate &= ~ST_NOBLOCK;
600 case TIOCCDTR: /* Clear DTR */
601 if(sc->sc_devstate & ST_CONNECTED)
603 NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
604 i4b_l4_drvrdisc(BDRV_RBCH, unit);
608 case I4B_RBCH_DIALOUT:
612 for (l = 0; l < TELNO_MAX && ((char *)data)[l]; l++)
616 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
617 i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
620 /* fall through to SDTR */
623 case TIOCSDTR: /* Set DTR */
624 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
625 i4b_l4_dialout(BDRV_RBCH, unit);
628 case TIOCSETA: /* Set termios struct */
631 case TIOCGETA: /* Get termios struct */
632 *(struct termios *)data = sc->it_in;
636 *(int *)data = TIOCM_LE|TIOCM_DTR|TIOCM_RTS|TIOCM_CTS|TIOCM_DSR;
637 if (sc->sc_devstate & ST_CONNECTED)
638 *(int *)data |= TIOCM_CD;
641 case I4B_RBCH_VR_REQ:
645 mvr = (msg_vr_req_t *)data;
647 mvr->version = VERSION;
653 default: /* Unknown stuff */
654 NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
663 /*---------------------------------------------------------------------------*
665 *---------------------------------------------------------------------------*/
667 i4brbchpoll(dev_t dev, int events, struct thread *td)
669 int revents = 0; /* Events we found */
671 int unit = minor(dev);
672 struct rbch_softc *sc = &rbch_softc[unit];
674 /* We can't check for anything but IN or OUT */
678 if(!(sc->sc_devstate & ST_ISOPEN))
685 * Writes are OK if we are connected and the
686 * transmit queue can take them
689 if((events & (POLLOUT|POLLWRNORM)) &&
690 (sc->sc_devstate & ST_CONNECTED) &&
691 !IF_QFULL(isdn_linktab[unit]->tx_queue))
693 revents |= (events & (POLLOUT|POLLWRNORM));
696 /* ... while reads are OK if we have any data */
698 if((events & (POLLIN|POLLRDNORM)) &&
699 (sc->sc_devstate & ST_CONNECTED))
703 if(sc->sc_bprot == BPROT_RHDLC)
706 iqp = isdn_linktab[unit]->rx_queue;
709 revents |= (events & (POLLIN|POLLRDNORM));
713 selrecord(td, &sc->selp);
719 #else /* OS_USES_POLL */
721 /*---------------------------------------------------------------------------*
722 * device driver select
723 *---------------------------------------------------------------------------*/
725 i4brbchselect(dev_t dev, int rw, struct thread *td)
727 int unit = minor(dev);
728 struct rbch_softc *sc = &rbch_softc[unit];
733 if(!(sc->sc_devstate & ST_ISOPEN))
736 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
740 if(sc->sc_devstate & ST_CONNECTED)
747 if(sc->sc_bprot == BPROT_RHDLC)
750 iqp = isdn_linktab[unit]->rx_queue;
760 if(!IF_QFULL(isdn_linktab[unit]->rx_queue))
772 selrecord(p, &sc->selp);
777 #endif /* OS_USES_POLL */
780 /*---------------------------------------------------------------------------*
782 *---------------------------------------------------------------------------*/
784 rbch_timeout(struct rbch_softc *sc)
786 bchan_statistics_t bs;
787 int unit = sc->sc_unit;
789 /* get # of bytes in and out from the HSCX driver */
791 (*isdn_linktab[unit]->bch_stat)
792 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
794 sc->sc_ioutb += bs.outbytes;
795 sc->sc_iinb += bs.inbytes;
797 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
799 int ri = (sc->sc_iinb - sc->sc_linb)/I4BRBCHACCTINTVL;
800 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BRBCHACCTINTVL;
802 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
807 sc->sc_linb = sc->sc_iinb;
808 sc->sc_loutb = sc->sc_ioutb;
810 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
811 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
813 callout_reset(&sc->sc_timeout, I4BRBCHACCTINTVL * hz,
814 (void *)rbch_timeout, sc);
816 #endif /* I4BRBCHACCT */
818 /*===========================================================================*
819 * ISDN INTERFACE ROUTINES
820 *===========================================================================*/
822 /*---------------------------------------------------------------------------*
823 * this routine is called from L4 handler at connect time
824 *---------------------------------------------------------------------------*/
826 rbch_connect(int unit, void *cdp)
828 call_desc_t *cd = (call_desc_t *)cdp;
829 struct rbch_softc *sc = &rbch_softc[unit];
831 sc->sc_bprot = cd->bprot;
834 if(sc->sc_bprot == BPROT_RHDLC)
841 callout_reset(&sc->sc_timeout, I4BRBCHACCTINTVL * hz,
842 (void *)rbch_timeout, sc);
845 if(!(sc->sc_devstate & ST_CONNECTED))
847 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
848 sc->sc_devstate |= ST_CONNECTED;
854 /*---------------------------------------------------------------------------*
855 * this routine is called from L4 handler at disconnect time
856 *---------------------------------------------------------------------------*/
858 rbch_disconnect(int unit, void *cdp)
860 call_desc_t *cd = (call_desc_t *)cdp;
861 struct rbch_softc *sc = &rbch_softc[unit];
867 NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
868 cd->driver_unit, cd->channelid);
874 NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
876 sc->sc_devstate &= ~ST_CONNECTED;
881 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
882 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
883 callout_stop(&sc->sc_timeout);
888 /*---------------------------------------------------------------------------*
889 * feedback from daemon in case of dial problems
890 *---------------------------------------------------------------------------*/
892 rbch_dialresponse(int unit, int status, cause_t cause)
896 /*---------------------------------------------------------------------------*
898 *---------------------------------------------------------------------------*/
900 rbch_updown(int unit, int updown)
904 /*---------------------------------------------------------------------------*
905 * this routine is called from the HSCX interrupt handler
906 * when a new frame (mbuf) has been received and is to be put on
908 *---------------------------------------------------------------------------*/
910 rbch_rx_data_rdy(int unit)
912 if(rbch_softc[unit].sc_bprot == BPROT_RHDLC)
916 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
919 m->m_pkthdr.len = m->m_len;
921 #if defined (__FreeBSD__) && __FreeBSD__ > 4
922 if (! IF_HANDOFF(&(rbch_softc[unit].sc_hdlcq), m, NULL))
924 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
927 if(IF_QFULL(&(rbch_softc[unit].sc_hdlcq)))
929 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
934 IF_ENQUEUE(&(rbch_softc[unit].sc_hdlcq), m);
939 if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
941 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
942 rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
943 wakeup((caddr_t) &isdn_linktab[unit]->rx_queue);
947 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
949 selwakeup(&rbch_softc[unit].selp);
952 /*---------------------------------------------------------------------------*
953 * this routine is called from the HSCX interrupt handler
954 * when the last frame has been sent out and there is no
955 * further frame (mbuf) in the tx queue.
956 *---------------------------------------------------------------------------*/
958 rbch_tx_queue_empty(int unit)
960 if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
962 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
963 rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
964 wakeup((caddr_t) &isdn_linktab[unit]->tx_queue);
968 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
970 selwakeup(&rbch_softc[unit].selp);
973 /*---------------------------------------------------------------------------*
974 * this routine is called from the HSCX interrupt handler
975 * each time a packet is received or transmitted
976 *---------------------------------------------------------------------------*/
978 rbch_activity(int unit, int rxtx)
980 if (rbch_softc[unit].sc_cd)
981 rbch_softc[unit].sc_cd->last_active_time = SECOND;
982 selwakeup(&rbch_softc[unit].selp);
985 /*---------------------------------------------------------------------------*
986 * clear an hdlc rx queue for a rbch unit
987 *---------------------------------------------------------------------------*/
993 #if defined (__FreeBSD__) && __FreeBSD__ > 4
995 IF_DRAIN(&rbch_softc[unit].sc_hdlcq);
1002 IF_DEQUEUE(&rbch_softc[unit].sc_hdlcq, m);
1013 /*---------------------------------------------------------------------------*
1014 * return this drivers linktab address
1015 *---------------------------------------------------------------------------*/
1017 rbch_ret_linktab(int unit)
1019 rbch_init_linktab(unit);
1020 return(&rbch_drvr_linktab[unit]);
1023 /*---------------------------------------------------------------------------*
1024 * setup the isdn_linktab for this driver
1025 *---------------------------------------------------------------------------*/
1027 rbch_set_linktab(int unit, isdn_link_t *ilt)
1029 isdn_linktab[unit] = ilt;
1032 /*---------------------------------------------------------------------------*
1033 * initialize this drivers linktab
1034 *---------------------------------------------------------------------------*/
1036 rbch_init_linktab(int unit)
1038 rbch_drvr_linktab[unit].unit = unit;
1039 rbch_drvr_linktab[unit].bch_rx_data_ready = rbch_rx_data_rdy;
1040 rbch_drvr_linktab[unit].bch_tx_queue_empty = rbch_tx_queue_empty;
1041 rbch_drvr_linktab[unit].bch_activity = rbch_activity;
1042 rbch_drvr_linktab[unit].line_connected = rbch_connect;
1043 rbch_drvr_linktab[unit].line_disconnected = rbch_disconnect;
1044 rbch_drvr_linktab[unit].dial_response = rbch_dialresponse;
1045 rbch_drvr_linktab[unit].updown_ind = rbch_updown;
1048 /*===========================================================================*/
1050 #endif /* NI4BRBCH > 0 */