1998-01-12 12:39:57 +03:00
|
|
|
/* $NetBSD: if_el.c,v 1.51 1998/01/12 09:43:36 thorpej Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
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-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"
|
1997-10-15 09:55:13 +04:00
|
|
|
#include "rnd.h"
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
1996-04-30 00:02:32 +04:00
|
|
|
#include <sys/systm.h>
|
1994-03-01 05:45:00 +03:00
|
|
|
#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>
|
1997-10-15 09:55:13 +04:00
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
1994-03-01 05:45:00 +03:00
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1994-03-01 05:45:00 +03:00
|
|
|
#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>
|
1996-05-13 03:51:23 +04:00
|
|
|
#include <machine/intr.h>
|
1996-08-03 23:33:19 +04:00
|
|
|
#include <machine/bus.h>
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
1995-01-29 10:36:54 +03:00
|
|
|
#include <dev/isa/if_elreg.h>
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
#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
|
1996-10-13 05:37:04 +04:00
|
|
|
#define DPRINTF(x) printf x
|
1994-03-01 05:45:00 +03:00
|
|
|
#else
|
1996-10-11 01:25:07 +04:00
|
|
|
#define DPRINTF(x)
|
1994-03-01 05:45:00 +03:00
|
|
|
#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;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1994-03-01 08:41:26 +03:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ethercom sc_ethercom; /* ethernet common */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t sc_iot; /* bus space identifier */
|
|
|
|
bus_space_handle_t sc_ioh; /* i/o handle */
|
1997-10-15 09:55:13 +04:00
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rndsource_element_t rnd_source;
|
|
|
|
#endif
|
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
|
|
|
*/
|
1995-04-17 16:06:30 +04:00
|
|
|
int elintr __P((void *));
|
1996-04-30 00:02:32 +04:00
|
|
|
void elinit __P((struct el_softc *));
|
1995-07-24 06:02:45 +04:00
|
|
|
int elioctl __P((struct ifnet *, u_long, caddr_t));
|
|
|
|
void elstart __P((struct ifnet *));
|
1996-05-07 05:55:13 +04:00
|
|
|
void elwatchdog __P((struct ifnet *));
|
1995-07-24 06:02:45 +04:00
|
|
|
void elreset __P((struct el_softc *));
|
|
|
|
void elstop __P((struct el_softc *));
|
1995-07-23 21:57:39 +04:00
|
|
|
static int el_xmit __P((struct el_softc *));
|
1995-07-24 06:02:45 +04:00
|
|
|
void elread __P((struct el_softc *, int));
|
1995-07-24 06:08:13 +04:00
|
|
|
struct mbuf *elget __P((struct el_softc *sc, int));
|
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
|
|
|
|
1997-11-30 18:31:23 +03:00
|
|
|
#ifdef __BROKEN_INDIRECT_CONFIG
|
1994-11-04 02:08:27 +03:00
|
|
|
int elprobe __P((struct device *, void *, void *));
|
1997-11-30 18:31:23 +03:00
|
|
|
#else
|
|
|
|
int elprobe __P((struct device *, struct cfdata *, void *));
|
|
|
|
#endif
|
1994-11-04 02:08:27 +03:00
|
|
|
void elattach __P((struct device *, struct device *, void *));
|
1994-03-29 08:35:37 +04:00
|
|
|
|
1996-03-17 03:43:52 +03:00
|
|
|
struct cfattach el_ca = {
|
|
|
|
sizeof(struct el_softc), elprobe, elattach
|
|
|
|
};
|
|
|
|
|
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
|
1994-11-04 02:08:27 +03:00
|
|
|
elprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
1997-11-30 18:31:23 +03:00
|
|
|
#ifdef __BROKEN_INDIRECT_CONFIG
|
|
|
|
void *match;
|
|
|
|
#else
|
|
|
|
struct cfdata *match;
|
|
|
|
#endif
|
|
|
|
void *aux;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = ia->ia_iobase;
|
1996-08-03 23:33:19 +04:00
|
|
|
u_int8_t station_addr[ETHER_ADDR_LEN];
|
|
|
|
u_int8_t i;
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
rval = 0;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* First check the base. */
|
1997-09-10 09:40:23 +04:00
|
|
|
if (iobase < 0x200 || iobase > 0x3f0)
|
1994-03-01 08:41:26 +03:00
|
|
|
return 0;
|
|
|
|
|
1996-08-03 23:33:19 +04:00
|
|
|
/* Map i/o space. */
|
1997-09-10 09:40:23 +04:00
|
|
|
if (bus_space_map(iot, iobase, 16, 0, &ioh))
|
1996-08-03 23:33:19 +04:00
|
|
|
return 0;
|
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
|
|
|
*/
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Probing 3c501 at 0x%x...\n", iobase));
|
1994-03-01 08:41:26 +03:00
|
|
|
|
|
|
|
/* Reset the board. */
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Resetting board...\n"));
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_RESET);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(5);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, 0);
|
1994-03-01 08:41:26 +03:00
|
|
|
|
|
|
|
/* Now read the address. */
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Reading station address...\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++) {
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_GPBL, i);
|
|
|
|
station_addr[i] = bus_space_read_1(iot, ioh, EL_EAW);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1996-10-11 01:25:07 +04: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) {
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Bad vendor code.\n"));
|
1996-08-03 23:33:19 +04:00
|
|
|
goto out;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Vendor code ok.\n"));
|
1994-03-29 08:35:37 +04:00
|
|
|
|
1997-09-10 09:40:23 +04:00
|
|
|
ia->ia_iosize = 16;
|
1994-03-29 08:35:37 +04:00
|
|
|
ia->ia_msize = 0;
|
1996-08-03 23:33:19 +04:00
|
|
|
rval = 1;
|
|
|
|
|
|
|
|
out:
|
1997-09-10 09:40:23 +04:00
|
|
|
bus_space_unmap(iot, ioh, 16);
|
1996-08-03 23:33:19 +04:00
|
|
|
return rval;
|
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;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
u_int8_t myaddr[ETHER_ADDR_LEN];
|
1996-08-03 23:33:19 +04:00
|
|
|
u_int8_t i;
|
|
|
|
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("\n");
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Attaching %s...\n", sc->sc_dev.dv_xname));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1996-08-03 23:33:19 +04:00
|
|
|
/* Map i/o space. */
|
1996-10-22 02:34:38 +04:00
|
|
|
if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: can't map i/o space\n", self->dv_xname);
|
1996-08-03 23:33:19 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
sc->sc_iot = iot;
|
1996-08-03 23:33:19 +04:00
|
|
|
sc->sc_ioh = ioh;
|
|
|
|
|
|
|
|
/* Reset the board. */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_RESET);
|
1996-08-03 23:33:19 +04:00
|
|
|
delay(5);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, 0);
|
1996-08-03 23:33:19 +04:00
|
|
|
|
|
|
|
/* Now read the address. */
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++) {
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_GPBL, i);
|
1997-03-15 21:09:08 +03:00
|
|
|
myaddr[i] = bus_space_read_1(iot, ioh, EL_EAW);
|
1996-08-03 23:33:19 +04:00
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Stop the board. */
|
1995-07-24 06:02:45 +04:00
|
|
|
elstop(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Initialize ifnet structure. */
|
1996-05-07 05:55:13 +04:00
|
|
|
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
|
|
|
|
ifp->if_softc = sc;
|
1995-07-24 06:02:45 +04:00
|
|
|
ifp->if_start = elstart;
|
|
|
|
ifp->if_ioctl = elioctl;
|
|
|
|
ifp->if_watchdog = elwatchdog;
|
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. */
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Attaching interface...\n"));
|
1994-03-01 05:45:00 +03:00
|
|
|
if_attach(ifp);
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_ifattach(ifp, myaddr);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Print out some information for the user. */
|
1997-03-15 21:09:08 +03:00
|
|
|
printf("%s: address %s\n", self->dv_xname, ether_sprintf(myaddr));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* Finally, attach to bpf filter if it is present. */
|
|
|
|
#if NBPFILTER > 0
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Attaching to BPF...\n"));
|
1994-05-13 10:13:43 +04:00
|
|
|
bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
|
1994-03-01 05:45:00 +03:00
|
|
|
#endif
|
|
|
|
|
1996-04-12 02:27:59 +04:00
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
|
|
|
|
IPL_NET, elintr, sc);
|
1994-04-07 10:48:19 +04:00
|
|
|
|
1997-10-15 09:55:13 +04:00
|
|
|
#if NRND > 0
|
|
|
|
DPRINTF(("Attaching to random...\n"));
|
|
|
|
rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname, RND_TYPE_NET);
|
|
|
|
#endif
|
|
|
|
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("elattach() finished.\n"));
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Reset interface.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
|
|
|
elreset(sc)
|
1994-03-01 08:41:26 +03:00
|
|
|
struct el_softc *sc;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("elreset()\n"));
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1995-07-24 06:02:45 +04:00
|
|
|
elstop(sc);
|
|
|
|
elinit(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Stop interface.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
|
|
|
elstop(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
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 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;
|
|
|
|
{
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-03-03 18:30:27 +03:00
|
|
|
int i;
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_RESET);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(5);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, 0);
|
1994-03-03 18:30:27 +03:00
|
|
|
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
1997-03-15 21:09:08 +03:00
|
|
|
bus_space_write_1(iot, ioh, i,
|
|
|
|
LLADDR(sc->sc_ethercom.ec_if.if_sadl)[i]);
|
1994-03-03 18:30:27 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 07:12:25 +03:00
|
|
|
/*
|
|
|
|
* Initialize interface.
|
|
|
|
*/
|
1996-04-30 00:02:32 +04:00
|
|
|
void
|
1995-07-24 06:02:45 +04:00
|
|
|
elinit(sc)
|
1994-03-01 05:45:00 +03:00
|
|
|
struct el_softc *sc;
|
1994-03-01 08:41:26 +03:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* 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. */
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Configuring rx...\n"));
|
1994-03-01 07:12:25 +03:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_RXC,
|
1996-08-03 23:33:19 +04:00
|
|
|
EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
|
|
|
|
EL_RXC_DOFLOW | EL_RXC_PROMISC);
|
1994-03-01 05:45:00 +03:00
|
|
|
else
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_RXC,
|
1996-08-03 23:33:19 +04:00
|
|
|
EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
|
|
|
|
EL_RXC_DOFLOW | EL_RXC_ABROAD);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_RBC, 0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Configure TX. */
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Configuring tx...\n"));
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_TXC, 0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Start reception. */
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("Starting reception...\n"));
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, 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. */
|
1995-07-24 06:02:45 +04:00
|
|
|
elstart(ifp);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
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,
|
1995-12-24 05:29:35 +03:00
|
|
|
* giving the receiver a chance between datagrams. Call only from splnet or
|
1994-03-01 08:41:26 +03:00
|
|
|
* interrupt level!
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
|
|
|
elstart(ifp)
|
1994-03-01 07:12:25 +03:00
|
|
|
struct ifnet *ifp;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
struct el_softc *sc = ifp->if_softc;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-03-01 05:45:00 +03:00
|
|
|
struct mbuf *m, *m0;
|
1995-07-23 21:50:56 +04:00
|
|
|
int s, i, off, retries;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("elstart()...\n"));
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Don't do anything if output is active. */
|
1995-07-23 21:50:56 +04:00
|
|
|
if ((ifp->if_flags & IFF_OACTIVE) != 0) {
|
|
|
|
splx(s);
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
1995-07-23 21:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ifp->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. */
|
1995-07-23 21:50:56 +04:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* If there's nothing to send, return. */
|
1995-07-23 21:50:56 +04:00
|
|
|
if (m0 == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/* Give the packet to the bpf, if any. */
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m0);
|
|
|
|
#endif
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Disable the receiver. */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_HOST);
|
|
|
|
bus_space_write_1(iot, ioh, EL_RBC, 0);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1995-07-23 21:50:56 +04:00
|
|
|
/* Transfer datagram to board. */
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("el: xfr pkt length=%d...\n", m0->m_pkthdr.len));
|
1995-07-23 21:50:56 +04:00
|
|
|
off = EL_BUFSIZ - max(m0->m_pkthdr.len, ETHER_MIN_LEN);
|
1996-08-03 23:33:19 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((off & 0xffff) != off)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: bogus off 0x%x\n",
|
1996-08-03 23:33:19 +04:00
|
|
|
sc->sc_dev.dv_xname, off);
|
|
|
|
#endif
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_GPBL, off & 0xff);
|
|
|
|
bus_space_write_1(iot, ioh, EL_GPBH, (off >> 8) & 0xff);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1995-07-23 21:50:56 +04:00
|
|
|
/* Copy the datagram to the buffer. */
|
|
|
|
for (m = m0; m != 0; m = m->m_next)
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_multi_1(iot, ioh, EL_BUF,
|
1996-08-03 23:33:19 +04:00
|
|
|
mtod(m, u_int8_t *), m->m_len);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1995-07-23 21:50:56 +04:00
|
|
|
m_freem(m0);
|
1994-03-01 08:41:26 +03:00
|
|
|
|
|
|
|
/* Now transmit the datagram. */
|
|
|
|
retries = 0;
|
1995-07-23 21:50:56 +04:00
|
|
|
for (;;) {
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_GPBL, off & 0xff);
|
|
|
|
bus_space_write_1(iot, ioh, EL_GPBH, (off >> 8) & 0xff);
|
1995-08-06 03:53:18 +04:00
|
|
|
if (el_xmit(sc)) {
|
|
|
|
ifp->if_oerrors++;
|
1994-03-01 05:45:00 +03:00
|
|
|
break;
|
1995-08-06 03:53:18 +04:00
|
|
|
}
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Check out status. */
|
1996-10-22 02:34:38 +04:00
|
|
|
i = bus_space_read_1(iot, ioh, EL_TXS);
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("tx status=0x%x\n", i));
|
1994-03-01 08:41:26 +03:00
|
|
|
if ((i & EL_TXS_READY) == 0) {
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("el: err txs=%x\n", i));
|
1994-03-01 08:41:26 +03:00
|
|
|
if (i & (EL_TXS_COLL | EL_TXS_COLL16)) {
|
1995-08-06 03:53:18 +04:00
|
|
|
ifp->if_collisions++;
|
1994-03-01 08:41:26 +03:00
|
|
|
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++;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh,
|
1996-08-03 23:33:19 +04:00
|
|
|
EL_AC, EL_AC_HOST);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1995-08-06 03:53:18 +04:00
|
|
|
} else {
|
|
|
|
ifp->if_oerrors++;
|
1995-07-23 21:50:56 +04:00
|
|
|
break;
|
1995-08-06 03:53:18 +04:00
|
|
|
}
|
1994-03-02 19:23:23 +03:00
|
|
|
} else {
|
1995-07-23 21:50:56 +04:00
|
|
|
ifp->if_opackets++;
|
|
|
|
break;
|
1994-03-02 19:23:23 +03:00
|
|
|
}
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
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...
|
|
|
|
*/
|
1996-10-22 02:34:38 +04:00
|
|
|
(void)bus_space_read_1(iot, ioh, EL_AS);
|
|
|
|
bus_space_write_1(iot, ioh, 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. */
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1995-07-23 21:50:56 +04:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
(void)bus_space_read_1(iot, ioh, EL_AS);
|
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_IRQE | EL_AC_RX);
|
1995-07-23 21:50:56 +04:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
splx(s);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
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
|
1995-12-24 05:29:35 +03:00
|
|
|
* board. Call at splnet or interrupt, after downloading data! Returns 0 on
|
1994-03-01 08:41:26 +03:00
|
|
|
* success, non-0 on failure.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
|
|
|
static int
|
1995-07-23 21:50:56 +04:00
|
|
|
el_xmit(sc)
|
1994-03-01 07:12:25 +03:00
|
|
|
struct el_softc *sc;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-03-01 05:45:00 +03:00
|
|
|
int i;
|
|
|
|
|
1995-08-06 03:53:18 +04:00
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* This busy-waits for the tx completion. Can we get an interrupt
|
|
|
|
* instead?
|
|
|
|
*/
|
|
|
|
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("el: xmit..."));
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_TXFRX);
|
1994-03-01 05:45:00 +03:00
|
|
|
i = 20000;
|
1996-10-22 02:34:38 +04:00
|
|
|
while ((bus_space_read_1(iot, ioh, 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) {
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("tx not ready\n"));
|
1994-03-01 08:41:26 +03:00
|
|
|
return -1;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("%d cycles.\n", 20000 - i));
|
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
|
|
|
/*
|
|
|
|
* Controller interrupt.
|
|
|
|
*/
|
1994-03-01 05:45:00 +03:00
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
elintr(arg)
|
|
|
|
void *arg;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
register struct el_softc *sc = arg;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1996-08-03 23:33:19 +04:00
|
|
|
u_int8_t rxstat;
|
|
|
|
int len;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("elintr: "));
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Check board status. */
|
1996-10-22 02:34:38 +04:00
|
|
|
if ((bus_space_read_1(iot, ioh, EL_AS) & EL_AS_RXBUSY) != 0) {
|
|
|
|
(void)bus_space_read_1(iot, ioh, EL_RXC);
|
|
|
|
bus_space_write_1(iot, ioh, 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
|
|
|
}
|
|
|
|
|
1995-07-23 21:50:56 +04:00
|
|
|
for (;;) {
|
1996-10-22 02:34:38 +04:00
|
|
|
rxstat = bus_space_read_1(iot, ioh, EL_RXS);
|
1995-07-23 21:50:56 +04:00
|
|
|
if (rxstat & EL_RXS_STALE)
|
|
|
|
break;
|
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) {
|
1996-10-11 01:25:07 +04: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. */
|
1997-03-15 21:09:08 +03:00
|
|
|
if (sc->sc_ethercom.ec_if.if_flags & IFF_PROMISC)
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_RXC,
|
1996-08-03 23:33:19 +04:00
|
|
|
EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
|
|
|
|
EL_RXC_DOFLOW | EL_RXC_PROMISC);
|
1994-03-01 05:45:00 +03:00
|
|
|
else
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_RXC,
|
1996-08-03 23:33:19 +04:00
|
|
|
EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
|
|
|
|
EL_RXC_DOFLOW | EL_RXC_ABROAD);
|
1996-10-22 02:34:38 +04:00
|
|
|
(void)bus_space_read_1(iot, ioh, EL_AS);
|
|
|
|
bus_space_write_1(iot, ioh, EL_RBC, 0);
|
1995-07-23 21:50:56 +04:00
|
|
|
break;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Incoming packet. */
|
1996-10-22 02:34:38 +04:00
|
|
|
len = bus_space_read_1(iot, ioh, EL_RBL);
|
|
|
|
len |= bus_space_read_1(iot, ioh, EL_RBH) << 8;
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("receive len=%d rxstat=%x ", len, rxstat));
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_HOST);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Pass data up to upper levels. */
|
1995-07-23 21:50:56 +04:00
|
|
|
elread(sc, len);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/* Is there another packet? */
|
1996-10-22 02:34:38 +04:00
|
|
|
if ((bus_space_read_1(iot, ioh, EL_AS) & EL_AS_RXBUSY) != 0)
|
1995-07-23 21:50:56 +04:00
|
|
|
break;
|
|
|
|
|
1997-10-15 09:55:13 +04:00
|
|
|
#if NRND > 0
|
|
|
|
rnd_add_uint32(&sc->rnd_source, rxstat);
|
|
|
|
#endif
|
|
|
|
|
1996-10-11 01:25:07 +04:00
|
|
|
DPRINTF(("<rescan> "));
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
(void)bus_space_read_1(iot, ioh, EL_RXC);
|
|
|
|
bus_space_write_1(iot, ioh, 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
|
|
|
/*
|
1995-07-24 06:02:45 +04:00
|
|
|
* Pass a packet to the higher levels.
|
1994-03-01 07:12:25 +03:00
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1995-07-23 21:50:56 +04:00
|
|
|
elread(sc, len)
|
1995-07-24 06:08:13 +04:00
|
|
|
register struct el_softc *sc;
|
1994-03-01 07:12:25 +03:00
|
|
|
int len;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1994-03-01 05:45:00 +03:00
|
|
|
struct mbuf *m;
|
1995-07-23 21:05:26 +04:00
|
|
|
struct ether_header *eh;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
if (len <= sizeof(struct ether_header) ||
|
|
|
|
len > ETHER_MAX_LEN) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: invalid packet size %d; dropping\n",
|
1995-07-24 08:12:45 +04:00
|
|
|
sc->sc_dev.dv_xname, len);
|
1995-07-24 06:02:45 +04:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-05-13 10:13:43 +04:00
|
|
|
/* Pull packet off interface. */
|
1995-07-24 06:02:45 +04:00
|
|
|
m = elget(sc, len);
|
|
|
|
if (m == 0) {
|
|
|
|
ifp->if_ierrors++;
|
1994-05-13 10:13:43 +04:00
|
|
|
return;
|
1995-07-24 06:02:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
1994-05-13 10:13:43 +04:00
|
|
|
|
1995-07-23 21:05:26 +04:00
|
|
|
/* We assume that the header fit entirely in one mbuf. */
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
|
1994-03-01 05:45:00 +03:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
1994-05-13 10:13:43 +04:00
|
|
|
* Check if there's a BPF listener on this interface.
|
1995-07-24 06:02:45 +04:00
|
|
|
* If so, hand off the raw packet to BPF.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1995-07-23 21:05:26 +04:00
|
|
|
if (ifp->if_bpf) {
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the interface cannot be in promiscuous mode if
|
1994-05-13 10:13:43 +04:00
|
|
|
* there are no BPF listeners. And if we are in promiscuous
|
|
|
|
* mode, we have to check if this packet is really ours.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1995-07-23 21:05:26 +04:00
|
|
|
if ((ifp->if_flags & IFF_PROMISC) &&
|
1994-05-13 10:13:43 +04:00
|
|
|
(eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
|
1997-03-15 21:09:08 +03:00
|
|
|
bcmp(eh->ether_dhost, LLADDR(ifp->if_sadl),
|
1994-05-13 10:13:43 +04:00
|
|
|
sizeof(eh->ether_dhost)) != 0) {
|
|
|
|
m_freem(m);
|
1994-03-01 05:45:00 +03:00
|
|
|
return;
|
1994-05-13 10:13:43 +04:00
|
|
|
}
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-07-23 21:05:26 +04:00
|
|
|
/* We assume that the header fit entirely in one mbuf. */
|
1995-07-24 06:02:45 +04:00
|
|
|
m_adj(m, sizeof(struct ether_header));
|
1995-07-23 21:05:26 +04:00
|
|
|
ether_input(ifp, 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
|
1994-05-13 10:13:43 +04:00
|
|
|
* header stripped. We copy the data into mbufs. When full cluster sized
|
|
|
|
* units are present we copy into clusters.
|
1994-03-01 05:45:00 +03:00
|
|
|
*/
|
1995-07-24 06:08:13 +04:00
|
|
|
struct mbuf *
|
1995-07-24 06:02:45 +04:00
|
|
|
elget(sc, totlen)
|
1995-07-23 21:50:56 +04:00
|
|
|
struct el_softc *sc;
|
1995-07-23 21:05:26 +04:00
|
|
|
int totlen;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1995-07-23 21:05:26 +04:00
|
|
|
struct mbuf *top, **mp, *m;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0)
|
|
|
|
return 0;
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
len = MHLEN;
|
|
|
|
top = 0;
|
|
|
|
mp = ⊤
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_GPBL, 0);
|
|
|
|
bus_space_write_1(iot, ioh, EL_GPBH, 0);
|
1995-07-23 21:50:56 +04:00
|
|
|
|
1995-07-23 21:05:26 +04:00
|
|
|
while (totlen > 0) {
|
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
m_freem(top);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
len = MLEN;
|
|
|
|
}
|
|
|
|
if (totlen >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
1997-04-24 12:05:13 +04:00
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
1997-04-28 21:03:58 +04:00
|
|
|
m_free(m);
|
1997-04-24 06:04:33 +04:00
|
|
|
m_freem(top);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
len = MCLBYTES;
|
1995-07-23 21:05:26 +04:00
|
|
|
}
|
|
|
|
m->m_len = len = min(totlen, len);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_read_multi_1(iot, ioh, EL_BUF, mtod(m, u_int8_t *), len);
|
1995-07-23 21:05:26 +04:00
|
|
|
totlen -= len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
}
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EL_RBC, 0);
|
|
|
|
bus_space_write_1(iot, ioh, EL_AC, EL_AC_RX);
|
1995-07-23 21:50:56 +04:00
|
|
|
|
1995-07-23 21:05:26 +04: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
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
int
|
|
|
|
elioctl(ifp, cmd, data)
|
1994-03-01 05:45:00 +03:00
|
|
|
register struct ifnet *ifp;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1994-03-01 05:45:00 +03:00
|
|
|
caddr_t data;
|
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
struct el_softc *sc = ifp->if_softc;
|
1994-05-13 10:13:43 +04:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
1994-03-01 05:45:00 +03:00
|
|
|
int s, error = 0;
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1994-05-13 10:13:43 +04:00
|
|
|
switch (cmd) {
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1995-07-24 06:02:45 +04:00
|
|
|
elinit(sc);
|
1997-03-15 21:09:08 +03:00
|
|
|
arp_ifinit(ifp, ifa);
|
1994-03-01 05:45:00 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NS
|
1995-06-09 22:09:27 +04: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 =
|
1997-03-15 21:09:08 +03:00
|
|
|
*(union ns_host *)LLADDR(ifp->if_sadl);
|
1995-06-09 22:09:27 +04:00
|
|
|
else
|
1997-03-15 21:09:08 +03:00
|
|
|
bcopy(ina->x_host.c_host, LLADDR(ifp->if_sadl),
|
|
|
|
ETHER_ADDR_LEN);
|
1994-03-01 08:41:26 +03:00
|
|
|
/* Set new address. */
|
1995-07-24 06:02:45 +04:00
|
|
|
elinit(sc);
|
1994-03-01 08:41:26 +03:00
|
|
|
break;
|
|
|
|
}
|
1994-03-01 05:45:00 +03:00
|
|
|
#endif
|
|
|
|
default:
|
1995-07-24 06:02:45 +04:00
|
|
|
elinit(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-05-13 10:13:43 +04:00
|
|
|
(ifp->if_flags & IFF_RUNNING) != 0) {
|
1994-03-01 08:41:26 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
elstop(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
1994-05-13 10:13:43 +04:00
|
|
|
} else if ((ifp->if_flags & IFF_UP) != 0 &&
|
1994-03-01 08:41:26 +03:00
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0) {
|
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
elinit(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.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
elreset(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1995-06-09 22:09:27 +04:00
|
|
|
break;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
1995-06-09 22:09:27 +04:00
|
|
|
break;
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|
1995-06-09 22:09:27 +04:00
|
|
|
|
1995-04-11 09:10:20 +04:00
|
|
|
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.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1996-05-07 05:55:13 +04:00
|
|
|
elwatchdog(ifp)
|
|
|
|
struct ifnet *ifp;
|
1994-03-01 05:45:00 +03:00
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
struct el_softc *sc = ifp->if_softc;
|
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);
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_oerrors++;
|
1994-03-01 05:45:00 +03:00
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
elreset(sc);
|
1994-03-01 05:45:00 +03:00
|
|
|
}
|