1996-08-03 06:23:57 +04:00
|
|
|
/* $NetBSD: if_eg.c,v 1.28 1996/08/03 02:23:57 thorpej Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1993 Dean Huxley <dean@fsa.ca>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Dean Huxley.
|
|
|
|
* 4. The name of Dean Huxley may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1996-01-10 21:21:52 +03:00
|
|
|
/*
|
|
|
|
* Support for 3Com 3c505 Etherlink+ card.
|
|
|
|
*/
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* To do:
|
|
|
|
* - multicast
|
|
|
|
* - promiscuous
|
1996-08-03 06:12:46 +04:00
|
|
|
* - get rid of isa indirect stuff
|
1994-08-23 21:59:33 +04:00
|
|
|
*/
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.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
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
1996-05-13 03:51:23 +04:00
|
|
|
#include <machine/intr.h>
|
1996-08-03 06:12:46 +04:00
|
|
|
#include <machine/bus.h>
|
1994-08-23 21:59:33 +04: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_egreg.h>
|
|
|
|
#include <dev/isa/elink.h>
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* for debugging convenience */
|
|
|
|
#ifdef EGDEBUG
|
1994-08-26 00:18:25 +04:00
|
|
|
#define dprintf(x) printf x
|
1994-08-23 21:59:33 +04:00
|
|
|
#else
|
1994-08-26 00:18:25 +04:00
|
|
|
#define dprintf(x)
|
1994-08-23 21:59:33 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ETHER_MIN_LEN 64
|
|
|
|
#define ETHER_MAX_LEN 1518
|
|
|
|
#define ETHER_ADDR_LEN 6
|
|
|
|
|
|
|
|
#define EG_INLEN 10
|
|
|
|
#define EG_BUFLEN 0x0670
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet software status per interface.
|
|
|
|
*/
|
|
|
|
struct eg_softc {
|
|
|
|
struct device sc_dev;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1994-08-23 21:59:33 +04:00
|
|
|
struct arpcom sc_arpcom; /* Ethernet common part */
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t sc_bc; /* bus chipset identifier */
|
|
|
|
bus_io_handle_t sc_ioh; /* i/o handle */
|
|
|
|
u_int8_t eg_rom_major; /* Cards ROM version (major number) */
|
|
|
|
u_int8_t eg_rom_minor; /* Cards ROM version (minor number) */
|
|
|
|
short eg_ram; /* Amount of RAM on the card */
|
|
|
|
u_int8_t eg_pcb[64]; /* Primary Command Block buffer */
|
|
|
|
u_int8_t eg_incount; /* Number of buffers currently used */
|
|
|
|
caddr_t eg_inbuf; /* Incoming packet buffer */
|
|
|
|
caddr_t eg_outbuf; /* Outgoing packet buffer */
|
1994-08-23 21:59:33 +04:00
|
|
|
};
|
|
|
|
|
1994-11-04 02:08:27 +03:00
|
|
|
int egprobe __P((struct device *, void *, void *));
|
|
|
|
void egattach __P((struct device *, struct device *, void *));
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-03-17 03:43:52 +03:00
|
|
|
struct cfattach eg_ca = {
|
|
|
|
sizeof(struct eg_softc), egprobe, egattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfdriver eg_cd = {
|
|
|
|
NULL, "eg", DV_IFNET
|
1994-08-23 21:59:33 +04:00
|
|
|
};
|
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
int egintr __P((void *));
|
1995-07-24 06:02:45 +04:00
|
|
|
void eginit __P((struct eg_softc *));
|
|
|
|
int egioctl __P((struct ifnet *, u_long, caddr_t));
|
1995-07-24 06:08:13 +04:00
|
|
|
void egrecv __P((struct eg_softc *));
|
1995-07-24 06:02:45 +04:00
|
|
|
void egstart __P((struct ifnet *));
|
1996-05-07 05:55:13 +04:00
|
|
|
void egwatchdog __P((struct ifnet *));
|
1995-07-24 06:02:45 +04:00
|
|
|
void egreset __P((struct eg_softc *));
|
|
|
|
void egread __P((struct eg_softc *, caddr_t, int));
|
|
|
|
struct mbuf *egget __P((struct eg_softc *, caddr_t, int));
|
|
|
|
void egstop __P((struct eg_softc *));
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Support stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
egprintpcb(sc)
|
|
|
|
struct eg_softc *sc;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->eg_pcb[1] + 2; i++)
|
1994-08-26 00:18:25 +04:00
|
|
|
dprintf(("pcb[%2d] = %x\n", i, sc->eg_pcb[i]));
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
egprintstat(b)
|
|
|
|
u_char b;
|
|
|
|
{
|
1994-08-26 00:18:25 +04:00
|
|
|
dprintf(("%s %s %s %s %s %s %s\n",
|
1994-08-23 21:59:33 +04:00
|
|
|
(b & EG_STAT_HCRE)?"HCRE":"",
|
|
|
|
(b & EG_STAT_ACRF)?"ACRF":"",
|
|
|
|
(b & EG_STAT_DIR )?"DIR ":"",
|
|
|
|
(b & EG_STAT_DONE)?"DONE":"",
|
|
|
|
(b & EG_STAT_ASF3)?"ASF3":"",
|
|
|
|
(b & EG_STAT_ASF2)?"ASF2":"",
|
|
|
|
(b & EG_STAT_ASF1)?"ASF1":""));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
egoutPCB(sc, b)
|
|
|
|
struct eg_softc *sc;
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int8_t b;
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < 4000; i++) {
|
1996-08-03 06:12:46 +04:00
|
|
|
if (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_HCRE) {
|
|
|
|
bus_io_write_1(bc, ioh, EG_COMMAND, b);
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
delay(10);
|
|
|
|
}
|
1994-08-26 00:18:25 +04:00
|
|
|
dprintf(("egoutPCB failed\n"));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
egreadPCBstat(sc, statb)
|
|
|
|
struct eg_softc *sc;
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int8_t statb;
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < 5000; i++) {
|
1996-08-03 06:12:46 +04:00
|
|
|
if ((bus_io_read_1(bc, ioh, EG_STATUS) &
|
|
|
|
EG_PCB_STAT) != EG_PCB_NULL)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
delay(10);
|
|
|
|
}
|
1996-08-03 06:12:46 +04:00
|
|
|
if ((bus_io_read_1(bc, ioh, EG_STATUS) & EG_PCB_STAT) == statb)
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
egreadPCBready(sc)
|
|
|
|
struct eg_softc *sc;
|
|
|
|
{
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < 10000; i++) {
|
1996-08-03 06:12:46 +04:00
|
|
|
if (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_ACRF)
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
delay(5);
|
|
|
|
}
|
1994-08-26 00:18:25 +04:00
|
|
|
dprintf(("PCB read not ready\n"));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
egwritePCB(sc)
|
|
|
|
struct eg_softc *sc;
|
|
|
|
{
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
int i;
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int8_t len;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL,
|
|
|
|
(bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_NULL);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
len = sc->eg_pcb[1] + 2;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
egoutPCB(sc, sc->eg_pcb[i]);
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
for (i=0; i < 4000; i++) {
|
1996-08-03 06:12:46 +04:00
|
|
|
if (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_HCRE)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
delay(10);
|
|
|
|
}
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL,
|
1996-08-03 06:23:57 +04:00
|
|
|
(bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_DONE);
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
egoutPCB(sc, len);
|
|
|
|
|
|
|
|
if (egreadPCBstat(sc, EG_PCB_ACCEPT))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
egreadPCB(sc)
|
|
|
|
struct eg_softc *sc;
|
|
|
|
{
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
int i;
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int8_t b;
|
|
|
|
|
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL,
|
|
|
|
(bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_NULL);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
bzero(sc->eg_pcb, sizeof(sc->eg_pcb));
|
|
|
|
|
|
|
|
if (egreadPCBready(sc))
|
|
|
|
return 1;
|
|
|
|
|
1996-08-03 06:23:57 +04:00
|
|
|
sc->eg_pcb[0] = bus_io_read_1(bc, ioh, EG_COMMAND);
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
if (egreadPCBready(sc))
|
|
|
|
return 1;
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
sc->eg_pcb[1] = bus_io_read_1(bc, ioh, EG_COMMAND);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
if (sc->eg_pcb[1] > 62) {
|
1994-08-26 00:18:25 +04:00
|
|
|
dprintf(("len %d too large\n", sc->eg_pcb[1]));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
for (i = 0; i < sc->eg_pcb[1]; i++) {
|
|
|
|
if (egreadPCBready(sc))
|
|
|
|
return 1;
|
1996-08-03 06:12:46 +04:00
|
|
|
sc->eg_pcb[2+i] = bus_io_read_1(bc, ioh, EG_COMMAND);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
if (egreadPCBready(sc))
|
|
|
|
return 1;
|
|
|
|
if (egreadPCBstat(sc, EG_PCB_DONE))
|
|
|
|
return 1;
|
1996-08-03 06:12:46 +04:00
|
|
|
if ((b = bus_io_read_1(bc, ioh, EG_COMMAND)) != sc->eg_pcb[1] + 2) {
|
1994-11-05 00:32:23 +03:00
|
|
|
dprintf(("%d != %d\n", b, sc->eg_pcb[1] + 2));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL,
|
|
|
|
(bus_io_read_1(bc, ioh, EG_CONTROL) &
|
|
|
|
~EG_PCB_STAT) | EG_PCB_ACCEPT);
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Real stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1994-11-04 02:08:27 +03:00
|
|
|
egprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1994-11-04 02:08:27 +03:00
|
|
|
struct eg_softc *sc = match;
|
1994-08-23 21:59:33 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = ia->ia_bc;
|
|
|
|
bus_io_handle_t ioh;
|
|
|
|
int i, rval;
|
|
|
|
|
|
|
|
rval = 0;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
if (ia->ia_iobase & ~0x07f0 != 0) {
|
1994-08-26 00:18:25 +04:00
|
|
|
dprintf(("Weird iobase %x\n", ia->ia_iobase));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1996-08-03 06:12:46 +04:00
|
|
|
|
|
|
|
/* Map i/o space. */
|
|
|
|
if (bus_io_map(bc, ia->ia_iobase, 0x08, &ioh)) {
|
|
|
|
dprintf(("egprobe: can't map i/o space in probe\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Indirect brokenness.
|
|
|
|
*/
|
|
|
|
sc->sc_bc = bc; /* XXX */
|
|
|
|
sc->sc_ioh = ioh; /* XXX */
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* hard reset card */
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_RESET);
|
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL, 0);
|
1994-08-23 21:59:33 +04:00
|
|
|
for (i = 0; i < 5000; i++) {
|
|
|
|
delay(1000);
|
1996-08-03 06:12:46 +04:00
|
|
|
if ((bus_io_read_1(bc, ioh, EG_STATUS) &
|
|
|
|
EG_PCB_STAT) == EG_PCB_NULL)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-08-03 06:12:46 +04:00
|
|
|
if ((bus_io_read_1(bc, ioh, EG_STATUS) & EG_PCB_STAT) != EG_PCB_NULL) {
|
|
|
|
dprintf(("egprobe: Reset failed\n"));
|
|
|
|
goto out;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
sc->eg_pcb[0] = EG_CMD_GETINFO; /* Get Adapter Info */
|
|
|
|
sc->eg_pcb[1] = 0;
|
|
|
|
if (egwritePCB(sc) != 0)
|
1996-08-03 06:12:46 +04:00
|
|
|
goto out;
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
if (egreadPCB(sc) != 0) {
|
|
|
|
egprintpcb(sc);
|
1996-08-03 06:12:46 +04:00
|
|
|
goto out;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->eg_pcb[0] != EG_RSP_GETINFO || /* Get Adapter Info Response */
|
|
|
|
sc->eg_pcb[1] != 0x0a) {
|
|
|
|
egprintpcb(sc);
|
1996-08-03 06:12:46 +04:00
|
|
|
goto out;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
sc->eg_rom_major = sc->eg_pcb[3];
|
|
|
|
sc->eg_rom_minor = sc->eg_pcb[2];
|
|
|
|
sc->eg_ram = sc->eg_pcb[6] | (sc->eg_pcb[7] << 8);
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
ia->ia_iosize = 0x08;
|
|
|
|
ia->ia_msize = 0;
|
1996-08-03 06:12:46 +04:00
|
|
|
rval = 1;
|
|
|
|
|
|
|
|
out:
|
|
|
|
bus_io_unmap(bc, ioh, 0x08);
|
|
|
|
return rval;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:08:13 +04:00
|
|
|
void
|
1994-08-23 21:59:33 +04:00
|
|
|
egattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
1994-08-24 03:40:55 +04:00
|
|
|
struct eg_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = ia->ia_bc;
|
|
|
|
bus_io_handle_t ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
|
|
|
int i;
|
1996-08-03 06:12:46 +04:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Map i/o space. */
|
|
|
|
if (bus_io_map(bc, ia->ia_iobase, ia->ia_iosize, &ioh)) {
|
|
|
|
printf("%s: can't map i/o space\n", self->dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_bc = bc;
|
|
|
|
sc->sc_ioh = ioh;
|
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
egstop(sc);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_GETEADDR; /* Get Station address */
|
|
|
|
sc->eg_pcb[1] = 0;
|
|
|
|
if (egwritePCB(sc) != 0) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: can't send Get Station Address\n", self->dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (egreadPCB(sc) != 0) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: can't read station address\n", self->dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
egprintpcb(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check Get station address response */
|
|
|
|
if (sc->eg_pcb[0] != EG_RSP_GETEADDR || sc->eg_pcb[1] != 0x06) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: card responded with garbage (1)\n",
|
|
|
|
self->dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
egprintpcb(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bcopy(&sc->eg_pcb[2], sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN);
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: ROM v%d.%02d %dk address %s\n", self->dv_xname,
|
1994-08-24 03:40:55 +04:00
|
|
|
sc->eg_rom_major, sc->eg_rom_minor, sc->eg_ram,
|
|
|
|
ether_sprintf(sc->sc_arpcom.ac_enaddr));
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_SETEADDR; /* Set station address */
|
|
|
|
if (egwritePCB(sc) != 0) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: can't send Set Station Address\n", self->dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (egreadPCB(sc) != 0) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: can't read Set Station Address status\n",
|
|
|
|
self->dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
egprintpcb(sc);
|
|
|
|
return;
|
|
|
|
}
|
1994-08-24 03:40:55 +04:00
|
|
|
if (sc->eg_pcb[0] != EG_RSP_SETEADDR || sc->eg_pcb[1] != 0x02 ||
|
1994-11-05 00:32:23 +03:00
|
|
|
sc->eg_pcb[2] != 0 || sc->eg_pcb[3] != 0) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: card responded with garbage (2)\n",
|
|
|
|
self->dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
egprintpcb(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-08-24 03:40:55 +04: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;
|
1994-08-23 21:59:33 +04:00
|
|
|
ifp->if_start = egstart;
|
|
|
|
ifp->if_ioctl = egioctl;
|
|
|
|
ifp->if_watchdog = egwatchdog;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
|
|
|
|
|
|
|
|
/* Now we can attach the interface. */
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp);
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
1994-08-24 03:40:55 +04:00
|
|
|
bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
|
1994-08-23 21:59:33 +04:00
|
|
|
#endif
|
1995-04-17 16:06:30 +04:00
|
|
|
|
1996-04-12 02:27:59 +04:00
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
|
|
|
|
IPL_NET, egintr, sc);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1994-08-23 21:59:33 +04:00
|
|
|
eginit(sc)
|
|
|
|
register struct eg_softc *sc;
|
|
|
|
{
|
|
|
|
register struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* soft reset the board */
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_FLSH);
|
1994-08-23 21:59:33 +04:00
|
|
|
delay(100);
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_ATTN);
|
1994-08-23 21:59:33 +04:00
|
|
|
delay(100);
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL, 0);
|
1994-08-23 21:59:33 +04:00
|
|
|
delay(200);
|
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_CONFIG82586; /* Configure 82586 */
|
|
|
|
sc->eg_pcb[1] = 2;
|
|
|
|
sc->eg_pcb[2] = 3; /* receive broadcast & multicast */
|
|
|
|
sc->eg_pcb[3] = 0;
|
|
|
|
if (egwritePCB(sc) != 0)
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: can't send Configure 82586\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
if (egreadPCB(sc) != 0) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: can't read Configure 82586 status\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
egprintpcb(sc);
|
|
|
|
} else if (sc->eg_pcb[2] != 0 || sc->eg_pcb[3] != 0)
|
1994-11-05 00:32:23 +03:00
|
|
|
printf("%s: configure card command failed\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_inbuf == NULL) {
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_inbuf = malloc(EG_BUFLEN, M_TEMP, M_NOWAIT);
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_inbuf == NULL) {
|
|
|
|
printf("%s: can't allocate inbuf\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
panic("eginit");
|
|
|
|
}
|
|
|
|
}
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_incount = 0;
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_outbuf == NULL) {
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_outbuf = malloc(EG_BUFLEN, M_TEMP, M_NOWAIT);
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_outbuf == NULL) {
|
|
|
|
printf("%s: can't allocate outbuf\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
panic("eginit");
|
|
|
|
}
|
|
|
|
}
|
1995-07-24 00:27:48 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL, EG_CTL_CMDE);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
|
|
|
sc->eg_incount = 0;
|
|
|
|
egrecv(sc);
|
|
|
|
|
|
|
|
/* Interface is now `running', with no output active. */
|
1994-08-23 21:59:33 +04:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
1995-07-24 00:54:23 +04:00
|
|
|
/* Attempt to start output, if any. */
|
1994-08-23 21:59:33 +04:00
|
|
|
egstart(ifp);
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1994-08-23 21:59:33 +04:00
|
|
|
egrecv(sc)
|
|
|
|
struct eg_softc *sc;
|
|
|
|
{
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
while (sc->eg_incount < EG_INLEN) {
|
|
|
|
sc->eg_pcb[0] = EG_CMD_RECVPACKET;
|
|
|
|
sc->eg_pcb[1] = 0x08;
|
|
|
|
sc->eg_pcb[2] = 0; /* address not used.. we send zero */
|
|
|
|
sc->eg_pcb[3] = 0;
|
|
|
|
sc->eg_pcb[4] = 0;
|
|
|
|
sc->eg_pcb[5] = 0;
|
1996-05-07 05:55:13 +04:00
|
|
|
sc->eg_pcb[6] = EG_BUFLEN & 0xff; /* our buffer size */
|
|
|
|
sc->eg_pcb[7] = (EG_BUFLEN >> 8) & 0xff;
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_pcb[8] = 0; /* timeout, 0 == none */
|
|
|
|
sc->eg_pcb[9] = 0;
|
1995-07-24 00:54:23 +04:00
|
|
|
if (egwritePCB(sc) != 0)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
1995-07-24 00:54:23 +04:00
|
|
|
sc->eg_incount++;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1994-08-23 21:59:33 +04:00
|
|
|
egstart(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
register struct eg_softc *sc = ifp->if_softc;
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
struct mbuf *m0, *m;
|
1995-07-24 00:27:48 +04:00
|
|
|
caddr_t buffer;
|
1994-08-23 21:59:33 +04:00
|
|
|
int len;
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int16_t *ptr;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* Don't transmit if interface is busy or not running */
|
1995-07-24 00:27:48 +04:00
|
|
|
if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
|
1995-07-23 23:45:42 +04:00
|
|
|
return;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1995-07-24 00:27:48 +04:00
|
|
|
loop:
|
1994-08-23 21:59:33 +04:00
|
|
|
/* Dequeue the next datagram. */
|
1995-07-24 00:27:48 +04:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m0);
|
|
|
|
if (m0 == 0)
|
1995-07-23 23:45:42 +04:00
|
|
|
return;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1995-07-24 00:27:48 +04:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
/* We need to use m->m_pkthdr.len, so require the header */
|
1996-08-03 06:12:46 +04:00
|
|
|
if ((m0->m_flags & M_PKTHDR) == 0) {
|
|
|
|
printf("%s: no header mbuf\n", sc->sc_dev.dv_xname);
|
|
|
|
panic("egstart");
|
|
|
|
}
|
1995-07-24 00:27:48 +04:00
|
|
|
len = max(m0->m_pkthdr.len, ETHER_MIN_LEN);
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
#if NBPFILTER > 0
|
1995-07-24 00:27:48 +04:00
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m0);
|
1994-08-23 21:59:33 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_SENDPACKET;
|
|
|
|
sc->eg_pcb[1] = 0x06;
|
|
|
|
sc->eg_pcb[2] = 0; /* address not used, we send zero */
|
|
|
|
sc->eg_pcb[3] = 0;
|
|
|
|
sc->eg_pcb[4] = 0;
|
|
|
|
sc->eg_pcb[5] = 0;
|
1995-07-24 00:27:48 +04:00
|
|
|
sc->eg_pcb[6] = len; /* length of packet */
|
|
|
|
sc->eg_pcb[7] = len >> 8;
|
|
|
|
if (egwritePCB(sc) != 0) {
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: can't send Send Packet command\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1995-07-24 00:27:48 +04:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1996-08-03 06:12:46 +04:00
|
|
|
m_freem(m0);
|
1995-07-24 00:27:48 +04:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = sc->eg_outbuf;
|
|
|
|
for (m = m0; m != 0; m = m->m_next) {
|
|
|
|
bcopy(mtod(m, caddr_t), buffer, m->m_len);
|
|
|
|
buffer += m->m_len;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1995-07-24 00:27:48 +04:00
|
|
|
|
1995-07-24 00:54:23 +04:00
|
|
|
/* set direction bit: host -> adapter */
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL,
|
|
|
|
bus_io_read_1(bc, ioh, EG_CONTROL) & ~EG_CTL_DIR);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
for (ptr = (u_int16_t *) sc->eg_outbuf; len > 0; len -= 2) {
|
|
|
|
bus_io_write_2(bc, ioh, EG_DATA, *ptr++);
|
|
|
|
while (!(bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_HRDY))
|
1995-07-24 00:27:48 +04:00
|
|
|
; /* XXX need timeout here */
|
|
|
|
}
|
|
|
|
|
|
|
|
m_freem(m0);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
egintr(arg)
|
|
|
|
void *arg;
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
register struct eg_softc *sc = arg;
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_chipset_tag_t bc = sc->sc_bc;
|
|
|
|
bus_io_handle_t ioh = sc->sc_ioh;
|
|
|
|
int i, len, serviced;
|
|
|
|
u_int16_t *ptr;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
serviced = 0;
|
|
|
|
|
|
|
|
while (bus_io_read_1(bc, ioh, EG_STATUS) & EG_STAT_ACRF) {
|
1994-08-23 21:59:33 +04:00
|
|
|
egreadPCB(sc);
|
1994-08-24 03:40:55 +04:00
|
|
|
switch (sc->eg_pcb[0]) {
|
1994-08-23 21:59:33 +04:00
|
|
|
case EG_RSP_RECVPACKET:
|
1994-11-05 00:32:23 +03:00
|
|
|
len = sc->eg_pcb[6] | (sc->eg_pcb[7] << 8);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
|
|
|
/* Set direction bit : Adapter -> host */
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(bc, ioh, EG_CONTROL,
|
|
|
|
bus_io_read_1(bc, ioh, EG_CONTROL) | EG_CTL_DIR);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
for (ptr = (u_int16_t *) sc->eg_inbuf;
|
|
|
|
len > 0; len -= 2) {
|
|
|
|
while (!(bus_io_read_1(bc, ioh, EG_STATUS) &
|
|
|
|
EG_STAT_HRDY))
|
1994-08-23 21:59:33 +04:00
|
|
|
;
|
1996-08-03 06:12:46 +04:00
|
|
|
*ptr++ = bus_io_read_2(bc, ioh, EG_DATA);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1995-07-24 00:54:23 +04:00
|
|
|
|
1994-11-05 00:32:23 +03:00
|
|
|
len = sc->eg_pcb[8] | (sc->eg_pcb[9] << 8);
|
1994-08-23 21:59:33 +04:00
|
|
|
egread(sc, sc->eg_inbuf, len);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_incount--;
|
1995-07-24 00:54:23 +04:00
|
|
|
egrecv(sc);
|
1996-08-03 06:12:46 +04:00
|
|
|
serviced = 1;
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EG_RSP_SENDPACKET:
|
|
|
|
if (sc->eg_pcb[6] || sc->eg_pcb[7]) {
|
1996-08-03 06:12:46 +04:00
|
|
|
dprintf(("%s: packet dropped\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->sc_arpcom.ac_if.if_oerrors++;
|
1994-08-24 03:40:55 +04:00
|
|
|
} else
|
|
|
|
sc->sc_arpcom.ac_if.if_opackets++;
|
1996-08-03 06:12:46 +04:00
|
|
|
sc->sc_arpcom.ac_if.if_collisions +=
|
|
|
|
sc->eg_pcb[8] & 0xf;
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
|
|
|
|
egstart(&sc->sc_arpcom.ac_if);
|
1996-08-03 06:12:46 +04:00
|
|
|
serviced = 1;
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
/* XXX byte-order and type-size bugs here... */
|
1994-08-23 21:59:33 +04:00
|
|
|
case EG_RSP_GETSTATS:
|
1996-08-03 06:12:46 +04:00
|
|
|
dprintf(("%s: Card Statistics\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
1994-08-26 00:18:25 +04:00
|
|
|
bcopy(&sc->eg_pcb[2], &i, sizeof(i));
|
|
|
|
dprintf(("Receive Packets %d\n", i));
|
|
|
|
bcopy(&sc->eg_pcb[6], &i, sizeof(i));
|
|
|
|
dprintf(("Transmit Packets %d\n", i));
|
1996-08-03 06:12:46 +04:00
|
|
|
dprintf(("CRC errors %d\n",
|
|
|
|
*(short *) &sc->eg_pcb[10]));
|
|
|
|
dprintf(("alignment errors %d\n",
|
|
|
|
*(short *) &sc->eg_pcb[12]));
|
|
|
|
dprintf(("no resources errors %d\n",
|
|
|
|
*(short *) &sc->eg_pcb[14]));
|
|
|
|
dprintf(("overrun errors %d\n",
|
|
|
|
*(short *) &sc->eg_pcb[16]));
|
|
|
|
serviced = 1;
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-08-03 06:12:46 +04:00
|
|
|
printf("%s: egintr: Unknown response %x??\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->eg_pcb[0]);
|
1994-08-26 00:18:25 +04:00
|
|
|
egprintpcb(sc);
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
return serviced;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet up to the higher levels.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1994-08-23 21:59:33 +04:00
|
|
|
egread(sc, buf, len)
|
|
|
|
struct eg_softc *sc;
|
|
|
|
caddr_t buf;
|
|
|
|
int len;
|
|
|
|
{
|
1995-07-24 06:02:45 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
1994-08-23 21:59:33 +04:00
|
|
|
struct mbuf *m;
|
1994-08-24 03:40:55 +04:00
|
|
|
struct ether_header *eh;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
if (len <= sizeof(struct ether_header) ||
|
|
|
|
len > ETHER_MAX_LEN) {
|
1995-07-24 06:02:45 +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++;
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
/* Pull packet off interface. */
|
1995-07-24 06:02:45 +04:00
|
|
|
m = egget(sc, buf, len);
|
1994-08-23 21:59:33 +04:00
|
|
|
if (m == 0) {
|
1995-07-24 06:02:45 +04:00
|
|
|
ifp->if_ierrors++;
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
/* We assume the header fit entirely in one mbuf. */
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
1994-08-24 03:40:55 +04:00
|
|
|
* If so, hand off the raw packet to BPF.
|
1994-08-23 21:59:33 +04:00
|
|
|
*/
|
1994-08-24 03:40:55 +04:00
|
|
|
if (ifp->if_bpf) {
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the interface cannot be in promiscuous mode if
|
|
|
|
* there are no BPF listeners. And if we are in promiscuous
|
|
|
|
* mode, we have to check if this packet is really ours.
|
|
|
|
*/
|
1994-08-24 03:40:55 +04:00
|
|
|
if ((ifp->if_flags & IFF_PROMISC) &&
|
1994-08-23 21:59:33 +04:00
|
|
|
(eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
|
|
|
|
bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr,
|
|
|
|
sizeof(eh->ether_dhost)) != 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
/* We assume the header fit entirely in one mbuf. */
|
1995-07-24 06:02:45 +04:00
|
|
|
m_adj(m, sizeof(struct ether_header));
|
1994-08-24 03:40:55 +04:00
|
|
|
ether_input(ifp, eh, m);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert buf into mbufs
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
struct mbuf *
|
|
|
|
egget(sc, buf, totlen)
|
|
|
|
struct eg_softc *sc;
|
1994-08-24 03:40:55 +04:00
|
|
|
caddr_t buf;
|
|
|
|
int totlen;
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1995-07-24 06:02:45 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
1994-08-24 03:40:55 +04:00
|
|
|
struct mbuf *top, **mp, *m;
|
|
|
|
int len;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
1995-07-24 06:02:45 +04:00
|
|
|
if (m == 0)
|
1994-08-24 03:40:55 +04:00
|
|
|
return 0;
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
len = MHLEN;
|
|
|
|
top = 0;
|
|
|
|
mp = ⊤
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
len = MCLBYTES;
|
|
|
|
}
|
|
|
|
m->m_len = len = min(totlen, len);
|
|
|
|
bcopy((caddr_t)buf, mtod(m, caddr_t), len);
|
|
|
|
buf += len;
|
|
|
|
totlen -= len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return top;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
int
|
|
|
|
egioctl(ifp, cmd, data)
|
1994-08-23 21:59:33 +04:00
|
|
|
register struct ifnet *ifp;
|
1995-07-24 06:02:45 +04:00
|
|
|
u_long cmd;
|
1994-08-23 21:59:33 +04:00
|
|
|
caddr_t data;
|
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
struct eg_softc *sc = ifp->if_softc;
|
1995-07-24 06:02:45 +04:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
1994-08-24 03:40:55 +04:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int s, error = 0;
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
switch (cmd) {
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1995-04-11 09:10:20 +04:00
|
|
|
eginit(sc);
|
|
|
|
arp_ifinit(&sc->sc_arpcom, ifa);
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NS
|
|
|
|
case AF_NS:
|
1994-08-24 03:40:55 +04:00
|
|
|
{
|
|
|
|
register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
if (ns_nullhost(*ina))
|
|
|
|
ina->x_host =
|
1996-08-03 06:12:46 +04:00
|
|
|
*(union ns_host *)(sc->sc_arpcom.ac_enaddr);
|
1994-08-24 03:40:55 +04:00
|
|
|
else
|
|
|
|
bcopy(ina->x_host.c_host,
|
|
|
|
sc->sc_arpcom.ac_enaddr,
|
|
|
|
sizeof(sc->sc_arpcom.ac_enaddr));
|
|
|
|
/* Set new address. */
|
|
|
|
eginit(sc);
|
|
|
|
break;
|
|
|
|
}
|
1994-08-23 21:59:33 +04:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
eginit(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) != 0) {
|
1994-08-24 03:40:55 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
1994-08-23 21:59:33 +04:00
|
|
|
egstop(sc);
|
1994-08-24 03:40:55 +04:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
1994-08-23 21:59:33 +04:00
|
|
|
} else if ((ifp->if_flags & IFF_UP) != 0 &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0) {
|
1994-08-24 03:40:55 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
1994-08-23 21:59:33 +04:00
|
|
|
eginit(sc);
|
|
|
|
} else {
|
1994-08-26 00:18:25 +04:00
|
|
|
sc->eg_pcb[0] = EG_CMD_GETSTATS;
|
|
|
|
sc->eg_pcb[1] = 0;
|
|
|
|
if (egwritePCB(sc) != 0)
|
|
|
|
dprintf(("write error\n"));
|
1994-08-23 21:59:33 +04:00
|
|
|
/*
|
|
|
|
* XXX deal with flags changes:
|
|
|
|
* IFF_MULTICAST, IFF_PROMISC,
|
|
|
|
* IFF_LINK0, IFF_LINK1,
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
break;
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
1995-07-24 06:02:45 +04:00
|
|
|
break;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1994-08-24 03:40:55 +04:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return error;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1994-08-23 21:59:33 +04:00
|
|
|
egreset(sc)
|
|
|
|
struct eg_softc *sc;
|
|
|
|
{
|
1994-08-24 03:40:55 +04:00
|
|
|
int s;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
dprintf(("%s: egreset()\n", sc->sc_dev.dv_xname));
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-08-24 03:40:55 +04:00
|
|
|
egstop(sc);
|
|
|
|
eginit(sc);
|
|
|
|
splx(s);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1996-05-07 05:55:13 +04:00
|
|
|
egwatchdog(ifp)
|
|
|
|
struct ifnet *ifp;
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
struct eg_softc *sc = ifp->if_softc;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
|
|
|
|
sc->sc_arpcom.ac_if.if_oerrors++;
|
|
|
|
|
|
|
|
egreset(sc);
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
1994-08-23 21:59:33 +04:00
|
|
|
egstop(sc)
|
|
|
|
register struct eg_softc *sc;
|
|
|
|
{
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
bus_io_write_1(sc->sc_bc, sc->sc_ioh, EG_CONTROL, 0);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|