1998-12-27 21:47:14 +00:00
|
|
|
/*
|
2002-03-17 09:33:15 +00:00
|
|
|
* Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* i4b_rbch.c - device driver for raw B channel data
|
|
|
|
* ---------------------------------------------------
|
2002-03-17 09:33:15 +00:00
|
|
|
* last edit-date: [Sun Mar 17 09:51:03 2002]
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
2003-06-10 23:23:33 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
#include "i4brbch.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
2002-03-17 09:33:15 +00:00
|
|
|
#include <sys/filio.h>
|
1998-12-27 21:47:14 +00:00
|
|
|
#include <sys/tty.h>
|
|
|
|
|
2002-03-17 09:33:15 +00:00
|
|
|
#include <net/if.h>
|
2000-10-09 13:18:17 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
#include <machine/i4b_ioctl.h>
|
1999-08-06 14:05:10 +00:00
|
|
|
#include <machine/i4b_rbch_ioctl.h>
|
1998-12-27 21:47:14 +00:00
|
|
|
#include <machine/i4b_debug.h>
|
|
|
|
|
|
|
|
#include <i4b/include/i4b_global.h>
|
|
|
|
#include <i4b/include/i4b_mbuf.h>
|
|
|
|
#include <i4b/include/i4b_l3l4.h>
|
|
|
|
|
|
|
|
#include <i4b/layer4/i4b_l4.h>
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
static drvr_link_t rbch_drvr_linktab[NI4BRBCH];
|
|
|
|
static isdn_link_t *isdn_linktab[NI4BRBCH];
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
#define I4BRBCHACCT 1 /* enable accounting messages */
|
|
|
|
#define I4BRBCHACCTINTVL 2 /* accounting msg interval in secs */
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
static struct rbch_softc {
|
1999-12-14 20:48:35 +00:00
|
|
|
int sc_unit; /* unit number */
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
int sc_devstate; /* state of driver */
|
|
|
|
#define ST_IDLE 0x00
|
|
|
|
#define ST_CONNECTED 0x01
|
|
|
|
#define ST_ISOPEN 0x02
|
|
|
|
#define ST_RDWAITDATA 0x04
|
|
|
|
#define ST_WRWAITEMPTY 0x08
|
|
|
|
#define ST_NOBLOCK 0x10
|
|
|
|
|
|
|
|
int sc_bprot; /* B-ch protocol used */
|
1999-12-14 20:48:35 +00:00
|
|
|
call_desc_t *sc_cd; /* Call Descriptor */
|
1998-12-27 21:47:14 +00:00
|
|
|
struct termios it_in;
|
|
|
|
|
|
|
|
struct ifqueue sc_hdlcq; /* hdlc read queue */
|
|
|
|
#define I4BRBCHMAXQLEN 10
|
|
|
|
|
|
|
|
struct selinfo selp; /* select / poll */
|
1999-12-14 20:48:35 +00:00
|
|
|
|
|
|
|
#if I4BRBCHACCT
|
|
|
|
struct callout_handle sc_callout;
|
|
|
|
int sc_iinb; /* isdn driver # of inbytes */
|
|
|
|
int sc_ioutb; /* isdn driver # of outbytes */
|
|
|
|
int sc_linb; /* last # of bytes rx'd */
|
|
|
|
int sc_loutb; /* last # of bytes tx'd */
|
|
|
|
int sc_fn; /* flag, first null acct */
|
|
|
|
#endif
|
1998-12-27 21:47:14 +00:00
|
|
|
} rbch_softc[NI4BRBCH];
|
|
|
|
|
|
|
|
static void rbch_rx_data_rdy(int unit);
|
|
|
|
static void rbch_tx_queue_empty(int unit);
|
|
|
|
static void rbch_connect(int unit, void *cdp);
|
|
|
|
static void rbch_disconnect(int unit, void *cdp);
|
|
|
|
static void rbch_init_linktab(int unit);
|
|
|
|
static void rbch_clrq(int unit);
|
|
|
|
|
2002-03-17 09:33:15 +00:00
|
|
|
static d_open_t i4brbchopen;
|
|
|
|
static d_close_t i4brbchclose;
|
|
|
|
static d_read_t i4brbchread;
|
|
|
|
static d_read_t i4brbchwrite;
|
|
|
|
static d_ioctl_t i4brbchioctl;
|
|
|
|
static d_poll_t i4brbchpoll;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
static struct cdevsw i4brbch_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = i4brbchopen,
|
|
|
|
.d_close = i4brbchclose,
|
|
|
|
.d_read = i4brbchread,
|
|
|
|
.d_write = i4brbchwrite,
|
|
|
|
.d_ioctl = i4brbchioctl,
|
|
|
|
.d_poll = i4brbchpoll,
|
|
|
|
.d_name = "i4brbch",
|
1998-12-27 21:47:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void i4brbchattach(void *);
|
|
|
|
PSEUDO_SET(i4brbchattach, i4b_rbch);
|
2003-11-10 14:02:22 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
/*===========================================================================*
|
|
|
|
* DEVICE DRIVER ROUTINES
|
|
|
|
*===========================================================================*/
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* interface attach routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static void
|
1998-12-27 21:47:14 +00:00
|
|
|
i4brbchattach(void *dummy)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("i4brbch: %d raw B channel access device(s) attached\n", NI4BRBCH);
|
|
|
|
|
|
|
|
for(i=0; i < NI4BRBCH; i++)
|
|
|
|
{
|
1999-08-27 07:26:26 +00:00
|
|
|
make_dev(&i4brbch_cdevsw, i,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600, "i4brbch%d", i);
|
1999-12-14 20:48:35 +00:00
|
|
|
|
|
|
|
#if I4BRBCHACCT
|
|
|
|
callout_handle_init(&rbch_softc[i].sc_callout);
|
|
|
|
rbch_softc[i].sc_fn = 1;
|
|
|
|
#endif
|
|
|
|
rbch_softc[i].sc_unit = i;
|
1998-12-27 21:47:14 +00:00
|
|
|
rbch_softc[i].sc_devstate = ST_IDLE;
|
|
|
|
rbch_softc[i].sc_hdlcq.ifq_maxlen = I4BRBCHMAXQLEN;
|
2002-03-17 09:33:15 +00:00
|
|
|
|
2001-12-30 09:27:28 +00:00
|
|
|
if(!mtx_initialized(&rbch_softc[i].sc_hdlcq.ifq_mtx))
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&rbch_softc[i].sc_hdlcq.ifq_mtx, "i4b_rbch", NULL, MTX_DEF);
|
2002-03-17 09:33:15 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
rbch_softc[i].it_in.c_ispeed = rbch_softc[i].it_in.c_ospeed = 64000;
|
|
|
|
termioschars(&rbch_softc[i].it_in);
|
|
|
|
rbch_init_linktab(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* open rbch device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
i4brbchopen(dev_t dev, int flag, int fmt, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
int unit = minor(dev);
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
if(unit >= NI4BRBCH)
|
1998-12-27 21:47:14 +00:00
|
|
|
return(ENXIO);
|
|
|
|
|
|
|
|
if(rbch_softc[unit].sc_devstate & ST_ISOPEN)
|
|
|
|
return(EBUSY);
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
#if 0
|
1998-12-27 21:47:14 +00:00
|
|
|
rbch_clrq(unit);
|
1999-12-14 20:48:35 +00:00
|
|
|
#endif
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
rbch_softc[unit].sc_devstate |= ST_ISOPEN;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, open", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* close rbch device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
i4brbchclose(dev_t dev, int flag, int fmt, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
int unit = minor(dev);
|
1999-12-14 20:48:35 +00:00
|
|
|
struct rbch_softc *sc = &rbch_softc[unit];
|
|
|
|
|
|
|
|
if(sc->sc_devstate & ST_CONNECTED)
|
1999-11-28 16:17:01 +00:00
|
|
|
i4b_l4_drvrdisc(BDRV_RBCH, unit);
|
1999-12-14 20:48:35 +00:00
|
|
|
|
|
|
|
sc->sc_devstate &= ~ST_ISOPEN;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
rbch_clrq(unit);
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, closed", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* read from rbch device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
1998-12-27 21:47:14 +00:00
|
|
|
i4brbchread(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
int error = 0;
|
|
|
|
int unit = minor(dev);
|
|
|
|
struct ifqueue *iqp;
|
1999-12-14 20:48:35 +00:00
|
|
|
struct rbch_softc *sc = &rbch_softc[unit];
|
|
|
|
|
|
|
|
CRIT_VAR;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, enter read", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_BEG;
|
1999-12-14 20:48:35 +00:00
|
|
|
if(!(sc->sc_devstate & ST_ISOPEN))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, read while not open", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
if((sc->sc_devstate & ST_NOBLOCK))
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
if(!(sc->sc_devstate & ST_CONNECTED)) {
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EWOULDBLOCK);
|
2000-10-09 13:18:17 +00:00
|
|
|
}
|
1998-12-27 21:47:14 +00:00
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
if(sc->sc_bprot == BPROT_RHDLC)
|
|
|
|
iqp = &sc->sc_hdlcq;
|
1998-12-27 21:47:14 +00:00
|
|
|
else
|
|
|
|
iqp = isdn_linktab[unit]->rx_queue;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
if(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN)) {
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EWOULDBLOCK);
|
1999-12-14 20:48:35 +00:00
|
|
|
}
|
2000-10-09 13:18:17 +00:00
|
|
|
}
|
1999-12-14 20:48:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while(!(sc->sc_devstate & ST_CONNECTED))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, wait read init", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2003-03-02 16:54:40 +00:00
|
|
|
if((error = tsleep( &rbch_softc[unit],
|
2003-11-10 14:20:34 +00:00
|
|
|
I4BPRI | PCATCH,
|
1998-12-27 21:47:14 +00:00
|
|
|
"rrrbch", 0 )) != 0)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep", unit, error);
|
1998-12-27 21:47:14 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
if(sc->sc_bprot == BPROT_RHDLC)
|
|
|
|
iqp = &sc->sc_hdlcq;
|
1998-12-27 21:47:14 +00:00
|
|
|
else
|
|
|
|
iqp = isdn_linktab[unit]->rx_queue;
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
while(IF_QEMPTY(iqp) && (sc->sc_devstate & ST_ISOPEN))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_devstate |= ST_RDWAITDATA;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, wait read data", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2003-03-02 16:54:40 +00:00
|
|
|
if((error = tsleep( &isdn_linktab[unit]->rx_queue,
|
2003-11-10 14:20:34 +00:00
|
|
|
I4BPRI | PCATCH,
|
1998-12-27 21:47:14 +00:00
|
|
|
"rrbch", 0 )) != 0)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep read", unit, error);
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_devstate &= ~ST_RDWAITDATA;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IF_DEQUEUE(iqp, m);
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, read %d bytes", unit, m->m_len);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
if(m && m->m_len)
|
|
|
|
{
|
|
|
|
error = uiomove(m->m_data, m->m_len, uio);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, error %d uiomove", unit, error);
|
1998-12-27 21:47:14 +00:00
|
|
|
error = EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m)
|
|
|
|
i4b_Bfreembuf(m);
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* write to rbch device
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
1998-12-27 21:47:14 +00:00
|
|
|
i4brbchwrite(dev_t dev, struct uio * uio, int ioflag)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
int error = 0;
|
|
|
|
int unit = minor(dev);
|
1999-12-14 20:48:35 +00:00
|
|
|
struct rbch_softc *sc = &rbch_softc[unit];
|
1998-12-27 21:47:14 +00:00
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
CRIT_VAR;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, write", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_BEG;
|
1999-12-14 20:48:35 +00:00
|
|
|
if(!(sc->sc_devstate & ST_ISOPEN))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit);
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
if((sc->sc_devstate & ST_NOBLOCK))
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
if(!(sc->sc_devstate & ST_CONNECTED)) {
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EWOULDBLOCK);
|
2000-10-09 13:18:17 +00:00
|
|
|
}
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) {
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EWOULDBLOCK);
|
1999-12-14 20:48:35 +00:00
|
|
|
}
|
2000-10-09 13:18:17 +00:00
|
|
|
}
|
1999-12-14 20:48:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while(!(sc->sc_devstate & ST_CONNECTED))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2003-03-02 16:54:40 +00:00
|
|
|
error = tsleep( &rbch_softc[unit],
|
2003-11-10 14:20:34 +00:00
|
|
|
I4BPRI | PCATCH,
|
1998-12-27 21:47:14 +00:00
|
|
|
"wrrbch", 0 );
|
2000-10-09 13:18:17 +00:00
|
|
|
if(error == ERESTART) {
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return (ERESTART);
|
2000-10-09 13:18:17 +00:00
|
|
|
}
|
1999-12-14 20:48:35 +00:00
|
|
|
else if(error == EINTR)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EINTR);
|
1999-12-14 20:48:35 +00:00
|
|
|
}
|
|
|
|
else if(error)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error);
|
1998-12-27 21:47:14 +00:00
|
|
|
return(error);
|
|
|
|
}
|
2003-11-10 14:20:34 +00:00
|
|
|
tsleep( &rbch_softc[unit], I4BPRI | PCATCH, "xrbch", (hz*1));
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
while(_IF_QFULL(isdn_linktab[unit]->tx_queue) && (sc->sc_devstate & ST_ISOPEN))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_devstate |= ST_WRWAITEMPTY;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2003-03-02 16:54:40 +00:00
|
|
|
if ((error = tsleep( &isdn_linktab[unit]->tx_queue,
|
2003-11-10 14:20:34 +00:00
|
|
|
I4BPRI | PCATCH,
|
1998-12-27 21:47:14 +00:00
|
|
|
"wrbch", 0)) != 0) {
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_devstate &= ~ST_WRWAITEMPTY;
|
|
|
|
if(error == ERESTART)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(ERESTART);
|
1999-12-14 20:48:35 +00:00
|
|
|
}
|
|
|
|
else if(error == EINTR)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
return(error);
|
1999-12-14 20:48:35 +00:00
|
|
|
}
|
|
|
|
else if(error)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
CRIT_END;
|
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error);
|
1998-12-27 21:47:14 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
if(!(sc->sc_devstate & ST_ISOPEN))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit);
|
1999-12-14 20:48:35 +00:00
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL)
|
|
|
|
{
|
|
|
|
m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid);
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
error = uiomove(m->m_data, m->m_len, uio);
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
(void) IF_HANDOFF(isdn_linktab[unit]->tx_queue, m, NULL);
|
2002-03-17 09:33:15 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
(*isdn_linktab[unit]->bch_tx_start)(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel);
|
|
|
|
}
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1999-08-06 14:05:10 +00:00
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* rbch device ioctl handlibg
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
|
|
|
i4brbchioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
1999-08-06 14:05:10 +00:00
|
|
|
{
|
1998-12-27 21:47:14 +00:00
|
|
|
int error = 0;
|
|
|
|
int unit = minor(dev);
|
1999-12-14 20:48:35 +00:00
|
|
|
struct rbch_softc *sc = &rbch_softc[unit];
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case FIOASYNC: /* Set async mode */
|
1999-08-06 14:05:10 +00:00
|
|
|
if (*(int *)data)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, setting async mode", unit);
|
1999-08-06 14:05:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, clearing async mode", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
case FIONBIO:
|
1999-08-06 14:05:10 +00:00
|
|
|
if (*(int *)data)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, setting non-blocking mode", unit);
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_devstate |= ST_NOBLOCK;
|
1999-08-06 14:05:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, clearing non-blocking mode", unit);
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_devstate &= ~ST_NOBLOCK;
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
case TIOCCDTR: /* Clear DTR */
|
1999-12-14 20:48:35 +00:00
|
|
|
if(sc->sc_devstate & ST_CONNECTED)
|
1999-08-06 14:05:10 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, disconnecting for DTR down", unit);
|
1999-11-28 16:17:01 +00:00
|
|
|
i4b_l4_drvrdisc(BDRV_RBCH, unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-08-06 14:05:10 +00:00
|
|
|
|
|
|
|
case I4B_RBCH_DIALOUT:
|
|
|
|
{
|
|
|
|
size_t l;
|
|
|
|
|
|
|
|
for (l = 0; l < TELNO_MAX && ((char *)data)[l]; l++)
|
|
|
|
;
|
|
|
|
if (l)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout to %s", unit, (char *)data);
|
1999-08-06 14:05:10 +00:00
|
|
|
i4b_l4_dialoutnumber(BDRV_RBCH, unit, l, (char *)data);
|
|
|
|
break;
|
|
|
|
}
|
2002-08-25 13:23:09 +00:00
|
|
|
/* FALLTHROUGH to SDTR */
|
1999-08-06 14:05:10 +00:00
|
|
|
}
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
case TIOCSDTR: /* Set DTR */
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, attempting dialout (DTR)", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_l4_dialout(BDRV_RBCH, unit);
|
|
|
|
break;
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
case TIOCSETA: /* Set termios struct */
|
|
|
|
break;
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
case TIOCGETA: /* Get termios struct */
|
1999-12-14 20:48:35 +00:00
|
|
|
*(struct termios *)data = sc->it_in;
|
1998-12-27 21:47:14 +00:00
|
|
|
break;
|
1999-08-06 14:05:10 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
case TIOCMGET:
|
|
|
|
*(int *)data = TIOCM_LE|TIOCM_DTR|TIOCM_RTS|TIOCM_CTS|TIOCM_DSR;
|
1999-12-14 20:48:35 +00:00
|
|
|
if (sc->sc_devstate & ST_CONNECTED)
|
1998-12-27 21:47:14 +00:00
|
|
|
*(int *)data |= TIOCM_CD;
|
|
|
|
break;
|
1999-08-06 14:05:10 +00:00
|
|
|
|
|
|
|
case I4B_RBCH_VR_REQ:
|
|
|
|
{
|
|
|
|
msg_vr_req_t *mvr;
|
|
|
|
|
|
|
|
mvr = (msg_vr_req_t *)data;
|
|
|
|
|
|
|
|
mvr->version = VERSION;
|
|
|
|
mvr->release = REL;
|
|
|
|
mvr->step = STEP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
default: /* Unknown stuff */
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, ioctl, unknown cmd %lx", unit, (u_long)cmd);
|
1998-12-27 21:47:14 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* device driver poll
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-17 09:33:15 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
i4brbchpoll(dev_t dev, int events, struct thread *td)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
int revents = 0; /* Events we found */
|
|
|
|
int s;
|
|
|
|
int unit = minor(dev);
|
1999-12-14 20:48:35 +00:00
|
|
|
struct rbch_softc *sc = &rbch_softc[unit];
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
/* We can't check for anything but IN or OUT */
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
if(!(sc->sc_devstate & ST_ISOPEN))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
splx(s);
|
|
|
|
return(POLLNVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Writes are OK if we are connected and the
|
|
|
|
* transmit queue can take them
|
|
|
|
*/
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
if((events & (POLLOUT|POLLWRNORM)) &&
|
1999-12-14 20:48:35 +00:00
|
|
|
(sc->sc_devstate & ST_CONNECTED) &&
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
!_IF_QFULL(isdn_linktab[unit]->tx_queue))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
revents |= (events & (POLLOUT|POLLWRNORM));
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ... while reads are OK if we have any data */
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
if((events & (POLLIN|POLLRDNORM)) &&
|
1999-12-14 20:48:35 +00:00
|
|
|
(sc->sc_devstate & ST_CONNECTED))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
struct ifqueue *iqp;
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
if(sc->sc_bprot == BPROT_RHDLC)
|
|
|
|
iqp = &sc->sc_hdlcq;
|
1998-12-27 21:47:14 +00:00
|
|
|
else
|
|
|
|
iqp = isdn_linktab[unit]->rx_queue;
|
|
|
|
|
|
|
|
if(!IF_QEMPTY(iqp))
|
1999-05-20 10:14:57 +00:00
|
|
|
revents |= (events & (POLLIN|POLLRDNORM));
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(revents == 0)
|
2001-09-12 08:38:13 +00:00
|
|
|
selrecord(td, &sc->selp);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return(revents);
|
|
|
|
}
|
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
#if I4BRBCHACCT
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* watchdog routine
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_timeout(struct rbch_softc *sc)
|
|
|
|
{
|
|
|
|
bchan_statistics_t bs;
|
|
|
|
int unit = sc->sc_unit;
|
|
|
|
|
|
|
|
/* get # of bytes in and out from the HSCX driver */
|
|
|
|
|
|
|
|
(*isdn_linktab[unit]->bch_stat)
|
|
|
|
(isdn_linktab[unit]->unit, isdn_linktab[unit]->channel, &bs);
|
|
|
|
|
|
|
|
sc->sc_ioutb += bs.outbytes;
|
|
|
|
sc->sc_iinb += bs.inbytes;
|
|
|
|
|
|
|
|
if((sc->sc_iinb != sc->sc_linb) || (sc->sc_ioutb != sc->sc_loutb) || sc->sc_fn)
|
|
|
|
{
|
|
|
|
int ri = (sc->sc_iinb - sc->sc_linb)/I4BRBCHACCTINTVL;
|
|
|
|
int ro = (sc->sc_ioutb - sc->sc_loutb)/I4BRBCHACCTINTVL;
|
|
|
|
|
|
|
|
if((sc->sc_iinb == sc->sc_linb) && (sc->sc_ioutb == sc->sc_loutb))
|
|
|
|
sc->sc_fn = 0;
|
|
|
|
else
|
|
|
|
sc->sc_fn = 1;
|
|
|
|
|
|
|
|
sc->sc_linb = sc->sc_iinb;
|
|
|
|
sc->sc_loutb = sc->sc_ioutb;
|
|
|
|
|
|
|
|
i4b_l4_accounting(BDRV_RBCH, unit, ACCT_DURING,
|
|
|
|
sc->sc_ioutb, sc->sc_iinb, ro, ri, sc->sc_ioutb, sc->sc_iinb);
|
|
|
|
}
|
2000-10-09 13:18:17 +00:00
|
|
|
START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
|
1999-12-14 20:48:35 +00:00
|
|
|
}
|
|
|
|
#endif /* I4BRBCHACCT */
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
/*===========================================================================*
|
|
|
|
* ISDN INTERFACE ROUTINES
|
|
|
|
*===========================================================================*/
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from L4 handler at connect time
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_connect(int unit, void *cdp)
|
|
|
|
{
|
|
|
|
call_desc_t *cd = (call_desc_t *)cdp;
|
1999-12-14 20:48:35 +00:00
|
|
|
struct rbch_softc *sc = &rbch_softc[unit];
|
1998-12-27 21:47:14 +00:00
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_bprot = cd->bprot;
|
|
|
|
|
|
|
|
#if I4BRBCHACCT
|
|
|
|
if(sc->sc_bprot == BPROT_RHDLC)
|
|
|
|
{
|
|
|
|
sc->sc_iinb = 0;
|
|
|
|
sc->sc_ioutb = 0;
|
|
|
|
sc->sc_linb = 0;
|
|
|
|
sc->sc_loutb = 0;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
START_TIMER(sc->sc_callout, rbch_timeout, sc, I4BRBCHACCTINTVL*hz);
|
1999-12-14 20:48:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if(!(sc->sc_devstate & ST_CONNECTED))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
|
1999-12-14 20:48:35 +00:00
|
|
|
sc->sc_devstate |= ST_CONNECTED;
|
|
|
|
sc->sc_cd = cdp;
|
2003-03-02 16:54:40 +00:00
|
|
|
wakeup(sc);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from L4 handler at disconnect time
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_disconnect(int unit, void *cdp)
|
|
|
|
{
|
1999-12-14 20:48:35 +00:00
|
|
|
call_desc_t *cd = (call_desc_t *)cdp;
|
|
|
|
struct rbch_softc *sc = &rbch_softc[unit];
|
|
|
|
|
|
|
|
CRIT_VAR;
|
|
|
|
|
|
|
|
if(cd != sc->sc_cd)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "rbch%d: channel %d not active",
|
|
|
|
cd->driver_unit, cd->channelid);
|
1999-12-14 20:48:35 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-12-27 21:47:14 +00:00
|
|
|
|
1999-12-14 20:48:35 +00:00
|
|
|
CRIT_BEG;
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, disconnect", unit);
|
1999-12-14 20:48:35 +00:00
|
|
|
|
|
|
|
sc->sc_devstate &= ~ST_CONNECTED;
|
|
|
|
|
|
|
|
sc->sc_cd = NULL;
|
|
|
|
|
|
|
|
#if I4BRBCHACCT
|
|
|
|
i4b_l4_accounting(BDRV_RBCH, unit, ACCT_FINAL,
|
|
|
|
sc->sc_ioutb, sc->sc_iinb, 0, 0, sc->sc_ioutb, sc->sc_iinb);
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
STOP_TIMER(sc->sc_callout, rbch_timeout, sc);
|
1999-12-14 20:48:35 +00:00
|
|
|
#endif
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* feedback from daemon in case of dial problems
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
1999-05-20 10:14:57 +00:00
|
|
|
rbch_dialresponse(int unit, int status, cause_t cause)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* interface up/down
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_updown(int unit, int updown)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from the HSCX interrupt handler
|
|
|
|
* when a new frame (mbuf) has been received and is to be put on
|
|
|
|
* the rx queue.
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_rx_data_rdy(int unit)
|
|
|
|
{
|
|
|
|
if(rbch_softc[unit].sc_bprot == BPROT_RHDLC)
|
|
|
|
{
|
|
|
|
register struct mbuf *m;
|
|
|
|
|
|
|
|
if((m = *isdn_linktab[unit]->rx_mbuf) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m->m_pkthdr.len = m->m_len;
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if (! IF_HANDOFF(&(rbch_softc[unit].sc_hdlcq), m, NULL))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d: hdlc rx queue full!", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
}
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
if(rbch_softc[unit].sc_devstate & ST_RDWAITDATA)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
rbch_softc[unit].sc_devstate &= ~ST_RDWAITDATA;
|
2003-03-02 16:54:40 +00:00
|
|
|
wakeup( &isdn_linktab[unit]->rx_queue);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
2003-11-10 14:20:34 +00:00
|
|
|
selwakeuppri(&rbch_softc[unit].selp, I4BPRI);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from the HSCX interrupt handler
|
|
|
|
* when the last frame has been sent out and there is no
|
|
|
|
* further frame (mbuf) in the tx queue.
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_tx_queue_empty(int unit)
|
|
|
|
{
|
|
|
|
if(rbch_softc[unit].sc_devstate & ST_WRWAITEMPTY)
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, wakeup", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
rbch_softc[unit].sc_devstate &= ~ST_WRWAITEMPTY;
|
2003-03-02 16:54:40 +00:00
|
|
|
wakeup( &isdn_linktab[unit]->tx_queue);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL4(L4_RBCHDBG, "unit %d, NO wakeup", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
2003-11-09 09:17:26 +00:00
|
|
|
selwakeuppri(&rbch_softc[unit].selp, TTOPRI);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* this routine is called from the HSCX interrupt handler
|
|
|
|
* each time a packet is received or transmitted
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_activity(int unit, int rxtx)
|
|
|
|
{
|
1999-12-14 20:48:35 +00:00
|
|
|
if (rbch_softc[unit].sc_cd)
|
|
|
|
rbch_softc[unit].sc_cd->last_active_time = SECOND;
|
2003-11-10 14:20:34 +00:00
|
|
|
selwakeuppri(&rbch_softc[unit].selp, I4BPRI);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* clear an hdlc rx queue for a rbch unit
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_clrq(int unit)
|
|
|
|
{
|
1999-12-14 20:48:35 +00:00
|
|
|
CRIT_VAR;
|
2001-01-15 14:54:43 +00:00
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
CRIT_BEG;
|
|
|
|
IF_DRAIN(&rbch_softc[unit].sc_hdlcq);
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* return this drivers linktab address
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
drvr_link_t *
|
|
|
|
rbch_ret_linktab(int unit)
|
|
|
|
{
|
|
|
|
rbch_init_linktab(unit);
|
|
|
|
return(&rbch_drvr_linktab[unit]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* setup the isdn_linktab for this driver
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
rbch_set_linktab(int unit, isdn_link_t *ilt)
|
|
|
|
{
|
|
|
|
isdn_linktab[unit] = ilt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* initialize this drivers linktab
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rbch_init_linktab(int unit)
|
|
|
|
{
|
|
|
|
rbch_drvr_linktab[unit].unit = unit;
|
|
|
|
rbch_drvr_linktab[unit].bch_rx_data_ready = rbch_rx_data_rdy;
|
|
|
|
rbch_drvr_linktab[unit].bch_tx_queue_empty = rbch_tx_queue_empty;
|
|
|
|
rbch_drvr_linktab[unit].bch_activity = rbch_activity;
|
|
|
|
rbch_drvr_linktab[unit].line_connected = rbch_connect;
|
|
|
|
rbch_drvr_linktab[unit].line_disconnected = rbch_disconnect;
|
|
|
|
rbch_drvr_linktab[unit].dial_response = rbch_dialresponse;
|
|
|
|
rbch_drvr_linktab[unit].updown_ind = rbch_updown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*/
|