1994-12-02 23:23:01 +00:00
|
|
|
/*
|
|
|
|
* Cronyx-Sigma adapter driver for FreeBSD.
|
|
|
|
* Supports PPP/HDLC and Cisco/HDLC protocol in synchronous mode,
|
|
|
|
* and asyncronous channels with full modem control.
|
|
|
|
* Keepalive protocol implemented in both Cisco and PPP modes.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1994 Cronyx Ltd.
|
|
|
|
* Author: Serge Vakulenko, <vak@zebub.msk.su>
|
|
|
|
*
|
|
|
|
* This software is distributed with NO WARRANTIES, not even the implied
|
|
|
|
* warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Authors grant any other persons or organisations permission to use
|
|
|
|
* or modify this software as long as this message is kept with the software,
|
|
|
|
* all derivative works or modified versions.
|
|
|
|
*
|
1995-10-04 22:24:16 +00:00
|
|
|
* Version 1.9, Wed Oct 4 18:58:15 MSK 1995
|
1994-12-02 23:23:01 +00:00
|
|
|
*/
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include "cx.h"
|
1995-11-18 08:21:15 +00:00
|
|
|
#include "bpfilter.h"
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
1994-12-04 08:51:58 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
1994-12-02 23:23:01 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
#include <i386/isa/isa_device.h>
|
|
|
|
#ifdef DEVFS
|
1995-12-08 11:19:42 +00:00
|
|
|
extern struct cdevsw cx_cdevsw;
|
1995-12-10 13:40:44 +00:00
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
|
|
|
#include <sys/devconf.h>
|
|
|
|
#define watchdog_func_t void(*)(struct ifnet *)
|
|
|
|
#define start_func_t void(*)(struct ifnet*)
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
#include <net/if_sppp.h>
|
1994-12-04 08:51:58 +00:00
|
|
|
#include <machine/cronyx.h>
|
1994-12-02 23:23:01 +00:00
|
|
|
#include <i386/isa/cxreg.h>
|
|
|
|
|
1995-12-15 00:54:32 +00:00
|
|
|
/* XXX exported. */
|
|
|
|
void cxswitch (cx_chan_t *c, cx_soft_opt_t new);
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static int cxprobe __P((struct isa_device *id));
|
|
|
|
static int cxattach __P((struct isa_device *id));
|
|
|
|
static void cxput __P((cx_chan_t *c, char b));
|
|
|
|
static void cxsend __P((cx_chan_t *c));
|
|
|
|
static void cxrinth __P((cx_chan_t *c));
|
|
|
|
static int cxtinth __P((cx_chan_t *c));
|
1995-11-18 08:21:15 +00:00
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
# define print(s) printf s
|
|
|
|
#else
|
1995-10-04 22:24:16 +00:00
|
|
|
# define print(s) {/*void*/}
|
1994-12-02 23:23:01 +00:00
|
|
|
#endif
|
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
#define TXTIMEOUT 10 /* transmit timeout in seconds */
|
1994-12-02 23:23:01 +00:00
|
|
|
#define DMABUFSZ (6*256) /* buffer size */
|
|
|
|
#define PPP_HEADER_LEN 4 /* size of PPP header */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Under BSDI it's possible to use general p2p protocol scheme,
|
|
|
|
* as well as our own one. Switching is done via IFF_ALTPHYS flag.
|
|
|
|
* Our ifnet pointer holds the buffer large enough to contain
|
|
|
|
* any of sppp and p2p structures.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
#define IFSTRUCTSZ (sizeof (struct sppp))
|
1994-12-02 23:23:01 +00:00
|
|
|
#define IFNETSZ (sizeof (struct ifnet))
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static int cxsioctl (struct ifnet *ifp, int cmd, caddr_t data);
|
|
|
|
static void cxstart (struct ifnet *ifp);
|
|
|
|
static void cxwatchdog (struct ifnet *ifp);
|
|
|
|
static void cxinput (cx_chan_t *c, void *buf, unsigned len);
|
|
|
|
extern int cxrinta (cx_chan_t *c);
|
|
|
|
extern void cxtinta (cx_chan_t *c);
|
|
|
|
extern void cxmint (cx_chan_t *c);
|
|
|
|
extern void cxtimeout (caddr_t a);
|
|
|
|
static void cxdown (cx_chan_t *c);
|
|
|
|
static void cxup (cx_chan_t *c);
|
1994-12-02 23:23:01 +00:00
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
cx_board_t cxboard [NCX]; /* adapter state structures */
|
|
|
|
cx_chan_t *cxchan [NCX*NCHAN]; /* unit to channel struct pointer */
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
static unsigned short irq_valid_values [] = { 3, 5, 7, 10, 11, 12, 15, 0 };
|
|
|
|
static unsigned short drq_valid_values [] = { 5, 6, 7, 0 };
|
|
|
|
static unsigned short port_valid_values [] = {
|
|
|
|
0x240, 0x260, 0x280, 0x300, 0x320, 0x380, 0x3a0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static char cxdescription [80];
|
|
|
|
struct kern_devconf kdc_cx [NCX] = { {
|
|
|
|
0, 0, 0, "cx", 0, { MDDT_ISA, 0, "net" },
|
|
|
|
isa_generic_externalize, 0, 0, ISA_EXTERNALLEN, &kdc_isa0, 0,
|
1995-04-12 20:48:13 +00:00
|
|
|
DC_IDLE, cxdescription, DC_CLS_SERIAL
|
1994-12-02 23:23:01 +00:00
|
|
|
} };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the value is contained in the list of correct values.
|
|
|
|
*/
|
|
|
|
static int valid (unsigned short value, unsigned short *list)
|
|
|
|
{
|
|
|
|
while (*list)
|
|
|
|
if (value == *list++)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the mbuf chain, for debug purposes only.
|
|
|
|
*/
|
|
|
|
static void printmbuf (struct mbuf *m)
|
|
|
|
{
|
|
|
|
printf ("mbuf:");
|
|
|
|
for (; m; m=m->m_next) {
|
|
|
|
if (m->m_flags & M_PKTHDR)
|
|
|
|
printf (" HDR %d:", m->m_pkthdr.len);
|
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
printf (" EXT:");
|
|
|
|
printf (" %d", m->m_len);
|
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make an mbuf from data.
|
|
|
|
*/
|
|
|
|
static struct mbuf *makembuf (void *buf, unsigned len)
|
|
|
|
{
|
|
|
|
struct mbuf *m, *o, *p;
|
|
|
|
|
|
|
|
MGETHDR (m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (! m)
|
|
|
|
return (0);
|
|
|
|
if (len >= MINCLSIZE)
|
|
|
|
MCLGET (m, M_DONTWAIT);
|
|
|
|
m->m_pkthdr.len = len;
|
|
|
|
m->m_len = 0;
|
|
|
|
|
|
|
|
p = m;
|
|
|
|
while (len) {
|
|
|
|
unsigned n = M_TRAILINGSPACE (p);
|
|
|
|
if (n > len)
|
|
|
|
n = len;
|
|
|
|
|
|
|
|
if (! n) {
|
|
|
|
/* Allocate new mbuf. */
|
|
|
|
o = p;
|
|
|
|
MGET (p, M_DONTWAIT, MT_DATA);
|
|
|
|
if (! p) {
|
|
|
|
m_freem (m);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (len >= MINCLSIZE)
|
|
|
|
MCLGET (p, M_DONTWAIT);
|
|
|
|
p->m_len = 0;
|
|
|
|
o->m_next = p;
|
|
|
|
|
|
|
|
n = M_TRAILINGSPACE (p);
|
|
|
|
if (n > len)
|
|
|
|
n = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy (buf, mtod (p, caddr_t) + p->m_len, n);
|
|
|
|
|
|
|
|
p->m_len += n;
|
|
|
|
buf += n;
|
|
|
|
len -= n;
|
|
|
|
}
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the presence of the adapter on the given i/o port.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
|
|
|
cxprobe (struct isa_device *id)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
int unit = id->id_unit;
|
|
|
|
int iobase = id->id_iobase;
|
|
|
|
int irq = id->id_irq;
|
|
|
|
int drq = id->id_drq;
|
|
|
|
int irqnum;
|
|
|
|
irqnum = ffs (irq) - 1;
|
|
|
|
|
|
|
|
print (("cx%d: probe iobase=0x%x irq=%d drq=%d\n",
|
|
|
|
unit, iobase, irqnum, drq));
|
|
|
|
if (! valid (irqnum, irq_valid_values)) {
|
|
|
|
printf ("cx%d: Incorrect IRQ: %d\n", unit, irqnum);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (! valid (iobase, port_valid_values)) {
|
|
|
|
printf ("cx%d: Incorrect port address: 0x%x\n", unit, iobase);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (! valid (drq, drq_valid_values)) {
|
|
|
|
printf ("cx%d: Incorrect DMA channel: %d\n", unit, drq);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (! cx_probe_board (iobase))
|
|
|
|
return (0);
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The adapter is present, initialize the driver structures.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
|
|
|
cxattach (struct isa_device *id)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
int unit = id->id_unit;
|
|
|
|
int iobase = id->id_iobase;
|
|
|
|
int irq = id->id_irq;
|
|
|
|
int drq = id->id_drq;
|
|
|
|
cx_board_t *b = cxboard + unit;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Initialize the board structure. */
|
|
|
|
cx_init (b, unit, iobase, ffs(irq)-1, drq);
|
|
|
|
|
|
|
|
for (i=0; i<NCHAN; ++i) {
|
|
|
|
cx_chan_t *c = b->chan + i;
|
|
|
|
int u = b->num*NCHAN + i;
|
|
|
|
cxchan[u] = c;
|
|
|
|
|
|
|
|
if (c->type == T_NONE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Allocate the buffer memory. */
|
|
|
|
c->arbuf = malloc (DMABUFSZ, M_DEVBUF, M_NOWAIT);
|
|
|
|
c->brbuf = malloc (DMABUFSZ, M_DEVBUF, M_NOWAIT);
|
|
|
|
c->atbuf = malloc (DMABUFSZ, M_DEVBUF, M_NOWAIT);
|
|
|
|
c->btbuf = malloc (DMABUFSZ, M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
/* All buffers should be located in lower 16M of memory! */
|
|
|
|
if (!c->arbuf || !c->brbuf || !c->atbuf || !c->btbuf) {
|
|
|
|
printf ("cx%d.%d: No memory for channel buffers\n",
|
|
|
|
c->board->num, c->num);
|
|
|
|
c->type = T_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c->type) {
|
|
|
|
case T_SYNC_RS232:
|
|
|
|
case T_SYNC_V35:
|
|
|
|
case T_SYNC_RS449:
|
|
|
|
case T_UNIV_RS232:
|
|
|
|
case T_UNIV_RS449:
|
|
|
|
case T_UNIV_V35:
|
|
|
|
c->ifp = malloc (IFSTRUCTSZ, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (! c->ifp) {
|
|
|
|
printf ("cx%d.%d: No memory for ifnet buffer\n",
|
|
|
|
c->board->num, c->num);
|
|
|
|
c->type = T_NONE;
|
|
|
|
continue;
|
|
|
|
}
|
1995-10-04 22:24:16 +00:00
|
|
|
bzero (c->ifp, IFSTRUCTSZ);
|
|
|
|
c->master = c->ifp;
|
1994-12-02 23:23:01 +00:00
|
|
|
c->ifp->if_unit = u;
|
|
|
|
c->ifp->if_name = "cx";
|
|
|
|
c->ifp->if_mtu = PP_MTU;
|
1995-10-04 22:24:16 +00:00
|
|
|
c->ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
|
1994-12-02 23:23:01 +00:00
|
|
|
c->ifp->if_ioctl = cxsioctl;
|
|
|
|
c->ifp->if_start = (start_func_t) cxstart;
|
|
|
|
c->ifp->if_watchdog = (watchdog_func_t) cxwatchdog;
|
|
|
|
/* Init routine is never called by upper level? */
|
|
|
|
sppp_attach (c->ifp);
|
|
|
|
if_attach (c->ifp);
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/* If BPF is in the kernel, call the attach for it. */
|
|
|
|
bpfattach (&c->bpf, c->ifp, DLT_PPP, PPP_HEADER_LEN);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the adapter. */
|
|
|
|
cx_setup_board (b);
|
|
|
|
|
|
|
|
/* Activate the timeout routine. */
|
|
|
|
if (unit == 0)
|
|
|
|
timeout ((timeout_func_t) cxtimeout, 0, hz*5);
|
|
|
|
|
|
|
|
if (unit != 0)
|
|
|
|
kdc_cx[unit] = kdc_cx[0];
|
|
|
|
kdc_cx[unit].kdc_unit = unit;
|
|
|
|
kdc_cx[unit].kdc_isa = id;
|
|
|
|
sprintf (cxdescription, "Cronyx-Sigma-%s sync/async serial adapter",
|
|
|
|
b->name);
|
|
|
|
dev_attach (&kdc_cx[unit]);
|
|
|
|
printf ("cx%d: <Cronyx-%s>\n", unit, b->name);
|
1995-11-29 10:49:16 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
{
|
1995-12-08 11:19:42 +00:00
|
|
|
void *x;
|
1995-11-29 10:49:16 +00:00
|
|
|
x=devfs_add_devsw(
|
|
|
|
/* path name devsw minor type uid gid perm*/
|
1995-12-08 11:19:42 +00:00
|
|
|
"/", "cx", &cx_cdevsw, 0, DV_CHR, 0, 0, 0600);
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
1994-12-02 23:23:01 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct isa_driver cxdriver = { cxprobe, cxattach, "cx" };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
|
|
|
cxsioctl (struct ifnet *ifp, int cmd, caddr_t data)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
1995-10-04 22:24:16 +00:00
|
|
|
cx_chan_t *q, *c = cxchan[ifp->if_unit];
|
|
|
|
int error, s, was_up, should_be_up;
|
1994-12-02 23:23:01 +00:00
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
/*
|
|
|
|
* No socket ioctls while the channel is in async mode.
|
|
|
|
*/
|
1994-12-02 23:23:01 +00:00
|
|
|
if (c->type==T_NONE || c->mode==M_ASYNC)
|
|
|
|
return (EINVAL);
|
1995-10-04 22:24:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Socket ioctls on slave subchannels are not allowed.
|
|
|
|
*/
|
|
|
|
if (c->master != c->ifp)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
was_up = (ifp->if_flags & IFF_RUNNING) != 0;
|
1994-12-02 23:23:01 +00:00
|
|
|
error = sppp_ioctl (ifp, cmd, data);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
1995-10-04 22:24:16 +00:00
|
|
|
|
|
|
|
print (("cxioctl (%d.%d, ", c->board->num, c->num));
|
|
|
|
switch (cmd) {
|
|
|
|
default:
|
|
|
|
print (("0x%x)\n", cmd));
|
|
|
|
return (0);
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
print (("SIOCADDMULTI)\n"));
|
|
|
|
return (0);
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
print (("SIOCDELMULTI)\n"));
|
1994-12-02 23:23:01 +00:00
|
|
|
return (0);
|
1995-10-04 22:24:16 +00:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
print (("SIOCSIFFLAGS)\n"));
|
|
|
|
break;
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
print (("SIOCSIFADDR)\n"));
|
|
|
|
break;
|
|
|
|
}
|
1994-12-02 23:23:01 +00:00
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
/* We get here only in case of SIFFLAGS or SIFADDR. */
|
1994-12-02 23:23:01 +00:00
|
|
|
s = splimp ();
|
1995-10-04 22:24:16 +00:00
|
|
|
should_be_up = (ifp->if_flags & IFF_RUNNING) != 0;
|
|
|
|
if (!was_up && should_be_up) {
|
|
|
|
/* Interface goes up -- start it. */
|
|
|
|
cxup (c);
|
|
|
|
|
|
|
|
/* Start all slave subchannels. */
|
|
|
|
for (q=c->slaveq; q; q=q->slaveq)
|
|
|
|
cxup (q);
|
|
|
|
|
|
|
|
cxstart (c->ifp);
|
|
|
|
} else if (was_up && !should_be_up) {
|
|
|
|
/* Interface is going down -- stop it. */
|
|
|
|
cxdown (c);
|
|
|
|
|
|
|
|
/* Stop all slave subchannels. */
|
|
|
|
for (q=c->slaveq; q; q=q->slaveq)
|
|
|
|
cxdown (q);
|
|
|
|
|
|
|
|
/* Flush the interface output queue */
|
|
|
|
if (! c->sopt.ext)
|
|
|
|
sppp_flush (c->ifp);
|
|
|
|
}
|
1994-12-02 23:23:01 +00:00
|
|
|
splx (s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-10-04 22:24:16 +00:00
|
|
|
* Stop the interface. Called on splimp().
|
1994-12-02 23:23:01 +00:00
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxdown (cx_chan_t *c)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
unsigned short port = c->chip->port;
|
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
print (("cx%d.%d: cxdown\n", c->board->num, c->num));
|
1994-12-02 23:23:01 +00:00
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
/* The interface is down, stop it */
|
|
|
|
c->ifp->if_flags &= ~IFF_OACTIVE;
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
/* Reset the channel (for sync modes only) */
|
|
|
|
outb (CAR(port), c->num & 3);
|
|
|
|
outb (STCR(port), STC_ABORTTX | STC_SNDSPC);
|
1995-10-04 22:24:16 +00:00
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
cx_setup_chan (c);
|
1995-10-04 22:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the interface. Called on splimp().
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxup (cx_chan_t *c)
|
1995-10-04 22:24:16 +00:00
|
|
|
{
|
|
|
|
unsigned short port = c->chip->port;
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
/* The interface is up, start it */
|
1995-12-10 13:40:44 +00:00
|
|
|
print (("cx%d.%d: cxup\n", c->board->num, c->num));
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
kdc_cx[c->board->num].kdc_state = DC_BUSY;
|
1995-12-10 13:40:44 +00:00
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
/* Initialize channel, enable receiver and transmitter */
|
|
|
|
cx_cmd (port, CCR_INITCH | CCR_ENRX | CCR_ENTX);
|
|
|
|
/* Repeat the command, to avoid the rev.H bug */
|
|
|
|
cx_cmd (port, CCR_INITCH | CCR_ENRX | CCR_ENTX);
|
|
|
|
|
|
|
|
/* Start receiver */
|
|
|
|
outw (ARBCNT(port), DMABUFSZ);
|
|
|
|
outb (ARBSTS(port), BSTS_OWN24);
|
|
|
|
outw (BRBCNT(port), DMABUFSZ);
|
|
|
|
outb (BRBSTS(port), BSTS_OWN24);
|
|
|
|
|
|
|
|
/* Raise DTR and RTS */
|
|
|
|
cx_chan_dtr (c, 1);
|
|
|
|
cx_chan_rts (c, 1);
|
|
|
|
|
|
|
|
/* Enable interrupts */
|
|
|
|
outb (IER(port), IER_RXD | IER_TXD);
|
1995-10-04 22:24:16 +00:00
|
|
|
}
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill transmitter buffer with data.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxput (cx_chan_t *c, char b)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
unsigned char *buf;
|
|
|
|
unsigned short port = c->chip->port, len, cnt_port, sts_port;
|
|
|
|
|
|
|
|
/* Choose the buffer. */
|
|
|
|
if (b == 'A') {
|
|
|
|
buf = c->atbuf;
|
|
|
|
cnt_port = ATBCNT(port);
|
|
|
|
sts_port = ATBSTS(port);
|
|
|
|
} else {
|
|
|
|
buf = c->btbuf;
|
|
|
|
cnt_port = BTBCNT(port);
|
|
|
|
sts_port = BTBSTS(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is it busy? */
|
|
|
|
if (inb (sts_port) & BSTS_OWN24) {
|
1995-10-04 22:24:16 +00:00
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
print (("cx%d.%d: tbuf %c already busy, bsts=%b\n",
|
|
|
|
c->board->num, c->num, b,
|
|
|
|
inb (sts_port), BSTS_BITS));
|
|
|
|
goto ret;
|
1994-12-02 23:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the packet to send. */
|
1995-10-04 22:24:16 +00:00
|
|
|
m = sppp_dequeue (c->master);
|
1994-12-02 23:23:01 +00:00
|
|
|
if (! m)
|
|
|
|
return;
|
|
|
|
len = m->m_pkthdr.len;
|
1995-10-04 22:24:16 +00:00
|
|
|
|
|
|
|
/* Count the transmitted bytes to the subchannel, not the master. */
|
|
|
|
c->master->if_obytes -= len + 3;
|
|
|
|
c->ifp->if_obytes += len + 3;
|
|
|
|
c->stat->obytes += len + 3;
|
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
if (len >= DMABUFSZ) {
|
1995-10-04 22:24:16 +00:00
|
|
|
printf ("cx%d.%d: too long packet: %d bytes: ",
|
1994-12-02 23:23:01 +00:00
|
|
|
c->board->num, c->num, len);
|
|
|
|
printmbuf (m);
|
|
|
|
m_freem (m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_copydata (m, 0, len, buf);
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (c->bpf)
|
|
|
|
bpf_mtap (c->bpf, m);
|
|
|
|
#endif
|
|
|
|
m_freem (m);
|
|
|
|
|
|
|
|
/* Start transmitter. */
|
|
|
|
outw (cnt_port, len);
|
|
|
|
outb (sts_port, BSTS_EOFR | BSTS_INTR | BSTS_OWN24);
|
1995-10-04 22:24:16 +00:00
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
1995-10-04 22:24:16 +00:00
|
|
|
print (("cx%d.%d: enqueue %d bytes to %c\n",
|
|
|
|
c->board->num, c->num, len, buf==c->atbuf ? 'A' : 'B'));
|
|
|
|
ret:
|
1994-12-02 23:23:01 +00:00
|
|
|
c->ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-10-04 22:24:16 +00:00
|
|
|
* Start output on the (slave) interface. Get another datagram to send
|
1994-12-02 23:23:01 +00:00
|
|
|
* off of the interface queue, and copy it to the interface
|
|
|
|
* before starting the output.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxsend (cx_chan_t *c)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
unsigned short port = c->chip->port;
|
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
print (("cx%d.%d: cxsend\n", c->board->num, c->num));
|
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
/* No output if the interface is down. */
|
1995-10-04 22:24:16 +00:00
|
|
|
if (! (c->ifp->if_flags & IFF_RUNNING))
|
1994-12-02 23:23:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Set the current channel number. */
|
|
|
|
outb (CAR(port), c->num & 3);
|
|
|
|
|
|
|
|
/* Determine the buffer order. */
|
|
|
|
if (inb (DMABSTS(port)) & DMABSTS_NTBUF) {
|
|
|
|
cxput (c, 'B');
|
|
|
|
cxput (c, 'A');
|
|
|
|
} else {
|
|
|
|
cxput (c, 'A');
|
|
|
|
cxput (c, 'B');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up transmit timeout. */
|
1995-10-04 22:24:16 +00:00
|
|
|
if (c->master->if_flags & IFF_OACTIVE)
|
|
|
|
c->master->if_timer = TXTIMEOUT;
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable TXMPTY interrupt,
|
|
|
|
* to catch the case when the second buffer is empty.
|
|
|
|
*/
|
|
|
|
if ((inb (ATBSTS(port)) & BSTS_OWN24) &&
|
|
|
|
(inb (BTBSTS(port)) & BSTS_OWN24)) {
|
|
|
|
outb (IER(port), IER_RXD | IER_TXD | IER_TXMPTY);
|
|
|
|
} else
|
|
|
|
outb (IER(port), IER_RXD | IER_TXD);
|
|
|
|
}
|
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
/*
|
|
|
|
* Start output on the (master) interface and all slave interfaces.
|
|
|
|
* Always called on splimp().
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxstart (struct ifnet *ifp)
|
1995-10-04 22:24:16 +00:00
|
|
|
{
|
|
|
|
cx_chan_t *q, *c = cxchan[ifp->if_unit];
|
|
|
|
|
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
print (("cx%d.%d: cxstart\n", c->board->num, c->num));
|
|
|
|
|
|
|
|
/* Start the master subchannel. */
|
|
|
|
cxsend (c);
|
|
|
|
|
|
|
|
/* Start all slave subchannels. */
|
|
|
|
if (c->slaveq && ! sppp_isempty (c->master))
|
|
|
|
for (q=c->slaveq; q; q=q->slaveq)
|
|
|
|
if ((q->ifp->if_flags & IFF_RUNNING) &&
|
|
|
|
! (q->ifp->if_flags & IFF_OACTIVE))
|
|
|
|
cxsend (q);
|
|
|
|
}
|
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
/*
|
|
|
|
* Handle transmit timeouts.
|
|
|
|
* Recover after lost transmit interrupts.
|
1995-10-04 22:24:16 +00:00
|
|
|
* Always called on splimp().
|
1994-12-02 23:23:01 +00:00
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxwatchdog (struct ifnet *ifp)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
1995-12-05 02:01:59 +00:00
|
|
|
cx_chan_t *q, *c = cxchan[ifp->if_unit];
|
1995-10-04 22:24:16 +00:00
|
|
|
|
1995-12-05 02:01:59 +00:00
|
|
|
if (! (ifp->if_flags & IFF_RUNNING))
|
1995-10-04 22:24:16 +00:00
|
|
|
return;
|
1995-12-05 02:01:59 +00:00
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
1995-10-04 22:24:16 +00:00
|
|
|
printf ("cx%d.%d: device timeout\n", c->board->num, c->num);
|
|
|
|
|
|
|
|
cxdown (c);
|
|
|
|
for (q=c->slaveq; q; q=q->slaveq)
|
|
|
|
cxdown (q);
|
|
|
|
|
|
|
|
cxup (c);
|
|
|
|
for (q=c->slaveq; q; q=q->slaveq)
|
|
|
|
cxup (q);
|
1994-12-02 23:23:01 +00:00
|
|
|
|
1995-12-05 02:01:59 +00:00
|
|
|
cxstart (ifp);
|
1994-12-02 23:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle receive interrupts, including receive errors and
|
|
|
|
* receive timeout interrupt.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxrinth (cx_chan_t *c)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
unsigned short port = c->chip->port;
|
|
|
|
unsigned short len, risr = inw (RISR(port));
|
|
|
|
|
|
|
|
/* Receive errors. */
|
|
|
|
if (risr & (RIS_BUSERR | RIS_OVERRUN | RISH_CRCERR | RISH_RXABORT)) {
|
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
printf ("cx%d.%d: receive error, risr=%b\n",
|
|
|
|
c->board->num, c->num, risr, RISH_BITS);
|
|
|
|
++c->ifp->if_ierrors;
|
1995-10-04 22:24:16 +00:00
|
|
|
++c->stat->ierrs;
|
1994-12-02 23:23:01 +00:00
|
|
|
if (risr & RIS_OVERRUN)
|
|
|
|
++c->ifp->if_collisions;
|
|
|
|
} else if (risr & RIS_EOBUF) {
|
1995-10-04 22:24:16 +00:00
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
print (("cx%d.%d: hdlc receive interrupt, risr=%b, arbsts=%b, brbsts=%b\n",
|
|
|
|
c->board->num, c->num, risr, RISH_BITS,
|
|
|
|
inb (ARBSTS(port)), BSTS_BITS,
|
|
|
|
inb (BRBSTS(port)), BSTS_BITS));
|
|
|
|
++c->stat->ipkts;
|
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
/* Handle received data. */
|
|
|
|
len = (risr & RIS_BB) ? inw(BRBCNT(port)) : inw(ARBCNT(port));
|
1995-10-04 22:24:16 +00:00
|
|
|
c->stat->ibytes += len;
|
1994-12-02 23:23:01 +00:00
|
|
|
if (len > DMABUFSZ) {
|
|
|
|
/* Fatal error: actual DMA transfer size
|
|
|
|
* exceeds our buffer size. It could be caused
|
|
|
|
* by incorrectly programmed DMA register or
|
|
|
|
* hardware fault. Possibly, should panic here. */
|
|
|
|
printf ("cx%d.%d: panic! DMA buffer overflow: %d bytes\n",
|
|
|
|
c->board->num, c->num, len);
|
|
|
|
++c->ifp->if_ierrors;
|
|
|
|
} else if (! (risr & RIS_EOFR)) {
|
|
|
|
/* The received frame does not fit in the DMA buffer.
|
|
|
|
* It could be caused by serial lie noise,
|
|
|
|
* or if the peer has too big MTU. */
|
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
printf ("cx%d.%d: received frame length exceeds MTU, risr=%b\n",
|
|
|
|
c->board->num, c->num, risr, RISH_BITS);
|
|
|
|
++c->ifp->if_ierrors;
|
|
|
|
} else {
|
|
|
|
/* Valid frame received. */
|
1995-10-04 22:24:16 +00:00
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
print (("cx%d.%d: hdlc received %d bytes\n",
|
1994-12-02 23:23:01 +00:00
|
|
|
c->board->num, c->num, len));
|
|
|
|
cxinput (c, (risr & RIS_BB) ? c->brbuf : c->arbuf, len);
|
|
|
|
++c->ifp->if_ipackets;
|
|
|
|
}
|
1995-10-04 22:24:16 +00:00
|
|
|
} else if (c->ifp->if_flags & IFF_DEBUG) {
|
|
|
|
print (("cx%d.%d: unknown hdlc receive interrupt, risr=%b\n",
|
|
|
|
c->board->num, c->num, risr, RISH_BITS));
|
|
|
|
++c->stat->ierrs;
|
1994-12-02 23:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restart receiver. */
|
|
|
|
if (! (inb (ARBSTS(port)) & BSTS_OWN24)) {
|
|
|
|
outw (ARBCNT(port), DMABUFSZ);
|
|
|
|
outb (ARBSTS(port), BSTS_OWN24);
|
|
|
|
}
|
|
|
|
if (! (inb (BRBSTS(port)) & BSTS_OWN24)) {
|
|
|
|
outw (BRBCNT(port), DMABUFSZ);
|
|
|
|
outb (BRBSTS(port), BSTS_OWN24);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle transmit interrupt.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
|
|
|
cxtinth (cx_chan_t *c)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
unsigned short port = c->chip->port;
|
|
|
|
unsigned char tisr = inb (TISR(port));
|
|
|
|
unsigned char teoir = 0;
|
|
|
|
|
1995-10-04 22:24:16 +00:00
|
|
|
c->ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
if (c->ifp == c->master)
|
|
|
|
c->ifp->if_timer = 0;
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
if (tisr & (TIS_BUSERR | TIS_UNDERRUN)) {
|
1995-10-04 22:24:16 +00:00
|
|
|
/* if (c->ifp->if_flags & IFF_DEBUG) */
|
|
|
|
print (("cx%d.%d: transmit error, tisr=%b, atbsts=%b, btbsts=%b\n",
|
|
|
|
c->board->num, c->num, tisr, TIS_BITS,
|
|
|
|
inb (ATBSTS(port)), BSTS_BITS,
|
|
|
|
inb (BTBSTS(port)), BSTS_BITS));
|
1994-12-02 23:23:01 +00:00
|
|
|
++c->ifp->if_oerrors;
|
1995-10-04 22:24:16 +00:00
|
|
|
++c->stat->oerrs;
|
|
|
|
|
1994-12-02 23:23:01 +00:00
|
|
|
/* Terminate the failed buffer. */
|
1995-10-04 22:24:16 +00:00
|
|
|
/* teoir = TEOI_TERMBUFF; */
|
|
|
|
} else if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
print (("cx%d.%d: hdlc transmit interrupt, tisr=%b, atbsts=%b, btbsts=%b\n",
|
|
|
|
c->board->num, c->num, tisr, TIS_BITS,
|
|
|
|
inb (ATBSTS(port)), BSTS_BITS,
|
|
|
|
inb (BTBSTS(port)), BSTS_BITS));
|
|
|
|
|
|
|
|
if (tisr & TIS_EOFR) {
|
1994-12-02 23:23:01 +00:00
|
|
|
++c->ifp->if_opackets;
|
1995-10-04 22:24:16 +00:00
|
|
|
++c->stat->opkts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start output on the (sub-) channel. */
|
|
|
|
cxsend (c);
|
1994-12-02 23:23:01 +00:00
|
|
|
|
|
|
|
return (teoir);
|
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
void
|
|
|
|
cxintr (int bnum)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
cx_board_t *b = cxboard + bnum;
|
|
|
|
while (! (inw (BSR(b->port)) & BSR_NOINTR)) {
|
|
|
|
/* Acknowledge the interrupt to enter the interrupt context. */
|
|
|
|
/* Read the local interrupt vector register. */
|
|
|
|
unsigned char livr = inb (IACK(b->port, BRD_INTR_LEVEL));
|
|
|
|
cx_chan_t *c = b->chan + (livr>>2 & 0xf);
|
|
|
|
unsigned short port = c->chip->port;
|
|
|
|
unsigned short eoiport = REOIR(port);
|
|
|
|
unsigned char eoi = 0;
|
|
|
|
|
|
|
|
if (c->type == T_NONE) {
|
|
|
|
printf ("cx%d.%d: unexpected interrupt, livr=0x%x\n",
|
|
|
|
c->board->num, c->num, livr);
|
|
|
|
continue; /* incorrect channel number? */
|
|
|
|
}
|
|
|
|
/* print (("cx%d.%d: interrupt, livr=0x%x\n",
|
|
|
|
c->board->num, c->num, livr)); */
|
|
|
|
|
|
|
|
/* Clear RTS to stop receiver data flow while we are busy
|
|
|
|
* processing the interrupt, thus avoiding underruns. */
|
|
|
|
if (! c->sopt.norts) {
|
|
|
|
outb (MSVR_RTS(port), 0);
|
|
|
|
c->rts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (livr & 3) {
|
|
|
|
case LIV_EXCEP: /* receive exception */
|
|
|
|
case LIV_RXDATA: /* receive interrupt */
|
1995-10-04 22:24:16 +00:00
|
|
|
++c->stat->rintr;
|
1994-12-02 23:23:01 +00:00
|
|
|
switch (c->mode) {
|
|
|
|
case M_ASYNC: eoi = cxrinta (c); break;
|
|
|
|
case M_HDLC: cxrinth (c); break;
|
|
|
|
default:; /* No bisync and X.21 yet */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIV_TXDATA: /* transmit interrupt */
|
1995-10-04 22:24:16 +00:00
|
|
|
++c->stat->tintr;
|
1994-12-02 23:23:01 +00:00
|
|
|
eoiport = TEOIR(port);
|
|
|
|
switch (c->mode) {
|
|
|
|
case M_ASYNC: cxtinta (c); break;
|
|
|
|
case M_HDLC: eoi = cxtinth (c); break;
|
|
|
|
default:; /* No bisync and X.21 yet */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIV_MODEM: /* modem/timer interrupt */
|
1995-10-04 22:24:16 +00:00
|
|
|
++c->stat->mintr;
|
1994-12-02 23:23:01 +00:00
|
|
|
eoiport = MEOIR(port);
|
|
|
|
cxmint (c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Raise RTS for this channel if and only if
|
|
|
|
* both receive buffers are empty. */
|
|
|
|
if (! c->sopt.norts && (inb (CSR(port)) & CSRA_RXEN) &&
|
|
|
|
(inb (ARBSTS(port)) & BSTS_OWN24) &&
|
|
|
|
(inb (BRBSTS(port)) & BSTS_OWN24)) {
|
|
|
|
outb (MSVR_RTS(port), MSV_RTS);
|
|
|
|
c->rts = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exit from interrupt context. */
|
|
|
|
outb (eoiport, eoi);
|
1995-10-04 22:24:16 +00:00
|
|
|
|
|
|
|
/* Master channel - start output on all idle subchannels. */
|
|
|
|
if (c->master == c->ifp && c->slaveq &&
|
|
|
|
(livr & 3) == LIV_TXDATA && c->mode == M_HDLC &&
|
|
|
|
! sppp_isempty (c->ifp)) {
|
|
|
|
cx_chan_t *q;
|
|
|
|
|
|
|
|
for (q=c->slaveq; q; q=q->slaveq)
|
|
|
|
if ((q->ifp->if_flags & IFF_RUNNING) &&
|
|
|
|
! (q->ifp->if_flags & IFF_OACTIVE))
|
|
|
|
cxsend (q);
|
|
|
|
}
|
1994-12-02 23:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the received packet.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
cxinput (cx_chan_t *c, void *buf, unsigned len)
|
1994-12-02 23:23:01 +00:00
|
|
|
{
|
|
|
|
/* Make an mbuf. */
|
|
|
|
struct mbuf *m = makembuf (buf, len);
|
|
|
|
if (! m) {
|
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
|
|
|
printf ("cx%d.%d: no memory for packet\n",
|
|
|
|
c->board->num, c->num);
|
|
|
|
++c->ifp->if_iqdrops;
|
|
|
|
return;
|
|
|
|
}
|
1995-10-04 22:24:16 +00:00
|
|
|
m->m_pkthdr.rcvif = c->master;
|
1994-12-02 23:23:01 +00:00
|
|
|
#ifdef DEBUG
|
1995-10-04 22:24:16 +00:00
|
|
|
if (c->ifp->if_flags & IFF_DEBUG)
|
1994-12-02 23:23:01 +00:00
|
|
|
printmbuf (m);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
1995-05-30 08:16:23 +00:00
|
|
|
* If so, hand off the raw packet to bpf.
|
1994-12-02 23:23:01 +00:00
|
|
|
*/
|
|
|
|
if (c->bpf)
|
|
|
|
bpf_tap (c->bpf, buf, len);
|
|
|
|
#endif
|
1995-10-04 22:24:16 +00:00
|
|
|
|
|
|
|
/* Count the received bytes to the subchannel, not the master. */
|
|
|
|
c->master->if_ibytes -= len + 3;
|
|
|
|
c->ifp->if_ibytes += len + 3;
|
|
|
|
|
|
|
|
sppp_input (c->master, m);
|
1994-12-02 23:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cxswitch (cx_chan_t *c, cx_soft_opt_t new)
|
|
|
|
{
|
|
|
|
new.ext = 0;
|
|
|
|
if (! new.ext) {
|
|
|
|
struct sppp *sp = (struct sppp*) c->ifp;
|
|
|
|
|
|
|
|
if (new.cisco)
|
|
|
|
sp->pp_flags |= PP_CISCO;
|
|
|
|
else
|
|
|
|
sp->pp_flags &= ~PP_CISCO;
|
|
|
|
if (new.keepalive)
|
|
|
|
sp->pp_flags |= PP_KEEPALIVE;
|
|
|
|
else
|
|
|
|
sp->pp_flags &= ~PP_KEEPALIVE;
|
|
|
|
}
|
|
|
|
c->sopt = new;
|
|
|
|
}
|