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.9 2004/02/13 17:45:49 joerg 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>
52 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
53 #include <sys/callout.h>
56 #if defined (__NetBSD__) || defined (__OpenBSD__)
57 extern cc_t ttydefchars;
58 #define termioschars(t) memcpy((t)->c_cc, &ttydefchars, sizeof((t)->c_cc))
61 #if defined(__DragonFly__) || defined(__FreeBSD__)
64 #include <sys/devfsext.h>
67 #endif /* __FreeBSD__ */
70 #include <sys/filio.h>
73 #if defined(__DragonFly__) || defined(__FreeBSD__)
74 #include <net/i4b/include/machine/i4b_ioctl.h>
75 #include <net/i4b/include/machine/i4b_rbch_ioctl.h>
76 #include <net/i4b/include/machine/i4b_debug.h>
78 #include <i4b/i4b_ioctl.h>
79 #include <i4b/i4b_rbch_ioctl.h>
80 #include <i4b/i4b_debug.h>
83 #include "../include/i4b_global.h"
84 #include "../include/i4b_mbuf.h"
85 #include "../include/i4b_l3l4.h"
86 #include "../layer4/i4b_l4.h"
89 #include <sys/device.h>
93 #include <sys/ioccom.h>
96 #include <sys/fcntl.h>
97 #include <sys/ioctl.h>
100 #if defined(__DragonFly__) || defined(__FreeBSD__)
101 #include <sys/filio.h>
104 static drvr_link_t rbch_drvr_linktab[NI4BRBCH];
105 static isdn_link_t *isdn_linktab[NI4BRBCH];
107 #define I4BRBCHACCT 1 /* enable accounting messages */
108 #define I4BRBCHACCTINTVL 2 /* accounting msg interval in secs */
110 static struct rbch_softc {
112 int sc_unit; /* unit number */
114 int sc_devstate; /* state of driver */
116 #define ST_CONNECTED 0x01
117 #define ST_ISOPEN 0x02
118 #define ST_RDWAITDATA 0x04
119 #define ST_WRWAITEMPTY 0x08
120 #define ST_NOBLOCK 0x10
122 int sc_bprot; /* B-ch protocol used */
124 call_desc_t *sc_cd; /* Call Descriptor */
126 struct termios it_in;
128 struct ifqueue sc_hdlcq; /* hdlc read queue */
129 #define I4BRBCHMAXQLEN 10
131 struct selinfo selp; /* select / poll */
134 #if defined(__DragonFly__) || defined(__FreeBSD__)
135 struct callout_handle sc_callout;
137 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
138 struct callout sc_callout;
141 int sc_iinb; /* isdn driver # of inbytes */
142 int sc_ioutb; /* isdn driver # of outbytes */
143 int sc_linb; /* last # of bytes rx'd */
144 int sc_loutb; /* last # of bytes tx'd */
145 int sc_fn; /* flag, first null acct */
147 } rbch_softc[NI4BRBCH];
149 static void rbch_rx_data_rdy(int unit);
150 static void rbch_tx_queue_empty(int unit);
151 static void rbch_connect(int unit, void *cdp);
152 static void rbch_disconnect(int unit, void *cdp);
153 static void rbch_init_linktab(int unit);
154 static void rbch_clrq(int unit);
156 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
157 #define PDEVSTATIC /* - not static - */
158 #define IOCTL_CMD_T u_long
159 void i4brbchattach (void);
160 int i4brbchopen (dev_t dev, int flag, int fmt, struct proc *p);
161 int i4brbchclose (dev_t dev, int flag, int fmt, struct proc *p);
162 int i4brbchread (dev_t dev, struct uio *uio, int ioflag);
163 int i4brbchwrite (dev_t dev, struct uio *uio, int ioflag);
164 int i4brbchioctl (dev_t dev, IOCTL_CMD_T cmd, caddr_t arg, int flag, struct proc* pr);
166 int i4brbchpoll (dev_t dev, int events, struct proc *p);
168 PDEVSTATIC int i4brbchselect (dev_t dev, int rw, struct proc *p);
172 #if defined(__DragonFly__) || (BSD > 199306 && defined(__FreeBSD__))
173 #define PDEVSTATIC static
174 #define IOCTL_CMD_T u_long
176 PDEVSTATIC d_open_t i4brbchopen;
177 PDEVSTATIC d_close_t i4brbchclose;
178 PDEVSTATIC d_read_t i4brbchread;
179 PDEVSTATIC d_read_t i4brbchwrite;
180 PDEVSTATIC d_ioctl_t i4brbchioctl;
183 PDEVSTATIC d_poll_t i4brbchpoll;
184 #define POLLFIELD i4brbchpoll
186 PDEVSTATIC d_select_t i4brbchselect;
187 #define POLLFIELD i4brbchselect
190 #define CDEV_MAJOR 57
192 static struct cdevsw i4brbch_cdevsw = {
193 /* name */ "i4brbch",
194 /* maj */ CDEV_MAJOR,
199 /* open */ i4brbchopen,
200 /* close */ i4brbchclose,
201 /* read */ i4brbchread,
202 /* write */ i4brbchwrite,
203 /* ioctl */ i4brbchioctl,
204 /* poll */ POLLFIELD,
206 /* strategy */ nostrategy,
211 static void i4brbchattach(void *);
212 PSEUDO_SET(i4brbchattach, i4b_rbch);
214 /*===========================================================================*
215 * DEVICE DRIVER ROUTINES
216 *===========================================================================*/
218 /*---------------------------------------------------------------------------*
219 * initialization at kernel load time
220 *---------------------------------------------------------------------------*/
222 i4brbchinit(void *unused)
224 cdevsw_add(&i4brbch_cdevsw);
227 SYSINIT(i4brbchdev, SI_SUB_DRIVERS,
228 SI_ORDER_MIDDLE+CDEV_MAJOR, &i4brbchinit, NULL);
230 #endif /* BSD > 199306 && defined(__FreeBSD__) */
233 int i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux);
234 void dummy_i4brbchattach(struct device*, struct device *, void *);
236 #define CDEV_MAJOR 61
238 static struct cfdriver i4brbchcd =
239 { NULL, "i4brbch", i4brbchmatch, dummy_i4brbchattach, DV_DULL,
240 sizeof(struct cfdriver) };
241 struct devsw i4brbchsw =
243 i4brbchopen, i4brbchclose, i4brbchread, i4brbchwrite,
244 i4brbchioctl, seltrue, nommap, nostrat,
245 nodump, nopsize, 0, nostop
249 i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux)
251 printf("i4brbchmatch: aux=0x%x\n", aux);
255 dummy_i4brbchattach(struct device *parent, struct device *self, void *aux)
257 printf("dummy_i4brbchattach: aux=0x%x\n", aux);
259 #endif /* __bsdi__ */
261 /*---------------------------------------------------------------------------*
262 * interface attach routine
263 *---------------------------------------------------------------------------*/
265 #if defined(__DragonFly__) || defined(__FreeBSD__)
266 i4brbchattach(void *dummy)
273 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
274 printf("i4brbch: %d raw B channel access device(s) attached\n", NI4BRBCH);
277 for(i=0; i < NI4BRBCH; i++)
279 #if defined(__DragonFly__) || defined(__FreeBSD__)
280 make_dev(&i4brbch_cdevsw, i,
281 UID_ROOT, GID_WHEEL, 0600, "i4brbch%d", i);
285 #if defined(__DragonFly__) || defined(__FreeBSD__)
286 callout_handle_init(&rbch_softc[i].sc_callout);
288 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
289 callout_init(&rbch_softc[i].sc_callout);
291 rbch_softc[i].sc_fn = 1;
293 rbch_softc[i].sc_unit = i;
294 rbch_softc[i].sc_devstate = ST_IDLE;
295 rbch_softc[i].sc_hdlcq.ifq_maxlen = I4BRBCHMAXQLEN;
296 #if defined(__FreeBSD__) && __FreeBSD__ > 4
297 mtx_init(&rbch_softc[i].sc_hdlcq.ifq_mtx, "i4b_rbch", MTX_DEF);
299 rbch_softc[i].it_in.c_ispeed = rbch_softc[i].it_in.c_ospeed = 64000;
300 termioschars(&rbch_softc[i].it_in);
301 rbch_init_linktab(i);
305 /*---------------------------------------------------------------------------*
307 *---------------------------------------------------------------------------*/
309 i4brbchopen(dev_t dev, int flag, int fmt, struct thread *td)
311 int unit = minor(dev);
316 if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
323 rbch_softc[unit].sc_devstate |= ST_ISOPEN;
325 NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
330 /*---------------------------------------------------------------------------*
332 *---------------------------------------------------------------------------*/
334 i4brbchclose(dev_t dev, int flag, int fmt, struct thread *td)
336 int unit = minor(dev);
337 struct rbch_softc *sc = &rbch_softc[unit];
339 if(sc->sc_devstate & ST_CONNECTED)
340 i4b_l4_drvrdisc(BDRV_RBCH, unit);
342 sc->sc_devstate &= ~ST_ISOPEN;
346 NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
351 /*---------------------------------------------------------------------------*
352 * read from rbch device
353 *---------------------------------------------------------------------------*/
355 i4brbchread(dev_t dev, struct uio *uio, int ioflag)
359 int unit = minor(dev);
361 struct rbch_softc *sc = &rbch_softc[unit];
365 NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
368 if(!(sc->sc_devstate & ST_ISOPEN))
371 NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
375 if((sc->sc_devstate & ST_NOBLOCK))
377 if(!(sc->sc_devstate & ST_CONNECTED)) {
382 if(sc->sc_bprot == BPROT_RHDLC)
385 iqp = isdn_linktab[unit]->rx_queue;
387 if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
394 while(!(sc->sc_devstate & ST_CONNECTED))
396 NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
398 if((error = tsleep((caddr_t) &rbch_softc[unit],
399 PCATCH, "rrrbch", 0 )) != 0)
402 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep", unit, error);
407 if(sc->sc_bprot == BPROT_RHDLC)
410 iqp = isdn_linktab[unit]->rx_queue;
412 while(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
414 sc->sc_devstate |= ST_RDWAITDATA;
416 NDBGL4(L4_RBCHDBG, "unit %d, wait read data", unit);
418 if((error = tsleep((caddr_t) &isdn_linktab[unit]->rx_queue,
419 PCATCH, "rrbch", 0 )) != 0)
422 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep read", unit, error);
423 sc->sc_devstate &= ~ST_RDWAITDATA;
431 NDBGL4(L4_RBCHDBG, "unit %d, read %d bytes", unit, m->m_len);
435 error = uiomove(m->m_data, m->m_len, uio);
439 NDBGL4(L4_RBCHDBG, "unit %d, error %d uiomove", unit, error);
451 /*---------------------------------------------------------------------------*
452 * write to rbch device
453 *---------------------------------------------------------------------------*/
455 i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
459 int unit = minor(dev);
460 struct rbch_softc *sc = &rbch_softc[unit];
464 NDBGL4(L4_RBCHDBG, "unit %d, write", unit);
467 if(!(sc->sc_devstate & ST_ISOPEN))
469 NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit);
474 if((sc->sc_devstate & ST_NOBLOCK))
476 if(!(sc->sc_devstate & ST_CONNECTED)) {
480 if(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) {
487 while(!(sc->sc_devstate & ST_CONNECTED))
489 NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit);
491 error = tsleep((caddr_t) &rbch_softc[unit],
492 PCATCH, "wrrbch", 0 );
493 if(error == ERESTART) {
497 else if(error == EINTR)
500 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit);
506 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error);
509 tsleep((caddr_t) &rbch_softc[unit], PCATCH, "xrbch", (hz*1));
512 while(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
514 sc->sc_devstate |= ST_WRWAITEMPTY;
516 NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit);
518 if ((error = tsleep((caddr_t) &isdn_linktab[unit]->tx_queue,
519 PCATCH, "wrbch", 0)) != 0) {
520 sc->sc_devstate &= ~ST_WRWAITEMPTY;
521 if(error == ERESTART)
526 else if(error == EINTR)
529 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
535 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
542 if(!(sc->sc_devstate & ST_ISOPEN))
544 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
549 if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
551 m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
553 NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
555 error = uiomove(m->m_data, m->m_len, uio);
557 #if defined (__FreeBSD__) && __FreeBSD__ > 4
558 (void) IF_HANDOFF(isdn_linktab[unit]->tx_queue, m, NULL);
560 if(IF_QFULL(isdn_linktab[unit]->tx_queue))
563 IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
565 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
573 /*---------------------------------------------------------------------------*
574 * rbch device ioctl handlibg
575 *---------------------------------------------------------------------------*/
577 i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct thread *td)
580 int unit = minor(dev);
581 struct rbch_softc *sc = &rbch_softc[unit];
585 case FIOASYNC: /* Set async mode */
588 NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
592 NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
599 NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
600 sc->sc_devstate |= ST_NOBLOCK;
604 NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
605 sc->sc_devstate &= ~ST_NOBLOCK;
609 case TIOCCDTR: /* Clear DTR */
610 if(sc->sc_devstate & ST_CONNECTED)
612 NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
613 i4b_l4_drvrdisc(BDRV_RBCH, unit);
617 case I4B_RBCH_DIALOUT:
621 for (l = 0; l < TELNO_MAX && ((char *)data)[l]; l++)
625 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
626 i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
629 /* fall through to SDTR */
632 case TIOCSDTR: /* Set DTR */
633 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
634 i4b_l4_dialout(BDRV_RBCH, unit);
637 case TIOCSETA: /* Set termios struct */
640 case TIOCGETA: /* Get termios struct */
641 *(struct termios *)data = sc->it_in;
645 *(int *)data = TIOCM_LE|TIOCM_DTR|TIOCM_RTS|TIOCM_CTS|TIOCM_DSR;
646 if (sc->sc_devstate & ST_CONNECTED)
647 *(int *)data |= TIOCM_CD;
650 case I4B_RBCH_VR_REQ:
654 mvr = (msg_vr_req_t *)data;
656 mvr->version = VERSION;
662 default: /* Unknown stuff */
663 NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
672 /*---------------------------------------------------------------------------*
674 *---------------------------------------------------------------------------*/
676 i4brbchpoll(dev_t dev, int events, struct thread *td)
678 int revents = 0; /* Events we found */
680 int unit = minor(dev);
681 struct rbch_softc *sc = &rbch_softc[unit];
683 /* We can't check for anything but IN or OUT */
687 if(!(sc->sc_devstate & ST_ISOPEN))
694 * Writes are OK if we are connected and the
695 * transmit queue can take them
698 if((events & (POLLOUT|POLLWRNORM)) &&
699 (sc->sc_devstate & ST_CONNECTED) &&
700 !_IF_QFULL(isdn_linktab[unit]->tx_queue))
702 revents |= (events & (POLLOUT|POLLWRNORM));
705 /* ... while reads are OK if we have any data */
707 if((events & (POLLIN|POLLRDNORM)) &&
708 (sc->sc_devstate & ST_CONNECTED))
712 if(sc->sc_bprot == BPROT_RHDLC)
715 iqp = isdn_linktab[unit]->rx_queue;
718 revents |= (events & (POLLIN|POLLRDNORM));
722 selrecord(td, &sc->selp);
728 #else /* OS_USES_POLL */
730 /*---------------------------------------------------------------------------*
731 * device driver select
732 *---------------------------------------------------------------------------*/
734 i4brbchselect(dev_t dev, int rw, struct thread *td)
736 int unit = minor(dev);
737 struct rbch_softc *sc = &rbch_softc[unit];
742 if(!(sc->sc_devstate & ST_ISOPEN))
745 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
749 if(sc->sc_devstate & ST_CONNECTED)
756 if(sc->sc_bprot == BPROT_RHDLC)
759 iqp = isdn_linktab[unit]->rx_queue;
769 if(!_IF_QFULL(isdn_linktab[unit]->rx_queue))
781 selrecord(p, &sc->selp);
786 #endif /* OS_USES_POLL */
789 /*---------------------------------------------------------------------------*
791 *---------------------------------------------------------------------------*/
793 rbch_timeout(struct rbch_softc *sc)
795 bchan_statistics_t bs;
796 int unit = sc->sc_unit;
798 /* get # of bytes in and out from the HSCX driver */
800 (*isdn_linktab[unit]->bch_stat)
801 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
803 sc->sc_ioutb += bs.outbytes;
804 sc->sc_iinb += bs.inbytes;
806 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
808 int ri = (sc->sc_iinb - sc->sc_linb)/I4BRBCHACCTINTVL;
809 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BRBCHACCTINTVL;
811 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
816 sc->sc_linb = sc->sc_iinb;
817 sc->sc_loutb = sc->sc_ioutb;
819 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
820 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
822 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
824 #endif /* I4BRBCHACCT */
826 /*===========================================================================*
827 * ISDN INTERFACE ROUTINES
828 *===========================================================================*/
830 /*---------------------------------------------------------------------------*
831 * this routine is called from L4 handler at connect time
832 *---------------------------------------------------------------------------*/
834 rbch_connect(int unit, void *cdp)
836 call_desc_t *cd = (call_desc_t *)cdp;
837 struct rbch_softc *sc = &rbch_softc[unit];
839 sc->sc_bprot = cd->bprot;
842 if(sc->sc_bprot == BPROT_RHDLC)
849 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
852 if(!(sc->sc_devstate & ST_CONNECTED))
854 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
855 sc->sc_devstate |= ST_CONNECTED;
861 /*---------------------------------------------------------------------------*
862 * this routine is called from L4 handler at disconnect time
863 *---------------------------------------------------------------------------*/
865 rbch_disconnect(int unit, void *cdp)
867 call_desc_t *cd = (call_desc_t *)cdp;
868 struct rbch_softc *sc = &rbch_softc[unit];
874 NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
875 cd->driver_unit, cd->channelid);
881 NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
883 sc->sc_devstate &= ~ST_CONNECTED;
888 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
889 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
891 STOP_TIMER(sc->sc_callout, rbch_timeout, sc);
896 /*---------------------------------------------------------------------------*
897 * feedback from daemon in case of dial problems
898 *---------------------------------------------------------------------------*/
900 rbch_dialresponse(int unit, int status, cause_t cause)
904 /*---------------------------------------------------------------------------*
906 *---------------------------------------------------------------------------*/
908 rbch_updown(int unit, int updown)
912 /*---------------------------------------------------------------------------*
913 * this routine is called from the HSCX interrupt handler
914 * when a new frame (mbuf) has been received and is to be put on
916 *---------------------------------------------------------------------------*/
918 rbch_rx_data_rdy(int unit)
920 if(rbch_softc[unit].sc_bprot == BPROT_RHDLC)
924 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
927 m->m_pkthdr.len = m->m_len;
929 #if defined (__FreeBSD__) && __FreeBSD__ > 4
930 if (! IF_HANDOFF(&(rbch_softc[unit].sc_hdlcq), m, NULL))
932 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
935 if(IF_QFULL(&(rbch_softc[unit].sc_hdlcq)))
937 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
942 IF_ENQUEUE(&(rbch_softc[unit].sc_hdlcq), m);
947 if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
949 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
950 rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
951 wakeup((caddr_t) &isdn_linktab[unit]->rx_queue);
955 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
957 selwakeup(&rbch_softc[unit].selp);
960 /*---------------------------------------------------------------------------*
961 * this routine is called from the HSCX interrupt handler
962 * when the last frame has been sent out and there is no
963 * further frame (mbuf) in the tx queue.
964 *---------------------------------------------------------------------------*/
966 rbch_tx_queue_empty(int unit)
968 if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
970 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
971 rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
972 wakeup((caddr_t) &isdn_linktab[unit]->tx_queue);
976 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
978 selwakeup(&rbch_softc[unit].selp);
981 /*---------------------------------------------------------------------------*
982 * this routine is called from the HSCX interrupt handler
983 * each time a packet is received or transmitted
984 *---------------------------------------------------------------------------*/
986 rbch_activity(int unit, int rxtx)
988 if (rbch_softc[unit].sc_cd)
989 rbch_softc[unit].sc_cd->last_active_time = SECOND;
990 selwakeup(&rbch_softc[unit].selp);
993 /*---------------------------------------------------------------------------*
994 * clear an hdlc rx queue for a rbch unit
995 *---------------------------------------------------------------------------*/
1001 #if defined (__FreeBSD__) && __FreeBSD__ > 4
1003 IF_DRAIN(&rbch_softc[unit].sc_hdlcq);
1010 IF_DEQUEUE(&rbch_softc[unit].sc_hdlcq, m);
1021 /*---------------------------------------------------------------------------*
1022 * return this drivers linktab address
1023 *---------------------------------------------------------------------------*/
1025 rbch_ret_linktab(int unit)
1027 rbch_init_linktab(unit);
1028 return(&rbch_drvr_linktab[unit]);
1031 /*---------------------------------------------------------------------------*
1032 * setup the isdn_linktab for this driver
1033 *---------------------------------------------------------------------------*/
1035 rbch_set_linktab(int unit, isdn_link_t *ilt)
1037 isdn_linktab[unit] = ilt;
1040 /*---------------------------------------------------------------------------*
1041 * initialize this drivers linktab
1042 *---------------------------------------------------------------------------*/
1044 rbch_init_linktab(int unit)
1046 rbch_drvr_linktab[unit].unit = unit;
1047 rbch_drvr_linktab[unit].bch_rx_data_ready = rbch_rx_data_rdy;
1048 rbch_drvr_linktab[unit].bch_tx_queue_empty = rbch_tx_queue_empty;
1049 rbch_drvr_linktab[unit].bch_activity = rbch_activity;
1050 rbch_drvr_linktab[unit].line_connected = rbch_connect;
1051 rbch_drvr_linktab[unit].line_disconnected = rbch_disconnect;
1052 rbch_drvr_linktab[unit].dial_response = rbch_dialresponse;
1053 rbch_drvr_linktab[unit].updown_ind = rbch_updown;
1056 /*===========================================================================*/
1058 #endif /* NI4BRBCH > 0 */