1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, Matthew E. Kimmel. Permission is hereby granted
|
1994-03-01 05:45:00 +03:00
|
|
|
* to use, copy, modify and distribute this software provided that both
|
|
|
|
* the copyright notice and this permission notice appear in all copies
|
|
|
|
* of the software, derivative works or modified versions, and any
|
|
|
|
* portions thereof.
|
|
|
|
*/
|
1994-03-01 07:12:25 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 3COM Etherlink 3C501 device driver
|
|
|
|
*
|
1994-04-08 22:22:15 +04:00
|
|
|
* $Id: if_el.c,v 1.10 1994/04/08 18:22:24 mycroft Exp $
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 07:12:25 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bugs/possible improvements:
|
1994-03-01 05:45:00 +03:00
|
|
|
* - Does not currently support DMA
|
|
|
|
* - Does not currently support multicasts
|
|
|
|
*/
|
1994-03-01 07:12:25 +03:00
|
|
|
|
1994-03-01 05:45:00 +03:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
1994-03-01 08:41:26 +03:00
|
|
|
#include <sys/device.h>
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
1994-03-08 15:21:10 +03:00
|
|
|
#include <machine/cpu.h>
|
1994-03-01 05:45:00 +03:00
|
|
|
#include <machine/pio.h>
|
|
|
|
|
|
|
|
#include <i386/isa/isa.h>
|
1994-03-29 08:35:37 +04:00
|
|
|
#include <i386/isa/isavar.h>
|
1994-03-01 05:45:00 +03:00
|
|
|
#include <i386/isa/icu.h>
|
|
|
|
#include <i386/isa/if_elreg.h>
|
|
|
|
|
|
|
|
#define ETHER_MIN_LEN 64
|
|
|
|
#define ETHER_MAX_LEN 1518
|
1994-03-01 08:41:26 +03:00
|
|
|
#define ETHER_ADDR_LEN 6
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* for debugging convenience */
|
1994-03-01 05:45:00 +03:00
|
|
|
#ifdef EL_DEBUG
|
|
|
|
#define dprintf(x) printf x
|
|
|
|
#else
|
|
|
|
#define dprintf(x)
|
|
|
|
#endif
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* per-line info and status
|
1994-03-01 07:12:25 +03:00
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
struct el_softc {
|
1994-03-01 08:41:26 +03:00
|
|
|
struct device sc_dev;
|
1994-04-07 10:48:19 +04:00
|
|
|
struct intrhand sc_ih;
|
1994-03-01 08:41:26 +03:00
|
|
|
|
|
|
|
struct arpcom sc_arpcom; /* ethernet common */
|
|
|
|
u_short sc_iobase; /* base I/O addr */
|
|
|
|
caddr_t sc_bpf; /* BPF magic cookie */
|
|
|
|
char sc_pktbuf[EL_BUFSIZ]; /* frame buffer */
|
1994-03-29 08:35:37 +04:00
|
|
|
};
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* prototypes
|
1994-03-01 07:12:25 +03:00
|
|
|
*/
|
1994-04-07 10:48:19 +04:00
|
|
|
int elintr __P((struct el_softc *));
|
1994-03-01 08:41:26 +03:00
|
|
|
static int el_init __P((struct el_softc *));
|
1994-03-01 07:12:25 +03:00
|
|
|
static int el_ioctl __P((struct ifnet *, int, caddr_t));
|
1994-03-01 05:45:00 +03:00
|
|
|
static int el_start __P((struct ifnet *));
|
|
|
|
static int el_watchdog __P((int));
|
1994-03-01 08:41:26 +03:00
|
|
|
static void el_reset __P((struct el_softc *));
|
|
|
|
static void el_stop __P((struct el_softc *));
|
1994-03-01 07:12:25 +03:00
|
|
|
static int el_xmit __P((struct el_softc *, int));
|
|
|
|
static inline void elread __P((struct el_softc *, caddr_t, int));
|
|
|
|
static struct mbuf *elget __P((caddr_t, int, int, struct ifnet *));
|
1994-03-03 18:30:27 +03:00
|
|
|
static inline void el_hardreset __P((struct el_softc *));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
int elprobe();
|
|
|
|
void elattach();
|
|
|
|
|
1994-03-01 05:45:00 +03:00
|
|
|
/* isa_driver structure for autoconf */
|
1994-03-29 08:35:37 +04:00
|
|
|
struct cfdriver elcd = {
|
|
|
|
NULL, "el", elprobe, elattach, DV_IFNET, sizeof(struct el_softc)
|
1994-03-01 05:45:00 +03:00
|
|
|
};
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
struct trailer_header {
|
|
|
|
u_short ether_type;
|
|
|
|
u_short ether_residual;
|
|
|
|
};
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Probe routine.
|
|
|
|
*
|
|
|
|
* See if the card is there and at the right place.
|
|
|
|
* (XXX - cgd -- needs help)
|
|
|
|
*/
|
1994-03-29 08:35:37 +04:00
|
|
|
int
|
|
|
|
elprobe(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct el_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
u_short iobase = ia->ia_iobase;
|
1994-03-01 05:45:00 +03:00
|
|
|
u_char station_addr[ETHER_ADDR_LEN];
|
|
|
|
int i;
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* First check the base. */
|
|
|
|
if (iobase < 0x280 || iobase > 0x3f0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Grab some info for our structure. */
|
|
|
|
sc->sc_iobase = iobase;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Now attempt to grab the station address from the PROM and see if it
|
|
|
|
* contains the 3com vendor code.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
dprintf(("Probing 3c501 at 0x%x...\n", iobase));
|
|
|
|
|
|
|
|
/* Reset the board. */
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("Resetting board...\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_AC, EL_AC_RESET);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(5);
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_AC, 0);
|
|
|
|
|
|
|
|
/* Now read the address. */
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("Reading station address...\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++) {
|
|
|
|
outb(iobase+EL_GPBL, i);
|
|
|
|
station_addr[i] = inb(iobase+EL_EAW);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1994-03-01 07:12:25 +03:00
|
|
|
dprintf(("Address is %s\n", ether_sprintf(station_addr)));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* If the vendor code is ok, return a 1. We'll assume that whoever
|
|
|
|
* configured this system is right about the IRQ.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
if (station_addr[0] != 0x02 || station_addr[1] != 0x60 ||
|
|
|
|
station_addr[2] != 0x8c) {
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("Bad vendor code.\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
return 0;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1994-03-01 08:41:26 +03:00
|
|
|
|
|
|
|
dprintf(("Vendor code ok.\n"));
|
|
|
|
/* Copy the station address into the arpcom structure. */
|
|
|
|
bcopy(station_addr, sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN);
|
1994-03-29 08:35:37 +04:00
|
|
|
|
|
|
|
ia->ia_iosize = 4; /* XXX */
|
|
|
|
ia->ia_msize = 0;
|
|
|
|
return 1;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Attach the interface to the kernel data structures. By the time this is
|
|
|
|
* called, we know that the card exists at the given I/O address. We still
|
|
|
|
* assume that the IRQ given is correct.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-29 08:35:37 +04:00
|
|
|
void
|
|
|
|
elattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct el_softc *sc = (void *)self;
|
1994-04-07 10:48:19 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1994-03-01 08:41:26 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
1994-03-01 05:45:00 +03:00
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
dprintf(("Attaching %s...\n", sc->sc_dev.dv_xname));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Stop the board. */
|
|
|
|
el_stop(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Initialize ifnet structure. */
|
1994-03-29 08:35:37 +04:00
|
|
|
ifp->if_unit = sc->sc_dev.dv_unit;
|
|
|
|
ifp->if_name = elcd.cd_name;
|
1994-03-01 05:45:00 +03:00
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_output = ether_output;
|
|
|
|
ifp->if_start = el_start;
|
|
|
|
ifp->if_ioctl = el_ioctl;
|
|
|
|
ifp->if_watchdog = el_watchdog;
|
1994-03-01 08:41:26 +03:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Now we can attach the interface. */
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("Attaching interface...\n"));
|
|
|
|
if_attach(ifp);
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Put the station address in the ifa address list's AF_LINK entry, if
|
|
|
|
* any.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
ifa = ifp->if_addrlist;
|
1994-03-01 08:41:26 +03:00
|
|
|
while (ifa && ifa->ifa_addr) {
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_LINK) {
|
|
|
|
/*
|
|
|
|
* Fill in the link-level address for this interface.
|
|
|
|
*/
|
|
|
|
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
|
|
|
sdl->sdl_type = IFT_ETHER;
|
|
|
|
sdl->sdl_alen = ETHER_ADDR_LEN;
|
|
|
|
sdl->sdl_slen = 0;
|
|
|
|
bcopy(sc->sc_arpcom.ac_enaddr, LLADDR(sdl),
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
ifa = ifa->ifa_next;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Print out some information for the user. */
|
|
|
|
printf("%s: address %s\n", sc->sc_dev.dv_xname,
|
|
|
|
ether_sprintf(sc->sc_arpcom.ac_enaddr));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* Finally, attach to bpf filter if it is present. */
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
dprintf(("Attaching to BPF...\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
bpfattach(&sc->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
|
1994-03-01 05:45:00 +03:00
|
|
|
#endif
|
|
|
|
|
1994-04-07 10:48:19 +04:00
|
|
|
sc->sc_ih.ih_fun = elintr;
|
|
|
|
sc->sc_ih.ih_arg = sc;
|
|
|
|
sc->sc_ih.ih_level = IPL_NET;
|
|
|
|
intr_establish(ia->ia_irq, &sc->sc_ih);
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
dprintf(("elattach() finished.\n"));
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Reset interface.
|
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
static void
|
1994-03-01 08:41:26 +03:00
|
|
|
el_reset(sc)
|
|
|
|
struct el_softc *sc;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
dprintf(("elreset()\n"));
|
|
|
|
s = splimp();
|
1994-03-01 08:41:26 +03:00
|
|
|
el_stop(sc);
|
|
|
|
el_init(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Stop interface.
|
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
static void
|
1994-03-01 08:41:26 +03:00
|
|
|
el_stop(sc)
|
1994-03-01 05:45:00 +03:00
|
|
|
struct el_softc *sc;
|
1994-03-01 08:41:26 +03:00
|
|
|
{
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(sc->sc_iobase+EL_AC, 0);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-03 18:30:27 +03:00
|
|
|
/*
|
|
|
|
* Do a hardware reset of the board, and upload the ethernet address again in
|
|
|
|
* case the board forgets.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
el_hardreset(sc)
|
|
|
|
struct el_softc *sc;
|
|
|
|
{
|
|
|
|
u_short iobase = sc->sc_iobase;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
outb(iobase+EL_AC, EL_AC_RESET);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(5);
|
1994-03-03 18:30:27 +03:00
|
|
|
outb(iobase+EL_AC, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
outb(iobase+i, sc->sc_arpcom.ac_enaddr[i]);
|
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Initialize interface.
|
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
static int
|
1994-03-01 08:41:26 +03:00
|
|
|
el_init(sc)
|
1994-03-01 05:45:00 +03:00
|
|
|
struct el_softc *sc;
|
1994-03-01 08:41:26 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
|
|
|
u_short iobase = sc->sc_iobase;
|
1994-03-01 05:45:00 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
/* If address not known, do nothing. */
|
1994-03-01 08:41:26 +03:00
|
|
|
if (ifp->if_addrlist == 0)
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
/* First, reset the board. */
|
1994-03-03 18:30:27 +03:00
|
|
|
el_hardreset(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Configure rx. */
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("Configuring rx...\n"));
|
1994-03-01 07:12:25 +03:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_RXC, EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB | EL_RXC_DOFLOW | EL_RXC_PROMISC);
|
1994-03-01 05:45:00 +03:00
|
|
|
else
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_RXC, EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB | EL_RXC_DOFLOW | EL_RXC_ABROAD);
|
|
|
|
outb(iobase+EL_RBC, 0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Configure TX. */
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("Configuring tx...\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_TXC, 0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Start reception. */
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("Starting reception...\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Set flags appropriately. */
|
1994-03-01 05:45:00 +03:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
/* And start output. */
|
|
|
|
el_start(ifp);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Start output on interface. Get datagrams from the queue and output them,
|
|
|
|
* giving the receiver a chance between datagrams. Call only from splimp or
|
|
|
|
* interrupt level!
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
static int
|
1994-03-01 07:12:25 +03:00
|
|
|
el_start(ifp)
|
|
|
|
struct ifnet *ifp;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct el_softc *sc = elcd.cd_devs[ifp->if_unit];
|
1994-03-01 08:41:26 +03:00
|
|
|
u_short iobase = sc->sc_iobase;
|
1994-03-01 05:45:00 +03:00
|
|
|
struct mbuf *m, *m0;
|
|
|
|
int s, i, len, retries, done;
|
|
|
|
|
|
|
|
dprintf(("el_start()...\n"));
|
|
|
|
s = splimp();
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Don't do anything if output is active. */
|
|
|
|
if (sc->sc_arpcom.ac_if.if_flags & IFF_OACTIVE)
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
1994-03-01 08:41:26 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_flags |= IFF_OACTIVE;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/*
|
|
|
|
* The main loop. They warned me against endless loops, but would I
|
|
|
|
* listen? NOOO....
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
for (;;) {
|
|
|
|
/* Dequeue the next datagram. */
|
|
|
|
IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* If there's nothing to send, return. */
|
1994-03-01 08:41:26 +03:00
|
|
|
if (!m0) {
|
|
|
|
sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
|
1994-03-01 05:45:00 +03:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Disable the receiver. */
|
|
|
|
outb(iobase+EL_AC, EL_AC_HOST);
|
|
|
|
outb(iobase+EL_RBC, 0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* Copy the datagram to the buffer. */
|
|
|
|
len = 0;
|
1994-03-01 08:41:26 +03:00
|
|
|
for (m = m0; m; m = m->m_next) {
|
1994-03-01 07:12:25 +03:00
|
|
|
if (m->m_len == 0)
|
1994-03-01 05:45:00 +03:00
|
|
|
continue;
|
1994-03-01 08:41:26 +03:00
|
|
|
bcopy(mtod(m, caddr_t), sc->sc_pktbuf + len, m->m_len);
|
1994-03-01 05:45:00 +03:00
|
|
|
len += m->m_len;
|
|
|
|
}
|
|
|
|
m_freem(m0);
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
len = max(len, ETHER_MIN_LEN);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Give the packet to the bpf, if any. */
|
1994-03-01 05:45:00 +03:00
|
|
|
#if NBPFILTER > 0
|
1994-03-01 08:41:26 +03:00
|
|
|
if (sc->sc_bpf)
|
|
|
|
bpf_tap(sc->sc_bpf, sc->sc_pktbuf, len);
|
1994-03-01 05:45:00 +03:00
|
|
|
#endif
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Transfer datagram to board. */
|
1994-03-01 07:12:25 +03:00
|
|
|
dprintf(("el: xfr pkt length=%d...\n", len));
|
1994-03-01 05:45:00 +03:00
|
|
|
i = EL_BUFSIZ - len;
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_GPBL, i);
|
|
|
|
outb(iobase+EL_GPBH, i >> 8);
|
|
|
|
outsb(iobase+EL_BUF, sc->sc_pktbuf, len);
|
|
|
|
|
|
|
|
/* Now transmit the datagram. */
|
|
|
|
retries = 0;
|
|
|
|
done = 0;
|
|
|
|
while (!done) {
|
|
|
|
if (el_xmit(sc, len)) {
|
|
|
|
/* Something went wrong. */
|
1994-03-01 05:45:00 +03:00
|
|
|
done = -1;
|
|
|
|
break;
|
|
|
|
}
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Check out status. */
|
|
|
|
i = inb(iobase+EL_TXS);
|
1994-03-01 07:12:25 +03:00
|
|
|
dprintf(("tx status=0x%x\n", i));
|
1994-03-01 08:41:26 +03:00
|
|
|
if ((i & EL_TXS_READY) == 0) {
|
1994-03-01 07:12:25 +03:00
|
|
|
dprintf(("el: err txs=%x\n", i));
|
1994-03-01 08:41:26 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_oerrors++;
|
|
|
|
if (i & (EL_TXS_COLL | EL_TXS_COLL16)) {
|
|
|
|
if ((i & EL_TXC_DCOLL16) == 0 &&
|
1994-03-01 07:12:25 +03:00
|
|
|
retries < 15) {
|
1994-03-01 05:45:00 +03:00
|
|
|
retries++;
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_AC, EL_AC_HOST);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1994-03-01 07:12:25 +03:00
|
|
|
} else
|
1994-03-01 05:45:00 +03:00
|
|
|
done = 1;
|
1994-03-02 19:23:23 +03:00
|
|
|
} else {
|
|
|
|
sc->sc_arpcom.ac_if.if_opackets++;
|
1994-03-01 05:45:00 +03:00
|
|
|
done = 1;
|
1994-03-02 19:23:23 +03:00
|
|
|
}
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1994-03-01 08:41:26 +03:00
|
|
|
if (done == -1)
|
|
|
|
/* Packet not transmitted. */
|
1994-03-01 05:45:00 +03:00
|
|
|
continue;
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Now give the card a chance to receive.
|
1994-03-01 05:45:00 +03:00
|
|
|
* Gotta love 3c501s...
|
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
(void)inb(iobase+EL_AS);
|
|
|
|
outb(iobase+EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1994-03-01 05:45:00 +03:00
|
|
|
splx(s);
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Interrupt here. */
|
1994-03-01 05:45:00 +03:00
|
|
|
s = splimp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* This function actually attempts to transmit a datagram downloaded to the
|
|
|
|
* board. Call at splimp or interrupt, after downloading data! Returns 0 on
|
|
|
|
* success, non-0 on failure.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
static int
|
1994-03-01 07:12:25 +03:00
|
|
|
el_xmit(sc, len)
|
|
|
|
struct el_softc *sc;
|
|
|
|
int len;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1994-03-01 08:41:26 +03:00
|
|
|
u_short iobase = sc->sc_iobase;
|
1994-03-01 05:45:00 +03:00
|
|
|
int gpl;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gpl = EL_BUFSIZ - len;
|
|
|
|
dprintf(("el: xmit..."));
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_GPBL, gpl);
|
|
|
|
outb(iobase+EL_GPBH, gpl >> 8);
|
|
|
|
outb(iobase+EL_AC, EL_AC_TXFRX);
|
1994-03-01 05:45:00 +03:00
|
|
|
i = 20000;
|
1994-03-01 08:41:26 +03:00
|
|
|
while ((inb(iobase+EL_AS) & EL_AS_TXBUSY) && (i > 0))
|
1994-03-01 05:45:00 +03:00
|
|
|
i--;
|
1994-03-01 07:12:25 +03:00
|
|
|
if (i == 0) {
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("tx not ready\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_oerrors++;
|
|
|
|
return -1;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1994-03-01 08:41:26 +03:00
|
|
|
dprintf(("%d cycles.\n", 20000 - i));
|
|
|
|
return 0;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/*
|
|
|
|
* Controller interrupt.
|
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
int
|
1994-04-07 10:48:19 +04:00
|
|
|
elintr(sc)
|
|
|
|
register struct el_softc *sc;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1994-03-01 08:41:26 +03:00
|
|
|
u_short iobase = sc->sc_iobase;
|
1994-03-01 05:45:00 +03:00
|
|
|
int stat, rxstat, len, done;
|
|
|
|
|
|
|
|
dprintf(("elintr: "));
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Check board status. */
|
|
|
|
stat = inb(iobase+EL_AS);
|
1994-03-01 07:12:25 +03:00
|
|
|
if (stat & EL_AS_RXBUSY) {
|
1994-03-01 08:41:26 +03:00
|
|
|
(void)inb(iobase+EL_RXC);
|
|
|
|
outb(iobase+EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1994-04-08 22:22:15 +04:00
|
|
|
return 0;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
done = 0;
|
1994-03-01 08:41:26 +03:00
|
|
|
while (!done) {
|
|
|
|
rxstat = inb(iobase+EL_RXS);
|
1994-03-01 07:12:25 +03:00
|
|
|
if (rxstat & EL_RXS_STALE) {
|
1994-03-01 08:41:26 +03:00
|
|
|
(void)inb(iobase+EL_RXC);
|
|
|
|
outb(iobase+EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1994-04-08 22:22:15 +04:00
|
|
|
return 1;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If there's an overflow, reinit the board. */
|
1994-03-01 08:41:26 +03:00
|
|
|
if ((rxstat & EL_RXS_NOFLOW) == 0) {
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("overflow.\n"));
|
1994-03-03 18:30:27 +03:00
|
|
|
el_hardreset(sc);
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Put board back into receive mode. */
|
|
|
|
if (sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC)
|
|
|
|
outb(iobase+EL_RXC, EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB | EL_RXC_DOFLOW | EL_RXC_PROMISC);
|
1994-03-01 05:45:00 +03:00
|
|
|
else
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_RXC, EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB | EL_RXC_DOFLOW | EL_RXC_ABROAD);
|
|
|
|
(void)inb(iobase+EL_AS);
|
|
|
|
outb(iobase+EL_RBC, 0);
|
|
|
|
(void)inb(iobase+EL_RXC);
|
|
|
|
outb(iobase+EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1994-04-08 22:22:15 +04:00
|
|
|
return 1;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Incoming packet. */
|
|
|
|
len = inb(iobase+EL_RBL);
|
|
|
|
len |= inb(iobase+EL_RBH) << 8;
|
1994-03-01 07:12:25 +03:00
|
|
|
dprintf(("receive len=%d rxstat=%x ", len, rxstat));
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_AC, EL_AC_HOST);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* If packet too short or too long, restore rx mode and return.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
if (len <= sizeof(struct ether_header) ||
|
|
|
|
len > ETHER_MAX_LEN) {
|
|
|
|
if (sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC)
|
|
|
|
outb(iobase+EL_RXC, EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB | EL_RXC_DOFLOW | EL_RXC_PROMISC);
|
1994-03-01 05:45:00 +03:00
|
|
|
else
|
1994-03-01 08:41:26 +03:00
|
|
|
outb(iobase+EL_RXC, EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB | EL_RXC_DOFLOW | EL_RXC_ABROAD);
|
|
|
|
(void)inb(iobase+EL_AS);
|
|
|
|
outb(iobase+EL_RBC, 0);
|
|
|
|
(void)inb(iobase+EL_RXC);
|
|
|
|
outb(iobase+EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1994-04-08 22:22:15 +04:00
|
|
|
return 1;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_ipackets++;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Copy the data into our buffer. */
|
|
|
|
outb(iobase+EL_GPBL, 0);
|
|
|
|
outb(iobase+EL_GPBH, 0);
|
|
|
|
insb(iobase+EL_BUF, sc->sc_pktbuf, len);
|
|
|
|
outb(iobase+EL_RBC, 0);
|
|
|
|
outb(iobase+EL_AC, EL_AC_RX);
|
|
|
|
dprintf(("%s-->", ether_sprintf(sc->sc_pktbuf+6)));
|
|
|
|
dprintf(("%s\n", ether_sprintf(sc->sc_pktbuf)));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Pass data up to upper levels. */
|
1994-03-01 05:45:00 +03:00
|
|
|
len -= sizeof(struct ether_header);
|
1994-03-01 08:41:26 +03:00
|
|
|
elread(sc, (caddr_t)sc->sc_pktbuf, len);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* Is there another packet? */
|
1994-03-01 08:41:26 +03:00
|
|
|
stat = inb(iobase+EL_AS);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* If so, do it all again (i.e. don't set done to 1). */
|
|
|
|
if ((stat & EL_AS_RXBUSY) == 0)
|
1994-03-01 05:45:00 +03:00
|
|
|
dprintf(("<rescan> "));
|
|
|
|
else
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
(void)inb(iobase+EL_RXC);
|
|
|
|
outb(iobase+EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1994-04-08 22:22:15 +04:00
|
|
|
return 1;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Pass a packet up to the higher levels. Deal with trailer protocol.
|
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
static inline void
|
1994-03-01 07:12:25 +03:00
|
|
|
elread(sc, buf, len)
|
|
|
|
struct el_softc *sc;
|
|
|
|
caddr_t buf;
|
|
|
|
int len;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
|
|
|
register struct ether_header *eh;
|
|
|
|
struct mbuf *m;
|
|
|
|
int off, resid;
|
1994-03-01 08:41:26 +03:00
|
|
|
u_short etype;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Deal with trailer protocol: if type is trailer type get true type
|
|
|
|
* from first 16-bit word past data. Remember that type was trailer by
|
|
|
|
* setting off.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
eh = (struct ether_header *)buf;
|
1994-03-01 08:41:26 +03:00
|
|
|
etype = ntohs(eh->ether_type);
|
1994-03-01 07:12:25 +03:00
|
|
|
#define eldataaddr(eh, off, type) ((type)(((caddr_t)((eh)+1)+(off))))
|
1994-03-01 08:41:26 +03:00
|
|
|
if (etype >= ETHERTYPE_TRAIL &&
|
|
|
|
etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
|
|
|
|
off = (etype - ETHERTYPE_TRAIL) << 9;
|
|
|
|
if ((off + sizeof(struct trailer_header)) > len)
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
1994-03-01 07:12:25 +03:00
|
|
|
eh->ether_type = *eldataaddr(eh, off, u_short *);
|
1994-03-01 08:41:26 +03:00
|
|
|
resid = ntohs(*eldataaddr(eh, off+2, u_short *));
|
|
|
|
if ((off + resid) > len)
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
|
|
|
len = off + resid;
|
1994-03-01 07:12:25 +03:00
|
|
|
} else
|
1994-03-01 05:45:00 +03:00
|
|
|
off = 0;
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
if (len <= 0)
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Check if there's a bpf filter listening on this interface. If so,
|
|
|
|
* hand off the raw packet to bpf, which must deal with trailers in its
|
|
|
|
* own way.
|
1994-03-01 07:12:25 +03:00
|
|
|
*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Comparing to if_ed, this code does bpf on trailer packets
|
|
|
|
* incorrectly -- the ether type's already been copied over...
|
|
|
|
* XXX - cgd
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
if (sc->sc_bpf) {
|
|
|
|
bpf_tap(sc->sc_bpf, buf, len + sizeof(struct ether_header));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the interface cannot be in promiscuous mode if
|
|
|
|
* there are no bpf listeners. And if el are in promiscuous
|
|
|
|
* mode, el have to check if this packet is really ours.
|
|
|
|
*
|
1994-03-01 08:41:26 +03:00
|
|
|
* XXX This test does not support multicasts.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
if ((sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC) &&
|
|
|
|
bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr,
|
|
|
|
sizeof(eh->ether_dhost)) != 0 &&
|
|
|
|
bcmp(eh->ether_dhost, etherbroadcastaddr,
|
|
|
|
sizeof(eh->ether_dhost)) != 0)
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Pull packet off interface. Off is nonzero if packet has trailing
|
|
|
|
* header; neget will then force this header information to be at the
|
|
|
|
* front, but we still have to drop the type and length which are at
|
|
|
|
* the front of any trailer data.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
m = elget(buf, len, off, &sc->sc_arpcom.ac_if);
|
|
|
|
if (!m)
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
ether_input(&sc->sc_arpcom.ac_if, eh, m);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Pull read data off a interface. Len is length of data, with local net
|
|
|
|
* header stripped. Off is non-zero if a trailer protocol was used, and gives
|
|
|
|
* the offset of the trailer information. We copy the trailer information and
|
|
|
|
* then all the normal data into mbufs. When full cluster sized units are
|
|
|
|
* present we copy into clusters.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
struct mbuf *
|
|
|
|
elget(buf, totlen, off0, ifp)
|
|
|
|
caddr_t buf;
|
|
|
|
int totlen, off0;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct mbuf *top, **mp, *m, *p;
|
|
|
|
int off = off0, len;
|
|
|
|
register caddr_t cp = buf;
|
|
|
|
char *epkt;
|
|
|
|
|
|
|
|
buf += sizeof(struct ether_header);
|
|
|
|
cp = buf;
|
|
|
|
epkt = cp + totlen;
|
|
|
|
|
|
|
|
if (off) {
|
|
|
|
cp += off + 2 * sizeof(u_short);
|
|
|
|
totlen -= 2 * sizeof(u_short);
|
|
|
|
}
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
1994-03-01 08:41:26 +03:00
|
|
|
if (!m)
|
|
|
|
return 0;
|
1994-03-01 05:45:00 +03:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
m->m_len = MHLEN;
|
|
|
|
top = 0;
|
|
|
|
mp = ⊤
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
m_freem(top);
|
1994-03-01 08:41:26 +03:00
|
|
|
return 0;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
m->m_len = MLEN;
|
|
|
|
}
|
|
|
|
len = min(totlen, epkt - cp);
|
|
|
|
if (len >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
m->m_len = len = min(len, MCLBYTES);
|
|
|
|
else
|
|
|
|
len = m->m_len;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Place initial small packet/header at end of mbuf.
|
|
|
|
*/
|
|
|
|
if (len < m->m_len) {
|
|
|
|
if (top == 0 && len + max_linkhdr <= m->m_len)
|
|
|
|
m->m_data += max_linkhdr;
|
|
|
|
m->m_len = len;
|
|
|
|
} else
|
|
|
|
len = m->m_len;
|
|
|
|
}
|
|
|
|
bcopy(cp, mtod(m, caddr_t), (unsigned)len);
|
|
|
|
cp += len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
totlen -= len;
|
|
|
|
if (cp == epkt)
|
|
|
|
cp = buf;
|
|
|
|
}
|
1994-03-01 08:41:26 +03:00
|
|
|
return top;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* Process an ioctl request. This code needs some work - it looks pretty ugly.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
el_ioctl(ifp, command, data)
|
|
|
|
register struct ifnet *ifp;
|
|
|
|
int command;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct el_softc *sc = elcd.cd_devs[ifp->if_unit];
|
1994-03-01 08:41:26 +03:00
|
|
|
register struct ifaddr *ifa = (struct ifaddr *)data;
|
1994-03-01 05:45:00 +03:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1994-03-01 08:41:26 +03:00
|
|
|
el_init(sc); /* before arpwhohas */
|
1994-03-01 05:45:00 +03:00
|
|
|
/*
|
|
|
|
* See if another station has *our* IP address.
|
|
|
|
* i.e.: There is an address conflict! If a
|
|
|
|
* conflict exists, a message is sent to the
|
|
|
|
* console.
|
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
sc->sc_arpcom.ac_ipaddr = IA_SIN(ifa)->sin_addr;
|
|
|
|
arpwhohas(&sc->sc_arpcom, &IA_SIN(ifa)->sin_addr);
|
1994-03-01 05:45:00 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NS
|
|
|
|
/*
|
1994-03-01 08:41:26 +03:00
|
|
|
* XXX - This code is probably wrong.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
case AF_NS:
|
1994-03-01 08:41:26 +03:00
|
|
|
{
|
|
|
|
register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
|
|
|
|
|
|
|
|
if (ns_nullhost(*ina))
|
|
|
|
ina->x_host =
|
|
|
|
*(union ns_host *)(sc->sc_arpcom.ac_enaddr);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
*
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1994-03-01 08:41:26 +03:00
|
|
|
bcopy((caddr_t)ina->x_host.c_host,
|
|
|
|
(caddr_t)sc->sc_arpcom.ac_enaddr,
|
|
|
|
sizeof(sc->sc_arpcom.ac_enaddr));
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Set new address. */
|
|
|
|
el_init(sc);
|
|
|
|
break;
|
|
|
|
}
|
1994-03-01 05:45:00 +03:00
|
|
|
#endif
|
|
|
|
default:
|
1994-03-01 08:41:26 +03:00
|
|
|
el_init(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
1994-03-01 08:41:26 +03:00
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
1994-03-01 05:45:00 +03:00
|
|
|
(ifp->if_flags & IFF_RUNNING)) {
|
1994-03-01 08:41:26 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
|
|
|
el_stop(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
1994-03-01 08:41:26 +03:00
|
|
|
} else if ((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0) {
|
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
el_init(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
} else {
|
1994-03-01 08:41:26 +03:00
|
|
|
/*
|
|
|
|
* Some other important flag might have changed, so
|
|
|
|
* reset.
|
|
|
|
*/
|
|
|
|
el_reset(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
(void) splx(s);
|
1994-03-01 08:41:26 +03:00
|
|
|
return error;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/*
|
|
|
|
* Device timeout routine.
|
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
static int
|
1994-03-01 07:12:25 +03:00
|
|
|
el_watchdog(unit)
|
|
|
|
int unit;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct el_softc *sc = elcd.cd_devs[unit];
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
|
|
|
|
sc->sc_arpcom.ac_if.if_oerrors++;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
el_reset(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|