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 $
32 * last edit-date: [Sat Aug 11 18:06:57 2001]
34 *---------------------------------------------------------------------------*/
40 #include <sys/param.h>
41 #include <sys/systm.h>
45 #include <sys/kernel.h>
47 #include <sys/socket.h>
51 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
52 #include <sys/callout.h>
55 #if defined (__NetBSD__) || defined (__OpenBSD__)
56 extern cc_t ttydefchars;
57 #define termioschars(t) memcpy((t)->c_cc, &ttydefchars, sizeof((t)->c_cc))
63 #include <sys/devfsext.h>
66 #endif /* __FreeBSD__ */
69 #include <sys/filio.h>
73 #include <machine/i4b_ioctl.h>
74 #include <machine/i4b_rbch_ioctl.h>
75 #include <machine/i4b_debug.h>
77 #include <i4b/i4b_ioctl.h>
78 #include <i4b/i4b_rbch_ioctl.h>
79 #include <i4b/i4b_debug.h>
82 #include <i4b/include/i4b_global.h>
83 #include <i4b/include/i4b_mbuf.h>
84 #include <i4b/include/i4b_l3l4.h>
86 #include <i4b/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(__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(__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);
157 #define PDEVSTATIC /* - not static - */
158 #define IOCTL_CMD_T u_long
159 void i4brbchattach __P((void));
160 int i4brbchopen __P((dev_t dev, int flag, int fmt, struct proc *p));
161 int i4brbchclose __P((dev_t dev, int flag, int fmt, struct proc *p));
162 int i4brbchread __P((dev_t dev, struct uio *uio, int ioflag));
163 int i4brbchwrite __P((dev_t dev, struct uio *uio, int ioflag));
164 int i4brbchioctl __P((dev_t dev, IOCTL_CMD_T cmd, caddr_t arg, int flag, struct proc* pr));
166 int i4brbchpoll __P((dev_t dev, int events, struct proc *p));
168 PDEVSTATIC int i4brbchselect __P((dev_t dev, int rw, struct proc *p));
172 #if 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 /* open */ i4brbchopen,
194 /* close */ i4brbchclose,
195 /* read */ i4brbchread,
196 /* write */ i4brbchwrite,
197 /* ioctl */ i4brbchioctl,
198 /* poll */ POLLFIELD,
200 /* strategy */ nostrategy,
201 /* name */ "i4brbch",
202 /* maj */ CDEV_MAJOR,
209 static void i4brbchattach(void *);
210 PSEUDO_SET(i4brbchattach, i4b_rbch);
212 /*===========================================================================*
213 * DEVICE DRIVER ROUTINES
214 *===========================================================================*/
216 /*---------------------------------------------------------------------------*
217 * initialization at kernel load time
218 *---------------------------------------------------------------------------*/
220 i4brbchinit(void *unused)
222 cdevsw_add(&i4brbch_cdevsw);
225 SYSINIT(i4brbchdev, SI_SUB_DRIVERS,
226 SI_ORDER_MIDDLE+CDEV_MAJOR, &i4brbchinit, NULL);
228 #endif /* BSD > 199306 && defined(__FreeBSD__) */
231 int i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux);
232 void dummy_i4brbchattach(struct device*, struct device *, void *);
234 #define CDEV_MAJOR 61
236 static struct cfdriver i4brbchcd =
237 { NULL, "i4brbch", i4brbchmatch, dummy_i4brbchattach, DV_DULL,
238 sizeof(struct cfdriver) };
239 struct devsw i4brbchsw =
241 i4brbchopen, i4brbchclose, i4brbchread, i4brbchwrite,
242 i4brbchioctl, seltrue, nommap, nostrat,
243 nodump, nopsize, 0, nostop
247 i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux)
249 printf("i4brbchmatch: aux=0x%x\n", aux);
253 dummy_i4brbchattach(struct device *parent, struct device *self, void *aux)
255 printf("dummy_i4brbchattach: aux=0x%x\n", aux);
257 #endif /* __bsdi__ */
259 /*---------------------------------------------------------------------------*
260 * interface attach routine
261 *---------------------------------------------------------------------------*/
264 i4brbchattach(void *dummy)
271 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
272 printf("i4brbch: %d raw B channel access device(s) attached\n", NI4BRBCH);
275 for(i=0; i < NI4BRBCH; i++)
277 #if defined(__FreeBSD__)
278 make_dev(&i4brbch_cdevsw, i,
279 UID_ROOT, GID_WHEEL, 0600, "i4brbch%d", i);
283 #if defined(__FreeBSD__)
284 callout_handle_init(&rbch_softc[i].sc_callout);
286 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
287 callout_init(&rbch_softc[i].sc_callout);
289 rbch_softc[i].sc_fn = 1;
291 rbch_softc[i].sc_unit = i;
292 rbch_softc[i].sc_devstate = ST_IDLE;
293 rbch_softc[i].sc_hdlcq.ifq_maxlen = I4BRBCHMAXQLEN;
294 #if defined(__FreeBSD__) && __FreeBSD__ > 4
295 mtx_init(&rbch_softc[i].sc_hdlcq.ifq_mtx, "i4b_rbch", MTX_DEF);
297 rbch_softc[i].it_in.c_ispeed = rbch_softc[i].it_in.c_ospeed = 64000;
298 termioschars(&rbch_softc[i].it_in);
299 rbch_init_linktab(i);
303 /*---------------------------------------------------------------------------*
305 *---------------------------------------------------------------------------*/
307 i4brbchopen(dev_t dev, int flag, int fmt, struct proc *p)
309 int unit = minor(dev);
314 if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
321 rbch_softc[unit].sc_devstate |= ST_ISOPEN;
323 NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
328 /*---------------------------------------------------------------------------*
330 *---------------------------------------------------------------------------*/
332 i4brbchclose(dev_t dev, int flag, int fmt, struct proc *p)
334 int unit = minor(dev);
335 struct rbch_softc *sc = &rbch_softc[unit];
337 if(sc->sc_devstate & ST_CONNECTED)
338 i4b_l4_drvrdisc(BDRV_RBCH, unit);
340 sc->sc_devstate &= ~ST_ISOPEN;
344 NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
349 /*---------------------------------------------------------------------------*
350 * read from rbch device
351 *---------------------------------------------------------------------------*/
353 i4brbchread(dev_t dev, struct uio *uio, int ioflag)
357 int unit = minor(dev);
359 struct rbch_softc *sc = &rbch_softc[unit];
363 NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
366 if(!(sc->sc_devstate & ST_ISOPEN))
369 NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
373 if((sc->sc_devstate & ST_NOBLOCK))
375 if(!(sc->sc_devstate & ST_CONNECTED)) {
380 if(sc->sc_bprot == BPROT_RHDLC)
383 iqp = isdn_linktab[unit]->rx_queue;
385 if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
392 while(!(sc->sc_devstate & ST_CONNECTED))
394 NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
396 if((error = tsleep((caddr_t) &rbch_softc[unit],
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,
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],
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], TTIPRI | 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,
522 sc->sc_devstate &= ~ST_WRWAITEMPTY;
523 if(error == ERESTART)
528 else if(error == EINTR)
531 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
537 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
544 if(!(sc->sc_devstate & ST_ISOPEN))
546 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
551 if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
553 m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
555 NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
557 error = uiomove(m->m_data, m->m_len, uio);
559 #if defined (__FreeBSD__) && __FreeBSD__ > 4
560 (void) IF_HANDOFF(isdn_linktab[unit]->tx_queue, m, NULL);
562 if(IF_QFULL(isdn_linktab[unit]->tx_queue))
565 IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
567 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
575 /*---------------------------------------------------------------------------*
576 * rbch device ioctl handlibg
577 *---------------------------------------------------------------------------*/
579 i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct proc *p)
582 int unit = minor(dev);
583 struct rbch_softc *sc = &rbch_softc[unit];
587 case FIOASYNC: /* Set async mode */
590 NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
594 NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
601 NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
602 sc->sc_devstate |= ST_NOBLOCK;
606 NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
607 sc->sc_devstate &= ~ST_NOBLOCK;
611 case TIOCCDTR: /* Clear DTR */
612 if(sc->sc_devstate & ST_CONNECTED)
614 NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
615 i4b_l4_drvrdisc(BDRV_RBCH, unit);
619 case I4B_RBCH_DIALOUT:
623 for (l = 0; l < TELNO_MAX && ((char *)data)[l]; l++)
627 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
628 i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
631 /* fall through to SDTR */
634 case TIOCSDTR: /* Set DTR */
635 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
636 i4b_l4_dialout(BDRV_RBCH, unit);
639 case TIOCSETA: /* Set termios struct */
642 case TIOCGETA: /* Get termios struct */
643 *(struct termios *)data = sc->it_in;
647 *(int *)data = TIOCM_LE|TIOCM_DTR|TIOCM_RTS|TIOCM_CTS|TIOCM_DSR;
648 if (sc->sc_devstate & ST_CONNECTED)
649 *(int *)data |= TIOCM_CD;
652 case I4B_RBCH_VR_REQ:
656 mvr = (msg_vr_req_t *)data;
658 mvr->version = VERSION;
664 default: /* Unknown stuff */
665 NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
674 /*---------------------------------------------------------------------------*
676 *---------------------------------------------------------------------------*/
678 i4brbchpoll(dev_t dev, int events, struct proc *p)
680 int revents = 0; /* Events we found */
682 int unit = minor(dev);
683 struct rbch_softc *sc = &rbch_softc[unit];
685 /* We can't check for anything but IN or OUT */
689 if(!(sc->sc_devstate & ST_ISOPEN))
696 * Writes are OK if we are connected and the
697 * transmit queue can take them
700 if((events & (POLLOUT|POLLWRNORM)) &&
701 (sc->sc_devstate & ST_CONNECTED) &&
702 !_IF_QFULL(isdn_linktab[unit]->tx_queue))
704 revents |= (events & (POLLOUT|POLLWRNORM));
707 /* ... while reads are OK if we have any data */
709 if((events & (POLLIN|POLLRDNORM)) &&
710 (sc->sc_devstate & ST_CONNECTED))
714 if(sc->sc_bprot == BPROT_RHDLC)
717 iqp = isdn_linktab[unit]->rx_queue;
720 revents |= (events & (POLLIN|POLLRDNORM));
724 selrecord(p, &sc->selp);
730 #else /* OS_USES_POLL */
732 /*---------------------------------------------------------------------------*
733 * device driver select
734 *---------------------------------------------------------------------------*/
736 i4brbchselect(dev_t dev, int rw, struct proc *p)
738 int unit = minor(dev);
739 struct rbch_softc *sc = &rbch_softc[unit];
744 if(!(sc->sc_devstate & ST_ISOPEN))
747 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
751 if(sc->sc_devstate & ST_CONNECTED)
758 if(sc->sc_bprot == BPROT_RHDLC)
761 iqp = isdn_linktab[unit]->rx_queue;
771 if(!_IF_QFULL(isdn_linktab[unit]->rx_queue))
783 selrecord(p, &sc->selp);
788 #endif /* OS_USES_POLL */
791 /*---------------------------------------------------------------------------*
793 *---------------------------------------------------------------------------*/
795 rbch_timeout(struct rbch_softc *sc)
797 bchan_statistics_t bs;
798 int unit = sc->sc_unit;
800 /* get # of bytes in and out from the HSCX driver */
802 (*isdn_linktab[unit]->bch_stat)
803 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
805 sc->sc_ioutb += bs.outbytes;
806 sc->sc_iinb += bs.inbytes;
808 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
810 int ri = (sc->sc_iinb - sc->sc_linb)/I4BRBCHACCTINTVL;
811 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BRBCHACCTINTVL;
813 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
818 sc->sc_linb = sc->sc_iinb;
819 sc->sc_loutb = sc->sc_ioutb;
821 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
822 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
824 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
826 #endif /* I4BRBCHACCT */
828 /*===========================================================================*
829 * ISDN INTERFACE ROUTINES
830 *===========================================================================*/
832 /*---------------------------------------------------------------------------*
833 * this routine is called from L4 handler at connect time
834 *---------------------------------------------------------------------------*/
836 rbch_connect(int unit, void *cdp)
838 call_desc_t *cd = (call_desc_t *)cdp;
839 struct rbch_softc *sc = &rbch_softc[unit];
841 sc->sc_bprot = cd->bprot;
844 if(sc->sc_bprot == BPROT_RHDLC)
851 START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
854 if(!(sc->sc_devstate & ST_CONNECTED))
856 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
857 sc->sc_devstate |= ST_CONNECTED;
863 /*---------------------------------------------------------------------------*
864 * this routine is called from L4 handler at disconnect time
865 *---------------------------------------------------------------------------*/
867 rbch_disconnect(int unit, void *cdp)
869 call_desc_t *cd = (call_desc_t *)cdp;
870 struct rbch_softc *sc = &rbch_softc[unit];
876 NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
877 cd->driver_unit, cd->channelid);
883 NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
885 sc->sc_devstate &= ~ST_CONNECTED;
890 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
891 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
893 STOP_TIMER(sc->sc_callout, rbch_timeout, sc);
898 /*---------------------------------------------------------------------------*
899 * feedback from daemon in case of dial problems
900 *---------------------------------------------------------------------------*/
902 rbch_dialresponse(int unit, int status, cause_t cause)
906 /*---------------------------------------------------------------------------*
908 *---------------------------------------------------------------------------*/
910 rbch_updown(int unit, int updown)
914 /*---------------------------------------------------------------------------*
915 * this routine is called from the HSCX interrupt handler
916 * when a new frame (mbuf) has been received and is to be put on
918 *---------------------------------------------------------------------------*/
920 rbch_rx_data_rdy(int unit)
922 if(rbch_softc[unit].sc_bprot == BPROT_RHDLC)
924 register struct mbuf *m;
926 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
929 m->m_pkthdr.len = m->m_len;
931 #if defined (__FreeBSD__) && __FreeBSD__ > 4
932 if (! IF_HANDOFF(&(rbch_softc[unit].sc_hdlcq), m, NULL))
934 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
937 if(IF_QFULL(&(rbch_softc[unit].sc_hdlcq)))
939 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
944 IF_ENQUEUE(&(rbch_softc[unit].sc_hdlcq), m);
949 if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
951 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
952 rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
953 wakeup((caddr_t) &isdn_linktab[unit]->rx_queue);
957 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
959 selwakeup(&rbch_softc[unit].selp);
962 /*---------------------------------------------------------------------------*
963 * this routine is called from the HSCX interrupt handler
964 * when the last frame has been sent out and there is no
965 * further frame (mbuf) in the tx queue.
966 *---------------------------------------------------------------------------*/
968 rbch_tx_queue_empty(int unit)
970 if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
972 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
973 rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
974 wakeup((caddr_t) &isdn_linktab[unit]->tx_queue);
978 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
980 selwakeup(&rbch_softc[unit].selp);
983 /*---------------------------------------------------------------------------*
984 * this routine is called from the HSCX interrupt handler
985 * each time a packet is received or transmitted
986 *---------------------------------------------------------------------------*/
988 rbch_activity(int unit, int rxtx)
990 if (rbch_softc[unit].sc_cd)
991 rbch_softc[unit].sc_cd->last_active_time = SECOND;
992 selwakeup(&rbch_softc[unit].selp);
995 /*---------------------------------------------------------------------------*
996 * clear an hdlc rx queue for a rbch unit
997 *---------------------------------------------------------------------------*/
1003 #if defined (__FreeBSD__) && __FreeBSD__ > 4
1005 IF_DRAIN(&rbch_softc[unit].sc_hdlcq);
1012 IF_DEQUEUE(&rbch_softc[unit].sc_hdlcq, m);
1023 /*---------------------------------------------------------------------------*
1024 * return this drivers linktab address
1025 *---------------------------------------------------------------------------*/
1027 rbch_ret_linktab(int unit)
1029 rbch_init_linktab(unit);
1030 return(&rbch_drvr_linktab[unit]);
1033 /*---------------------------------------------------------------------------*
1034 * setup the isdn_linktab for this driver
1035 *---------------------------------------------------------------------------*/
1037 rbch_set_linktab(int unit, isdn_link_t *ilt)
1039 isdn_linktab[unit] = ilt;
1042 /*---------------------------------------------------------------------------*
1043 * initialize this drivers linktab
1044 *---------------------------------------------------------------------------*/
1046 rbch_init_linktab(int unit)
1048 rbch_drvr_linktab[unit].unit = unit;
1049 rbch_drvr_linktab[unit].bch_rx_data_ready = rbch_rx_data_rdy;
1050 rbch_drvr_linktab[unit].bch_tx_queue_empty = rbch_tx_queue_empty;
1051 rbch_drvr_linktab[unit].bch_activity = rbch_activity;
1052 rbch_drvr_linktab[unit].line_connected = rbch_connect;
1053 rbch_drvr_linktab[unit].line_disconnected = rbch_disconnect;
1054 rbch_drvr_linktab[unit].dial_response = rbch_dialresponse;
1055 rbch_drvr_linktab[unit].updown_ind = rbch_updown;
1058 /*===========================================================================*/
1060 #endif /* NI4BRBCH > 0 */