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.4 2003/07/21 05:50:42 dillon Exp $
33 * last edit-date: [Sat Aug 11 18:06:57 2001]
35 *---------------------------------------------------------------------------*/
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))
64 #include <sys/devfsext.h>
67 #endif /* __FreeBSD__ */
70 #include <sys/filio.h>
74 #include <machine/i4b_ioctl.h>
75 #include <machine/i4b_rbch_ioctl.h>
76 #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 <i4b/include/i4b_global.h>
84 #include <i4b/include/i4b_mbuf.h>
85 #include <i4b/include/i4b_l3l4.h>
87 #include <i4b/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(__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 #if defined(__FreeBSD__)
136 struct callout_handle sc_callout;
138 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
139 struct callout sc_callout;
142 int sc_iinb; /* isdn driver # of inbytes */
143 int sc_ioutb; /* isdn driver # of outbytes */
144 int sc_linb; /* last # of bytes rx'd */
145 int sc_loutb; /* last # of bytes tx'd */
146 int sc_fn; /* flag, first null acct */
148 } rbch_softc[NI4BRBCH];
150 static void rbch_rx_data_rdy(int unit);
151 static void rbch_tx_queue_empty(int unit);
152 static void rbch_connect(int unit, void *cdp);
153 static void rbch_disconnect(int unit, void *cdp);
154 static void rbch_init_linktab(int unit);
155 static void rbch_clrq(int unit);
158 #define PDEVSTATIC /* - not static - */
159 #define IOCTL_CMD_T u_long
160 void i4brbchattach __P((void));
161 int i4brbchopen __P((dev_t dev, int flag, int fmt, struct proc *p));
162 int i4brbchclose __P((dev_t dev, int flag, int fmt, struct proc *p));
163 int i4brbchread __P((dev_t dev, struct uio *uio, int ioflag));
164 int i4brbchwrite __P((dev_t dev, struct uio *uio, int ioflag));
165 int i4brbchioctl __P((dev_t dev, IOCTL_CMD_T cmd, caddr_t arg, int flag, struct proc* pr));
167 int i4brbchpoll __P((dev_t dev, int events, struct proc *p));
169 PDEVSTATIC int i4brbchselect __P((dev_t dev, int rw, struct proc *p));
173 #if BSD > 199306 && defined(__FreeBSD__)
174 #define PDEVSTATIC static
175 #define IOCTL_CMD_T u_long
177 PDEVSTATIC d_open_t i4brbchopen;
178 PDEVSTATIC d_close_t i4brbchclose;
179 PDEVSTATIC d_read_t i4brbchread;
180 PDEVSTATIC d_read_t i4brbchwrite;
181 PDEVSTATIC d_ioctl_t i4brbchioctl;
184 PDEVSTATIC d_poll_t i4brbchpoll;
185 #define POLLFIELD i4brbchpoll
187 PDEVSTATIC d_select_t i4brbchselect;
188 #define POLLFIELD i4brbchselect
191 #define CDEV_MAJOR 57
193 static struct cdevsw i4brbch_cdevsw = {
194 /* name */ "i4brbch",
195 /* maj */ CDEV_MAJOR,
200 /* open */ i4brbchopen,
201 /* close */ i4brbchclose,
202 /* read */ i4brbchread,
203 /* write */ i4brbchwrite,
204 /* ioctl */ i4brbchioctl,
205 /* poll */ POLLFIELD,
207 /* strategy */ nostrategy,
212 static void i4brbchattach(void *);
213 PSEUDO_SET(i4brbchattach, i4b_rbch);
215 /*===========================================================================*
216 * DEVICE DRIVER ROUTINES
217 *===========================================================================*/
219 /*---------------------------------------------------------------------------*
220 * initialization at kernel load time
221 *---------------------------------------------------------------------------*/
223 i4brbchinit(void *unused)
225 cdevsw_add(&i4brbch_cdevsw);
228 SYSINIT(i4brbchdev, SI_SUB_DRIVERS,
229 SI_ORDER_MIDDLE+CDEV_MAJOR, &i4brbchinit, NULL);
231 #endif /* BSD > 199306 && defined(__FreeBSD__) */
234 int i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux);
235 void dummy_i4brbchattach(struct device*, struct device *, void *);
237 #define CDEV_MAJOR 61
239 static struct cfdriver i4brbchcd =
240 { NULL, "i4brbch", i4brbchmatch, dummy_i4brbchattach, DV_DULL,
241 sizeof(struct cfdriver) };
242 struct devsw i4brbchsw =
244 i4brbchopen, i4brbchclose, i4brbchread, i4brbchwrite,
245 i4brbchioctl, seltrue, nommap, nostrat,
246 nodump, nopsize, 0, nostop
250 i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux)
252 printf("i4brbchmatch: aux=0x%x\n", aux);
256 dummy_i4brbchattach(struct device *parent, struct device *self, void *aux)
258 printf("dummy_i4brbchattach: aux=0x%x\n", aux);
260 #endif /* __bsdi__ */
262 /*---------------------------------------------------------------------------*
263 * interface attach routine
264 *---------------------------------------------------------------------------*/
267 i4brbchattach(void *dummy)
274 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
275 printf("i4brbch: %d raw B channel access device(s) attached\n", NI4BRBCH);
278 for(i=0; i < NI4BRBCH; i++)
280 #if defined(__FreeBSD__)
281 make_dev(&i4brbch_cdevsw, i,
282 UID_ROOT, GID_WHEEL, 0600, "i4brbch%d", i);
286 #if defined(__FreeBSD__)
287 callout_handle_init(&rbch_softc[i].sc_callout);
289 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
290 callout_init(&rbch_softc[i].sc_callout);
292 rbch_softc[i].sc_fn = 1;
294 rbch_softc[i].sc_unit = i;
295 rbch_softc[i].sc_devstate = ST_IDLE;
296 rbch_softc[i].sc_hdlcq.ifq_maxlen = I4BRBCHMAXQLEN;
297 #if defined(__FreeBSD__) && __FreeBSD__ > 4
298 mtx_init(&rbch_softc[i].sc_hdlcq.ifq_mtx, "i4b_rbch", MTX_DEF);
300 rbch_softc[i].it_in.c_ispeed = rbch_softc[i].it_in.c_ospeed = 64000;
301 termioschars(&rbch_softc[i].it_in);
302 rbch_init_linktab(i);
306 /*---------------------------------------------------------------------------*
308 *---------------------------------------------------------------------------*/
310 i4brbchopen(dev_t dev, int flag, int fmt, struct proc *p)
312 int unit = minor(dev);
317 if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
324 rbch_softc[unit].sc_devstate |= ST_ISOPEN;
326 NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
331 /*---------------------------------------------------------------------------*
333 *---------------------------------------------------------------------------*/
335 i4brbchclose(dev_t dev, int flag, int fmt, struct proc *p)
337 int unit = minor(dev);
338 struct rbch_softc *sc = &rbch_softc[unit];
340 if(sc->sc_devstate & ST_CONNECTED)
341 i4b_l4_drvrdisc(BDRV_RBCH, unit);
343 sc->sc_devstate &= ~ST_ISOPEN;
347 NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
352 /*---------------------------------------------------------------------------*
353 * read from rbch device
354 *---------------------------------------------------------------------------*/
356 i4brbchread(dev_t dev, struct uio *uio, int ioflag)
360 int unit = minor(dev);
362 struct rbch_softc *sc = &rbch_softc[unit];
366 NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
369 if(!(sc->sc_devstate & ST_ISOPEN))
372 NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
376 if((sc->sc_devstate & ST_NOBLOCK))
378 if(!(sc->sc_devstate & ST_CONNECTED)) {
383 if(sc->sc_bprot == BPROT_RHDLC)
386 iqp = isdn_linktab[unit]->rx_queue;
388 if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
395 while(!(sc->sc_devstate & ST_CONNECTED))
397 NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
399 if((error = tsleep((caddr_t) &rbch_softc[unit],
400 PCATCH, "rrrbch", 0 )) != 0)
403 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep", unit, error);
408 if(sc->sc_bprot == BPROT_RHDLC)
411 iqp = isdn_linktab[unit]->rx_queue;
413 while(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
415 sc->sc_devstate |= ST_RDWAITDATA;
417 NDBGL4(L4_RBCHDBG, "unit %d, wait read data", unit);
419 if((error = tsleep((caddr_t) &isdn_linktab[unit]->rx_queue,
420 PCATCH, "rrbch", 0 )) != 0)
423 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep read", unit, error);
424 sc->sc_devstate &= ~ST_RDWAITDATA;
432 NDBGL4(L4_RBCHDBG, "unit %d, read %d bytes", unit, m->m_len);
436 error = uiomove(m->m_data, m->m_len, uio);
440 NDBGL4(L4_RBCHDBG, "unit %d, error %d uiomove", unit, error);
452 /*---------------------------------------------------------------------------*
453 * write to rbch device
454 *---------------------------------------------------------------------------*/
456 i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
460 int unit = minor(dev);
461 struct rbch_softc *sc = &rbch_softc[unit];
465 NDBGL4(L4_RBCHDBG, "unit %d, write", unit);
468 if(!(sc->sc_devstate & ST_ISOPEN))
470 NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit);
475 if((sc->sc_devstate & ST_NOBLOCK))
477 if(!(sc->sc_devstate & ST_CONNECTED)) {
481 if(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) {
488 while(!(sc->sc_devstate & ST_CONNECTED))
490 NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit);
492 error = tsleep((caddr_t) &rbch_softc[unit],
493 PCATCH, "wrrbch", 0 );
494 if(error == ERESTART) {
498 else if(error == EINTR)
501 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit);
507 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error);
510 tsleep((caddr_t) &rbch_softc[unit], PCATCH, "xrbch", (hz*1));
513 while(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
515 sc->sc_devstate |= ST_WRWAITEMPTY;
517 NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit);
519 if ((error = tsleep((caddr_t) &isdn_linktab[unit]->tx_queue,
520 PCATCH, "wrbch", 0)) != 0) {
521 sc->sc_devstate &= ~ST_WRWAITEMPTY;
522 if(error == ERESTART)
527 else if(error == EINTR)
530 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
536 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
543 if(!(sc->sc_devstate & ST_ISOPEN))
545 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
550 if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
552 m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
554 NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
556 error = uiomove(m->m_data, m->m_len, uio);
558 #if defined (__FreeBSD__) && __FreeBSD__ > 4
559 (void) IF_HANDOFF(isdn_linktab[unit]->tx_queue, m, NULL);
561 if(IF_QFULL(isdn_linktab[unit]->tx_queue))
564 IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
566 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
574 /*---------------------------------------------------------------------------*
575 * rbch device ioctl handlibg
576 *---------------------------------------------------------------------------*/
578 i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
581 int unit = minor(dev);
582 struct rbch_softc *sc = &rbch_softc[unit];
586 case FIOASYNC: /* Set async mode */
589 NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
593 NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
600 NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
601 sc->sc_devstate |= ST_NOBLOCK;
605 NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
606 sc->sc_devstate &= ~ST_NOBLOCK;
610 case TIOCCDTR: /* Clear DTR */
611 if(sc->sc_devstate & ST_CONNECTED)
613 NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
614 i4b_l4_drvrdisc(BDRV_RBCH, unit);
618 case I4B_RBCH_DIALOUT:
622 for (l = 0; l < TELNO_MAX && ((char *)data)[l]; l++)
626 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
627 i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
630 /* fall through to SDTR */
633 case TIOCSDTR: /* Set DTR */
634 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
635 i4b_l4_dialout(BDRV_RBCH, unit);
638 case TIOCSETA: /* Set termios struct */
641 case TIOCGETA: /* Get termios struct */
642 *(struct termios *)data = sc->it_in;
646 *(int *)data = TIOCM_LE|TIOCM_DTR|TIOCM_RTS|TIOCM_CTS|TIOCM_DSR;
647 if (sc->sc_devstate & ST_CONNECTED)
648 *(int *)data |= TIOCM_CD;
651 case I4B_RBCH_VR_REQ:
655 mvr = (msg_vr_req_t *)data;
657 mvr->version = VERSION;
663 default: /* Unknown stuff */
664 NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
673 /*---------------------------------------------------------------------------*
675 *---------------------------------------------------------------------------*/
677 i4brbchpoll(dev_t dev, int events, struct proc *p)
679 int revents = 0; /* Events we found */
681 int unit = minor(dev);
682 struct rbch_softc *sc = &rbch_softc[unit];
684 /* We can't check for anything but IN or OUT */
688 if(!(sc->sc_devstate & ST_ISOPEN))
695 * Writes are OK if we are connected and the
696 * transmit queue can take them
699 if((events & (POLLOUT|POLLWRNORM)) &&
700 (sc->sc_devstate & ST_CONNECTED) &&
701 !_IF_QFULL(isdn_linktab[unit]->tx_queue))
703 revents |= (events & (POLLOUT|POLLWRNORM));
706 /* ... while reads are OK if we have any data */
708 if((events & (POLLIN|POLLRDNORM)) &&
709 (sc->sc_devstate & ST_CONNECTED))
713 if(sc->sc_bprot == BPROT_RHDLC)
716 iqp = isdn_linktab[unit]->rx_queue;
719 revents |= (events & (POLLIN|POLLRDNORM));
723 selrecord(p, &sc->selp);
729 #else /* OS_USES_POLL */
731 /*---------------------------------------------------------------------------*
732 * device driver select
733 *---------------------------------------------------------------------------*/
735 i4brbchselect(dev_t dev, int rw, struct proc *p)
737 int unit = minor(dev);
738 struct rbch_softc *sc = &rbch_softc[unit];
743 if(!(sc->sc_devstate & ST_ISOPEN))
746 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
750 if(sc->sc_devstate & ST_CONNECTED)
757 if(sc->sc_bprot == BPROT_RHDLC)
760 iqp = isdn_linktab[unit]->rx_queue;
770 if(!_IF_QFULL(isdn_linktab[unit]->rx_queue))
782 selrecord(p, &sc->selp);
787 #endif /* OS_USES_POLL */
790 /*---------------------------------------------------------------------------*
792 *---------------------------------------------------------------------------*/
794 rbch_timeout(struct rbch_softc *sc)
796 bchan_statistics_t bs;
797 int unit = sc->sc_unit;
799 /* get # of bytes in and out from the HSCX driver */
801 (*isdn_linktab[unit]->bch_stat)
802 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
804 sc->sc_ioutb += bs.outbytes;
805 sc->sc_iinb += bs.inbytes;
807 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
809 int ri = (sc->sc_iinb - sc->sc_linb)/I4BRBCHACCTINTVL;
810 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BRBCHACCTINTVL;
812 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
817 sc->sc_linb = sc->sc_iinb;
818 sc->sc_loutb = sc->sc_ioutb;
820 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
821 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
823 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
825 #endif /* I4BRBCHACCT */
827 /*===========================================================================*
828 * ISDN INTERFACE ROUTINES
829 *===========================================================================*/
831 /*---------------------------------------------------------------------------*
832 * this routine is called from L4 handler at connect time
833 *---------------------------------------------------------------------------*/
835 rbch_connect(int unit, void *cdp)
837 call_desc_t *cd = (call_desc_t *)cdp;
838 struct rbch_softc *sc = &rbch_softc[unit];
840 sc->sc_bprot = cd->bprot;
843 if(sc->sc_bprot == BPROT_RHDLC)
850 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
853 if(!(sc->sc_devstate & ST_CONNECTED))
855 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
856 sc->sc_devstate |= ST_CONNECTED;
862 /*---------------------------------------------------------------------------*
863 * this routine is called from L4 handler at disconnect time
864 *---------------------------------------------------------------------------*/
866 rbch_disconnect(int unit, void *cdp)
868 call_desc_t *cd = (call_desc_t *)cdp;
869 struct rbch_softc *sc = &rbch_softc[unit];
875 NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
876 cd->driver_unit, cd->channelid);
882 NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
884 sc->sc_devstate &= ~ST_CONNECTED;
889 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
890 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
892 STOP_TIMER(sc->sc_callout, rbch_timeout, sc);
897 /*---------------------------------------------------------------------------*
898 * feedback from daemon in case of dial problems
899 *---------------------------------------------------------------------------*/
901 rbch_dialresponse(int unit, int status, cause_t cause)
905 /*---------------------------------------------------------------------------*
907 *---------------------------------------------------------------------------*/
909 rbch_updown(int unit, int updown)
913 /*---------------------------------------------------------------------------*
914 * this routine is called from the HSCX interrupt handler
915 * when a new frame (mbuf) has been received and is to be put on
917 *---------------------------------------------------------------------------*/
919 rbch_rx_data_rdy(int unit)
921 if(rbch_softc[unit].sc_bprot == BPROT_RHDLC)
923 register struct mbuf *m;
925 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
928 m->m_pkthdr.len = m->m_len;
930 #if defined (__FreeBSD__) && __FreeBSD__ > 4
931 if (! IF_HANDOFF(&(rbch_softc[unit].sc_hdlcq), m, NULL))
933 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
936 if(IF_QFULL(&(rbch_softc[unit].sc_hdlcq)))
938 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
943 IF_ENQUEUE(&(rbch_softc[unit].sc_hdlcq), m);
948 if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
950 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
951 rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
952 wakeup((caddr_t) &isdn_linktab[unit]->rx_queue);
956 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
958 selwakeup(&rbch_softc[unit].selp);
961 /*---------------------------------------------------------------------------*
962 * this routine is called from the HSCX interrupt handler
963 * when the last frame has been sent out and there is no
964 * further frame (mbuf) in the tx queue.
965 *---------------------------------------------------------------------------*/
967 rbch_tx_queue_empty(int unit)
969 if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
971 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
972 rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
973 wakeup((caddr_t) &isdn_linktab[unit]->tx_queue);
977 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
979 selwakeup(&rbch_softc[unit].selp);
982 /*---------------------------------------------------------------------------*
983 * this routine is called from the HSCX interrupt handler
984 * each time a packet is received or transmitted
985 *---------------------------------------------------------------------------*/
987 rbch_activity(int unit, int rxtx)
989 if (rbch_softc[unit].sc_cd)
990 rbch_softc[unit].sc_cd->last_active_time = SECOND;
991 selwakeup(&rbch_softc[unit].selp);
994 /*---------------------------------------------------------------------------*
995 * clear an hdlc rx queue for a rbch unit
996 *---------------------------------------------------------------------------*/
1002 #if defined (__FreeBSD__) && __FreeBSD__ > 4
1004 IF_DRAIN(&rbch_softc[unit].sc_hdlcq);
1011 IF_DEQUEUE(&rbch_softc[unit].sc_hdlcq, m);
1022 /*---------------------------------------------------------------------------*
1023 * return this drivers linktab address
1024 *---------------------------------------------------------------------------*/
1026 rbch_ret_linktab(int unit)
1028 rbch_init_linktab(unit);
1029 return(&rbch_drvr_linktab[unit]);
1032 /*---------------------------------------------------------------------------*
1033 * setup the isdn_linktab for this driver
1034 *---------------------------------------------------------------------------*/
1036 rbch_set_linktab(int unit, isdn_link_t *ilt)
1038 isdn_linktab[unit] = ilt;
1041 /*---------------------------------------------------------------------------*
1042 * initialize this drivers linktab
1043 *---------------------------------------------------------------------------*/
1045 rbch_init_linktab(int unit)
1047 rbch_drvr_linktab[unit].unit = unit;
1048 rbch_drvr_linktab[unit].bch_rx_data_ready = rbch_rx_data_rdy;
1049 rbch_drvr_linktab[unit].bch_tx_queue_empty = rbch_tx_queue_empty;
1050 rbch_drvr_linktab[unit].bch_activity = rbch_activity;
1051 rbch_drvr_linktab[unit].line_connected = rbch_connect;
1052 rbch_drvr_linktab[unit].line_disconnected = rbch_disconnect;
1053 rbch_drvr_linktab[unit].dial_response = rbch_dialresponse;
1054 rbch_drvr_linktab[unit].updown_ind = rbch_updown;
1057 /*===========================================================================*/
1059 #endif /* NI4BRBCH > 0 */