Make code more clean: backout support for 3.x branch.
This commit is contained in:
parent
5980decb5b
commit
3cc90ff9d1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130971
@ -45,9 +45,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <sys/tty.h>
|
||||
#if __FreeBSD_version >= 400000
|
||||
# include <sys/bus.h>
|
||||
#endif
|
||||
#include <sys/bus.h>
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
#include <net/if.h>
|
||||
@ -76,18 +74,11 @@ __FBSDID("$FreeBSD$");
|
||||
#else
|
||||
# include <net/if_sppp.h>
|
||||
# define PP_CISCO IFF_LINK2
|
||||
# if __FreeBSD_version < 400000
|
||||
# include <bpfilter.h>
|
||||
# if NBPFILTER > 0
|
||||
# include <net/bpf.h>
|
||||
# endif
|
||||
# else
|
||||
# if __FreeBSD_version < 500000
|
||||
# include <bpf.h>
|
||||
# endif
|
||||
# include <net/bpf.h>
|
||||
# define NBPFILTER NBPF
|
||||
#endif
|
||||
# if __FreeBSD_version < 500000
|
||||
# include <bpf.h>
|
||||
# endif
|
||||
# include <net/bpf.h>
|
||||
# define NBPFILTER NBPF
|
||||
#endif
|
||||
#if __FreeBSD_version >= 500000
|
||||
#include <dev/cx/machdep.h>
|
||||
@ -112,7 +103,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#define CDEV_MAJOR 134
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static int cp_probe __P((device_t));
|
||||
static int cp_attach __P((device_t));
|
||||
static int cp_detach __P((device_t));
|
||||
@ -140,7 +130,6 @@ static driver_t cp_driver = {
|
||||
};
|
||||
|
||||
static devclass_t cp_devclass;
|
||||
#endif
|
||||
|
||||
typedef struct _drv_t {
|
||||
char name [8];
|
||||
@ -160,9 +149,7 @@ typedef struct _drv_t {
|
||||
#else
|
||||
struct sppp pp;
|
||||
#endif
|
||||
#if __FreeBSD_version >= 400000
|
||||
struct cdev *devt;
|
||||
#endif
|
||||
} drv_t;
|
||||
|
||||
static void cp_receive (cp_chan_t *c, unsigned char *data, int len);
|
||||
@ -227,14 +214,6 @@ static struct mbuf *makembuf (void *buf, unsigned len)
|
||||
return m;
|
||||
}
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
static const char *cp_probe (pcici_t tag, pcidi_t type)
|
||||
{
|
||||
if (tag->vendor == cp_vendor_id && tag->device == cp_device_id)
|
||||
return "Cronyx-Tau-PCI serial adapter";
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static int cp_probe (device_t dev)
|
||||
{
|
||||
if ((pci_get_vendor (dev) == cp_vendor_id) &&
|
||||
@ -244,7 +223,6 @@ static int cp_probe (device_t dev)
|
||||
}
|
||||
return ENXIO;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void cp_timeout (void *arg)
|
||||
{
|
||||
@ -300,12 +278,8 @@ static void cp_led_off (void *arg)
|
||||
|
||||
static void cp_intr (void *arg)
|
||||
{
|
||||
#if __FreeBSD_version < 400000
|
||||
cp_board_t *b = arg;
|
||||
#else
|
||||
bdrv_t *bd = arg;
|
||||
cp_board_t *b = bd->board;
|
||||
#endif
|
||||
int s = splimp ();
|
||||
if (cp_destroy) {
|
||||
splx (s);
|
||||
@ -327,17 +301,11 @@ extern struct cdevsw cp_cdevsw;
|
||||
/*
|
||||
* Called if the probe succeeded.
|
||||
*/
|
||||
#if __FreeBSD_version < 400000
|
||||
static void cp_attach (pcici_t tag, int unit)
|
||||
{
|
||||
vm_offset_t pbase;
|
||||
#else
|
||||
static int cp_attach (device_t dev)
|
||||
{
|
||||
bdrv_t *bd = device_get_softc (dev);
|
||||
int unit = device_get_unit (dev);
|
||||
int rid, error;
|
||||
#endif
|
||||
vm_offset_t vbase;
|
||||
cp_board_t *b;
|
||||
cp_chan_t *c;
|
||||
@ -348,25 +316,12 @@ static int cp_attach (device_t dev)
|
||||
b = malloc (sizeof(cp_board_t), M_DEVBUF, M_WAITOK);
|
||||
if (!b) {
|
||||
printf ("cp%d: couldn't allocate memory\n", unit);
|
||||
#if __FreeBSD_version < 400000
|
||||
splx (s);
|
||||
return;
|
||||
#else
|
||||
splx (s);
|
||||
return (ENXIO);
|
||||
#endif
|
||||
}
|
||||
adapter[unit] = b;
|
||||
bzero (b, sizeof(cp_board_t));
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
if (! pci_map_mem (tag, PCIR_MAPS, &vbase, &pbase)) {
|
||||
printf ("cp%d: cannot map memory\n", unit);
|
||||
free (b, M_DEVBUF);
|
||||
splx (s);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
bd->board = b;
|
||||
b->sys = bd;
|
||||
rid = PCIR_BAR(0);
|
||||
@ -379,21 +334,14 @@ static int cp_attach (device_t dev)
|
||||
return (ENXIO);
|
||||
}
|
||||
vbase = (vm_offset_t) rman_get_virtual (bd->cp_res);
|
||||
#endif
|
||||
|
||||
res = cp_init (b, unit, (u_char*) vbase);
|
||||
if (res) {
|
||||
printf ("cp%d: can't init, error code:%x\n", unit, res);
|
||||
#if __FreeBSD_version >= 400000
|
||||
bus_release_resource (dev, SYS_RES_MEMORY, PCIR_BAR(0), bd->cp_res);
|
||||
#endif
|
||||
free (b, M_DEVBUF);
|
||||
splx (s);
|
||||
#if __FreeBSD_version >= 400000
|
||||
return (ENXIO);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
queue[unit] = contigmalloc (sizeof(cp_qbuf_t), M_DEVBUF, M_WAITOK,
|
||||
0x100000, 0xffffffff, 16, 0);
|
||||
@ -401,18 +349,10 @@ static int cp_attach (device_t dev)
|
||||
printf ("cp%d: allocate memory for qbuf_t\n", unit);
|
||||
free (b, M_DEVBUF);
|
||||
splx (s);
|
||||
#if __FreeBSD_version >= 400000
|
||||
return (ENXIO);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
cp_reset (b, queue[unit], vtophys (queue[unit]));
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
if (! pci_map_int (tag, cp_intr, b, &net_imask))
|
||||
printf ("cp%d: cannot map interrupt\n", unit);
|
||||
#else
|
||||
rid = 0;
|
||||
bd->cp_irq = bus_alloc_resource (dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
|
||||
RF_SHAREABLE | RF_ACTIVE);
|
||||
@ -435,7 +375,6 @@ static int cp_attach (device_t dev)
|
||||
splx (s);
|
||||
return (ENXIO);
|
||||
}
|
||||
#endif
|
||||
printf ("cp%d: %s, clock %ld MHz\n", unit, b->name, b->osc / 1000000);
|
||||
|
||||
for (c=b->chan; c<b->chan+NCHAN; ++c) {
|
||||
@ -500,11 +439,9 @@ static int cp_attach (device_t dev)
|
||||
if_attach (&d->pp.pp_if);
|
||||
d->pp.pp_tlf = cp_tlf;
|
||||
d->pp.pp_tls = cp_tls;
|
||||
#if __FreeBSD_version >= 400000 || NBPFILTER > 0
|
||||
/* If BPF is in the kernel, call the attach for it.
|
||||
* The header size of PPP or Cisco/HDLC is 4 bytes. */
|
||||
bpfattach (&d->pp.pp_if, DLT_PPP, 4);
|
||||
#endif
|
||||
#endif /*NETGRAPH*/
|
||||
cp_start_e1 (c);
|
||||
cp_start_chan (c, 1, 1, &d->buf, vtophys (&d->buf));
|
||||
@ -513,18 +450,13 @@ static int cp_attach (device_t dev)
|
||||
cp_register_transmit (c, &cp_transmit);
|
||||
cp_register_receive (c, &cp_receive);
|
||||
cp_register_error (c, &cp_error);
|
||||
#if __FreeBSD_version >= 400000
|
||||
d->devt = make_dev (&cp_cdevsw, b->num*NCHAN+c->num, UID_ROOT,
|
||||
GID_WHEEL, 0600, "cp%d", b->num*NCHAN+c->num);
|
||||
#endif
|
||||
}
|
||||
splx (s);
|
||||
#if __FreeBSD_version >= 400000
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static int cp_detach (device_t dev)
|
||||
{
|
||||
bdrv_t *bd = device_get_softc (dev);
|
||||
@ -616,29 +548,14 @@ static int cp_detach (device_t dev)
|
||||
continue;
|
||||
channel [b->num*NCHAN + c->num] = 0;
|
||||
/* Deallocate buffers. */
|
||||
#if __FreeBSD_version < 400000
|
||||
free (d, M_DEVBUF);
|
||||
#else
|
||||
contigfree (d, sizeof (*d), M_DEVBUF);
|
||||
#endif
|
||||
}
|
||||
adapter [b->num] = 0;
|
||||
#if __FreeBSD_version < 400000
|
||||
free (queue[b->num], M_DEVBUF);
|
||||
#else
|
||||
contigfree (queue[b->num], sizeof (cp_qbuf_t), M_DEVBUF);
|
||||
#endif
|
||||
free (b, M_DEVBUF);
|
||||
splx (s);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
static u_long cp_count;
|
||||
static struct pci_device cp_driver = {"cp", cp_probe, cp_attach, &cp_count, 0};
|
||||
DATA_SET (pcidevice_set, cp_driver);
|
||||
#endif
|
||||
|
||||
#ifndef NETGRAPH
|
||||
static void cp_ifstart (struct ifnet *ifp)
|
||||
@ -785,7 +702,7 @@ static void cp_send (drv_t *d)
|
||||
#endif
|
||||
if (! m)
|
||||
return;
|
||||
#if (__FreeBSD_version >= 400000 || NBPFILTER > 0) && !defined (NETGRAPH)
|
||||
#ifndef NETGRAPH
|
||||
if (d->pp.pp_if.if_bpf)
|
||||
#if __FreeBSD_version >= 500000
|
||||
BPF_MTAP (&d->pp.pp_if, m);
|
||||
@ -899,7 +816,6 @@ static void cp_receive (cp_chan_t *c, unsigned char *data, int len)
|
||||
#else
|
||||
++d->pp.pp_if.if_ipackets;
|
||||
m->m_pkthdr.rcvif = &d->pp.pp_if;
|
||||
#if __FreeBSD_version >= 400000 || NBPFILTER > 0
|
||||
/* Check if there's a BPF listener on this interface.
|
||||
* If so, hand off the raw packet to bpf. */
|
||||
if (d->pp.pp_if.if_bpf)
|
||||
@ -907,7 +823,6 @@ static void cp_receive (cp_chan_t *c, unsigned char *data, int len)
|
||||
BPF_TAP (&d->pp.pp_if, data, len);
|
||||
#else
|
||||
bpf_tap (&d->pp.pp_if, data, len);
|
||||
#endif
|
||||
#endif
|
||||
sppp_input (&d->pp.pp_if, m);
|
||||
#endif
|
||||
@ -1044,9 +959,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETPROTO:
|
||||
CP_DEBUG2 (d, ("ioctl: setproto\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1081,9 +994,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETKEEPALIVE:
|
||||
CP_DEBUG2 (d, ("ioctl: setkeepalive\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1109,9 +1020,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETMODE:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1131,9 +1040,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETCFG:
|
||||
CP_DEBUG2 (d, ("ioctl: setcfg\n"));
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1232,9 +1139,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_CLRSTAT:
|
||||
CP_DEBUG2 (d, ("ioctl: clrstat\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1267,9 +1172,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETBAUD:
|
||||
CP_DEBUG2 (d, ("ioctl: setbaud\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1289,9 +1192,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETLOOP:
|
||||
CP_DEBUG2 (d, ("ioctl: setloop\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1313,9 +1214,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETDPLL:
|
||||
CP_DEBUG2 (d, ("ioctl: setdpll\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1339,9 +1238,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETNRZI:
|
||||
CP_DEBUG2 (d, ("ioctl: setnrzi\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1363,9 +1260,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETDEBUG:
|
||||
CP_DEBUG2 (d, ("ioctl: setdebug\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1391,9 +1286,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETHIGAIN:
|
||||
CP_DEBUG2 (d, ("ioctl: sethigain\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1417,9 +1310,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETPHONY:
|
||||
CP_DEBUG2 (d, ("ioctl: setphony\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1443,9 +1334,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETUNFRAM:
|
||||
CP_DEBUG2 (d, ("ioctl: setunfram\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1469,9 +1358,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETSCRAMBLER:
|
||||
CP_DEBUG2 (d, ("ioctl: setscrambler\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1498,9 +1385,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETMONITOR:
|
||||
CP_DEBUG2 (d, ("ioctl: setmonitor\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1524,9 +1409,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETUSE16:
|
||||
CP_DEBUG2 (d, ("ioctl: setuse16\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1550,9 +1433,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETCRC4:
|
||||
CP_DEBUG2 (d, ("ioctl: setcrc4\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1587,9 +1468,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETCLK:
|
||||
CP_DEBUG2 (d, ("ioctl: setclk\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1624,9 +1503,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETTIMESLOTS:
|
||||
CP_DEBUG2 (d, ("ioctl: settimeslots\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1654,9 +1531,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETINVCLK:
|
||||
CP_DEBUG2 (d, ("ioctl: setinvclk\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1681,9 +1556,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETINVTCLK:
|
||||
CP_DEBUG2 (d, ("ioctl: setinvtclk\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1707,9 +1580,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETINVRCLK:
|
||||
CP_DEBUG2 (d, ("ioctl: setinvrclk\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1736,9 +1607,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_RESET:
|
||||
CP_DEBUG2 (d, ("ioctl: reset\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1753,9 +1622,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_HARDRESET:
|
||||
CP_DEBUG2 (d, ("ioctl: hardreset\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1787,9 +1654,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETDIR:
|
||||
CP_DEBUG2 (d, ("ioctl: setdir\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1816,9 +1681,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
if (c->type != T_E3 && c->type != T_T3 && c->type != T_STS1)
|
||||
return EINVAL;
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1842,9 +1705,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
if (c->type != T_T3 && c->type != T_STS1)
|
||||
return EINVAL;
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else
|
||||
error = suser (td);
|
||||
@ -1896,14 +1757,7 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
static struct cdevsw cp_cdevsw = {
|
||||
cp_open, cp_close, noread, nowrite,
|
||||
cp_ioctl, nullstop, nullreset, nodevtotty,
|
||||
seltrue, nommap, NULL, "cp",
|
||||
NULL, -1
|
||||
};
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
static struct cdevsw cp_cdevsw = {
|
||||
cp_open, cp_close, noread, nowrite,
|
||||
cp_ioctl, nopoll, nommap, nostrategy,
|
||||
@ -2410,14 +2264,8 @@ static int ng_cp_rmnode (node_p node)
|
||||
node->flags |= NG_INVALID;
|
||||
ng_cutlinks (node);
|
||||
#ifdef KLD_MODULE
|
||||
#if __FreeBSD_version >= 400000
|
||||
/* We do so because of pci module problem, see also comment in
|
||||
cp_unload. Not in 4.x. */
|
||||
ng_unname (node);
|
||||
ng_unref (node);
|
||||
#else
|
||||
node->flags &= ~NG_INVALID;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
@ -2478,178 +2326,7 @@ static int ng_cp_disconnect (hook_p hook)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
|
||||
#ifdef KLD_MODULE
|
||||
extern STAILQ_HEAD(devlist, pci_devinfo) pci_devq;
|
||||
|
||||
static
|
||||
struct pci_devinfo *pci_device_find (u_int16_t device, u_int16_t vendor, int unit)
|
||||
{
|
||||
pcicfgregs *cfg;
|
||||
struct pci_devinfo *dinfo;
|
||||
int u=0,i;
|
||||
|
||||
for (dinfo = STAILQ_FIRST (&pci_devq), i=0;
|
||||
dinfo && (i < pci_numdevs);
|
||||
dinfo = STAILQ_NEXT (dinfo, pci_links), i++) {
|
||||
cfg = &dinfo->cfg;
|
||||
if ((device == cfg->device) && (vendor == cfg->vendor)) {
|
||||
if (u == unit)
|
||||
return dinfo;
|
||||
u++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function called when loading the driver.
|
||||
*/
|
||||
static int cp_load (void)
|
||||
{
|
||||
int i, s;
|
||||
pcicfgregs *cfg;
|
||||
struct pci_devinfo *dinfo;
|
||||
|
||||
s = splimp ();
|
||||
for (i=0; i<NBRD; ++i) {
|
||||
dinfo = pci_device_find (cp_device_id, cp_vendor_id, i);
|
||||
if (! dinfo)
|
||||
break;
|
||||
|
||||
cfg = &dinfo->cfg;
|
||||
cp_attach (cfg, i);
|
||||
dinfo->device = &cp_driver;
|
||||
strncpy (dinfo->conf.pd_name, cp_driver.pd_name,
|
||||
sizeof(dinfo->conf.pd_name));
|
||||
dinfo->conf.pd_name[sizeof(dinfo->conf.pd_name) - 1] = 0;
|
||||
dinfo->conf.pd_unit = i;
|
||||
}
|
||||
splx (s);
|
||||
if (! i) {
|
||||
/* Deactivate the timeout routine. */
|
||||
untimeout (cp_timeout, 0, timeout_handle);
|
||||
return ENXIO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function called when unloading the driver.
|
||||
*/
|
||||
static int cp_unload (void)
|
||||
{
|
||||
#if 1
|
||||
/* Currently pci loadable module not fully supported, so we just
|
||||
return EBUSY. Do not forget to correct ng_cp_rmnode then probelm
|
||||
would be solved. */
|
||||
return EBUSY;
|
||||
#else
|
||||
int i, s;
|
||||
|
||||
/* Check if the device is busy (open). */
|
||||
for (i=0; i<NBRD*NCHAN; ++i) {
|
||||
drv_t *d = channel[i];
|
||||
|
||||
if (d && d->chan->type && d->running)
|
||||
return EBUSY;
|
||||
}
|
||||
|
||||
s = splimp ();
|
||||
|
||||
/* Deactivate the timeout routine. */
|
||||
untimeout (cp_timeout, 0, timeout_handle);
|
||||
|
||||
/* OK to unload the driver, unregister the interrupt first. */
|
||||
for (i=0; i<NBRD; ++i) {
|
||||
cp_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->type)
|
||||
continue;
|
||||
|
||||
cp_reset (b, 0 ,0);
|
||||
/* pci_unmap_int (tag, cp_intr, b, &net_imask);*/
|
||||
/* Here should be something like pci_unmap_mem ()*/
|
||||
}
|
||||
|
||||
for (i=0; i<NBRD; i++)
|
||||
if (led_timo[i].callout)
|
||||
untimeout (cp_led_off, adapter + i, led_timo[i]);
|
||||
|
||||
/* Detach the interfaces, free buffer memory. */
|
||||
for (i=0; i<NBRD*NCHAN; ++i) {
|
||||
drv_t *d = channel[i];
|
||||
|
||||
if (! d)
|
||||
continue;
|
||||
#ifndef NETGRAPH
|
||||
#if __FreeBSD_version >= 400000 || NBPFILTER > 0
|
||||
/* Detach from the packet filter list of interfaces. */
|
||||
{
|
||||
struct bpf_if *q, **b = &bpf_iflist;
|
||||
|
||||
while ((q = *b)) {
|
||||
if (q->bif_ifp == d->pp.pp_if) {
|
||||
*b = q->bif_next;
|
||||
free (q, M_DEVBUF);
|
||||
}
|
||||
b = &(q->bif_next);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Detach from the sync PPP list. */
|
||||
sppp_detach (&d->pp.pp_if);
|
||||
|
||||
/* Detach from the system list of interfaces. */
|
||||
{
|
||||
struct ifaddr *ifa;
|
||||
TAILQ_FOREACH (ifa, &d->pp.pp_if.if_addrhead, ifa_link) {
|
||||
TAILQ_REMOVE (&d->pp.pp_if.if_addrhead, ifa, ifa_link);
|
||||
free (ifa, M_IFADDR);
|
||||
}
|
||||
TAILQ_REMOVE (&ifnet, &d->pp.pp_if, if_link);
|
||||
}
|
||||
#endif
|
||||
/* Deallocate buffers. */
|
||||
/* free (d, M_DEVBUF);*/
|
||||
}
|
||||
|
||||
for (i=0; i<NBRD; ++i) {
|
||||
cp_board_t *b = adapter + i;
|
||||
|
||||
if (b && b->type)
|
||||
free (b, M_DEVBUF);
|
||||
}
|
||||
splx (s);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
#ifdef KLD_MODULE
|
||||
static int cp_modevent (module_t mod, int type, void *unused)
|
||||
{
|
||||
dev_t dev;
|
||||
|
||||
switch (type) {
|
||||
case MOD_LOAD:
|
||||
dev = makedev (CDEV_MAJOR, 0);
|
||||
cdevsw_add (&dev, &cp_cdevsw, 0);
|
||||
timeout_handle = timeout (cp_timeout, 0, hz*5);
|
||||
return cp_load ();
|
||||
case MOD_UNLOAD:
|
||||
return cp_unload ();
|
||||
case MOD_SHUTDOWN:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* KLD_MODULE */
|
||||
|
||||
#else /* __FreeBSD_version >= 400000 */
|
||||
static int cp_modevent (module_t mod, int type, void *unused)
|
||||
{
|
||||
struct cdev *dev;
|
||||
@ -2697,7 +2374,6 @@ static int cp_modevent (module_t mod, int type, void *unused)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
|
||||
#ifdef NETGRAPH
|
||||
static struct ng_type typestruct = {
|
||||
@ -2711,10 +2387,6 @@ static struct ng_type typestruct = {
|
||||
.rcvdata = ng_cp_rcvdata,
|
||||
.disconnect = ng_cp_disconnect,
|
||||
};
|
||||
#if __FreeBSD_version < 400000
|
||||
NETGRAPH_INIT_ORDERED (cp, &typestruct, SI_SUB_DRIVERS,\
|
||||
SI_ORDER_MIDDLE + CDEV_MAJOR);
|
||||
#endif
|
||||
#endif /*NETGRAPH*/
|
||||
|
||||
#if __FreeBSD_version >= 500000
|
||||
@ -2734,38 +2406,5 @@ DRIVER_MODULE (cp, pci, cp_driver, cp_devclass, ng_mod_event, &typestruct);
|
||||
#else
|
||||
DRIVER_MODULE (cp, pci, cp_driver, cp_devclass, cp_modevent, NULL);
|
||||
#endif
|
||||
#else /* __FreeBSD_version < 400000 */
|
||||
#ifdef KLD_MODULE
|
||||
#ifndef NETGRAPH
|
||||
static moduledata_t cpmod = { "cp", cp_modevent, NULL};
|
||||
DECLARE_MODULE (cp, cpmod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR);
|
||||
#endif
|
||||
#else /* KLD_MODULE */
|
||||
|
||||
/*
|
||||
* Now for some driver initialisation.
|
||||
* Occurs ONCE during boot (very early).
|
||||
* This is if we are NOT a loadable module.
|
||||
*/
|
||||
static void cp_drvinit (void *unused)
|
||||
{
|
||||
dev_t dev;
|
||||
|
||||
dev = makedev (CDEV_MAJOR, 0);
|
||||
cdevsw_add (&dev, &cp_cdevsw, 0);
|
||||
|
||||
/* Activate the timeout routine. */
|
||||
timeout_handle = timeout (cp_timeout, 0, hz);
|
||||
#ifdef NETGRAPH
|
||||
#if 0
|
||||
/* Register our node type in netgraph */
|
||||
if (ng_newtype (&typestruct))
|
||||
printf ("Failed to register ng_cp\n");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
SYSINIT (cpdev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+CDEV_MAJOR, cp_drvinit, 0)
|
||||
#endif /* KLD_MODULE */
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
#endif /* __FreeBSD_version >= 400000 */
|
||||
#endif /* NPCI */
|
||||
|
@ -43,12 +43,10 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/tty.h>
|
||||
#if __FreeBSD_version >= 400000
|
||||
# include <sys/bus.h>
|
||||
# include <machine/bus.h>
|
||||
# include <sys/rman.h>
|
||||
# include <isa/isavar.h>
|
||||
#endif
|
||||
#include <sys/bus.h>
|
||||
#include <machine/bus.h>
|
||||
#include <sys/rman.h>
|
||||
#include <isa/isavar.h>
|
||||
#include <sys/interrupt.h>
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
@ -57,34 +55,22 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/cserial.h>
|
||||
#include <machine/clock.h>
|
||||
#if __FreeBSD_version < 500000
|
||||
#include <i386/isa/isa_device.h>
|
||||
# include <i386/isa/isa_device.h>
|
||||
#endif
|
||||
#if __FreeBSD_version >= 400000
|
||||
#include <machine/resource.h>
|
||||
# if __FreeBSD_version <= 501000
|
||||
#if __FreeBSD_version <= 501000
|
||||
# include <i386/isa/intr_machdep.h>
|
||||
# endif
|
||||
#endif
|
||||
#if __FreeBSD_version >= 400000
|
||||
#include <dev/cx/machdep.h>
|
||||
#include <dev/ctau/ctddk.h>
|
||||
#include <dev/cx/cronyxfw.h>
|
||||
#else
|
||||
#include <i386/isa/cronyx/machdep.h>
|
||||
#include <i386/isa/cronyx/ctddk.h>
|
||||
#include <i386/isa/cronyx/cronyxfw.h>
|
||||
#endif
|
||||
#include "opt_ng_cronyx.h"
|
||||
#ifdef NETGRAPH_CRONYX
|
||||
# include "opt_netgraph.h"
|
||||
# include <netgraph/ng_message.h>
|
||||
# include <netgraph/netgraph.h>
|
||||
#if __FreeBSD_version >= 400000
|
||||
# include <dev/ctau/ng_ct.h>
|
||||
#else
|
||||
# include <netgraph/ng_ct.h>
|
||||
#endif
|
||||
#else
|
||||
# include <net/if_types.h>
|
||||
# if __FreeBSD_version < 500000
|
||||
# include "sppp.h"
|
||||
@ -94,19 +80,12 @@ __FBSDID("$FreeBSD$");
|
||||
# endif
|
||||
# include <net/if_sppp.h>
|
||||
# define PP_CISCO IFF_LINK2
|
||||
#if __FreeBSD_version < 400000
|
||||
# include <bpfilter.h>
|
||||
# if NBPFILTER > 0
|
||||
# include <net/bpf.h>
|
||||
# endif
|
||||
#else
|
||||
# if __FreeBSD_version < 500000
|
||||
# include <bpf.h>
|
||||
# endif
|
||||
# include <net/bpf.h>
|
||||
# define NBPFILTER NBPF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* If we don't have Cronyx's sppp version, we don't have fr support via sppp */
|
||||
#ifndef PP_FR
|
||||
@ -119,7 +98,6 @@ __FBSDID("$FreeBSD$");
|
||||
printf ("%s: ", d->name); printf s;}})
|
||||
#define CDEV_MAJOR 99
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static void ct_identify __P((driver_t *, device_t));
|
||||
static int ct_probe __P((device_t));
|
||||
static int ct_attach __P((device_t));
|
||||
@ -151,7 +129,6 @@ static driver_t ct_isa_driver = {
|
||||
};
|
||||
|
||||
static devclass_t ct_devclass;
|
||||
#endif
|
||||
|
||||
typedef struct _drv_t {
|
||||
char name [8];
|
||||
@ -171,9 +148,7 @@ typedef struct _drv_t {
|
||||
#else
|
||||
struct sppp pp;
|
||||
#endif
|
||||
#if __FreeBSD_version >= 400000
|
||||
struct cdev *devt;
|
||||
#endif
|
||||
} drv_t;
|
||||
|
||||
static void ct_receive (ct_chan_t *c, char *data, int len);
|
||||
@ -266,16 +241,10 @@ static void ct_led_off (void *arg)
|
||||
/*
|
||||
* Activate interupt handler from DDK.
|
||||
*/
|
||||
#if __FreeBSD_version >= 400000
|
||||
static void ct_intr (void *arg)
|
||||
{
|
||||
bdrv_t *bd = arg;
|
||||
ct_board_t *b = bd->board;
|
||||
#else
|
||||
static void ct_intr (int bnum)
|
||||
{
|
||||
ct_board_t *b = adapter [bnum];
|
||||
#endif
|
||||
int s = splimp ();
|
||||
|
||||
/* Turn LED on. */
|
||||
@ -326,7 +295,6 @@ static short porttab [] = {
|
||||
static char dmatab [] = { 7, 6, 5, 0 };
|
||||
static char irqtab [] = { 5, 10, 11, 7, 3, 15, 12, 0 };
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static int ct_is_free_res (device_t dev, int rid, int type, u_long start,
|
||||
u_long end, u_long count)
|
||||
{
|
||||
@ -476,128 +444,22 @@ static int ct_probe (device_t dev)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* __FreeBSD_version < 400000 */
|
||||
static int ct_probe (struct isa_device *id)
|
||||
{
|
||||
int unit = id->id_unit;
|
||||
int iobase;
|
||||
ct_board_t *b;
|
||||
int i;
|
||||
|
||||
iobase = id->id_iobase;
|
||||
if (iobase < 0) {
|
||||
/* Autodetect the adapter. */
|
||||
|
||||
for (i=0; ; i++) {
|
||||
if (! porttab[i]) {
|
||||
iobase = -1;
|
||||
return 0;
|
||||
}
|
||||
iobase = porttab[i];
|
||||
if (unit > 0 && adapter[0] && adapter[0]->port == iobase)
|
||||
continue;
|
||||
if (unit > 1 && adapter[1] && adapter[1]->port == iobase)
|
||||
continue;
|
||||
if (! haveseen_isadev (id, CC_IOADDR | CC_QUIET) &&
|
||||
ct_probe_board (iobase, -1, -1))
|
||||
break;
|
||||
}
|
||||
} else if (! ct_probe_board (iobase, -1, -1))
|
||||
return 0;
|
||||
|
||||
if (id->id_drq < 0) {
|
||||
/* Find available 16-bit DRQ. */
|
||||
|
||||
for (i=0; ; ++i) {
|
||||
if (! dmatab[i]) {
|
||||
printf ("ct%d: no available drq found\n",
|
||||
unit);
|
||||
id->id_drq = -1;
|
||||
return 0;
|
||||
}
|
||||
id->id_drq = dmatab[i];
|
||||
if (! haveseen_isadev (id, CC_DRQ | CC_QUIET)
|
||||
&& !isa_dma_acquire (id->id_drq))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b = malloc (sizeof (ct_board_t), M_DEVBUF, M_WAITOK);
|
||||
if (!b) {
|
||||
printf ("ct:%d: Couldn't allocate memory\n", unit);
|
||||
return (ENXIO);
|
||||
}
|
||||
adapter[unit] = b;
|
||||
bzero (b, sizeof(ct_board_t));
|
||||
|
||||
if (! ct_open_board (b, unit, iobase,
|
||||
id->id_irq ? ffs (id->id_irq) - 1 : -1, id->id_drq)) {
|
||||
printf ("ct%d: error loading firmware\n", unit);
|
||||
adapter [unit] = 0;
|
||||
free (b, M_DEVBUF);
|
||||
isa_dma_release (id->id_drq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (id->id_irq) {
|
||||
if (! probe_irq (b, ffs (id->id_irq) - 1))
|
||||
printf ("ct%d: irq %d not functional\n",
|
||||
unit, ffs (id->id_irq) - 1);
|
||||
} else {
|
||||
/* Find available IRQ. */
|
||||
|
||||
for (i=0; ; ++i) {
|
||||
if (! irqtab[i]) {
|
||||
printf ("ct%d: no available irq found\n",
|
||||
unit);
|
||||
id->id_irq = -1;
|
||||
isa_dma_release (id->id_drq);
|
||||
adapter [unit] = 0;
|
||||
free (b, M_DEVBUF);
|
||||
return 0;
|
||||
}
|
||||
id->id_irq = 1 << irqtab[i];
|
||||
if (haveseen_isadev (id, CC_IRQ | CC_QUIET))
|
||||
continue;
|
||||
#ifdef KLD_MODULE
|
||||
if (register_intr (irqtab[i], 0, 0, (inthand2_t*)
|
||||
ct_intr, &net_imask, unit) != 0)
|
||||
continue;
|
||||
unregister_intr (irqtab[i], (inthand2_t*) ct_intr);
|
||||
#endif
|
||||
if (probe_irq (b, irqtab[i]))
|
||||
break;
|
||||
}
|
||||
}
|
||||
ct_init_board (b, b->num, b->port, ffs (id->id_irq) - 1, b->dma,
|
||||
b->type, b->osc);
|
||||
ct_setup_board (b, 0, 0, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
|
||||
extern struct cdevsw ct_cdevsw;
|
||||
/*
|
||||
* The adapter is present, initialize the driver structures.
|
||||
*/
|
||||
#if __FreeBSD_version < 400000
|
||||
static int ct_attach (struct isa_device *id)
|
||||
{
|
||||
#else
|
||||
static int ct_attach (device_t dev)
|
||||
{
|
||||
bdrv_t *bd = device_get_softc (dev);
|
||||
u_long iobase, drq, irq, rescount;
|
||||
int unit = device_get_unit (dev);
|
||||
int i;
|
||||
int s;
|
||||
#endif
|
||||
ct_board_t *b;
|
||||
ct_chan_t *c;
|
||||
drv_t *d;
|
||||
int i;
|
||||
int s;
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
KASSERT ((bd != NULL), ("ct%d: NULL device softc\n", unit));
|
||||
|
||||
bus_get_resource (dev, SYS_RES_IOPORT, 0, &iobase, &rescount);
|
||||
@ -722,15 +584,9 @@ static int ct_attach (device_t dev)
|
||||
|
||||
ct_init_board (b, b->num, b->port, irq, drq, b->type, b->osc);
|
||||
ct_setup_board (b, 0, 0, 0);
|
||||
#else
|
||||
b = adapter [id->id_unit];
|
||||
#endif
|
||||
|
||||
printf ("ct%d: <Cronyx-%s>, clock %s MHz\n", b->num, b->name,
|
||||
b->osc == 20000000 ? "20" : "16.384");
|
||||
#if __FreeBSD_version < 400000
|
||||
id->id_ointr = ct_intr;
|
||||
#endif
|
||||
|
||||
for (c=b->chan; c<b->chan+NCHAN; ++c) {
|
||||
d = contigmalloc (sizeof(drv_t), M_DEVBUF, M_WAITOK,
|
||||
@ -747,11 +603,7 @@ static int ct_attach (device_t dev)
|
||||
printf ("%s: cannot make common node\n", d->name);
|
||||
channel [b->num*NCHAN + c->num] = 0;
|
||||
c->sys = 0;
|
||||
#if __FreeBSD_version < 400000
|
||||
free (d, M_DEVBUF);
|
||||
#else
|
||||
contigfree (d, sizeof (*d), M_DEVBUF);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
#if __FreeBSD_version >= 500000
|
||||
@ -771,11 +623,7 @@ static int ct_attach (device_t dev)
|
||||
#endif
|
||||
channel [b->num*NCHAN + c->num] = 0;
|
||||
c->sys = 0;
|
||||
#if __FreeBSD_version < 400000
|
||||
free (d, M_DEVBUF);
|
||||
#else
|
||||
contigfree (d, sizeof (*d), M_DEVBUF);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
d->queue.ifq_maxlen = IFQ_MAXLEN;
|
||||
@ -802,30 +650,22 @@ static int ct_attach (device_t dev)
|
||||
if_attach (&d->pp.pp_if);
|
||||
d->pp.pp_tlf = ct_tlf;
|
||||
d->pp.pp_tls = ct_tls;
|
||||
#if __FreeBSD_version >= 400000 || NBPFILTER > 0
|
||||
/* If BPF is in the kernel, call the attach for it.
|
||||
* Header size is 4 bytes. */
|
||||
bpfattach (&d->pp.pp_if, DLT_PPP, 4);
|
||||
#endif
|
||||
#endif /*NETGRAPH*/
|
||||
ct_start_chan (c, &d->buf, vtophys (&d->buf));
|
||||
ct_register_receive (c, &ct_receive);
|
||||
ct_register_transmit (c, &ct_transmit);
|
||||
ct_register_error (c, &ct_error);
|
||||
#if __FreeBSD_version >= 400000
|
||||
d->devt = make_dev (&ct_cdevsw, b->num*NCHAN+c->num, UID_ROOT,
|
||||
GID_WHEEL, 0600, "ct%d", b->num*NCHAN+c->num);
|
||||
}
|
||||
splx (s);
|
||||
|
||||
return 0;
|
||||
#else /* __FreeBSD_version < 400000 */
|
||||
}
|
||||
return 1;
|
||||
#endif /*__FreeBSD_version */
|
||||
}
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static int ct_detach (device_t dev)
|
||||
{
|
||||
bdrv_t *bd = device_get_softc (dev);
|
||||
@ -908,11 +748,7 @@ static int ct_detach (device_t dev)
|
||||
continue;
|
||||
|
||||
/* Deallocate buffers. */
|
||||
#if __FreeBSD_version < 400000
|
||||
free (d, M_DEVBUF);
|
||||
#else
|
||||
contigfree (d, sizeof (*d), M_DEVBUF);
|
||||
#endif
|
||||
}
|
||||
bd->board = 0;
|
||||
adapter [b->num] = 0;
|
||||
@ -921,7 +757,6 @@ static int ct_detach (device_t dev)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NETGRAPH
|
||||
static void ct_ifstart (struct ifnet *ifp)
|
||||
@ -1067,7 +902,7 @@ static void ct_send (drv_t *d)
|
||||
#endif
|
||||
if (! m)
|
||||
return;
|
||||
#if (__FreeBSD_version >= 400000 || NBPFILTER > 0) && !defined (NETGRAPH)
|
||||
#ifndef NETGRAPH
|
||||
if (d->pp.pp_if.if_bpf)
|
||||
#if __FreeBSD_version >= 500000
|
||||
BPF_MTAP (&d->pp.pp_if, m);
|
||||
@ -1192,7 +1027,6 @@ static void ct_receive (ct_chan_t *c, char *data, int len)
|
||||
#else
|
||||
++d->pp.pp_if.if_ipackets;
|
||||
m->m_pkthdr.rcvif = &d->pp.pp_if;
|
||||
#if __FreeBSD_version >= 400000 || NBPFILTER > 0
|
||||
/* Check if there's a BPF listener on this interface.
|
||||
* If so, hand off the raw packet to bpf. */
|
||||
if (d->pp.pp_if.if_bpf)
|
||||
@ -1200,7 +1034,6 @@ static void ct_receive (ct_chan_t *c, char *data, int len)
|
||||
BPF_TAP (&d->pp.pp_if, data, len);
|
||||
#else
|
||||
bpf_tap (&d->pp.pp_if, data, len);
|
||||
#endif
|
||||
#endif
|
||||
sppp_input (&d->pp.pp_if, m);
|
||||
#endif
|
||||
@ -1345,9 +1178,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETPROTO:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1379,9 +1210,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETKEEPALIVE:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1414,9 +1243,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETCFG:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1496,9 +1323,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_CLRSTAT:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1525,9 +1350,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETBAUD:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1545,9 +1368,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETLOOP:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1567,9 +1388,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETDPLL:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1591,9 +1410,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETNRZI:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1613,9 +1430,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETDEBUG:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1639,9 +1454,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETHIGAIN:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1665,9 +1478,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
if (c->mode != M_E1)
|
||||
return EINVAL;
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1692,9 +1503,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETCLK:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1720,9 +1529,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETTIMESLOTS:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1742,9 +1549,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETSUBCHAN:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1772,9 +1577,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETINVCLK:
|
||||
case SERIAL_SETINVTCLK:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1790,9 +1593,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
|
||||
case SERIAL_SETINVRCLK:
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1854,15 +1655,7 @@ static int ct_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
struct isa_driver ctdriver = { ct_probe, ct_attach, "ct" };
|
||||
static struct cdevsw ct_cdevsw = {
|
||||
ct_open, ct_close, noread, nowrite,
|
||||
ct_ioctl, nostop, noreset, nodevtotty,
|
||||
seltrue, nommap, NULL, "ct",
|
||||
NULL, -1,
|
||||
};
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
static struct cdevsw ct_cdevsw = {
|
||||
ct_open, ct_close, noread, nowrite,
|
||||
ct_ioctl, nopoll, nommap, nostrategy,
|
||||
@ -2444,184 +2237,6 @@ static int ng_ct_disconnect (hook_p hook)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KLD_MODULE
|
||||
#if __FreeBSD_version < 400000
|
||||
/*
|
||||
* Function called when loading the driver.
|
||||
*/
|
||||
static int ct_load (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0;i<NCTAU; ++i) {
|
||||
struct isa_device id = {-1, &ctdriver, -1, 0, -1, 0, 0, (inthand2_t *)ct_intr, i, 0, 0, 0, 0 ,0 ,1 ,0 ,0};
|
||||
disable_intr();
|
||||
if (!ct_probe (&id)) {
|
||||
enable_intr();
|
||||
break;
|
||||
}
|
||||
ct_attach (&id);
|
||||
register_intr ((adapter [i])->irq, 0, 0, (inthand2_t*) ct_intr,
|
||||
&net_imask, id.id_unit);
|
||||
enable_intr();
|
||||
}
|
||||
if (!i) {
|
||||
/* Deactivate the timeout routine. */
|
||||
untimeout (ct_timeout, 0, timeout_handle);
|
||||
|
||||
return ENXIO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function called when unloading the driver.
|
||||
*/
|
||||
static int ct_unload (void)
|
||||
{
|
||||
int i, s;
|
||||
|
||||
/* Check if the device is busy (open). */
|
||||
for (i=0; i<NCTAU*NCHAN; ++i) {
|
||||
drv_t *d = channel[i];
|
||||
|
||||
if (!d)
|
||||
continue;
|
||||
if (d->running)
|
||||
return EBUSY;
|
||||
}
|
||||
|
||||
/* OK to unload the driver, unregister the interrupt first. */
|
||||
s = splimp ();
|
||||
|
||||
/* Deactivate the timeout routine. */
|
||||
for (i=0; i<NCTAU; ++i) {
|
||||
if (!adapter [i])
|
||||
continue;
|
||||
untimeout (ct_timeout, 0, timeout_handle);
|
||||
break;
|
||||
}
|
||||
|
||||
for (i=0; i<NCTAU; ++i) {
|
||||
ct_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->port)
|
||||
continue;
|
||||
|
||||
ct_close_board (b);
|
||||
}
|
||||
|
||||
for (i=0; i<NCTAU; ++i) {
|
||||
ct_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->port)
|
||||
continue;
|
||||
|
||||
if (led_timo[i].callout)
|
||||
untimeout (ct_led_off, b, led_timo[i]);
|
||||
}
|
||||
|
||||
for (i=0; i<NCTAU; ++i) {
|
||||
ct_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->port)
|
||||
continue;
|
||||
|
||||
/* Disable the interrupt request. */
|
||||
disable_intr();
|
||||
unregister_intr (b->irq, (inthand2_t *)ct_intr);
|
||||
isa_dma_release (b->dma);
|
||||
enable_intr();
|
||||
}
|
||||
|
||||
/* Detach the interfaces, free buffer memory. */
|
||||
for (i=0; i<NCTAU*NCHAN; ++i) {
|
||||
drv_t *d = channel[i];
|
||||
|
||||
if (!d)
|
||||
continue;
|
||||
|
||||
#ifndef NETGRAPH
|
||||
#if NBPFILTER > 0
|
||||
/* Detach from the packet filter list of interfaces. */
|
||||
{
|
||||
struct bpf_if *q, **b = &bpf_iflist;
|
||||
|
||||
while ((q = *b)) {
|
||||
if (q->bif_ifp == d->pp.pp_if) {
|
||||
*b = q->bif_next;
|
||||
free (q, M_DEVBUF);
|
||||
}
|
||||
b = &(q->bif_next);
|
||||
}
|
||||
}
|
||||
#endif /* NBPFILTER > 0 */
|
||||
/* Detach from the sync PPP list. */
|
||||
sppp_detach (&d->pp.pp_if);
|
||||
|
||||
/* Detach from the system list of interfaces. */
|
||||
{
|
||||
struct ifaddr *ifa;
|
||||
TAILQ_FOREACH (ifa, &d->pp.pp_if.if_addrhead, ifa_link) {
|
||||
TAILQ_REMOVE (&d->pp.pp_if.if_addrhead, ifa, ifa_link);
|
||||
free (ifa, M_IFADDR);
|
||||
}
|
||||
TAILQ_REMOVE (&ifnet, &d->pp.pp_if, if_link);
|
||||
}
|
||||
#endif /* !NETGRAPH */
|
||||
/* Deallocate buffers. */
|
||||
/* free (d, M_DEVBUF);*/
|
||||
}
|
||||
for (i=0; i<NCTAU; ++i) {
|
||||
ct_board_t *b = adapter [i];
|
||||
if (!b)
|
||||
continue;
|
||||
adapter [i] = 0;
|
||||
free (b, M_DEVBUF);
|
||||
}
|
||||
splx(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define devsw(a) cdevsw[major((a))]
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
#endif /* KLD_MODULE */
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
#ifdef KLD_MODULE
|
||||
static int ct_modevent (module_t mod, int type, void *unused)
|
||||
{
|
||||
dev_t dev;
|
||||
int result;
|
||||
static int load_count = 0;
|
||||
|
||||
dev = makedev (CDEV_MAJOR, 0);
|
||||
switch (type) {
|
||||
case MOD_LOAD:
|
||||
if (devsw(dev))
|
||||
return (ENXIO);
|
||||
load_count ++;
|
||||
cdevsw_add (&dev, &ct_cdevsw, NULL);
|
||||
timeout_handle = timeout (ct_timeout, 0, hz*5);
|
||||
result = ct_load ();
|
||||
return result;
|
||||
case MOD_UNLOAD:
|
||||
result = ct_unload ();
|
||||
if (result)
|
||||
return result;
|
||||
if (devsw(dev)&&!(load_count-1)) {
|
||||
cdevsw_add (&dev, NULL, NULL);
|
||||
}
|
||||
load_count --;
|
||||
return result;
|
||||
case MOD_SHUTDOWN:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* KLD_MODULE */
|
||||
#else /* __FreeBSD_version >= 400000 */
|
||||
static int ct_modevent (module_t mod, int type, void *unused)
|
||||
{
|
||||
struct cdev *dev;
|
||||
@ -2670,7 +2285,6 @@ static int ct_modevent (module_t mod, int type, void *unused)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* __FreeBSD_version >= 400000 */
|
||||
|
||||
#ifdef NETGRAPH
|
||||
static struct ng_type typestruct = {
|
||||
@ -2685,10 +2299,6 @@ static struct ng_type typestruct = {
|
||||
.disconnect = ng_ct_disconnect
|
||||
};
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
NETGRAPH_INIT_ORDERED (ct, &typestruct, SI_SUB_DRIVERS,\
|
||||
SI_ORDER_MIDDLE + CDEV_MAJOR);
|
||||
#endif
|
||||
#endif /*NETGRAPH*/
|
||||
|
||||
#if __FreeBSD_version >= 500000
|
||||
@ -2708,38 +2318,5 @@ DRIVER_MODULE(ct, isa, ct_isa_driver, ct_devclass, ng_mod_event, &typestruct);
|
||||
#else
|
||||
DRIVER_MODULE(ct, isa, ct_isa_driver, ct_devclass, ct_modevent, 0);
|
||||
#endif
|
||||
#else /* __FreeBSD_version < 400000 */
|
||||
#ifdef KLD_MODULE
|
||||
#ifndef NETGRAPH
|
||||
static moduledata_t ctmod = { "ct", ct_modevent, };
|
||||
DECLARE_MODULE (ct, ctmod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR);
|
||||
#endif /* !NETGRAPH */
|
||||
#else /* KLD_MODULE */
|
||||
|
||||
/*
|
||||
* Now for some driver initialisation.
|
||||
* Occurs ONCE during boot (very early).
|
||||
* This is if we are NOT a loadable module.
|
||||
*/
|
||||
static void ct_drvinit (void *unused)
|
||||
{
|
||||
dev_t dev;
|
||||
|
||||
dev = makedev (CDEV_MAJOR, 0);
|
||||
cdevsw_add (&dev, &ct_cdevsw, NULL);
|
||||
|
||||
/* Activate the timeout routine. */
|
||||
timeout_handle = timeout (ct_timeout, 0, hz);
|
||||
#ifdef NETGRAPH
|
||||
#if 0
|
||||
/* Register our node type in netgraph */
|
||||
if (ng_newtype (&typestruct))
|
||||
printf ("Failed to register ng_ct\n");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
SYSINIT (ctdev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+CDEV_MAJOR, ct_drvinit, 0)
|
||||
#endif /* KLD_MODULE */
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
#endif /* __FreeBSD_version >= 400000 */
|
||||
#endif /* NCTAU */
|
||||
|
@ -44,12 +44,10 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/tty.h>
|
||||
#if __FreeBSD_version >= 400000
|
||||
# include <sys/bus.h>
|
||||
# include <machine/bus.h>
|
||||
# include <sys/rman.h>
|
||||
# include <isa/isavar.h>
|
||||
#endif
|
||||
#include <sys/bus.h>
|
||||
#include <machine/bus.h>
|
||||
#include <sys/rman.h>
|
||||
#include <isa/isavar.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/interrupt.h>
|
||||
#include <vm/vm.h>
|
||||
@ -62,31 +60,19 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/ipl.h>
|
||||
#include <i386/isa/isa_device.h>
|
||||
#endif
|
||||
#if __FreeBSD_version >= 400000
|
||||
# include <machine/resource.h>
|
||||
# if __FreeBSD_version <= 501000
|
||||
# include <i386/isa/intr_machdep.h>
|
||||
# endif
|
||||
#endif
|
||||
#if __FreeBSD_version >= 400000
|
||||
# include <dev/cx/machdep.h>
|
||||
# include <dev/cx/cxddk.h>
|
||||
# include <dev/cx/cronyxfw.h>
|
||||
#else
|
||||
# include <i386/isa/cronyx/machdep.h>
|
||||
# include <i386/isa/cronyx/cxddk.h>
|
||||
# include <i386/isa/cronyx/cronyxfw.h>
|
||||
#include <machine/resource.h>
|
||||
#if __FreeBSD_version <= 501000
|
||||
# include <i386/isa/intr_machdep.h>
|
||||
#endif
|
||||
#include <dev/cx/machdep.h>
|
||||
#include <dev/cx/cxddk.h>
|
||||
#include <dev/cx/cronyxfw.h>
|
||||
#include "opt_ng_cronyx.h"
|
||||
#ifdef NETGRAPH_CRONYX
|
||||
# include "opt_netgraph.h"
|
||||
# include <netgraph/ng_message.h>
|
||||
# include <netgraph/netgraph.h>
|
||||
# if __FreeBSD_version >= 400000
|
||||
# include <dev/cx/ng_cx.h>
|
||||
# else
|
||||
# include <netgraph/ng_cx.h>
|
||||
# endif
|
||||
# include <dev/cx/ng_cx.h>
|
||||
#else
|
||||
# include <net/if_types.h>
|
||||
# if __FreeBSD_version < 500000
|
||||
@ -97,19 +83,12 @@ __FBSDID("$FreeBSD$");
|
||||
# endif
|
||||
# include <net/if_sppp.h>
|
||||
# define PP_CISCO IFF_LINK2
|
||||
#if __FreeBSD_version < 400000
|
||||
# include <bpfilter.h>
|
||||
# if NBPFILTER > 0
|
||||
# include <net/bpf.h>
|
||||
# endif
|
||||
#else
|
||||
# if __FreeBSD_version < 500000
|
||||
# include <bpf.h>
|
||||
# endif
|
||||
# include <net/bpf.h>
|
||||
# define NBPFILTER NBPF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version < 502113
|
||||
#define ttyld_modem(foo, bar) ((*linesw[(foo)->t_line].l_modem)((foo), (bar)))
|
||||
@ -150,7 +129,6 @@ typedef struct _async_q {
|
||||
#define AQ_POP(q,c) {c = *((q)->buf + (q)->beg);\
|
||||
(q)->beg = ((q)->beg + 1)%BF_SZ;}
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static void cx_identify __P((driver_t *, device_t));
|
||||
static int cx_probe __P((device_t));
|
||||
static int cx_attach __P((device_t));
|
||||
@ -182,7 +160,6 @@ static driver_t cx_isa_driver = {
|
||||
};
|
||||
|
||||
static devclass_t cx_devclass;
|
||||
#endif
|
||||
|
||||
typedef struct _drv_t {
|
||||
char name [8];
|
||||
@ -211,12 +188,10 @@ typedef struct _drv_t {
|
||||
#else
|
||||
struct sppp pp;
|
||||
#endif
|
||||
#if __FreeBSD_version >= 400000
|
||||
struct cdev *devt[3];
|
||||
#endif
|
||||
async_q aqueue;
|
||||
#define CX_READ 1
|
||||
#define CX_WRITE 2
|
||||
#define CX_READ 1
|
||||
#define CX_WRITE 2
|
||||
int intr_action;
|
||||
short atimeout;
|
||||
} drv_t;
|
||||
@ -265,9 +240,7 @@ static cx_board_t *adapter [NCX];
|
||||
static drv_t *channel [NCX*NCHAN];
|
||||
static struct callout_handle led_timo [NCX];
|
||||
static struct callout_handle timeout_handle;
|
||||
#if __FreeBSD_version >= 400000
|
||||
extern struct cdevsw cx_cdevsw;
|
||||
#endif
|
||||
extern struct cdevsw cx_cdevsw;
|
||||
|
||||
static int MY_SOFT_INTR;
|
||||
|
||||
@ -382,16 +355,10 @@ static void cx_led_off (void *arg)
|
||||
/*
|
||||
* Activate interupt handler from DDK.
|
||||
*/
|
||||
#if __FreeBSD_version >= 400000
|
||||
static void cx_intr (void *arg)
|
||||
{
|
||||
bdrv_t *bd = arg;
|
||||
cx_board_t *b = bd->board;
|
||||
#else
|
||||
static void cx_intr (int bnum)
|
||||
{
|
||||
cx_board_t *b = adapter [bnum];
|
||||
#endif
|
||||
int s = splhigh ();
|
||||
|
||||
/* Turn LED on. */
|
||||
@ -442,7 +409,6 @@ static short porttab [] = {
|
||||
static char dmatab [] = { 7, 6, 5, 0 };
|
||||
static char irqtab [] = { 5, 10, 11, 7, 3, 15, 12, 0 };
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static int cx_is_free_res (device_t dev, int rid, int type, u_long start,
|
||||
u_long end, u_long count)
|
||||
{
|
||||
@ -604,129 +570,21 @@ static int cx_probe (device_t dev)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* __FreeBSD_version < 400000 */
|
||||
static int cx_probe (struct isa_device *id)
|
||||
{
|
||||
cx_board_t *b;
|
||||
int i;
|
||||
|
||||
#ifndef NETGRAPH
|
||||
if (! sppp_attach) {
|
||||
printf ("cx%d: no synchronous PPP driver configured\n",
|
||||
id->id_unit);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (id->id_iobase < 0) {
|
||||
/* Autodetect the adapter. */
|
||||
for (i=0; ; i++) {
|
||||
if (! porttab[i]) {
|
||||
id->id_iobase = -1;
|
||||
return 0;
|
||||
}
|
||||
id->id_iobase = porttab[i];
|
||||
if (id->id_unit > 0 && adapter[0] && adapter[0]->port == id->id_iobase)
|
||||
continue;
|
||||
if (id->id_unit > 1 && adapter[1] && adapter[1]->port == id->id_iobase)
|
||||
continue;
|
||||
if (! haveseen_isadev (id, CC_IOADDR | CC_QUIET) &&
|
||||
cx_probe_board (id->id_iobase, -1, -1))
|
||||
break;
|
||||
}
|
||||
} else if (! cx_probe_board (id->id_iobase, -1, -1))
|
||||
return 0;
|
||||
|
||||
if (id->id_drq < 0) {
|
||||
/* Find available 16-bit DRQ. */
|
||||
|
||||
for (i=0; ; ++i) {
|
||||
if (! dmatab[i]) {
|
||||
printf ("cx%d: no available drq found\n",
|
||||
id->id_unit);
|
||||
id->id_drq = -1;
|
||||
return 0;
|
||||
}
|
||||
id->id_drq = dmatab[i];
|
||||
if (! haveseen_isadev (id, CC_DRQ | CC_QUIET)
|
||||
&& !isa_dma_acquire (id->id_drq))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b = malloc (sizeof (cx_board_t), M_DEVBUF, M_WAITOK);
|
||||
if (!b) {
|
||||
printf ("cx:%d: Couldn't allocate memory\n", id->id_unit);
|
||||
return (ENXIO);
|
||||
}
|
||||
adapter[id->id_unit] = b;
|
||||
bzero (b, sizeof(cx_board_t));
|
||||
|
||||
if (! cx_open_board (b, id->id_unit, id->id_iobase,
|
||||
id->id_irq ? ffs (id->id_irq) - 1 : -1, id->id_drq)) {
|
||||
printf ("cx%d: cannot initialize adapter\n", id->id_unit);
|
||||
isa_dma_release (id->id_drq);
|
||||
adapter[id->id_unit] = 0;
|
||||
free (b, M_DEVBUF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (id->id_irq) {
|
||||
if (! probe_irq (b, ffs (id->id_irq) - 1))
|
||||
printf ("cx%d: irq %d not functional\n",
|
||||
id->id_unit, ffs (id->id_irq) - 1);
|
||||
} else {
|
||||
/* Find available IRQ. */
|
||||
|
||||
for (i=0; ; ++i) {
|
||||
if (! irqtab[i]) {
|
||||
printf ("cx%d: no available irq found\n",
|
||||
id->id_unit);
|
||||
id->id_irq = -1;
|
||||
isa_dma_release (id->id_drq);
|
||||
adapter[id->id_unit] = 0;
|
||||
free (b, M_DEVBUF);
|
||||
return 0;
|
||||
}
|
||||
id->id_irq = 1 << irqtab[i];
|
||||
if (haveseen_isadev (id, CC_IRQ | CC_QUIET))
|
||||
continue;
|
||||
#ifdef KLD_MODULE
|
||||
if (register_intr (irqtab[i], 0, 0, (inthand2_t*)
|
||||
cx_intr, &net_imask, id->id_unit) != 0)
|
||||
continue;
|
||||
unregister_intr (irqtab[i], (inthand2_t*) cx_intr);
|
||||
#endif
|
||||
if (probe_irq (b, irqtab[i]))
|
||||
break;
|
||||
}
|
||||
}
|
||||
cx_init (b, b->num, b->port, ffs (id->id_irq) - 1, b->dma);
|
||||
cx_setup_board (b, 0, 0, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
|
||||
/*
|
||||
* The adapter is present, initialize the driver structures.
|
||||
*/
|
||||
#if __FreeBSD_version < 400000
|
||||
static int cx_attach (struct isa_device *id)
|
||||
{
|
||||
#else
|
||||
static int cx_attach (device_t dev)
|
||||
{
|
||||
bdrv_t *bd = device_get_softc (dev);
|
||||
u_long iobase, drq, irq, rescount;
|
||||
int unit = device_get_unit (dev);
|
||||
int i;
|
||||
int s;
|
||||
#endif
|
||||
cx_board_t *b;
|
||||
cx_chan_t *c;
|
||||
drv_t *d;
|
||||
int i;
|
||||
int s;
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
KASSERT ((bd != NULL), ("cx%d: NULL device softc\n", unit));
|
||||
|
||||
bus_get_resource (dev, SYS_RES_IOPORT, 0, &iobase, &rescount);
|
||||
@ -851,20 +709,12 @@ static int cx_attach (device_t dev)
|
||||
|
||||
cx_init (b, b->num, b->port, irq, drq);
|
||||
cx_setup_board (b, 0, 0, 0);
|
||||
#else /* __FreeBSD_version >= 400000 */
|
||||
b = adapter[id->id_unit];
|
||||
#endif /* __FreeBSD_version >= 400000 */
|
||||
|
||||
printf ("cx%d: <Cronyx-Sigma-%s>\n", b->num, b->name);
|
||||
#if __FreeBSD_version < 400000
|
||||
id->id_ointr = cx_intr;
|
||||
#endif
|
||||
|
||||
for (c=b->chan; c<b->chan+NCHAN; ++c) {
|
||||
#if __FreeBSD_version >= 400000
|
||||
char *dnmt="tty %x";
|
||||
char *dnmc="cua %x";
|
||||
#endif
|
||||
if (c->type == T_NONE)
|
||||
continue;
|
||||
d = contigmalloc (sizeof(drv_t), M_DEVBUF, M_WAITOK,
|
||||
@ -891,11 +741,7 @@ static int cx_attach (device_t dev)
|
||||
printf ("%s: cannot make common node\n", d->name);
|
||||
channel [b->num*NCHAN + c->num] = 0;
|
||||
c->sys = 0;
|
||||
#if __FreeBSD_version < 400000
|
||||
free (d, M_DEVBUF);
|
||||
#else
|
||||
contigfree (d, sizeof (*d), M_DEVBUF);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
#if __FreeBSD_version >= 500000
|
||||
@ -915,11 +761,7 @@ static int cx_attach (device_t dev)
|
||||
#endif
|
||||
channel [b->num*NCHAN + c->num] = 0;
|
||||
c->sys = 0;
|
||||
#if __FreeBSD_version < 400000
|
||||
free (d, M_DEVBUF);
|
||||
#else
|
||||
contigfree (d, sizeof (*d), M_DEVBUF);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
d->lo_queue.ifq_maxlen = IFQ_MAXLEN;
|
||||
@ -946,11 +788,9 @@ static int cx_attach (device_t dev)
|
||||
if_attach (&d->pp.pp_if);
|
||||
d->pp.pp_tlf = cx_tlf;
|
||||
d->pp.pp_tls = cx_tls;
|
||||
#if __FreeBSD_version >= 400000 || NBPFILTER > 0
|
||||
/* If BPF is in the kernel, call the attach for it.
|
||||
* Size of PPP header is 4 bytes. */
|
||||
bpfattach (&d->pp.pp_if, DLT_PPP, 4);
|
||||
#endif
|
||||
#endif /*NETGRAPH*/
|
||||
}
|
||||
cx_start_chan (c, &d->buf, vtophys (&d->buf));
|
||||
@ -958,7 +798,6 @@ static int cx_attach (device_t dev)
|
||||
cx_register_transmit (c, &cx_transmit);
|
||||
cx_register_error (c, &cx_error);
|
||||
cx_register_modem (c, &cx_modem);
|
||||
#if __FreeBSD_version >= 400000
|
||||
dnmt[3] = 'x'+b->num;
|
||||
dnmc[3] = 'x'+b->num;
|
||||
d->devt[0] = make_dev (&cx_cdevsw, b->num*NCHAN + c->num, UID_ROOT, GID_WHEEL, 0644, dnmt, b->num*NCHAN + c->num);
|
||||
@ -968,14 +807,8 @@ static int cx_attach (device_t dev)
|
||||
splx (s);
|
||||
|
||||
return 0;
|
||||
#else /* __FreeBSD_version < 400000 */
|
||||
}
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __FreeBSD_version >= 400000
|
||||
static int cx_detach (device_t dev)
|
||||
{
|
||||
bdrv_t *bd = device_get_softc (dev);
|
||||
@ -1095,7 +928,6 @@ static int cx_detach (device_t dev)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NETGRAPH
|
||||
static void cx_ifstart (struct ifnet *ifp)
|
||||
@ -1246,7 +1078,7 @@ static void cx_send (drv_t *d)
|
||||
#endif
|
||||
if (! m)
|
||||
return;
|
||||
#if (__FreeBSD_version >= 400000 || NBPFILTER > 0) && !defined (NETGRAPH)
|
||||
#ifndef NETGRAPH
|
||||
if (d->pp.pp_if.if_bpf)
|
||||
#if __FreeBSD_version >= 500000
|
||||
BPF_MTAP (&d->pp.pp_if, m);
|
||||
@ -1414,7 +1246,6 @@ static void cx_receive (cx_chan_t *c, char *data, int len)
|
||||
#else
|
||||
++d->pp.pp_if.if_ipackets;
|
||||
m->m_pkthdr.rcvif = &d->pp.pp_if;
|
||||
#if __FreeBSD_version >= 400000 || NBPFILTER > 0
|
||||
/* Check if there's a BPF listener on this interface.
|
||||
* If so, hand off the raw packet to bpf. */
|
||||
if (d->pp.pp_if.if_bpf)
|
||||
@ -1422,7 +1253,6 @@ static void cx_receive (cx_chan_t *c, char *data, int len)
|
||||
BPF_TAP (&d->pp.pp_if, data, len);
|
||||
#else
|
||||
bpf_tap (&d->pp.pp_if, data, len);
|
||||
#endif
|
||||
#endif
|
||||
sppp_input (&d->pp.pp_if, m);
|
||||
#endif
|
||||
@ -1590,13 +1420,9 @@ static int cx_open (struct cdev *dev, int flag, int mode, struct thread *td)
|
||||
d->tty = ttymalloc (d->tty);
|
||||
d->tty->t_oproc = cx_oproc;
|
||||
d->tty->t_param = cx_param;
|
||||
#if __FreeBSD_version >= 400000
|
||||
d->tty->t_stop = cx_stop;
|
||||
#endif
|
||||
}
|
||||
#if __FreeBSD_version >= 400000
|
||||
dev->si_tty = d->tty;
|
||||
#endif
|
||||
d->tty->t_dev = dev;
|
||||
again:
|
||||
if (d->dtroff) {
|
||||
@ -1833,9 +1659,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETPORT:
|
||||
CX_DEBUG2 (d, ("ioctl: setproto\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1861,9 +1685,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETPROTO:
|
||||
CX_DEBUG2 (d, ("ioctl: setproto\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1902,9 +1724,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETKEEPALIVE:
|
||||
CX_DEBUG2 (d, ("ioctl: setkeepalive\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1934,9 +1754,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETMODE:
|
||||
CX_DEBUG2 (d, ("ioctl: setmode\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -1989,9 +1807,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_CLRSTAT:
|
||||
CX_DEBUG2 (d, ("ioctl: clrstat\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -2023,9 +1839,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETBAUD:
|
||||
CX_DEBUG2 (d, ("ioctl: setbaud\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -2051,9 +1865,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETLOOP:
|
||||
CX_DEBUG2 (d, ("ioctl: setloop\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -2079,9 +1891,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETDPLL:
|
||||
CX_DEBUG2 (d, ("ioctl: setdpll\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -2107,9 +1917,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETNRZI:
|
||||
CX_DEBUG2 (d, ("ioctl: setnrzi\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -2133,9 +1941,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case SERIAL_SETDEBUG:
|
||||
CX_DEBUG2 (d, ("ioctl: setdebug\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -2244,9 +2050,7 @@ static int cx_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc
|
||||
case TIOCMSDTRWAIT:
|
||||
CX_DEBUG2 (d, ("ioctl: tiocmsdtrwait\n"));
|
||||
/* Only for superuser! */
|
||||
#if __FreeBSD_version < 400000
|
||||
error = suser (p->p_ucred, &p->p_acflag);
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
error = suser (p);
|
||||
#else /* __FreeBSD_version >= 500000 */
|
||||
error = suser (td);
|
||||
@ -2494,17 +2298,6 @@ static int cx_param (struct tty *tp, struct termios *t)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
static struct tty *cx_devtotty (dev_t dev)
|
||||
{
|
||||
int unit = UNIT (dev);
|
||||
|
||||
if (unit == UNIT_CTL || unit >= NCX*NCHAN || ! channel[unit])
|
||||
return 0;
|
||||
return channel[unit]->tty;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Stop output on a line
|
||||
*/
|
||||
@ -2570,15 +2363,7 @@ static void cx_modem (cx_chan_t *c)
|
||||
d->dcd_timeout_handle = timeout (cx_carrier, d, hz/2);
|
||||
}
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
struct isa_driver cxdriver = { cx_probe, cx_attach, "cx" };
|
||||
static struct cdevsw cx_cdevsw = {
|
||||
cx_open, cx_close, cx_read, cx_write,
|
||||
cx_ioctl, cx_stop, noreset, cx_devtotty,
|
||||
ttpoll, nommap, NULL, "cx",
|
||||
NULL, -1,
|
||||
};
|
||||
#elif __FreeBSD_version < 500000
|
||||
#if __FreeBSD_version < 500000
|
||||
static struct cdevsw cx_cdevsw = {
|
||||
cx_open, cx_close, cx_read, cx_write,
|
||||
cx_ioctl, ttypoll, nommap, nostrategy,
|
||||
@ -2959,217 +2744,6 @@ static int ng_cx_disconnect (hook_p hook)
|
||||
}
|
||||
#endif /*NETGRAPH*/
|
||||
|
||||
#ifdef KLD_MODULE
|
||||
#if __FreeBSD_version < 400000
|
||||
/*
|
||||
* Function called when loading the driver.
|
||||
*/
|
||||
static int cx_load (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0;i<NCX; ++i) {
|
||||
struct isa_device id = {-1, &cxdriver, -1, 0, -1, 0, 0, (inthand2_t *)cx_intr, i, 0, 0, 0, 0 ,0 ,1 ,0 ,0};
|
||||
|
||||
disable_intr();
|
||||
if (!cx_probe (&id)) {
|
||||
enable_intr();
|
||||
break;
|
||||
}
|
||||
cx_attach (&id);
|
||||
register_intr ((adapter [i])->irq, 0, 0, (inthand2_t*) cx_intr,
|
||||
&net_imask, id.id_unit);
|
||||
enable_intr();
|
||||
}
|
||||
if (!i) {
|
||||
/* Deactivate the timeout routine. And soft interrupt*/
|
||||
untimeout (cx_timeout, 0, timeout_handle);
|
||||
unregister_swi (SWI_TTY, cx_softintr);
|
||||
return ENXIO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function called when unloading the driver.
|
||||
*/
|
||||
static int cx_unload (void)
|
||||
{
|
||||
int i, s;
|
||||
|
||||
/* Check if the device is busy (open). */
|
||||
for (i=0; i<NCX*NCHAN; ++i) {
|
||||
drv_t *d = channel[i];
|
||||
cx_chan_t *c;
|
||||
|
||||
if (!d || (c=d->chan)->type == T_NONE)
|
||||
continue;
|
||||
if (d->lock)
|
||||
return EBUSY;
|
||||
if (c->mode == M_ASYNC && d->tty && (d->tty->t_state & TS_ISOPEN) &&
|
||||
(d->open_dev|0x2))
|
||||
return EBUSY;
|
||||
if (d->running)
|
||||
return EBUSY;
|
||||
|
||||
}
|
||||
|
||||
s = splhigh ();
|
||||
|
||||
/* Deactivate the timeout routine. And soft interrupt*/
|
||||
for (i=0; i<NCX; ++i) {
|
||||
cx_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->port)
|
||||
continue;
|
||||
untimeout (cx_timeout, 0, timeout_handle);
|
||||
unregister_swi (SWI_TTY, cx_softintr);
|
||||
break;
|
||||
}
|
||||
|
||||
for (i=0; i<NCX*NCHAN; ++i) {
|
||||
drv_t *d = channel[i];
|
||||
cx_chan_t *c;
|
||||
|
||||
if (!d || (c=d->chan)->type == T_NONE)
|
||||
continue;
|
||||
|
||||
if (d->dtr_timeout_handle.callout)
|
||||
untimeout (cx_dtrwakeup, d, d->dtr_timeout_handle);
|
||||
if (d->dcd_timeout_handle.callout)
|
||||
untimeout (cx_carrier, c, d->dcd_timeout_handle);
|
||||
}
|
||||
|
||||
/* Close all active boards. */
|
||||
for (i=0; i<NCX; ++i) {
|
||||
cx_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->port)
|
||||
continue;
|
||||
|
||||
cx_close_board (b);
|
||||
}
|
||||
|
||||
for (i=0; i<NCX; ++i) {
|
||||
cx_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->port)
|
||||
continue;
|
||||
|
||||
if (led_timo[i].callout)
|
||||
untimeout (cx_led_off, b, led_timo[i]);
|
||||
}
|
||||
|
||||
/* OK to unload the driver, unregister the interrupt first. */
|
||||
for (i=0; i<NCX; ++i) {
|
||||
cx_board_t *b = adapter [i];
|
||||
|
||||
if (!b || ! b->port)
|
||||
continue;
|
||||
/* Disable the interrupt request. */
|
||||
disable_intr();
|
||||
unregister_intr (b->irq, (inthand2_t *)cx_intr);
|
||||
isa_dma_release (b->dma);
|
||||
enable_intr();
|
||||
}
|
||||
splx (s);
|
||||
|
||||
s = splhigh ();
|
||||
/* Detach the interfaces, free buffer memory. */
|
||||
for (i=0; i<NCX*NCHAN; ++i) {
|
||||
drv_t *d = channel[i];
|
||||
cx_chan_t *c;
|
||||
|
||||
if (!d || (c=d->chan)->type == T_NONE)
|
||||
continue;
|
||||
|
||||
#ifndef NETGRAPH
|
||||
#if NBPFILTER > 0
|
||||
/* Detach from the packet filter list of interfaces. */
|
||||
{
|
||||
struct bpf_if *q, **b = &bpf_iflist;
|
||||
|
||||
while ((q = *b)) {
|
||||
if (q->bif_ifp == d->pp.pp_if) {
|
||||
*b = q->bif_next;
|
||||
free (q, M_DEVBUF);
|
||||
}
|
||||
b = &(q->bif_next);
|
||||
}
|
||||
}
|
||||
#endif /* NBPFILTER */
|
||||
/* Detach from the sync PPP list. */
|
||||
sppp_detach (&d->pp.pp_if);
|
||||
|
||||
/* Detach from the system list of interfaces. */
|
||||
{
|
||||
struct ifaddr *ifa;
|
||||
TAILQ_FOREACH (ifa, &d->pp.pp_if.if_addrhead, ifa_link) {
|
||||
TAILQ_REMOVE (&d->pp.pp_if.if_addrhead, ifa, ifa_link);
|
||||
free (ifa, M_IFADDR);
|
||||
}
|
||||
TAILQ_REMOVE (&ifnet, &d->pp.pp_if, if_link);
|
||||
}
|
||||
#endif /* !NETGRAPH */
|
||||
/* Deallocate buffers. */
|
||||
/* free (d, M_DEVBUF);*/
|
||||
}
|
||||
|
||||
for (i=0; i<NCX; ++i) {
|
||||
cx_board_t *b = adapter [i];
|
||||
if (!b)
|
||||
continue;
|
||||
adapter [b->num] = 0;
|
||||
free (b, M_DEVBUF);
|
||||
}
|
||||
|
||||
splx (s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define devsw(a) cdevsw[major((a))]
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
#endif /* KLD_MODULE */
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
#ifdef KLD_MODULE
|
||||
static int cx_modevent (module_t mod, int type, void *unused)
|
||||
{
|
||||
dev_t dev;
|
||||
int result;
|
||||
static int load_count = 0;
|
||||
|
||||
dev = makedev (CDEV_MAJOR, 0);
|
||||
switch (type) {
|
||||
case MOD_LOAD:
|
||||
if (devsw(dev))
|
||||
return (ENXIO);
|
||||
load_count ++;
|
||||
cdevsw_add (&dev, &cx_cdevsw, NULL);
|
||||
timeout_handle = timeout (cx_timeout, 0, hz*5);
|
||||
|
||||
/* Software interrupt. */
|
||||
register_swi (SWI_TTY, cx_softintr);
|
||||
|
||||
result = cx_load ();
|
||||
return result;
|
||||
case MOD_UNLOAD:
|
||||
result = cx_unload ();
|
||||
if (result)
|
||||
return result;
|
||||
if (devsw(dev)&&!(load_count-1)) {
|
||||
cdevsw_add (&dev, NULL, NULL);
|
||||
}
|
||||
load_count --;
|
||||
return result;
|
||||
case MOD_SHUTDOWN:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* KLD_MODULE */
|
||||
#else /* __FreeBSD_version >= 400000 */
|
||||
static int cx_modevent (module_t mod, int type, void *unused)
|
||||
{
|
||||
struct cdev *dev;
|
||||
@ -3230,7 +2804,6 @@ static int cx_modevent (module_t mod, int type, void *unused)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* __FreeBSD_version >= 400000 */
|
||||
|
||||
#ifdef NETGRAPH
|
||||
static struct ng_type typestruct = {
|
||||
@ -3245,10 +2818,6 @@ static struct ng_type typestruct = {
|
||||
.disconnect = ng_cx_disconnect
|
||||
};
|
||||
|
||||
#if __FreeBSD_version < 400000
|
||||
NETGRAPH_INIT_ORDERED (cx, &typestruct, SI_SUB_DRIVERS,\
|
||||
SI_ORDER_MIDDLE + CDEV_MAJOR);
|
||||
#endif
|
||||
#endif /*NETGRAPH*/
|
||||
|
||||
#if __FreeBSD_version >= 500000
|
||||
@ -3268,46 +2837,5 @@ DRIVER_MODULE(cx, isa, cx_isa_driver, cx_devclass, ng_mod_event, &typestruct);
|
||||
#else
|
||||
DRIVER_MODULE(cx, isa, cx_isa_driver, cx_devclass, cx_modevent, 0);
|
||||
#endif
|
||||
#else /* __FreeBSD_version < 400000 */
|
||||
#ifdef KLD_MODULE
|
||||
#ifndef NETGRAPH
|
||||
static moduledata_t cxmod = { "cx", cx_modevent, NULL};
|
||||
DECLARE_MODULE (cx, cxmod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR);
|
||||
#endif
|
||||
#else /* KLD_MODULE */
|
||||
|
||||
/*
|
||||
* Now for some driver initialisation.
|
||||
* Occurs ONCE during boot (very early).
|
||||
* This is if we are NOT a loadable module.
|
||||
*/
|
||||
static void cx_drvinit (void *unused)
|
||||
{
|
||||
#if __FreeBSD_version < 400000
|
||||
dev_t dev;
|
||||
|
||||
dev = makedev (CDEV_MAJOR, 0);
|
||||
cdevsw_add (&dev, &cx_cdevsw, NULL);
|
||||
#else
|
||||
cdevsw_add (&cx_cdevsw);
|
||||
#endif
|
||||
|
||||
/* Activate the timeout routine. */
|
||||
timeout_handle = timeout (cx_timeout, 0, hz*5);
|
||||
|
||||
/* Software interrupt. */
|
||||
register_swi (SWI_TTY, cx_softintr);
|
||||
#ifdef NETGRAPH
|
||||
#if 0
|
||||
/* Register our node type in netgraph */
|
||||
if (ng_newtype (&typestruct))
|
||||
printf ("Failed to register ng_cx\n");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
SYSINIT (cxdev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+CDEV_MAJOR, cx_drvinit, 0)
|
||||
|
||||
#endif /* KLD_MODULE */
|
||||
#endif /* __FreeBSD_version < 400000 */
|
||||
#endif /* __FreeBSD_version >= 400000 */
|
||||
#endif /* NCX */
|
||||
|
Loading…
Reference in New Issue
Block a user