1993-07-11 15:18:23 +04:00
|
|
|
/*
|
|
|
|
* Isolan AT 4141-0 Ethernet driver
|
|
|
|
* Isolink 4110
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Copyright (c) 1994 Charles Hannum.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1993-07-11 15:18:23 +04:00
|
|
|
* Copyright (C) 1993, Paul Richards. This software may be used, modified,
|
|
|
|
* copied, distributed, and sold, in both source and binary form provided
|
|
|
|
* that the above copyright and these terms are retained. Under no
|
|
|
|
* circumstances is the author responsible for the proper functioning
|
|
|
|
* of this software, nor does the author assume any responsibility
|
|
|
|
* for damages incurred with its use.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1994-03-08 15:21:10 +03:00
|
|
|
* $Id: if_is.c,v 1.25 1994/03/08 12:21:26 mycroft Exp $
|
1994-02-15 03:46:16 +03:00
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-07-11 15:18:23 +04:00
|
|
|
/* TODO
|
1994-02-15 04:13:17 +03:00
|
|
|
* 1) Advertise for more packets until all transmit buffers are full
|
|
|
|
* 2) Add more of the timers/counters e.g. arpcom.opackets etc.
|
1994-02-15 03:46:16 +03:00
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#include "is.h"
|
1993-10-25 06:30:54 +03:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
1994-02-15 22:53:20 +03:00
|
|
|
#include <sys/device.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#ifdef INET
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/if_ether.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
1993-07-11 15:18:23 +04:00
|
|
|
#if NBPFILTER > 0
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
1993-07-11 15:18:23 +04:00
|
|
|
#endif
|
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <vm/vm.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
#include <machine/cpu.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/pio.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <i386/isa/isa_device.h>
|
|
|
|
#include <i386/isa/icu.h>
|
1994-02-15 03:46:16 +03:00
|
|
|
#include <i386/isa/if_isreg.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
#define ETHER_MIN_LEN 64
|
|
|
|
#define ETHER_MAX_LEN 1518
|
|
|
|
#define ETHER_ADDR_LEN 6
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
char *card_type[] = {"unknown", "BICC Isolan", "NE2100"};
|
|
|
|
char *chip_type[] = {"unknown", "Am7990 LANCE", "Am79960 PCnet-ISA"};
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet software status per interface.
|
|
|
|
*
|
|
|
|
* Each interface is referenced by a network interface structure,
|
1993-07-11 15:18:23 +04:00
|
|
|
* arpcom.ac_if, which the routing code uses to locate the interface.
|
1993-03-21 12:45:37 +03:00
|
|
|
* This structure contains the output queue for the interface, its address, ...
|
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
struct is_softc {
|
1994-02-15 22:53:20 +03:00
|
|
|
struct device sc_dev;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
struct arpcom sc_arpcom; /* Ethernet common part */
|
|
|
|
u_short sc_iobase; /* IO base address of card */
|
|
|
|
u_short sc_rap, sc_rdp;
|
|
|
|
int sc_chip, sc_card;
|
|
|
|
struct init_block *sc_init; /* Lance initialisation block */
|
|
|
|
struct mds *sc_rd, *sc_td;
|
|
|
|
u_char *sc_rbuf, *sc_tbuf;
|
|
|
|
int sc_last_rd, sc_last_td;
|
|
|
|
int sc_no_td;
|
|
|
|
#ifdef ISDEBUG
|
|
|
|
int sc_debug;
|
|
|
|
#endif
|
|
|
|
caddr_t sc_bpf; /* BPF "magic cookie" */
|
|
|
|
} is_softc[NIS];
|
|
|
|
|
|
|
|
int is_probe __P((struct isa_device *));
|
|
|
|
int ne2100_probe __P((struct isa_device *, struct is_softc *));
|
|
|
|
int bicc_probe __P((struct isa_device *, struct is_softc *));
|
|
|
|
int lance_probe __P((struct is_softc *));
|
|
|
|
int is_attach __P((struct isa_device *));
|
|
|
|
int isintr __P((int)); /* XXX can't be renamed till new interrupt code */
|
|
|
|
int is_ioctl __P((struct ifnet *, int, caddr_t));
|
|
|
|
int is_start __P((struct ifnet *));
|
|
|
|
int is_watchdog __P((/* short */));
|
|
|
|
void iswrcsr __P((/* struct is_softc *, u_short, u_short */));
|
|
|
|
u_short isrdcsr __P((/* struct is_softc *, u_short */));
|
|
|
|
void is_init __P((struct is_softc *));
|
|
|
|
void init_mem __P((struct is_softc *));
|
|
|
|
void is_reset __P((struct is_softc *));
|
|
|
|
void is_stop __P((struct is_softc *));
|
|
|
|
void is_tint __P((struct is_softc *));
|
|
|
|
void is_rint __P((struct is_softc *));
|
|
|
|
void is_read __P((/* struct is_softc *, u_char *, u_short */));
|
|
|
|
struct mbuf *is_get __P((u_char *, int, int, struct ifnet *));
|
|
|
|
#ifdef ISDEBUG
|
|
|
|
void recv_print __P((struct is_softc *, int));
|
|
|
|
void xmit_print __P((struct is_softc *, int));
|
|
|
|
#endif
|
|
|
|
void is_setladrf __P((struct arpcom *, u_long *));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
struct isa_driver isdriver = {
|
1993-07-11 15:18:23 +04:00
|
|
|
is_probe,
|
|
|
|
is_attach,
|
|
|
|
"is"
|
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
struct trailer_header {
|
|
|
|
u_short ether_type;
|
|
|
|
u_short ether_residual;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
iswrcsr(sc, port, val)
|
|
|
|
struct is_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
u_short port;
|
|
|
|
u_short val;
|
|
|
|
{
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
outw(sc->sc_rap, port);
|
|
|
|
outw(sc->sc_rdp, val);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
u_short
|
|
|
|
isrdcsr(sc, port)
|
|
|
|
struct is_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
u_short port;
|
|
|
|
{
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
outw(sc->sc_rap, port);
|
|
|
|
return inw(sc->sc_rdp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
int
|
1993-07-11 15:18:23 +04:00
|
|
|
is_probe(isa_dev)
|
|
|
|
struct isa_device *isa_dev;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
int unit = isa_dev->id_unit;
|
|
|
|
register struct is_softc *sc = &is_softc[unit];
|
|
|
|
int nports;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 22:53:20 +03:00
|
|
|
/* XXX HACK */
|
|
|
|
sprintf(sc->sc_dev.dv_xname, "%s%d", isdriver.name, isa_dev->id_unit);
|
|
|
|
sc->sc_dev.dv_unit = isa_dev->id_unit;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
if (nports = bicc_probe(isa_dev, sc))
|
|
|
|
goto found;
|
|
|
|
if (nports = ne2100_probe(isa_dev, sc))
|
|
|
|
goto found;
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
found:
|
|
|
|
/*
|
|
|
|
* XXX - hopefully have better way to get dma'able memory later,
|
|
|
|
* this code assumes that the physical memory address returned
|
|
|
|
* from malloc will be below 16Mb. The Lance's address registers
|
|
|
|
* are only 16 bits wide!
|
|
|
|
*/
|
|
|
|
#define MAXMEM ((NRBUF+NTBUF)*(BUFSIZE) + (NRBUF+NTBUF)*sizeof(struct mds) \
|
|
|
|
+ sizeof(struct init_block) + 8)
|
|
|
|
sc->sc_init = (struct init_block *)malloc(MAXMEM, M_TEMP, M_NOWAIT);
|
|
|
|
if (!sc->sc_init) {
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: couldn't allocate memory for card\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/*
|
|
|
|
* Make sure it's quadword aligned? This is kind of bogus, but
|
|
|
|
* what the Hell...
|
|
|
|
*/
|
|
|
|
sc->sc_init += 8 - ((u_long)sc->sc_init & 7);
|
|
|
|
|
|
|
|
return nports;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ne2100_probe(isa_dev, sc)
|
|
|
|
struct isa_device *isa_dev;
|
|
|
|
struct is_softc *sc;
|
|
|
|
{
|
|
|
|
u_short iobase = isa_dev->id_iobase;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc->sc_iobase = iobase;
|
|
|
|
sc->sc_rap = iobase + NE2100_RAP;
|
|
|
|
sc->sc_rdp = iobase + NE2100_RDP;
|
|
|
|
sc->sc_card = NE2100;
|
|
|
|
|
|
|
|
if (!(sc->sc_chip = lance_probe(sc)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the physical MAC address from the ROM.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
sc->sc_arpcom.ac_enaddr[i] = inb(iobase + i);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
return 24;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
int
|
|
|
|
bicc_probe(isa_dev, sc)
|
|
|
|
struct isa_device *isa_dev;
|
|
|
|
struct is_softc *sc;
|
|
|
|
{
|
|
|
|
u_short iobase = isa_dev->id_iobase;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc->sc_iobase = iobase;
|
|
|
|
sc->sc_rap = iobase + BICC_RAP;
|
|
|
|
sc->sc_rdp = iobase + BICC_RDP;
|
|
|
|
sc->sc_card = BICC;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
if (!(sc->sc_chip = lance_probe(sc)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the physical MAC address from the ROM.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
sc->sc_arpcom.ac_enaddr[i] = inb(iobase + (i * 2));
|
|
|
|
|
|
|
|
return 16;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Determine which chip is present on the card.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1993-10-25 06:30:54 +03:00
|
|
|
int
|
1994-02-15 03:46:16 +03:00
|
|
|
lance_probe(sc)
|
|
|
|
struct is_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
int type;
|
1993-10-25 06:30:54 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Stop the LANCE chip and put it in a known state. */
|
|
|
|
iswrcsr(sc, 0, STOP);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(100);
|
1994-02-15 03:46:16 +03:00
|
|
|
|
|
|
|
if (isrdcsr(sc, 0) != STOP)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Which bits are settable will depend on the type of chip.
|
|
|
|
*/
|
|
|
|
iswrcsr(sc, 3, PROBE_MASK);
|
|
|
|
|
|
|
|
switch (isrdcsr(sc, 3)) {
|
|
|
|
case LANCE_MASK:
|
|
|
|
type = LANCE;
|
|
|
|
break;
|
|
|
|
case PCnet_ISA_MASK:
|
|
|
|
type = PCnet_ISA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iswrcsr(sc, 3, 0);
|
|
|
|
return type;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Interface exists: make available by filling in network interface
|
|
|
|
* record. System will initialize the interface when it is ready
|
|
|
|
* to accept packets. We get the ethernet address here.
|
|
|
|
*/
|
1993-10-25 06:30:54 +03:00
|
|
|
int
|
|
|
|
is_attach(isa_dev)
|
1993-07-11 15:18:23 +04:00
|
|
|
struct isa_device *isa_dev;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
struct is_softc *sc = &is_softc[isa_dev->id_unit];
|
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
1993-10-25 06:30:54 +03:00
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct sockaddr_dl *sdl;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 22:53:20 +03:00
|
|
|
ifp->if_unit = sc->sc_dev.dv_unit;
|
1994-02-15 03:46:16 +03:00
|
|
|
ifp->if_name = isdriver.name;
|
1993-03-21 12:45:37 +03:00
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_output = ether_output;
|
1993-07-11 15:18:23 +04:00
|
|
|
ifp->if_start = is_start;
|
|
|
|
ifp->if_ioctl = is_ioctl;
|
|
|
|
ifp->if_watchdog = is_watchdog;
|
1994-02-15 03:46:16 +03:00
|
|
|
ifp->if_flags =
|
|
|
|
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
|
1993-07-11 15:18:23 +04:00
|
|
|
|
|
|
|
isa_dmacascade(isa_dev->id_drq);
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Attach the interface. */
|
1993-03-21 12:45:37 +03:00
|
|
|
if_attach(ifp);
|
1993-04-08 12:26:46 +04:00
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Search down the ifa address list looking for the AF_LINK type entry.
|
1993-10-25 06:30:54 +03:00
|
|
|
*/
|
|
|
|
ifa = ifp->if_addrlist;
|
1994-02-15 03:46:16 +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;
|
1993-10-25 06:30:54 +03:00
|
|
|
}
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: address %s, type %s %s\n", sc->sc_dev.dv_xname,
|
|
|
|
ether_sprintf(sc->sc_arpcom.ac_enaddr),
|
|
|
|
card_type[sc->sc_card], chip_type[sc->sc_chip]);
|
1993-07-28 06:20:34 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
1994-02-15 03:46:16 +03:00
|
|
|
bpfattach(&sc->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
|
1993-07-28 06:20:34 +04:00
|
|
|
#endif
|
1993-07-11 15:18:23 +04:00
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
is_reset(sc)
|
|
|
|
struct is_softc *sc;
|
|
|
|
{
|
|
|
|
|
1994-02-15 22:53:20 +03:00
|
|
|
log(LOG_NOTICE, "%s: reset\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
is_init(sc);
|
|
|
|
}
|
|
|
|
|
1993-07-11 15:18:23 +04:00
|
|
|
int
|
|
|
|
is_watchdog(unit)
|
1994-02-15 03:46:16 +03:00
|
|
|
short unit;
|
1993-07-11 15:18:23 +04:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
struct is_softc *sc = &is_softc[unit];
|
|
|
|
|
1994-02-15 22:53:20 +03:00
|
|
|
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
++sc->sc_arpcom.ac_if.if_oerrors;
|
|
|
|
is_reset(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Lance initialisation block set up. */
|
|
|
|
void
|
|
|
|
init_mem(sc)
|
|
|
|
struct is_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
1993-03-21 12:45:37 +03:00
|
|
|
int i;
|
1993-10-25 06:30:54 +03:00
|
|
|
void *temp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* At this point we assume that the memory allocated to the Lance is
|
|
|
|
* quadword aligned. If it isn't then the initialisation is going
|
1993-10-25 06:30:54 +03:00
|
|
|
* fail later on.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Set up lance initialisation block.
|
1993-10-25 06:30:54 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
temp = (void *)sc->sc_init;
|
1993-10-25 06:30:54 +03:00
|
|
|
temp += sizeof(struct init_block);
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_rd = temp;
|
|
|
|
temp += NRBUF * sizeof(struct mds);
|
|
|
|
sc->sc_td = temp;
|
|
|
|
temp += NTBUF * sizeof(struct mds);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
sc->sc_init->mode = PROM;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
sc->sc_init->mode = 0;
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
sc->sc_init->padr[i] = sc->sc_arpcom.ac_enaddr[i];
|
|
|
|
is_setladrf(&sc->sc_arpcom, sc->sc_init->ladrf);
|
|
|
|
sc->sc_init->rdra = kvtop(sc->sc_rd);
|
|
|
|
sc->sc_init->rlen = ((kvtop(sc->sc_rd) >> 16) & 0xff) | (RLEN << 13);
|
|
|
|
sc->sc_init->tdra = kvtop(sc->sc_td);
|
|
|
|
sc->sc_init->tlen = ((kvtop(sc->sc_td) >> 16) & 0xff) | (TLEN << 13);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Set up receive ring descriptors.
|
1993-10-25 06:30:54 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_rbuf = temp;
|
|
|
|
for (i = 0; i < NRBUF; i++) {
|
|
|
|
sc->sc_rd[i].addr = kvtop(temp);
|
|
|
|
sc->sc_rd[i].flags = ((kvtop(temp) >> 16) & 0xff) | OWN;
|
|
|
|
sc->sc_rd[i].bcnt = -BUFSIZE;
|
|
|
|
sc->sc_rd[i].mcnt = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
temp += BUFSIZE;
|
|
|
|
}
|
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Set up transmit ring descriptors.
|
1993-10-25 06:30:54 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_tbuf = temp;
|
|
|
|
for (i = 0; i < NTBUF; i++) {
|
|
|
|
sc->sc_td[i].addr = kvtop(temp);
|
|
|
|
sc->sc_td[i].flags= ((kvtop(temp) >> 16) & 0xff);
|
|
|
|
sc->sc_td[i].bcnt = 0;
|
|
|
|
sc->sc_td[i].mcnt = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
temp += BUFSIZE;
|
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
is_stop(sc)
|
|
|
|
struct is_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
iswrcsr(sc, 0, STOP);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface; set up initialization block
|
|
|
|
* and transmit/receive descriptor rings.
|
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
is_init(sc)
|
|
|
|
struct is_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
1993-03-21 12:45:37 +03:00
|
|
|
int s;
|
|
|
|
register i;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Address not known. */
|
|
|
|
if (!ifp->if_addrlist)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-08 15:21:10 +03:00
|
|
|
s = splimp();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Lance must be stopped to access registers.
|
1993-10-25 06:30:54 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
is_stop(sc);
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_last_rd = sc->sc_last_td = sc->sc_no_td = 0;
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Set up lance's memory area. */
|
|
|
|
init_mem(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* No byte swapping etc. */
|
|
|
|
iswrcsr(sc, 3, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Give lance the physical address of its memory area. */
|
|
|
|
iswrcsr(sc, 1, kvtop(sc->sc_init));
|
|
|
|
iswrcsr(sc, 2, (kvtop(sc->sc_init) >> 16) & 0xff);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* OK, let's try and initialise the Lance. */
|
|
|
|
iswrcsr(sc, 0, INIT);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Wait for initialisation to finish. */
|
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
if (isrdcsr(sc, 0) & IDON)
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-02-15 03:46:16 +03:00
|
|
|
|
|
|
|
if (isrdcsr(sc, 0) & IDON) {
|
|
|
|
/* Start the lance. */
|
|
|
|
iswrcsr(sc, 0, STRT | IDON | INEA);
|
1993-07-11 15:18:23 +04:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
1994-01-24 03:17:16 +03:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1993-07-11 15:18:23 +04:00
|
|
|
is_start(ifp);
|
1994-02-15 03:46:16 +03:00
|
|
|
} else
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: card failed to initialise\n", sc->sc_dev.dv_xname);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
(void) splx(s);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup output on interface.
|
1994-02-15 03:46:16 +03:00
|
|
|
* Get another datagram to send off of the interface queue, and map it to the
|
|
|
|
* interface before starting the output.
|
|
|
|
* Called only at splimp or interrupt level.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
int
|
1993-07-11 15:18:23 +04:00
|
|
|
is_start(ifp)
|
1993-03-21 12:45:37 +03:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
register struct is_softc *sc = &is_softc[ifp->if_unit];
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf *m0, *m;
|
1994-02-15 03:46:16 +03:00
|
|
|
u_char *buffer;
|
|
|
|
int len;
|
1993-03-21 12:45:37 +03:00
|
|
|
int i;
|
|
|
|
struct mds *cdm;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
if ((sc->sc_arpcom.ac_if.if_flags ^ IFF_RUNNING) &
|
|
|
|
(IFF_RUNNING | IFF_OACTIVE))
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
outloop:
|
|
|
|
if (++sc->sc_no_td > NTBUF) {
|
|
|
|
sc->sc_no_td = NTBUF;
|
|
|
|
sc->sc_arpcom.ac_if.if_flags |= IFF_OACTIVE;
|
|
|
|
#ifdef ISDEBUG
|
|
|
|
if (sc->sc_debug)
|
|
|
|
printf("no_td = %x, last_td = %x\n", sc->sc_no_td,
|
|
|
|
sc->sc_last_td);
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1994-02-15 03:46:16 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
cdm = &sc->sc_td[sc->sc_last_td];
|
|
|
|
#if 0 /* XXX redundant */
|
|
|
|
if (cdm->flags & OWN)
|
|
|
|
return;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m);
|
|
|
|
if (!m)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/*
|
|
|
|
* Copy the mbuf chain into the transmit buffer.
|
|
|
|
*/
|
|
|
|
buffer = sc->sc_tbuf + (BUFSIZE * sc->sc_last_td);
|
|
|
|
len = 0;
|
|
|
|
for (m0 = m; m; m = m->m_next) {
|
|
|
|
bcopy(mtod(m, caddr_t), buffer, m->m_len);
|
|
|
|
buffer += m->m_len;
|
|
|
|
len += m->m_len;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-07-11 15:18:23 +04:00
|
|
|
#if NBPFILTER > 0
|
1994-02-15 03:46:16 +03:00
|
|
|
if (sc->sc_bpf) {
|
1994-01-24 03:17:16 +03:00
|
|
|
u_short etype;
|
|
|
|
int off, datasize, resid;
|
|
|
|
struct ether_header *eh;
|
1994-02-15 03:46:16 +03:00
|
|
|
struct trailer_header trailer_header;
|
1994-01-24 03:17:16 +03:00
|
|
|
char ether_packet[ETHER_MAX_LEN];
|
|
|
|
char *ep;
|
|
|
|
|
|
|
|
ep = ether_packet;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We handle trailers below:
|
1994-02-15 03:46:16 +03:00
|
|
|
* Copy ether header first, then residual data, then data. Put
|
|
|
|
* all this in a temporary buffer 'ether_packet' and send off
|
|
|
|
* to bpf. Since the system has generated this packet, we
|
|
|
|
* assume that all of the offsets in the packet are correct; if
|
|
|
|
* they're not, the system will almost certainly crash in
|
|
|
|
* m_copydata. We make no assumptions about how the data is
|
|
|
|
* arranged in the mbuf chain (i.e. how much data is in each
|
|
|
|
* mbuf, if mbuf clusters are used, etc.), which is why we use
|
|
|
|
* m_copydata to get the ether header rather than assume that
|
|
|
|
* this is located in the first mbuf.
|
1994-01-24 03:17:16 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Copy ether header. */
|
1994-01-24 03:17:16 +03:00
|
|
|
m_copydata(m0, 0, sizeof(struct ether_header), ep);
|
|
|
|
eh = (struct ether_header *) ep;
|
|
|
|
ep += sizeof(struct ether_header);
|
|
|
|
etype = ntohs(eh->ether_type);
|
|
|
|
if (etype >= ETHERTYPE_TRAIL &&
|
|
|
|
etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
|
1994-02-15 03:46:16 +03:00
|
|
|
datasize = (etype - ETHERTYPE_TRAIL) << 9;
|
1994-01-24 03:17:16 +03:00
|
|
|
off = datasize + sizeof(struct ether_header);
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Copy trailer_header into a data structure. */
|
1994-01-24 03:17:16 +03:00
|
|
|
m_copydata(m0, off, sizeof(struct trailer_header),
|
1994-02-15 03:46:16 +03:00
|
|
|
&trailer_header.ether_type);
|
|
|
|
|
|
|
|
/* Copy residual data. */
|
|
|
|
m_copydata(m0, off + sizeof(struct trailer_header),
|
|
|
|
resid = ntohs(trailer_header.ether_residual) -
|
|
|
|
sizeof(struct trailer_header), ep);
|
1994-01-24 03:17:16 +03:00
|
|
|
ep += resid;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Copy data. */
|
|
|
|
m_copydata(m0, sizeof(struct ether_header), datasize,
|
|
|
|
ep);
|
1994-01-24 03:17:16 +03:00
|
|
|
ep += datasize;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Restore original ether packet type. */
|
1994-01-24 03:17:16 +03:00
|
|
|
eh->ether_type = trailer_header.ether_type;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
bpf_tap(sc->sc_bpf, ether_packet, ep - ether_packet);
|
1994-01-24 03:17:16 +03:00
|
|
|
} else
|
1994-02-15 03:46:16 +03:00
|
|
|
bpf_mtap(sc->sc_bpf, m0);
|
1994-01-24 03:17:16 +03:00
|
|
|
}
|
1993-07-11 15:18:23 +04:00
|
|
|
#endif
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
m_freem(m0);
|
|
|
|
len = max(len, ETHER_MIN_LEN);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/*
|
|
|
|
* Init transmit registers, and set transmit start flag.
|
|
|
|
*/
|
|
|
|
cdm->flags |= OWN | STP | ENP;
|
|
|
|
cdm->bcnt = -len;
|
|
|
|
cdm->mcnt = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
#ifdef ISDEBUG
|
1994-02-15 03:46:16 +03:00
|
|
|
if (sc->sc_debug)
|
|
|
|
xmit_print(sc, sc->sc_last_td);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
iswrcsr(sc, 0, TDMD | INEA);
|
|
|
|
if (++sc->sc_last_td >= NTBUF)
|
|
|
|
sc->sc_last_td = 0;
|
|
|
|
|
|
|
|
/* possible more packets */
|
|
|
|
goto outloop;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controller interrupt.
|
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
isintr(unit)
|
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
register struct is_softc *sc = &is_softc[unit];
|
1993-03-21 12:45:37 +03:00
|
|
|
u_short isr;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
isr = isrdcsr(sc, 0);
|
|
|
|
if ((isr & INTR) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (isr & ERR) {
|
|
|
|
if (isr & BABL){
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: BABL\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_oerrors++;
|
1993-07-21 08:25:07 +04:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
if (isr & CERR) {
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: CERR\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_collisions++;
|
1993-07-21 08:25:07 +04:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
if (isr & MISS) {
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: MISS\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_ierrors++;
|
1993-07-21 08:25:07 +04:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
if (isr & MERR)
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: MERR\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
iswrcsr(sc, 0, BABL | CERR | MISS | MERR | INEA);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
if ((isr & RXON) == 0) {
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: !RXON\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_ierrors++;
|
|
|
|
is_reset(sc);
|
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
if ((isr & TXON) == 0) {
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: !TXON\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_arpcom.ac_if.if_oerrors++;
|
|
|
|
is_reset(sc);
|
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
if (isr & RINT) {
|
|
|
|
/* Reset watchdog timer. */
|
|
|
|
sc->sc_arpcom.ac_if.if_timer = 0;
|
|
|
|
is_rint(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
if (isr & TINT) {
|
|
|
|
/* Reset watchdog timer. */
|
|
|
|
sc->sc_arpcom.ac_if.if_timer = 0;
|
|
|
|
iswrcsr(sc, 0, TINT | INEA);
|
|
|
|
is_tint(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
|
|
|
|
isr = isrdcsr(sc, 0);
|
|
|
|
} while (isr & INTR);
|
|
|
|
|
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
is_tint(sc)
|
|
|
|
struct is_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
register struct ifnet *ifp = &sc->sc_arpcom.ac_if;
|
|
|
|
int i, loopcount=0;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mds *cdm;
|
|
|
|
|
|
|
|
do {
|
1994-02-15 03:46:16 +03:00
|
|
|
if ((i = sc->sc_last_td - sc->sc_no_td) < 0)
|
|
|
|
i += NTBUF;
|
|
|
|
cdm = &sc->sc_td[i];
|
1993-10-25 06:30:54 +03:00
|
|
|
#ifdef ISDEBUG
|
1994-02-15 03:46:16 +03:00
|
|
|
if (sc->sc_debug)
|
|
|
|
printf("trans cdm = %x\n", cdm);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1994-02-15 03:46:16 +03:00
|
|
|
if (cdm->flags & OWN) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (loopcount)
|
|
|
|
break;
|
|
|
|
return;
|
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
loopcount++;
|
|
|
|
sc->sc_arpcom.ac_if.if_opackets++;
|
|
|
|
sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
|
|
|
|
} while (--sc->sc_no_td > 0);
|
|
|
|
|
1993-07-11 15:18:23 +04:00
|
|
|
is_start(ifp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NEXTRDS \
|
1994-02-15 03:46:16 +03:00
|
|
|
if (++rmd == NRBUF) rmd=0, cdm=sc->sc_rd; else ++cdm
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-07-11 15:18:23 +04:00
|
|
|
/* only called from one place, so may as well integrate */
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
is_rint(sc)
|
|
|
|
struct is_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
register int rmd = sc->sc_last_rd;
|
|
|
|
struct mds *cdm = &sc->sc_rd[rmd];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* Out of sync with hardware, should never happen */
|
|
|
|
|
|
|
|
if (cdm->flags & OWN) {
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: error: out of sync\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
iswrcsr(sc, 0, RINT|INEA);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Process all buffers with valid data. */
|
|
|
|
while ((cdm->flags & OWN) == 0) {
|
|
|
|
/* Clear interrupt to avoid race condition. */
|
|
|
|
iswrcsr(sc, 0, RINT | INEA);
|
|
|
|
if (cdm->flags & ERR) {
|
|
|
|
if (cdm->flags & FRAM)
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: FRAM\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
if (cdm->flags & OFLO)
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: OFLO\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
if (cdm->flags & CRC)
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: CRC\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
if (cdm->flags & RBUFF)
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: RBUFF\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
} else if (cdm->flags & (STP | ENP) != (STP | ENP)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
1994-02-15 03:46:16 +03:00
|
|
|
iswrcsr(sc, 0, RINT | INEA);
|
1993-03-21 12:45:37 +03:00
|
|
|
cdm->mcnt = 0;
|
|
|
|
cdm->flags |= OWN;
|
|
|
|
NEXTRDS;
|
1994-02-15 03:46:16 +03:00
|
|
|
} while ((cdm->flags & (OWN | ERR | STP | ENP)) == 0);
|
|
|
|
sc->sc_last_rd = rmd;
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: chained buffer\n", sc->sc_dev.dv_xname);
|
1994-02-15 03:46:16 +03:00
|
|
|
if ((cdm->flags & (OWN | ERR | STP | ENP)) != ENP) {
|
|
|
|
is_reset(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
} else {
|
1993-10-25 06:30:54 +03:00
|
|
|
#ifdef ISDEBUG
|
1994-02-15 03:46:16 +03:00
|
|
|
if (sc->sc_debug)
|
|
|
|
recv_print(sc, sc->sc_last_rd);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1994-02-15 03:46:16 +03:00
|
|
|
is_read(sc, sc->sc_rbuf + (BUFSIZE*rmd),
|
|
|
|
(int)cdm->mcnt);
|
|
|
|
sc->sc_arpcom.ac_if.if_ipackets++;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
cdm->flags |= OWN;
|
|
|
|
cdm->mcnt = 0;
|
|
|
|
NEXTRDS;
|
1993-10-25 06:30:54 +03:00
|
|
|
#ifdef ISDEBUG
|
1994-02-15 03:46:16 +03:00
|
|
|
if (sc->sc_debug)
|
|
|
|
printf("sc->sc_last_rd = %x, cdm = %x\n",
|
|
|
|
sc->sc_last_rd, cdm);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
} /* while */
|
1994-02-15 03:46:16 +03:00
|
|
|
|
|
|
|
sc->sc_last_rd = rmd;
|
1993-07-11 15:18:23 +04:00
|
|
|
} /* is_rint */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet to the higher levels.
|
|
|
|
* We deal with the trailer protocol here.
|
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
is_read(sc, buf, len)
|
|
|
|
struct is_softc *sc;
|
|
|
|
u_char *buf;
|
|
|
|
u_short len;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
struct ether_header *eh;
|
1994-01-24 03:17:16 +03:00
|
|
|
struct mbuf *m;
|
1994-02-15 03:46:16 +03:00
|
|
|
u_short off;
|
|
|
|
int resid;
|
1994-01-24 03:17:16 +03:00
|
|
|
u_short etype;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
eh = (struct ether_header *)buf;
|
1994-02-15 03:46:16 +03:00
|
|
|
etype = ntohs(eh->ether_type);
|
|
|
|
len -= sizeof(struct ether_header) + 4;
|
1993-07-11 15:18:23 +04:00
|
|
|
#define nedataaddr(eh, off, type) ((type)(((caddr_t)((eh)+1)+(off))))
|
1994-01-24 03:17:16 +03:00
|
|
|
if (etype >= ETHERTYPE_TRAIL &&
|
|
|
|
etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
|
1994-02-15 03:46:16 +03:00
|
|
|
off = (etype - ETHERTYPE_TRAIL) << 9;
|
|
|
|
if ((off + sizeof(struct trailer_header)) > len)
|
|
|
|
return;
|
1994-01-24 03:17:16 +03:00
|
|
|
eh->ether_type = *nedataaddr(eh, off, u_short *);
|
|
|
|
resid = ntohs(*(nedataaddr(eh, off+2, u_short *)));
|
1994-02-15 03:46:16 +03:00
|
|
|
if (off + resid > len)
|
|
|
|
return;
|
1994-01-24 03:17:16 +03:00
|
|
|
len = off + resid;
|
1994-02-15 03:46:16 +03:00
|
|
|
} else
|
|
|
|
off = 0;
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
1994-01-24 03:17:16 +03:00
|
|
|
|
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Pull packet off interface. Off is nonzero if packet has trailing
|
|
|
|
* header; is_get 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-01-24 03:17:16 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
m = is_get(buf, len, off, &sc->sc_arpcom.ac_if);
|
|
|
|
if (m == 0)
|
|
|
|
return;
|
|
|
|
|
1993-07-11 15:18:23 +04:00
|
|
|
#if NBPFILTER > 0
|
1994-01-24 03:17:16 +03:00
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
|
|
|
* If so, hand off the raw packet to bpf.
|
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
if (sc->sc_bpf) {
|
|
|
|
bpf_mtap(sc->sc_bpf, m);
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-01-24 03:17:16 +03: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.
|
|
|
|
*
|
|
|
|
* XXX This test does not support multicasts.
|
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
if ((sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC) &&
|
|
|
|
(eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
|
|
|
|
bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr,
|
|
|
|
sizeof(eh->ether_dhost)) != 0) {
|
1994-01-24 03:17:16 +03:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1993-07-11 15:18:23 +04:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
ether_input(&sc->sc_arpcom.ac_if, eh, m);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Supporting routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
struct mbuf *
|
1994-02-15 03:46:16 +03:00
|
|
|
is_get(buf, totlen, off0, ifp)
|
|
|
|
u_char *buf;
|
1994-01-24 03:17:16 +03:00
|
|
|
int totlen, off0;
|
|
|
|
struct ifnet *ifp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-01-24 03:17:16 +03:00
|
|
|
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);
|
|
|
|
if (m == 0)
|
1994-02-15 03:46:16 +03:00
|
|
|
return 0;
|
1994-01-24 03:17:16 +03:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
m->m_len = MHLEN;
|
|
|
|
top = 0;
|
|
|
|
mp = ⊤
|
1994-02-15 03:46:16 +03:00
|
|
|
|
1994-01-24 03:17:16 +03:00
|
|
|
while (totlen > 0) {
|
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
m_freem(top);
|
1994-02-15 03:46:16 +03:00
|
|
|
return 0;
|
1994-01-24 03:17:16 +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-02-15 03:46:16 +03:00
|
|
|
return top;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
int
|
1993-07-11 15:18:23 +04:00
|
|
|
is_ioctl(ifp, cmd, data)
|
1994-02-15 03:46:16 +03:00
|
|
|
struct ifnet *ifp;
|
1993-03-21 12:45:37 +03:00
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
1994-02-15 03:46:16 +03:00
|
|
|
struct is_softc *sc = &is_softc[ifp->if_unit];
|
1994-02-15 22:53:20 +03:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
1993-07-11 15:18:23 +04:00
|
|
|
int s, error = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-08 15:21:10 +03:00
|
|
|
s = splimp();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1994-02-15 03:46:16 +03:00
|
|
|
is_init(sc); /* before arpwhohas */
|
1994-01-24 03:17:16 +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-02-15 03:46:16 +03:00
|
|
|
sc->sc_arpcom.ac_ipaddr = IA_SIN(ifa)->sin_addr;
|
|
|
|
arpwhohas(&sc->sc_arpcom, &IA_SIN(ifa)->sin_addr);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NS
|
1994-02-15 03:46:16 +03:00
|
|
|
/* XXX - This code is probably wrong. */
|
1993-03-21 12:45:37 +03:00
|
|
|
case AF_NS:
|
|
|
|
{
|
1994-02-15 22:53:20 +03:00
|
|
|
register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (ns_nullhost(*ina))
|
1993-10-25 06:30:54 +03:00
|
|
|
ina->x_host =
|
1994-02-15 03:46:16 +03:00
|
|
|
*(union ns_host *)(sc->sc_arpcom.ac_enaddr);
|
1993-03-21 12:45:37 +03:00
|
|
|
else {
|
|
|
|
/*
|
1993-10-25 06:30:54 +03:00
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-02-15 22:53:20 +03:00
|
|
|
bcopy(ina->x_host.c_host,
|
|
|
|
sc->sc_arpcom.ac_enaddr,
|
1994-02-15 03:46:16 +03:00
|
|
|
sizeof(sc->sc_arpcom.ac_enaddr));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
/* Set new address. */
|
|
|
|
is_init(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
1994-02-15 03:46:16 +03:00
|
|
|
is_init(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
1994-01-24 03:17:16 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then stop it
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
1994-02-15 03:46:16 +03:00
|
|
|
(ifp->if_flags & IFF_RUNNING) != 0) {
|
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
|
|
|
is_stop(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
1994-02-15 03:46:16 +03:00
|
|
|
} else if ((ifp->if_flags & IFF_UP) != 0 &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0) {
|
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
is_init(sc);
|
1993-07-11 15:18:23 +04:00
|
|
|
} else {
|
1994-02-15 03:46:16 +03:00
|
|
|
/*
|
|
|
|
* Reset the interface to pick up changes in any other
|
|
|
|
* flags that affect hardware registers.
|
|
|
|
*/
|
|
|
|
/*is_stop(sc);*/
|
|
|
|
is_init(sc);
|
1993-10-25 06:30:54 +03:00
|
|
|
}
|
|
|
|
#ifdef ISDEBUG
|
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_debug = 1;
|
1993-10-25 06:30:54 +03:00
|
|
|
else
|
1994-02-15 03:46:16 +03:00
|
|
|
sc->sc_debug = 0;
|
1993-10-25 06:30:54 +03:00
|
|
|
#endif
|
1994-02-15 20:44:53 +03:00
|
|
|
break;
|
1994-02-15 03:46:16 +03:00
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = (cmd == SIOCADDMULTI) ?
|
1994-02-15 22:53:20 +03:00
|
|
|
ether_addmulti(ifr, &sc->sc_arpcom):
|
|
|
|
ether_delmulti(ifr, &sc->sc_arpcom);
|
1994-02-15 03:46:16 +03:00
|
|
|
|
|
|
|
if (error == ENETRESET) {
|
1994-01-24 03:17:16 +03:00
|
|
|
/*
|
1994-02-15 03:46:16 +03:00
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
1994-01-24 03:17:16 +03:00
|
|
|
*/
|
1994-02-15 03:46:16 +03:00
|
|
|
is_init(sc);
|
|
|
|
error = 0;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
case SIOCGHWADDR:
|
1994-02-15 22:53:20 +03:00
|
|
|
bcopy(sc->sc_arpcom.ac_enaddr, &ifr->ifr_data,
|
|
|
|
sizeof(sc->sc_arpcom.ac_enaddr));
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
1993-07-11 15:18:23 +04:00
|
|
|
(void) splx(s);
|
1994-02-15 03:46:16 +03:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1993-10-25 06:30:54 +03:00
|
|
|
#ifdef ISDEBUG
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
recv_print(sc, no)
|
|
|
|
struct is_softc *sc;
|
|
|
|
int no;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct mds *rmd;
|
1994-02-15 03:46:16 +03:00
|
|
|
int i, printed = 0;
|
|
|
|
u_short len;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
rmd = &sc->sc_rd[no];
|
1993-03-21 12:45:37 +03:00
|
|
|
len = rmd->mcnt;
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
|
|
|
|
len);
|
|
|
|
printf("%s: status %x\n", sc->sc_dev.dv_xname, isrdcsr(sc, 0));
|
1994-02-15 03:46:16 +03:00
|
|
|
for (i = 0; i < len; i++) {
|
1993-07-28 06:20:34 +04:00
|
|
|
if (!printed) {
|
1994-02-15 03:46:16 +03:00
|
|
|
printed = 1;
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: data: ", sc->sc_dev.dv_xname);
|
1993-07-28 06:20:34 +04:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
printf("%x ", *(sc->sc_rbuf + (BUFSIZE*no) + i));
|
1993-07-28 06:20:34 +04:00
|
|
|
}
|
|
|
|
if (printed)
|
|
|
|
printf("\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
void
|
|
|
|
xmit_print(sc, no)
|
|
|
|
struct is_softc *sc;
|
|
|
|
int no;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct mds *rmd;
|
1993-07-28 06:20:34 +04:00
|
|
|
int i, printed=0;
|
1993-03-21 12:45:37 +03:00
|
|
|
u_short len;
|
|
|
|
|
1994-02-15 03:46:16 +03:00
|
|
|
rmd = &sc->sc_td[no];
|
|
|
|
len = -rmd->bcnt;
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
|
|
|
|
len);
|
|
|
|
printf("%s: status %x\n", sc->sc_dev.dv_xname, isrdcsr(sc, 0));
|
|
|
|
printf("%s: addr %x, flags %x, bcnt %x, mcnt %x\n",
|
|
|
|
sc->sc_dev.dv_xname, rmd->addr, rmd->flags, rmd->bcnt, rmd->mcnt);
|
1994-02-15 03:46:16 +03:00
|
|
|
for (i = 0; i < len; i++) {
|
1993-07-28 06:20:34 +04:00
|
|
|
if (!printed) {
|
|
|
|
printed = 1;
|
1994-02-15 22:53:20 +03:00
|
|
|
printf("%s: data: ", sc->sc_dev.dv_xname);
|
1993-07-28 06:20:34 +04:00
|
|
|
}
|
1994-02-15 03:46:16 +03:00
|
|
|
printf("%x ", *(sc->sc_tbuf + (BUFSIZE*no) + i));
|
1993-07-28 06:20:34 +04:00
|
|
|
}
|
|
|
|
if (printed)
|
|
|
|
printf("\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-10-25 06:30:54 +03:00
|
|
|
#endif /* ISDEBUG */
|
1994-02-15 03:46:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the logical address filter.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
is_setladrf(ac, af)
|
|
|
|
struct arpcom *ac;
|
|
|
|
u_long *af;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &ac->ac_if;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
register u_char *cp, c;
|
|
|
|
register u_long crc;
|
|
|
|
register int i, len;
|
|
|
|
struct ether_multistep step;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up multicast address filter by passing all multicast addresses
|
|
|
|
* through a crc generator, and then using the high order 6 bits as an
|
|
|
|
* index into the 64 bit logical address filter. The high order bit
|
|
|
|
* selects the word, while the rest of the bits select the bit within
|
|
|
|
* the word.
|
|
|
|
*/
|
|
|
|
|
1994-02-16 23:22:04 +03:00
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
1994-02-16 23:15:18 +03:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
1994-02-15 03:46:16 +03:00
|
|
|
af[0] = af[1] = 0xffffffff;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
af[0] = af[1] = 0;
|
|
|
|
ETHER_FIRST_MULTI(step, ac, enm);
|
|
|
|
while (enm != NULL) {
|
|
|
|
if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
|
|
|
|
sizeof(enm->enm_addrlo)) != 0) {
|
|
|
|
/*
|
|
|
|
* We must listen to a range of multicast addresses.
|
|
|
|
* For now, just accept all multicasts, rather than
|
|
|
|
* trying to set only those filter bits needed to match
|
|
|
|
* the range. (At this time, the only use of address
|
|
|
|
* ranges is for IP multicast routing, for which the
|
|
|
|
* range is big enough to require all bits set.)
|
|
|
|
*/
|
1994-02-16 23:15:18 +03:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
1994-02-15 03:46:16 +03:00
|
|
|
af[0] = af[1] = 0xffffffff;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = enm->enm_addrlo;
|
|
|
|
crc = 0xffffffff;
|
|
|
|
for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
|
|
|
|
c = *cp++;
|
|
|
|
for (i = 8; --i >= 0;) {
|
|
|
|
if (((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01)) {
|
|
|
|
crc <<= 1;
|
|
|
|
crc ^= 0x04c11db6 | 1;
|
|
|
|
} else
|
|
|
|
crc <<= 1;
|
|
|
|
c >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Just want the 6 most significant bits. */
|
|
|
|
crc >>= 26;
|
|
|
|
|
|
|
|
/* Turn on the corresponding bit in the filter. */
|
|
|
|
af[crc >> 5] |= 1 << ((crc & 0x1f) ^ 24);
|
|
|
|
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
1994-02-16 23:15:18 +03:00
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
1994-02-15 03:46:16 +03:00
|
|
|
}
|
|
|
|
|