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.3 2003/07/19 21:14:36 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 /* open */ i4brbchopen,
195 /* close */ i4brbchclose,
196 /* read */ i4brbchread,
197 /* write */ i4brbchwrite,
198 /* ioctl */ i4brbchioctl,
199 /* poll */ POLLFIELD,
201 /* strategy */ nostrategy,
202 /* name */ "i4brbch",
203 /* maj */ CDEV_MAJOR,
210 static void i4brbchattach(void *);
211 PSEUDO_SET(i4brbchattach, i4b_rbch);
213 /*===========================================================================*
214 * DEVICE DRIVER ROUTINES
215 *===========================================================================*/
217 /*---------------------------------------------------------------------------*
218 * initialization at kernel load time
219 *---------------------------------------------------------------------------*/
221 i4brbchinit(void *unused)
223 cdevsw_add(&i4brbch_cdevsw);
226 SYSINIT(i4brbchdev, SI_SUB_DRIVERS,
227 SI_ORDER_MIDDLE+CDEV_MAJOR, &i4brbchinit, NULL);
229 #endif /* BSD > 199306 && defined(__FreeBSD__) */
232 int i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux);
233 void dummy_i4brbchattach(struct device*, struct device *, void *);
235 #define CDEV_MAJOR 61
237 static struct cfdriver i4brbchcd =
238 { NULL, "i4brbch", i4brbchmatch, dummy_i4brbchattach, DV_DULL,
239 sizeof(struct cfdriver) };
240 struct devsw i4brbchsw =
242 i4brbchopen, i4brbchclose, i4brbchread, i4brbchwrite,
243 i4brbchioctl, seltrue, nommap, nostrat,
244 nodump, nopsize, 0, nostop
248 i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux)
250 printf("i4brbchmatch: aux=0x%x\n", aux);
254 dummy_i4brbchattach(struct device *parent, struct device *self, void *aux)
256 printf("dummy_i4brbchattach: aux=0x%x\n", aux);
258 #endif /* __bsdi__ */
260 /*---------------------------------------------------------------------------*
261 * interface attach routine
262 *---------------------------------------------------------------------------*/
265 i4brbchattach(void *dummy)
272 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
273 printf("i4brbch: %d raw B channel access device(s) attached\n", NI4BRBCH);
276 for(i=0; i < NI4BRBCH; i++)
278 #if defined(__FreeBSD__)
279 make_dev(&i4brbch_cdevsw, i,
280 UID_ROOT, GID_WHEEL, 0600, "i4brbch%d", i);
284 #if defined(__FreeBSD__)
285 callout_handle_init(&rbch_softc[i].sc_callout);
287 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
288 callout_init(&rbch_softc[i].sc_callout);
290 rbch_softc[i].sc_fn = 1;
292 rbch_softc[i].sc_unit = i;
293 rbch_softc[i].sc_devstate = ST_IDLE;
294 rbch_softc[i].sc_hdlcq.ifq_maxlen = I4BRBCHMAXQLEN;
295 #if defined(__FreeBSD__) && __FreeBSD__ > 4
296 mtx_init(&rbch_softc[i].sc_hdlcq.ifq_mtx, "i4b_rbch", MTX_DEF);
298 rbch_softc[i].it_in.c_ispeed = rbch_softc[i].it_in.c_ospeed = 64000;
299 termioschars(&rbch_softc[i].it_in);
300 rbch_init_linktab(i);
304 /*---------------------------------------------------------------------------*
306 *---------------------------------------------------------------------------*/
308 i4brbchopen(dev_t dev, int flag, int fmt, struct proc *p)
310 int unit = minor(dev);
315 if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
322 rbch_softc[unit].sc_devstate |= ST_ISOPEN;
324 NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
329 /*---------------------------------------------------------------------------*
331 *---------------------------------------------------------------------------*/
333 i4brbchclose(dev_t dev, int flag, int fmt, struct proc *p)
335 int unit = minor(dev);
336 struct rbch_softc *sc = &rbch_softc[unit];
338 if(sc->sc_devstate & ST_CONNECTED)
339 i4b_l4_drvrdisc(BDRV_RBCH, unit);
341 sc->sc_devstate &= ~ST_ISOPEN;
345 NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
350 /*---------------------------------------------------------------------------*
351 * read from rbch device
352 *---------------------------------------------------------------------------*/
354 i4brbchread(dev_t dev, struct uio *uio, int ioflag)
358 int unit = minor(dev);
360 struct rbch_softc *sc = &rbch_softc[unit];
364 NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
367 if(!(sc->sc_devstate & ST_ISOPEN))
370 NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
374 if((sc->sc_devstate & ST_NOBLOCK))
376 if(!(sc->sc_devstate & ST_CONNECTED)) {
381 if(sc->sc_bprot == BPROT_RHDLC)
384 iqp = isdn_linktab[unit]->rx_queue;
386 if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
393 while(!(sc->sc_devstate & ST_CONNECTED))
395 NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
397 if((error = tsleep((caddr_t) &rbch_softc[unit],
398 PCATCH, "rrrbch", 0 )) != 0)
401 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep", unit, error);
406 if(sc->sc_bprot == BPROT_RHDLC)
409 iqp = isdn_linktab[unit]->rx_queue;
411 while(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
413 sc->sc_devstate |= ST_RDWAITDATA;
415 NDBGL4(L4_RBCHDBG, "unit %d, wait read data", unit);
417 if((error = tsleep((caddr_t) &isdn_linktab[unit]->rx_queue,
418 PCATCH, "rrbch", 0 )) != 0)
421 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep read", unit, error);
422 sc->sc_devstate &= ~ST_RDWAITDATA;
430 NDBGL4(L4_RBCHDBG, "unit %d, read %d bytes", unit, m->m_len);
434 error = uiomove(m->m_data, m->m_len, uio);
438 NDBGL4(L4_RBCHDBG, "unit %d, error %d uiomove", unit, error);
450 /*---------------------------------------------------------------------------*
451 * write to rbch device
452 *---------------------------------------------------------------------------*/
454 i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
458 int unit = minor(dev);
459 struct rbch_softc *sc = &rbch_softc[unit];
463 NDBGL4(L4_RBCHDBG, "unit %d, write", unit);
466 if(!(sc->sc_devstate & ST_ISOPEN))
468 NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit);
473 if((sc->sc_devstate & ST_NOBLOCK))
475 if(!(sc->sc_devstate & ST_CONNECTED)) {
479 if(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) {
486 while(!(sc->sc_devstate & ST_CONNECTED))
488 NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit);
490 error = tsleep((caddr_t) &rbch_softc[unit],
491 PCATCH, "wrrbch", 0 );
492 if(error == ERESTART) {
496 else if(error == EINTR)
499 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit);
505 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error);
508 tsleep((caddr_t) &rbch_softc[unit], PCATCH, "xrbch", (hz*1));
511 while(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
513 sc->sc_devstate |= ST_WRWAITEMPTY;
515 NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit);
517 if ((error = tsleep((caddr_t) &isdn_linktab[unit]->tx_queue,
518 PCATCH, "wrbch", 0)) != 0) {
519 sc->sc_devstate &= ~ST_WRWAITEMPTY;
520 if(error == ERESTART)
525 else if(error == EINTR)
528 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
534 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
541 if(!(sc->sc_devstate & ST_ISOPEN))
543 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
548 if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
550 m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
552 NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
554 error = uiomove(m->m_data, m->m_len, uio);
556 #if defined (__FreeBSD__) && __FreeBSD__ > 4
557 (void) IF_HANDOFF(isdn_linktab[unit]->tx_queue, m, NULL);
559 if(IF_QFULL(isdn_linktab[unit]->tx_queue))
562 IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
564 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
572 /*---------------------------------------------------------------------------*
573 * rbch device ioctl handlibg
574 *---------------------------------------------------------------------------*/
576 i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
579 int unit = minor(dev);
580 struct rbch_softc *sc = &rbch_softc[unit];
584 case FIOASYNC: /* Set async mode */
587 NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
591 NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
598 NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
599 sc->sc_devstate |= ST_NOBLOCK;
603 NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
604 sc->sc_devstate &= ~ST_NOBLOCK;
608 case TIOCCDTR: /* Clear DTR */
609 if(sc->sc_devstate & ST_CONNECTED)
611 NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
612 i4b_l4_drvrdisc(BDRV_RBCH, unit);
616 case I4B_RBCH_DIALOUT:
620 for (l = 0; l < TELNO_MAX && ((char *)data)[l]; l++)
624 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
625 i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
628 /* fall through to SDTR */
631 case TIOCSDTR: /* Set DTR */
632 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
633 i4b_l4_dialout(BDRV_RBCH, unit);
636 case TIOCSETA: /* Set termios struct */
639 case TIOCGETA: /* Get termios struct */
640 *(struct termios *)data = sc->it_in;
644 *(int *)data = TIOCM_LE|TIOCM_DTR|TIOCM_RTS|TIOCM_CTS|TIOCM_DSR;
645 if (sc->sc_devstate & ST_CONNECTED)
646 *(int *)data |= TIOCM_CD;
649 case I4B_RBCH_VR_REQ:
653 mvr = (msg_vr_req_t *)data;
655 mvr->version = VERSION;
661 default: /* Unknown stuff */
662 NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
671 /*---------------------------------------------------------------------------*
673 *---------------------------------------------------------------------------*/
675 i4brbchpoll(dev_t dev, int events, struct proc *p)
677 int revents = 0; /* Events we found */
679 int unit = minor(dev);
680 struct rbch_softc *sc = &rbch_softc[unit];
682 /* We can't check for anything but IN or OUT */
686 if(!(sc->sc_devstate & ST_ISOPEN))
693 * Writes are OK if we are connected and the
694 * transmit queue can take them
697 if((events & (POLLOUT|POLLWRNORM)) &&
698 (sc->sc_devstate & ST_CONNECTED) &&
699 !_IF_QFULL(isdn_linktab[unit]->tx_queue))
701 revents |= (events & (POLLOUT|POLLWRNORM));
704 /* ... while reads are OK if we have any data */
706 if((events & (POLLIN|POLLRDNORM)) &&
707 (sc->sc_devstate & ST_CONNECTED))
711 if(sc->sc_bprot == BPROT_RHDLC)
714 iqp = isdn_linktab[unit]->rx_queue;
717 revents |= (events & (POLLIN|POLLRDNORM));
721 selrecord(p, &sc->selp);
727 #else /* OS_USES_POLL */
729 /*---------------------------------------------------------------------------*
730 * device driver select
731 *---------------------------------------------------------------------------*/
733 i4brbchselect(dev_t dev, int rw, struct proc *p)
735 int unit = minor(dev);
736 struct rbch_softc *sc = &rbch_softc[unit];
741 if(!(sc->sc_devstate & ST_ISOPEN))
744 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
748 if(sc->sc_devstate & ST_CONNECTED)
755 if(sc->sc_bprot == BPROT_RHDLC)
758 iqp = isdn_linktab[unit]->rx_queue;
768 if(!_IF_QFULL(isdn_linktab[unit]->rx_queue))
780 selrecord(p, &sc->selp);
785 #endif /* OS_USES_POLL */
788 /*---------------------------------------------------------------------------*
790 *---------------------------------------------------------------------------*/
792 rbch_timeout(struct rbch_softc *sc)
794 bchan_statistics_t bs;
795 int unit = sc->sc_unit;
797 /* get # of bytes in and out from the HSCX driver */
799 (*isdn_linktab[unit]->bch_stat)
800 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
802 sc->sc_ioutb += bs.outbytes;
803 sc->sc_iinb += bs.inbytes;
805 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
807 int ri = (sc->sc_iinb - sc->sc_linb)/I4BRBCHACCTINTVL;
808 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BRBCHACCTINTVL;
810 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
815 sc->sc_linb = sc->sc_iinb;
816 sc->sc_loutb = sc->sc_ioutb;
818 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
819 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
821 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
823 #endif /* I4BRBCHACCT */
825 /*===========================================================================*
826 * ISDN INTERFACE ROUTINES
827 *===========================================================================*/
829 /*---------------------------------------------------------------------------*
830 * this routine is called from L4 handler at connect time
831 *---------------------------------------------------------------------------*/
833 rbch_connect(int unit, void *cdp)
835 call_desc_t *cd = (call_desc_t *)cdp;
836 struct rbch_softc *sc = &rbch_softc[unit];
838 sc->sc_bprot = cd->bprot;
841 if(sc->sc_bprot == BPROT_RHDLC)
848 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
851 if(!(sc->sc_devstate & ST_CONNECTED))
853 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
854 sc->sc_devstate |= ST_CONNECTED;
860 /*---------------------------------------------------------------------------*
861 * this routine is called from L4 handler at disconnect time
862 *---------------------------------------------------------------------------*/
864 rbch_disconnect(int unit, void *cdp)
866 call_desc_t *cd = (call_desc_t *)cdp;
867 struct rbch_softc *sc = &rbch_softc[unit];
873 NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
874 cd->driver_unit, cd->channelid);
880 NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
882 sc->sc_devstate &= ~ST_CONNECTED;
887 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
888 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
890 STOP_TIMER(sc->sc_callout, rbch_timeout, sc);
895 /*---------------------------------------------------------------------------*
896 * feedback from daemon in case of dial problems
897 *---------------------------------------------------------------------------*/
899 rbch_dialresponse(int unit, int status, cause_t cause)
903 /*---------------------------------------------------------------------------*
905 *---------------------------------------------------------------------------*/
907 rbch_updown(int unit, int updown)
911 /*---------------------------------------------------------------------------*
912 * this routine is called from the HSCX interrupt handler
913 * when a new frame (mbuf) has been received and is to be put on
915 *---------------------------------------------------------------------------*/
917 rbch_rx_data_rdy(int unit)
919 if(rbch_softc[unit].sc_bprot == BPROT_RHDLC)
921 register struct mbuf *m;
923 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
926 m->m_pkthdr.len = m->m_len;
928 #if defined (__FreeBSD__) && __FreeBSD__ > 4
929 if (! IF_HANDOFF(&(rbch_softc[unit].sc_hdlcq), m, NULL))
931 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
934 if(IF_QFULL(&(rbch_softc[unit].sc_hdlcq)))
936 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
941 IF_ENQUEUE(&(rbch_softc[unit].sc_hdlcq), m);
946 if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
948 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
949 rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
950 wakeup((caddr_t) &isdn_linktab[unit]->rx_queue);
954 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
956 selwakeup(&rbch_softc[unit].selp);
959 /*---------------------------------------------------------------------------*
960 * this routine is called from the HSCX interrupt handler
961 * when the last frame has been sent out and there is no
962 * further frame (mbuf) in the tx queue.
963 *---------------------------------------------------------------------------*/
965 rbch_tx_queue_empty(int unit)
967 if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
969 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
970 rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
971 wakeup((caddr_t) &isdn_linktab[unit]->tx_queue);
975 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
977 selwakeup(&rbch_softc[unit].selp);
980 /*---------------------------------------------------------------------------*
981 * this routine is called from the HSCX interrupt handler
982 * each time a packet is received or transmitted
983 *---------------------------------------------------------------------------*/
985 rbch_activity(int unit, int rxtx)
987 if (rbch_softc[unit].sc_cd)
988 rbch_softc[unit].sc_cd->last_active_time = SECOND;
989 selwakeup(&rbch_softc[unit].selp);
992 /*---------------------------------------------------------------------------*
993 * clear an hdlc rx queue for a rbch unit
994 *---------------------------------------------------------------------------*/
1000 #if defined (__FreeBSD__) && __FreeBSD__ > 4
1002 IF_DRAIN(&rbch_softc[unit].sc_hdlcq);
1009 IF_DEQUEUE(&rbch_softc[unit].sc_hdlcq, m);
1020 /*---------------------------------------------------------------------------*
1021 * return this drivers linktab address
1022 *---------------------------------------------------------------------------*/
1024 rbch_ret_linktab(int unit)
1026 rbch_init_linktab(unit);
1027 return(&rbch_drvr_linktab[unit]);
1030 /*---------------------------------------------------------------------------*
1031 * setup the isdn_linktab for this driver
1032 *---------------------------------------------------------------------------*/
1034 rbch_set_linktab(int unit, isdn_link_t *ilt)
1036 isdn_linktab[unit] = ilt;
1039 /*---------------------------------------------------------------------------*
1040 * initialize this drivers linktab
1041 *---------------------------------------------------------------------------*/
1043 rbch_init_linktab(int unit)
1045 rbch_drvr_linktab[unit].unit = unit;
1046 rbch_drvr_linktab[unit].bch_rx_data_ready = rbch_rx_data_rdy;
1047 rbch_drvr_linktab[unit].bch_tx_queue_empty = rbch_tx_queue_empty;
1048 rbch_drvr_linktab[unit].bch_activity = rbch_activity;
1049 rbch_drvr_linktab[unit].line_connected = rbch_connect;
1050 rbch_drvr_linktab[unit].line_disconnected = rbch_disconnect;
1051 rbch_drvr_linktab[unit].dial_response = rbch_dialresponse;
1052 rbch_drvr_linktab[unit].updown_ind = rbch_updown;
1055 /*===========================================================================*/
1057 #endif /* NI4BRBCH > 0 */