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.12 2004/09/16 04:36:30 dillon Exp $
33 * last edit-date: [Sat Aug 11 18:06:57 2001]
35 *---------------------------------------------------------------------------*/
37 #include "use_i4brbch.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
46 #include <sys/kernel.h>
48 #include <sys/socket.h>
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 struct callout sc_timeout;
136 int sc_iinb; /* isdn driver # of inbytes */
137 int sc_ioutb; /* isdn driver # of outbytes */
138 int sc_linb; /* last # of bytes rx'd */
139 int sc_loutb; /* last # of bytes tx'd */
140 int sc_fn; /* flag, first null acct */
142 } rbch_softc[NI4BRBCH];
144 static void rbch_rx_data_rdy(int unit);
145 static void rbch_tx_queue_empty(int unit);
146 static void rbch_connect(int unit, void *cdp);
147 static void rbch_disconnect(int unit, void *cdp);
148 static void rbch_init_linktab(int unit);
149 static void rbch_clrq(int unit);
151 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
152 #define PDEVSTATIC /* - not static - */
153 #define IOCTL_CMD_T u_long
154 void i4brbchattach (void);
155 int i4brbchopen (dev_t dev, int flag, int fmt, struct proc *p);
156 int i4brbchclose (dev_t dev, int flag, int fmt, struct proc *p);
157 int i4brbchread (dev_t dev, struct uio *uio, int ioflag);
158 int i4brbchwrite (dev_t dev, struct uio *uio, int ioflag);
159 int i4brbchioctl (dev_t dev, IOCTL_CMD_T cmd, caddr_t arg, int flag, struct proc* pr);
161 int i4brbchpoll (dev_t dev, int events, struct proc *p);
163 PDEVSTATIC int i4brbchselect (dev_t dev, int rw, struct proc *p);
167 #if defined(__DragonFly__) || (BSD > 199306 && defined(__FreeBSD__))
168 #define PDEVSTATIC static
169 #define IOCTL_CMD_T u_long
171 PDEVSTATIC d_open_t i4brbchopen;
172 PDEVSTATIC d_close_t i4brbchclose;
173 PDEVSTATIC d_read_t i4brbchread;
174 PDEVSTATIC d_read_t i4brbchwrite;
175 PDEVSTATIC d_ioctl_t i4brbchioctl;
178 PDEVSTATIC d_poll_t i4brbchpoll;
179 #define POLLFIELD i4brbchpoll
181 PDEVSTATIC d_select_t i4brbchselect;
182 #define POLLFIELD i4brbchselect
185 #define CDEV_MAJOR 57
187 static struct cdevsw i4brbch_cdevsw = {
188 /* name */ "i4brbch",
189 /* maj */ CDEV_MAJOR,
194 /* open */ i4brbchopen,
195 /* close */ i4brbchclose,
196 /* read */ i4brbchread,
197 /* write */ i4brbchwrite,
198 /* ioctl */ i4brbchioctl,
199 /* poll */ POLLFIELD,
201 /* strategy */ nostrategy,
206 static void i4brbchattach(void *);
207 PSEUDO_SET(i4brbchattach, i4b_rbch);
209 /*===========================================================================*
210 * DEVICE DRIVER ROUTINES
211 *===========================================================================*/
213 /*---------------------------------------------------------------------------*
214 * initialization at kernel load time
215 *---------------------------------------------------------------------------*/
217 i4brbchinit(void *unused)
219 cdevsw_add(&i4brbch_cdevsw, 0, 0);
222 SYSINIT(i4brbchdev, SI_SUB_DRIVERS,
223 SI_ORDER_MIDDLE+CDEV_MAJOR, &i4brbchinit, NULL);
225 #endif /* BSD > 199306 && defined(__FreeBSD__) */
228 int i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux);
229 void dummy_i4brbchattach(struct device*, struct device *, void *);
231 #define CDEV_MAJOR 61
233 static struct cfdriver i4brbchcd =
234 { NULL, "i4brbch", i4brbchmatch, dummy_i4brbchattach, DV_DULL,
235 sizeof(struct cfdriver) };
236 struct devsw i4brbchsw =
238 i4brbchopen, i4brbchclose, i4brbchread, i4brbchwrite,
239 i4brbchioctl, seltrue, nommap, nostrat,
240 nodump, nopsize, 0, nostop
244 i4brbchmatch(struct device *parent, struct cfdata *cf, void *aux)
246 printf("i4brbchmatch: aux=0x%x\n", aux);
250 dummy_i4brbchattach(struct device *parent, struct device *self, void *aux)
252 printf("dummy_i4brbchattach: aux=0x%x\n", aux);
254 #endif /* __bsdi__ */
256 /*---------------------------------------------------------------------------*
257 * interface attach routine
258 *---------------------------------------------------------------------------*/
260 #if defined(__DragonFly__) || defined(__FreeBSD__)
261 i4brbchattach(void *dummy)
268 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
269 printf("i4brbch: %d raw B channel access device(s) attached\n", NI4BRBCH);
272 for(i=0; i < NI4BRBCH; i++)
274 #if defined(__DragonFly__) || defined(__FreeBSD__)
275 make_dev(&i4brbch_cdevsw, i,
276 UID_ROOT, GID_WHEEL, 0600, "i4brbch%d", i);
280 callout_init(&rbch_softc[i].sc_timeout);
281 rbch_softc[i].sc_fn = 1;
283 rbch_softc[i].sc_unit = i;
284 rbch_softc[i].sc_devstate = ST_IDLE;
285 rbch_softc[i].sc_hdlcq.ifq_maxlen = I4BRBCHMAXQLEN;
286 #if defined(__FreeBSD__) && __FreeBSD__ > 4
287 mtx_init(&rbch_softc[i].sc_hdlcq.ifq_mtx, "i4b_rbch", MTX_DEF);
289 rbch_softc[i].it_in.c_ispeed = rbch_softc[i].it_in.c_ospeed = 64000;
290 termioschars(&rbch_softc[i].it_in);
291 rbch_init_linktab(i);
295 /*---------------------------------------------------------------------------*
297 *---------------------------------------------------------------------------*/
299 i4brbchopen(dev_t dev, int flag, int fmt, struct thread *td)
301 int unit = minor(dev);
306 if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
313 rbch_softc[unit].sc_devstate |= ST_ISOPEN;
315 NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
320 /*---------------------------------------------------------------------------*
322 *---------------------------------------------------------------------------*/
324 i4brbchclose(dev_t dev, int flag, int fmt, struct thread *td)
326 int unit = minor(dev);
327 struct rbch_softc *sc = &rbch_softc[unit];
329 if(sc->sc_devstate & ST_CONNECTED)
330 i4b_l4_drvrdisc(BDRV_RBCH, unit);
332 sc->sc_devstate &= ~ST_ISOPEN;
336 NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
341 /*---------------------------------------------------------------------------*
342 * read from rbch device
343 *---------------------------------------------------------------------------*/
345 i4brbchread(dev_t dev, struct uio *uio, int ioflag)
349 int unit = minor(dev);
351 struct rbch_softc *sc = &rbch_softc[unit];
355 NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
358 if(!(sc->sc_devstate & ST_ISOPEN))
361 NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
365 if((sc->sc_devstate & ST_NOBLOCK))
367 if(!(sc->sc_devstate & ST_CONNECTED)) {
372 if(sc->sc_bprot == BPROT_RHDLC)
375 iqp = isdn_linktab[unit]->rx_queue;
377 if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
384 while(!(sc->sc_devstate & ST_CONNECTED))
386 NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
388 if((error = tsleep((caddr_t) &rbch_softc[unit],
389 PCATCH, "rrrbch", 0 )) != 0)
392 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep", unit, error);
397 if(sc->sc_bprot == BPROT_RHDLC)
400 iqp = isdn_linktab[unit]->rx_queue;
402 while(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
404 sc->sc_devstate |= ST_RDWAITDATA;
406 NDBGL4(L4_RBCHDBG, "unit %d, wait read data", unit);
408 if((error = tsleep((caddr_t) &isdn_linktab[unit]->rx_queue,
409 PCATCH, "rrbch", 0 )) != 0)
412 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep read", unit, error);
413 sc->sc_devstate &= ~ST_RDWAITDATA;
421 NDBGL4(L4_RBCHDBG, "unit %d, read %d bytes", unit, m->m_len);
425 error = uiomove(m->m_data, m->m_len, uio);
429 NDBGL4(L4_RBCHDBG, "unit %d, error %d uiomove", unit, error);
441 /*---------------------------------------------------------------------------*
442 * write to rbch device
443 *---------------------------------------------------------------------------*/
445 i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
449 int unit = minor(dev);
450 struct rbch_softc *sc = &rbch_softc[unit];
454 NDBGL4(L4_RBCHDBG, "unit %d, write", unit);
457 if(!(sc->sc_devstate & ST_ISOPEN))
459 NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit);
464 if((sc->sc_devstate & ST_NOBLOCK))
466 if(!(sc->sc_devstate & ST_CONNECTED)) {
470 if(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) {
477 while(!(sc->sc_devstate & ST_CONNECTED))
479 NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit);
481 error = tsleep((caddr_t) &rbch_softc[unit],
482 PCATCH, "wrrbch", 0 );
483 if(error == ERESTART) {
487 else if(error == EINTR)
490 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit);
496 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error);
499 tsleep((caddr_t) &rbch_softc[unit], PCATCH, "xrbch", (hz*1));
502 while(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
504 sc->sc_devstate |= ST_WRWAITEMPTY;
506 NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit);
508 if ((error = tsleep((caddr_t) &isdn_linktab[unit]->tx_queue,
509 PCATCH, "wrbch", 0)) != 0) {
510 sc->sc_devstate &= ~ST_WRWAITEMPTY;
511 if(error == ERESTART)
516 else if(error == EINTR)
519 NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
525 NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
532 if(!(sc->sc_devstate & ST_ISOPEN))
534 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
539 if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
541 m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
543 NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
545 error = uiomove(m->m_data, m->m_len, uio);
547 #if defined (__FreeBSD__) && __FreeBSD__ > 4
548 (void) IF_HANDOFF(isdn_linktab[unit]->tx_queue, m, NULL);
550 if(IF_QFULL(isdn_linktab[unit]->tx_queue))
553 IF_ENQUEUE(isdn_linktab[unit]->tx_queue, m);
555 (*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
563 /*---------------------------------------------------------------------------*
564 * rbch device ioctl handlibg
565 *---------------------------------------------------------------------------*/
567 i4brbchioctl(dev_t dev, IOCTL_CMD_T cmd, caddr_t data, int flag, struct thread *td)
570 int unit = minor(dev);
571 struct rbch_softc *sc = &rbch_softc[unit];
575 case FIOASYNC: /* Set async mode */
578 NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
582 NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
589 NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
590 sc->sc_devstate |= ST_NOBLOCK;
594 NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
595 sc->sc_devstate &= ~ST_NOBLOCK;
599 case TIOCCDTR: /* Clear DTR */
600 if(sc->sc_devstate & ST_CONNECTED)
602 NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
603 i4b_l4_drvrdisc(BDRV_RBCH, unit);
607 case I4B_RBCH_DIALOUT:
611 for (l = 0; l < TELNO_MAX && ((char *)data)[l]; l++)
615 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
616 i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
619 /* fall through to SDTR */
622 case TIOCSDTR: /* Set DTR */
623 NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
624 i4b_l4_dialout(BDRV_RBCH, unit);
627 case TIOCSETA: /* Set termios struct */
630 case TIOCGETA: /* Get termios struct */
631 *(struct termios *)data = sc->it_in;
635 *(int *)data = TIOCM_LE|TIOCM_DTR|TIOCM_RTS|TIOCM_CTS|TIOCM_DSR;
636 if (sc->sc_devstate & ST_CONNECTED)
637 *(int *)data |= TIOCM_CD;
640 case I4B_RBCH_VR_REQ:
644 mvr = (msg_vr_req_t *)data;
646 mvr->version = VERSION;
652 default: /* Unknown stuff */
653 NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
662 /*---------------------------------------------------------------------------*
664 *---------------------------------------------------------------------------*/
666 i4brbchpoll(dev_t dev, int events, struct thread *td)
668 int revents = 0; /* Events we found */
670 int unit = minor(dev);
671 struct rbch_softc *sc = &rbch_softc[unit];
673 /* We can't check for anything but IN or OUT */
677 if(!(sc->sc_devstate & ST_ISOPEN))
684 * Writes are OK if we are connected and the
685 * transmit queue can take them
688 if((events & (POLLOUT|POLLWRNORM)) &&
689 (sc->sc_devstate & ST_CONNECTED) &&
690 !_IF_QFULL(isdn_linktab[unit]->tx_queue))
692 revents |= (events & (POLLOUT|POLLWRNORM));
695 /* ... while reads are OK if we have any data */
697 if((events & (POLLIN|POLLRDNORM)) &&
698 (sc->sc_devstate & ST_CONNECTED))
702 if(sc->sc_bprot == BPROT_RHDLC)
705 iqp = isdn_linktab[unit]->rx_queue;
708 revents |= (events & (POLLIN|POLLRDNORM));
712 selrecord(td, &sc->selp);
718 #else /* OS_USES_POLL */
720 /*---------------------------------------------------------------------------*
721 * device driver select
722 *---------------------------------------------------------------------------*/
724 i4brbchselect(dev_t dev, int rw, struct thread *td)
726 int unit = minor(dev);
727 struct rbch_softc *sc = &rbch_softc[unit];
732 if(!(sc->sc_devstate & ST_ISOPEN))
735 NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
739 if(sc->sc_devstate & ST_CONNECTED)
746 if(sc->sc_bprot == BPROT_RHDLC)
749 iqp = isdn_linktab[unit]->rx_queue;
759 if(!_IF_QFULL(isdn_linktab[unit]->rx_queue))
771 selrecord(p, &sc->selp);
776 #endif /* OS_USES_POLL */
779 /*---------------------------------------------------------------------------*
781 *---------------------------------------------------------------------------*/
783 rbch_timeout(struct rbch_softc *sc)
785 bchan_statistics_t bs;
786 int unit = sc->sc_unit;
788 /* get # of bytes in and out from the HSCX driver */
790 (*isdn_linktab[unit]->bch_stat)
791 (isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
793 sc->sc_ioutb += bs.outbytes;
794 sc->sc_iinb += bs.inbytes;
796 if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
798 int ri = (sc->sc_iinb - sc->sc_linb)/I4BRBCHACCTINTVL;
799 int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BRBCHACCTINTVL;
801 if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
806 sc->sc_linb = sc->sc_iinb;
807 sc->sc_loutb = sc->sc_ioutb;
809 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
810 sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
812 callout_reset(&sc->sc_timeout, I4BRBCHACCTINTVL * hz,
813 (void *)rbch_timeout, sc);
815 #endif /* I4BRBCHACCT */
817 /*===========================================================================*
818 * ISDN INTERFACE ROUTINES
819 *===========================================================================*/
821 /*---------------------------------------------------------------------------*
822 * this routine is called from L4 handler at connect time
823 *---------------------------------------------------------------------------*/
825 rbch_connect(int unit, void *cdp)
827 call_desc_t *cd = (call_desc_t *)cdp;
828 struct rbch_softc *sc = &rbch_softc[unit];
830 sc->sc_bprot = cd->bprot;
833 if(sc->sc_bprot == BPROT_RHDLC)
840 callout_reset(&sc->sc_timeout, I4BRBCHACCTINTVL * hz,
841 (void *)rbch_timeout, sc);
844 if(!(sc->sc_devstate & ST_CONNECTED))
846 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
847 sc->sc_devstate |= ST_CONNECTED;
853 /*---------------------------------------------------------------------------*
854 * this routine is called from L4 handler at disconnect time
855 *---------------------------------------------------------------------------*/
857 rbch_disconnect(int unit, void *cdp)
859 call_desc_t *cd = (call_desc_t *)cdp;
860 struct rbch_softc *sc = &rbch_softc[unit];
866 NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
867 cd->driver_unit, cd->channelid);
873 NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
875 sc->sc_devstate &= ~ST_CONNECTED;
880 i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
881 sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
882 callout_stop(&sc->sc_timeout);
887 /*---------------------------------------------------------------------------*
888 * feedback from daemon in case of dial problems
889 *---------------------------------------------------------------------------*/
891 rbch_dialresponse(int unit, int status, cause_t cause)
895 /*---------------------------------------------------------------------------*
897 *---------------------------------------------------------------------------*/
899 rbch_updown(int unit, int updown)
903 /*---------------------------------------------------------------------------*
904 * this routine is called from the HSCX interrupt handler
905 * when a new frame (mbuf) has been received and is to be put on
907 *---------------------------------------------------------------------------*/
909 rbch_rx_data_rdy(int unit)
911 if(rbch_softc[unit].sc_bprot == BPROT_RHDLC)
915 if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
918 m->m_pkthdr.len = m->m_len;
920 #if defined (__FreeBSD__) && __FreeBSD__ > 4
921 if (! IF_HANDOFF(&(rbch_softc[unit].sc_hdlcq), m, NULL))
923 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
926 if(IF_QFULL(&(rbch_softc[unit].sc_hdlcq)))
928 NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
933 IF_ENQUEUE(&(rbch_softc[unit].sc_hdlcq), m);
938 if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
940 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
941 rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
942 wakeup((caddr_t) &isdn_linktab[unit]->rx_queue);
946 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
948 selwakeup(&rbch_softc[unit].selp);
951 /*---------------------------------------------------------------------------*
952 * this routine is called from the HSCX interrupt handler
953 * when the last frame has been sent out and there is no
954 * further frame (mbuf) in the tx queue.
955 *---------------------------------------------------------------------------*/
957 rbch_tx_queue_empty(int unit)
959 if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
961 NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
962 rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
963 wakeup((caddr_t) &isdn_linktab[unit]->tx_queue);
967 NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
969 selwakeup(&rbch_softc[unit].selp);
972 /*---------------------------------------------------------------------------*
973 * this routine is called from the HSCX interrupt handler
974 * each time a packet is received or transmitted
975 *---------------------------------------------------------------------------*/
977 rbch_activity(int unit, int rxtx)
979 if (rbch_softc[unit].sc_cd)
980 rbch_softc[unit].sc_cd->last_active_time = SECOND;
981 selwakeup(&rbch_softc[unit].selp);
984 /*---------------------------------------------------------------------------*
985 * clear an hdlc rx queue for a rbch unit
986 *---------------------------------------------------------------------------*/
992 #if defined (__FreeBSD__) && __FreeBSD__ > 4
994 IF_DRAIN(&rbch_softc[unit].sc_hdlcq);
1001 IF_DEQUEUE(&rbch_softc[unit].sc_hdlcq, m);
1012 /*---------------------------------------------------------------------------*
1013 * return this drivers linktab address
1014 *---------------------------------------------------------------------------*/
1016 rbch_ret_linktab(int unit)
1018 rbch_init_linktab(unit);
1019 return(&rbch_drvr_linktab[unit]);
1022 /*---------------------------------------------------------------------------*
1023 * setup the isdn_linktab for this driver
1024 *---------------------------------------------------------------------------*/
1026 rbch_set_linktab(int unit, isdn_link_t *ilt)
1028 isdn_linktab[unit] = ilt;
1031 /*---------------------------------------------------------------------------*
1032 * initialize this drivers linktab
1033 *---------------------------------------------------------------------------*/
1035 rbch_init_linktab(int unit)
1037 rbch_drvr_linktab[unit].unit = unit;
1038 rbch_drvr_linktab[unit].bch_rx_data_ready = rbch_rx_data_rdy;
1039 rbch_drvr_linktab[unit].bch_tx_queue_empty = rbch_tx_queue_empty;
1040 rbch_drvr_linktab[unit].bch_activity = rbch_activity;
1041 rbch_drvr_linktab[unit].line_connected = rbch_connect;
1042 rbch_drvr_linktab[unit].line_disconnected = rbch_disconnect;
1043 rbch_drvr_linktab[unit].dial_response = rbch_dialresponse;
1044 rbch_drvr_linktab[unit].updown_ind = rbch_updown;
1047 /*===========================================================================*/
1049 #endif /* NI4BRBCH > 0 */