1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1990 The Regents of the University of California.
|
|
|
|
* 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 the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*
|
1993-05-22 11:56:12 +04:00
|
|
|
* from: @(#)if_le.c 7.6 (Berkeley) 5/8/91
|
1994-05-13 12:36:17 +04:00
|
|
|
* $Id: if_le.c,v 1.12 1994/05/13 08:36:17 mycroft Exp $
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "le.h"
|
|
|
|
#if NLE > 0
|
|
|
|
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AMD 7990 LANCE
|
|
|
|
*/
|
1994-02-05 08:06:54 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
#ifdef INET
|
1994-02-05 08:06:54 +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-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
1994-02-05 08:06:54 +03:00
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <hp300/hp300/isr.h>
|
|
|
|
#include <machine/mtpr.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
#include <hp300/dev/device.h>
|
|
|
|
#include <hp300/dev/if_lereg.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
/* offsets for: ID, REGS, MEM, NVRAM */
|
|
|
|
int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
|
|
|
|
|
|
|
|
struct isr le_isr[NLE];
|
|
|
|
int ledebug = 0; /* console error messages */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet software status per interface.
|
|
|
|
*
|
|
|
|
* Each interface is referenced by a network interface structure,
|
|
|
|
* le_if, which the routing code uses to locate the interface.
|
|
|
|
* This structure contains the output queue for the interface, its address, ...
|
|
|
|
*/
|
|
|
|
struct le_softc {
|
|
|
|
struct arpcom sc_ac; /* common Ethernet structures */
|
|
|
|
#define sc_if sc_ac.ac_if /* network-visible interface */
|
|
|
|
#define sc_addr sc_ac.ac_enaddr /* hardware Ethernet address */
|
|
|
|
struct lereg0 *sc_r0; /* DIO registers */
|
|
|
|
struct lereg1 *sc_r1; /* LANCE registers */
|
|
|
|
struct lereg2 *sc_r2; /* dual-port RAM */
|
|
|
|
int sc_rmd; /* predicted next rmd to process */
|
1994-02-05 09:58:08 +03:00
|
|
|
int sc_tmd; /* next available tmd */
|
|
|
|
int sc_txcnt; /* # of transmit buffers in use */
|
|
|
|
/* stats */
|
1993-05-13 17:56:20 +04:00
|
|
|
int sc_runt;
|
|
|
|
int sc_jab;
|
|
|
|
int sc_merr;
|
|
|
|
int sc_babl;
|
|
|
|
int sc_cerr;
|
|
|
|
int sc_miss;
|
1994-02-05 09:58:08 +03:00
|
|
|
int sc_rown;
|
1993-05-13 17:56:20 +04:00
|
|
|
int sc_xint;
|
|
|
|
int sc_xown;
|
1994-02-05 09:58:08 +03:00
|
|
|
int sc_xown2;
|
1993-05-13 17:56:20 +04:00
|
|
|
int sc_uflo;
|
|
|
|
int sc_rxlen;
|
|
|
|
int sc_rxoff;
|
|
|
|
int sc_txoff;
|
|
|
|
int sc_busy;
|
|
|
|
short sc_iflags;
|
|
|
|
} le_softc[NLE];
|
|
|
|
|
|
|
|
/* access LANCE registers */
|
|
|
|
#define LERDWR(cntl, src, dst) \
|
|
|
|
do { \
|
|
|
|
(dst) = (src); \
|
|
|
|
} while (((cntl)->ler0_status & LE_ACK) == 0);
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
int leattach __P((struct hp_device *));
|
1994-02-17 00:07:22 +03:00
|
|
|
void lesetladrf __P((struct arpcom *, u_long *));
|
1994-02-06 03:46:02 +03:00
|
|
|
void ledrinit __P((struct lereg2 *));
|
|
|
|
void lereset __P((struct le_softc *));
|
|
|
|
void leinit __P((int));
|
|
|
|
int lestart __P((struct ifnet *));
|
|
|
|
int leintr __P((int));
|
|
|
|
void lexint __P((struct le_softc *));
|
|
|
|
void lerint __P((struct le_softc *));
|
|
|
|
void leread __P((struct le_softc *, char *, int));
|
|
|
|
int leput __P((char *, struct mbuf *));
|
|
|
|
struct mbuf *leget __P((char *, int, int, struct ifnet *));
|
|
|
|
int leioctl __P((struct ifnet *, int, caddr_t));
|
|
|
|
void leerror __P((struct le_softc *, int));
|
|
|
|
void lererror __P((struct le_softc *, char *));
|
|
|
|
void lexerror __P((struct le_softc *));
|
|
|
|
int ether_output();
|
|
|
|
|
|
|
|
struct driver ledriver = {
|
|
|
|
leattach, "le",
|
|
|
|
};
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* Interface exists: make available by filling in network interface
|
|
|
|
* record. System will initialize the interface when it is ready
|
|
|
|
* to accept packets.
|
|
|
|
*/
|
1994-02-06 03:46:02 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
leattach(hd)
|
|
|
|
struct hp_device *hd;
|
|
|
|
{
|
|
|
|
register struct lereg0 *ler0;
|
|
|
|
register struct lereg2 *ler2;
|
|
|
|
struct lereg2 *lemem = 0;
|
1994-02-05 08:06:54 +03:00
|
|
|
struct le_softc *sc = &le_softc[hd->hp_unit];
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
1993-05-13 17:56:20 +04:00
|
|
|
char *cp;
|
|
|
|
int i;
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
ler0 = sc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
|
|
|
|
sc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)hd->hp_addr);
|
|
|
|
ler2 = sc->sc_r2 = (struct lereg2 *)(lestd[2] + (int)hd->hp_addr);
|
1993-05-13 17:56:20 +04:00
|
|
|
if (ler0->ler0_id != LEID)
|
|
|
|
return(0);
|
|
|
|
le_isr[hd->hp_unit].isr_intr = leintr;
|
|
|
|
hd->hp_ipl = le_isr[hd->hp_unit].isr_ipl = LE_IPL(ler0->ler0_status);
|
|
|
|
le_isr[hd->hp_unit].isr_arg = hd->hp_unit;
|
|
|
|
ler0->ler0_id = 0xFF;
|
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the ethernet address off the board, one nibble at a time.
|
|
|
|
*/
|
|
|
|
cp = (char *)(lestd[3] + (int)hd->hp_addr);
|
1994-02-05 08:06:54 +03:00
|
|
|
for (i = 0; i < sizeof(sc->sc_addr); i++) {
|
|
|
|
sc->sc_addr[i] = (*++cp & 0xF) << 4;
|
1993-05-13 17:56:20 +04:00
|
|
|
cp++;
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_addr[i] |= *++cp & 0xF;
|
1993-05-13 17:56:20 +04:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
printf("le%d: hardware address %s\n", hd->hp_unit,
|
1994-02-05 08:06:54 +03:00
|
|
|
ether_sprintf(sc->sc_addr));
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup for transmit/receive
|
|
|
|
*/
|
|
|
|
ler2->ler2_mode = LE_MODE;
|
|
|
|
ler2->ler2_rlen = LE_RLEN;
|
|
|
|
ler2->ler2_rdra = (int)lemem->ler2_rmd;
|
|
|
|
ler2->ler2_tlen = LE_TLEN;
|
|
|
|
ler2->ler2_tdra = (int)lemem->ler2_tmd;
|
|
|
|
isrlink(&le_isr[hd->hp_unit]);
|
|
|
|
ler0->ler0_status = LE_IE;
|
|
|
|
|
|
|
|
ifp->if_unit = hd->hp_unit;
|
|
|
|
ifp->if_name = "le";
|
|
|
|
ifp->if_ioctl = leioctl;
|
|
|
|
ifp->if_output = ether_output;
|
|
|
|
ifp->if_start = lestart;
|
1994-02-16 23:15:18 +03:00
|
|
|
ifp->if_flags =
|
|
|
|
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
|
1994-05-13 12:36:17 +04:00
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp);
|
1993-05-13 17:56:20 +04:00
|
|
|
#if NBPFILTER > 0
|
1994-05-13 12:36:17 +04:00
|
|
|
bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
/*
|
|
|
|
* Set up the logical address filter
|
|
|
|
*/
|
|
|
|
void
|
1994-02-16 23:15:18 +03:00
|
|
|
lesetladrf(ac, af)
|
|
|
|
struct arpcom *ac;
|
|
|
|
u_long *af;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1994-02-16 23:15:18 +03:00
|
|
|
struct ifnet *ifp = &ac->ac_if;
|
1994-02-05 08:06:54 +03:00
|
|
|
struct ether_multi *enm;
|
|
|
|
register u_char *cp, c;
|
|
|
|
register u_long crc;
|
|
|
|
register int i, len;
|
|
|
|
struct ether_multistep step;
|
|
|
|
|
|
|
|
/*
|
1994-02-15 02:03:54 +03:00
|
|
|
* 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-05 08:06:54 +03:00
|
|
|
*/
|
|
|
|
|
1994-02-16 23:15:18 +03:00
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
1994-02-15 02:03:54 +03:00
|
|
|
af[0] = af[1] = 0xffffffff;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
af[0] = af[1] = 0;
|
1994-02-16 23:15:18 +03:00
|
|
|
ETHER_FIRST_MULTI(step, ac, enm);
|
1994-02-05 08:06:54 +03:00
|
|
|
while (enm != NULL) {
|
1994-02-15 02:03:54 +03:00
|
|
|
if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
|
|
|
|
sizeof(enm->enm_addrlo)) != 0) {
|
1994-02-05 08:06:54 +03:00
|
|
|
/*
|
1994-02-15 02:03:54 +03:00
|
|
|
* 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-05 08:06:54 +03:00
|
|
|
*/
|
1994-02-16 23:15:18 +03:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
1994-02-15 02:03:54 +03:00
|
|
|
af[0] = af[1] = 0xffffffff;
|
1994-02-05 08:06:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-02-15 02:03:54 +03:00
|
|
|
cp = enm->enm_addrlo;
|
1994-02-05 08:06:54 +03:00
|
|
|
crc = 0xffffffff;
|
1994-02-15 02:03:54 +03:00
|
|
|
for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
|
1994-02-05 08:06:54 +03:00
|
|
|
c = *cp++;
|
|
|
|
for (i = 8; --i >= 0;) {
|
|
|
|
if ((c & 0x01) ^ (crc & 0x01)) {
|
|
|
|
crc >>= 1;
|
1994-02-15 02:03:54 +03:00
|
|
|
crc ^= 0x6db88320 | 0x80000000;
|
1994-02-05 08:06:54 +03:00
|
|
|
} else
|
|
|
|
crc >>= 1;
|
|
|
|
c >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Just want the 6 most significant bits. */
|
1994-02-15 02:03:54 +03:00
|
|
|
crc >>= 26;
|
1994-02-05 08:06:54 +03:00
|
|
|
|
|
|
|
/* Turn on the corresponding bit in the filter. */
|
1994-02-15 02:03:54 +03:00
|
|
|
af[crc >> 5] |= 1 << (crc & 0x1f);
|
1994-02-05 08:06:54 +03:00
|
|
|
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
1994-02-16 23:15:18 +03:00
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
1994-02-05 08:06:54 +03:00
|
|
|
}
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 09:58:08 +03:00
|
|
|
ledrinit(ler2)
|
|
|
|
register struct lereg2 *ler2;
|
|
|
|
{
|
|
|
|
register struct lereg2 *lemem = 0;
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
for (i = 0; i < LERBUF; i++) {
|
|
|
|
ler2->ler2_rmd[i].rmd0 = (int)lemem->ler2_rbuf[i];
|
|
|
|
ler2->ler2_rmd[i].rmd1 = LE_OWN;
|
|
|
|
ler2->ler2_rmd[i].rmd2 = -LEMTU;
|
|
|
|
ler2->ler2_rmd[i].rmd3 = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < LETBUF; i++) {
|
|
|
|
ler2->ler2_tmd[i].tmd0 = (int)lemem->ler2_tbuf[i];
|
|
|
|
ler2->ler2_tmd[i].tmd1 = 0;
|
|
|
|
ler2->ler2_tmd[i].tmd2 = 0;
|
|
|
|
ler2->ler2_tmd[i].tmd3 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 08:06:54 +03:00
|
|
|
lereset(sc)
|
|
|
|
register struct le_softc *sc;
|
|
|
|
{
|
|
|
|
register struct lereg0 *ler0 = sc->sc_r0;
|
|
|
|
register struct lereg1 *ler1 = sc->sc_r1;
|
|
|
|
register struct lereg2 *ler2 = sc->sc_r2;
|
|
|
|
struct lereg2 *lemem = 0;
|
|
|
|
register int timo, stat;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
1994-02-05 08:06:54 +03:00
|
|
|
if (sc->sc_if.if_flags & IFF_PROMISC)
|
1993-05-13 17:56:20 +04:00
|
|
|
/* set the promiscuous bit */
|
1994-02-05 08:06:54 +03:00
|
|
|
ler2->ler2_mode = LE_MODE|0x8000;
|
1993-05-13 17:56:20 +04:00
|
|
|
else
|
|
|
|
#endif
|
1994-02-05 08:06:54 +03:00
|
|
|
ler2->ler2_mode = LE_MODE;
|
1993-05-13 17:56:20 +04:00
|
|
|
LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
|
|
|
|
LERDWR(ler0, LE_STOP, ler1->ler1_rdp);
|
1994-02-05 08:06:54 +03:00
|
|
|
|
1994-02-05 09:58:08 +03:00
|
|
|
ler2->ler2_padr[0] = sc->sc_addr[1];
|
|
|
|
ler2->ler2_padr[1] = sc->sc_addr[0];
|
|
|
|
ler2->ler2_padr[2] = sc->sc_addr[3];
|
|
|
|
ler2->ler2_padr[3] = sc->sc_addr[2];
|
|
|
|
ler2->ler2_padr[4] = sc->sc_addr[5];
|
|
|
|
ler2->ler2_padr[5] = sc->sc_addr[4];
|
1994-02-17 00:07:22 +03:00
|
|
|
lesetladrf(&sc->sc_ac, ler2->ler2_ladrf);
|
1994-02-05 08:06:54 +03:00
|
|
|
ledrinit(ler2);
|
1994-02-05 18:04:18 +03:00
|
|
|
sc->sc_rmd = sc->sc_tmd = sc->sc_txcnt = 0;
|
1994-02-05 08:06:54 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
LERDWR(ler0, LE_CSR1, ler1->ler1_rap);
|
|
|
|
LERDWR(ler0, (int)&lemem->ler2_mode, ler1->ler1_rdp);
|
|
|
|
LERDWR(ler0, LE_CSR2, ler1->ler1_rap);
|
|
|
|
LERDWR(ler0, 0, ler1->ler1_rdp);
|
1994-02-05 08:06:54 +03:00
|
|
|
LERDWR(ler0, LE_CSR3, ler1->ler1_rap);
|
|
|
|
LERDWR(ler0, LE_BSWP, ler1->ler1_rdp);
|
1993-05-13 17:56:20 +04:00
|
|
|
LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
|
|
|
|
LERDWR(ler0, LE_INIT, ler1->ler1_rdp);
|
1994-02-05 08:06:54 +03:00
|
|
|
timo = 100000;
|
1993-05-13 17:56:20 +04:00
|
|
|
do {
|
|
|
|
if (--timo == 0) {
|
1994-02-05 08:06:54 +03:00
|
|
|
printf("le%d: init timeout, stat=0x%x\n",
|
|
|
|
sc->sc_if.if_unit, stat);
|
1993-05-13 17:56:20 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
LERDWR(ler0, ler1->ler1_rdp, stat);
|
1994-02-05 08:06:54 +03:00
|
|
|
} while ((stat & (LE_IDON | LE_ERR)) == 0);
|
|
|
|
if (stat & LE_ERR)
|
|
|
|
printf("le%d: init failed, stat=0x%x\n",
|
|
|
|
sc->sc_if.if_unit, stat);
|
|
|
|
else
|
|
|
|
LERDWR(ler0, LE_IDON, ler1->ler1_rdp);
|
|
|
|
sc->sc_if.if_flags &= ~IFF_OACTIVE;
|
1994-02-06 03:46:02 +03:00
|
|
|
LERDWR(ler0, LE_STRT | LE_INEA, ler1->ler1_rdp);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface
|
|
|
|
*/
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1993-05-13 17:56:20 +04:00
|
|
|
leinit(unit)
|
|
|
|
int unit;
|
|
|
|
{
|
1994-02-05 08:06:54 +03:00
|
|
|
struct le_softc *sc = &le_softc[unit];
|
|
|
|
register struct ifnet *ifp = &sc->sc_if;
|
1993-05-13 17:56:20 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
/* not yet, if address still unknown */
|
|
|
|
if (ifp->if_addrlist == (struct ifaddr *)0)
|
|
|
|
return;
|
|
|
|
if ((ifp->if_flags & IFF_RUNNING) == 0) {
|
|
|
|
s = splimp();
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
1994-02-05 08:06:54 +03:00
|
|
|
lereset(sc);
|
|
|
|
(void) lestart(ifp);
|
1993-05-13 17:56:20 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-05 09:58:08 +03:00
|
|
|
#define LENEXTTMP \
|
|
|
|
if (++bix == LETBUF) bix = 0, tmd = sc->sc_r2->ler2_tmd; else ++tmd
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* Start output on interface. Get another datagram to send
|
|
|
|
* off of the interface queue, and copy it to the interface
|
|
|
|
* before starting the output.
|
|
|
|
*/
|
1994-02-06 03:46:02 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
lestart(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
1994-02-05 08:06:54 +03:00
|
|
|
register struct le_softc *sc = &le_softc[ifp->if_unit];
|
1994-02-05 09:58:08 +03:00
|
|
|
register int bix;
|
1993-05-13 17:56:20 +04:00
|
|
|
register struct letmd *tmd;
|
|
|
|
register struct mbuf *m;
|
1994-02-05 09:58:08 +03:00
|
|
|
int len, gotone = 0;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
if ((sc->sc_if.if_flags & IFF_RUNNING) == 0)
|
1993-05-13 17:56:20 +04:00
|
|
|
return (0);
|
1994-02-05 09:58:08 +03:00
|
|
|
bix = sc->sc_tmd;
|
|
|
|
tmd = &sc->sc_r2->ler2_tmd[bix];
|
|
|
|
do {
|
|
|
|
if (tmd->tmd1 & LE_OWN) {
|
|
|
|
if (gotone)
|
|
|
|
break;
|
|
|
|
sc->sc_xown2++;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
IF_DEQUEUE(&sc->sc_if.if_snd, m);
|
|
|
|
if (m == 0) {
|
|
|
|
if (gotone)
|
|
|
|
break;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
len = leput(sc->sc_r2->ler2_tbuf[bix], m);
|
1993-05-13 17:56:20 +04:00
|
|
|
#if NBPFILTER > 0
|
1994-02-05 09:58:08 +03:00
|
|
|
/*
|
|
|
|
* If bpf is listening on this interface, let it
|
|
|
|
* see the packet before we commit it to the wire.
|
|
|
|
*/
|
1994-05-13 12:36:17 +04:00
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_tap(ifp->if_bpf, sc->sc_r2->ler2_tbuf[bix], len);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
1994-02-05 09:58:08 +03:00
|
|
|
tmd->tmd3 = 0;
|
|
|
|
tmd->tmd2 = -len;
|
|
|
|
tmd->tmd1 = LE_OWN | LE_STP | LE_ENP;
|
|
|
|
LENEXTTMP;
|
|
|
|
gotone++;
|
|
|
|
} while (++sc->sc_txcnt < LETBUF);
|
|
|
|
sc->sc_tmd = bix;
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_if.if_flags |= IFF_OACTIVE;
|
1994-02-06 03:46:02 +03:00
|
|
|
/* transmit as soon as possible */
|
|
|
|
LERDWR(sc->sc_r0, LE_INEA|LE_TDMD, sc->sc_r1->ler1_rdp);
|
1993-05-13 17:56:20 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
leintr(unit)
|
|
|
|
register int unit;
|
|
|
|
{
|
1994-02-05 08:06:54 +03:00
|
|
|
register struct le_softc *sc = &le_softc[unit];
|
|
|
|
register struct lereg0 *ler0 = sc->sc_r0;
|
1993-05-13 17:56:20 +04:00
|
|
|
register struct lereg1 *ler1;
|
|
|
|
register int stat;
|
|
|
|
|
|
|
|
if ((ler0->ler0_status & LE_IR) == 0)
|
|
|
|
return(0);
|
|
|
|
if (ler0->ler0_status & LE_JAB) {
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_jab++;
|
|
|
|
lereset(sc);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(1);
|
|
|
|
}
|
1994-02-05 08:06:54 +03:00
|
|
|
ler1 = sc->sc_r1;
|
1993-05-13 17:56:20 +04:00
|
|
|
LERDWR(ler0, ler1->ler1_rdp, stat);
|
|
|
|
if (stat & LE_SERR) {
|
1994-02-05 08:06:54 +03:00
|
|
|
leerror(sc, stat);
|
1993-05-13 17:56:20 +04:00
|
|
|
if (stat & LE_MERR) {
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_merr++;
|
|
|
|
lereset(sc);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
if (stat & LE_BABL)
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_babl++;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (stat & LE_CERR)
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_cerr++;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (stat & LE_MISS)
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_miss++;
|
1993-05-13 17:56:20 +04:00
|
|
|
LERDWR(ler0, LE_BABL|LE_CERR|LE_MISS|LE_INEA, ler1->ler1_rdp);
|
|
|
|
}
|
|
|
|
if ((stat & LE_RXON) == 0) {
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_rxoff++;
|
|
|
|
lereset(sc);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
if ((stat & LE_TXON) == 0) {
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_txoff++;
|
|
|
|
lereset(sc);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(1);
|
|
|
|
}
|
1994-02-05 09:58:08 +03:00
|
|
|
if (stat & LE_RINT)
|
1994-02-05 08:06:54 +03:00
|
|
|
lerint(sc);
|
1994-02-05 09:58:08 +03:00
|
|
|
if (stat & LE_TINT)
|
1994-02-05 08:06:54 +03:00
|
|
|
lexint(sc);
|
1993-05-13 17:56:20 +04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet interface transmitter interrupt.
|
|
|
|
* Start another output if more data to send.
|
|
|
|
*/
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 08:06:54 +03:00
|
|
|
lexint(sc)
|
|
|
|
register struct le_softc *sc;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1994-02-05 09:58:08 +03:00
|
|
|
register struct letmd *tmd;
|
1994-02-06 03:46:02 +03:00
|
|
|
int bix, gotone = 0;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0) {
|
|
|
|
sc->sc_xint++;
|
1993-05-13 17:56:20 +04:00
|
|
|
return;
|
|
|
|
}
|
1994-02-06 03:46:02 +03:00
|
|
|
if ((bix = sc->sc_tmd - sc->sc_txcnt) < 0)
|
|
|
|
bix += LETBUF;
|
|
|
|
tmd = &sc->sc_r2->ler2_tmd[bix];
|
1994-02-05 09:58:08 +03:00
|
|
|
do {
|
|
|
|
if (tmd->tmd1 & LE_OWN) {
|
|
|
|
if (gotone)
|
|
|
|
break;
|
|
|
|
sc->sc_xown++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear interrupt */
|
|
|
|
LERDWR(sc->sc_r0, LE_TINT|LE_INEA, sc->sc_r1->ler1_rdp);
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/* XXX documentation says BUFF not included in ERR */
|
1994-02-05 09:58:08 +03:00
|
|
|
if ((tmd->tmd1 & LE_ERR) || (tmd->tmd3 & LE_TBUFF)) {
|
|
|
|
lexerror(sc);
|
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
if (tmd->tmd3 & (LE_TBUFF|LE_UFLO)) {
|
|
|
|
sc->sc_uflo++;
|
|
|
|
lereset(sc);
|
|
|
|
} else if (tmd->tmd3 & LE_LCOL)
|
|
|
|
sc->sc_if.if_collisions++;
|
|
|
|
else if (tmd->tmd3 & LE_RTRY)
|
|
|
|
sc->sc_if.if_collisions += 16;
|
|
|
|
}
|
|
|
|
else if (tmd->tmd1 & LE_ONE)
|
|
|
|
sc->sc_if.if_collisions++;
|
|
|
|
else if (tmd->tmd1 & LE_MORE)
|
|
|
|
/* what is the real number? */
|
|
|
|
sc->sc_if.if_collisions += 2;
|
|
|
|
else
|
|
|
|
sc->sc_if.if_opackets++;
|
1994-02-06 03:46:02 +03:00
|
|
|
LENEXTTMP;
|
1994-02-05 09:58:08 +03:00
|
|
|
gotone++;
|
|
|
|
} while (--sc->sc_txcnt > 0);
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_if.if_flags &= ~IFF_OACTIVE;
|
|
|
|
(void) lestart(&sc->sc_if);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define LENEXTRMP \
|
1994-02-05 08:06:54 +03:00
|
|
|
if (++bix == LERBUF) bix = 0, rmd = sc->sc_r2->ler2_rmd; else ++rmd
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet interface receiver interrupt.
|
|
|
|
* If input error just drop packet.
|
|
|
|
* Decapsulate packet based on type and pass to type specific
|
|
|
|
* higher-level input routine.
|
|
|
|
*/
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 08:06:54 +03:00
|
|
|
lerint(sc)
|
|
|
|
register struct le_softc *sc;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1994-02-05 08:06:54 +03:00
|
|
|
register int bix = sc->sc_rmd;
|
|
|
|
register struct lermd *rmd = &sc->sc_r2->ler2_rmd[bix];
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Out of sync with hardware, should never happen?
|
|
|
|
*/
|
|
|
|
if (rmd->rmd1 & LE_OWN) {
|
1994-02-05 09:58:08 +03:00
|
|
|
sc->sc_rown++;
|
1994-02-05 08:06:54 +03:00
|
|
|
do {
|
|
|
|
LENEXTRMP;
|
|
|
|
} while ((rmd->rmd1 & LE_OWN) && bix != sc->sc_rmd);
|
|
|
|
if (bix == sc->sc_rmd) {
|
|
|
|
printf("le%d: rint with no buffer\n",
|
|
|
|
sc->sc_if.if_unit);
|
|
|
|
LERDWR(sc->sc_r0, LE_RINT|LE_INEA, sc->sc_r1->ler1_rdp);
|
|
|
|
return;
|
|
|
|
}
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process all buffers with valid data
|
|
|
|
*/
|
|
|
|
while ((rmd->rmd1 & LE_OWN) == 0) {
|
|
|
|
int len = rmd->rmd3;
|
|
|
|
|
|
|
|
/* Clear interrupt to avoid race condition */
|
1994-02-05 08:06:54 +03:00
|
|
|
LERDWR(sc->sc_r0, LE_RINT|LE_INEA, sc->sc_r1->ler1_rdp);
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
if (rmd->rmd1 & LE_ERR) {
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_rmd = bix;
|
|
|
|
lererror(sc, "bad packet");
|
|
|
|
sc->sc_if.if_ierrors++;
|
1993-05-13 17:56:20 +04:00
|
|
|
} else if ((rmd->rmd1 & (LE_STP|LE_ENP)) != (LE_STP|LE_ENP)) {
|
|
|
|
/*
|
|
|
|
* Find the end of the packet so we can see how long
|
|
|
|
* it was. We still throw it away.
|
|
|
|
*/
|
|
|
|
do {
|
1994-02-05 08:06:54 +03:00
|
|
|
LERDWR(sc->sc_r0, LE_RINT|LE_INEA,
|
|
|
|
sc->sc_r1->ler1_rdp);
|
1993-05-13 17:56:20 +04:00
|
|
|
rmd->rmd3 = 0;
|
|
|
|
rmd->rmd1 = LE_OWN;
|
|
|
|
LENEXTRMP;
|
|
|
|
} while (!(rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)));
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_rmd = bix;
|
|
|
|
lererror(sc, "chained buffer");
|
|
|
|
sc->sc_rxlen++;
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* If search terminated without successful completion
|
|
|
|
* we reset the hardware (conservative).
|
|
|
|
*/
|
|
|
|
if ((rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)) !=
|
|
|
|
LE_ENP) {
|
1994-02-05 08:06:54 +03:00
|
|
|
lereset(sc);
|
1993-05-13 17:56:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
1994-02-05 08:06:54 +03:00
|
|
|
leread(sc, sc->sc_r2->ler2_rbuf[bix], len);
|
1993-05-13 17:56:20 +04:00
|
|
|
rmd->rmd3 = 0;
|
|
|
|
rmd->rmd1 = LE_OWN;
|
|
|
|
LENEXTRMP;
|
|
|
|
}
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_rmd = bix;
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 08:06:54 +03:00
|
|
|
leread(sc, buf, len)
|
|
|
|
register struct le_softc *sc;
|
1993-05-13 17:56:20 +04:00
|
|
|
char *buf;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
register struct ether_header *et;
|
1994-02-05 08:06:54 +03:00
|
|
|
register struct ifnet *ifp = &sc->sc_if;
|
1993-05-13 17:56:20 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
ifp->if_ipackets++;
|
1993-05-13 17:56:20 +04:00
|
|
|
et = (struct ether_header *)buf;
|
|
|
|
/* adjust input length to account for header and CRC */
|
1994-02-05 08:06:54 +03:00
|
|
|
len -= sizeof(struct ether_header) + 4;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
if (len <= 0) {
|
|
|
|
if (ledebug)
|
|
|
|
log(LOG_WARNING,
|
|
|
|
"le%d: ierror(runt packet): from %s: len=%d\n",
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_if.if_unit, ether_sprintf(et->ether_shost),
|
|
|
|
len);
|
|
|
|
sc->sc_runt++;
|
|
|
|
ifp->if_ierrors++;
|
1993-05-13 17:56:20 +04:00
|
|
|
return;
|
|
|
|
}
|
1994-02-05 08:06:54 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Check if there's a bpf filter listening on this interface.
|
1994-02-05 08:06:54 +03:00
|
|
|
* If so, hand off the raw packet to bpf, then discard things
|
|
|
|
* not destined for us (but be sure to keep broadcast/multicast).
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
1994-05-13 12:36:17 +04:00
|
|
|
if (ifp->if_bpf) {
|
|
|
|
bpf_tap(ifp->if_bpf, buf, len + sizeof(struct ether_header));
|
1994-02-05 08:06:54 +03:00
|
|
|
if ((ifp->if_flags & IFF_PROMISC) &&
|
|
|
|
(et->ether_dhost[0] & 1) == 0 &&
|
|
|
|
bcmp(et->ether_dhost, sc->sc_addr,
|
1993-05-13 17:56:20 +04:00
|
|
|
sizeof(et->ether_dhost)) != 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
1994-02-05 08:06:54 +03:00
|
|
|
|
|
|
|
m = leget(buf, len, 0, ifp);
|
1993-05-13 17:56:20 +04:00
|
|
|
if (m == 0)
|
|
|
|
return;
|
1994-02-05 08:06:54 +03:00
|
|
|
|
|
|
|
ether_input(ifp, et, m);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine to copy from mbuf chain to transmit
|
|
|
|
* buffer in board local memory.
|
|
|
|
*/
|
1994-02-06 03:46:02 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
leput(lebuf, m)
|
|
|
|
register char *lebuf;
|
|
|
|
register struct mbuf *m;
|
|
|
|
{
|
|
|
|
register struct mbuf *mp;
|
|
|
|
register int len, tlen = 0;
|
|
|
|
|
|
|
|
for (mp = m; mp; mp = mp->m_next) {
|
|
|
|
len = mp->m_len;
|
|
|
|
if (len == 0)
|
|
|
|
continue;
|
|
|
|
tlen += len;
|
|
|
|
bcopy(mtod(mp, char *), lebuf, len);
|
|
|
|
lebuf += len;
|
|
|
|
}
|
|
|
|
m_freem(m);
|
|
|
|
if (tlen < LEMINSIZE) {
|
|
|
|
bzero(lebuf, LEMINSIZE - tlen);
|
|
|
|
tlen = LEMINSIZE;
|
|
|
|
}
|
|
|
|
return(tlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine to copy from board local memory into mbufs.
|
|
|
|
*/
|
|
|
|
struct mbuf *
|
|
|
|
leget(lebuf, totlen, off0, ifp)
|
|
|
|
char *lebuf;
|
|
|
|
int totlen, off0;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
register struct mbuf *m;
|
|
|
|
struct mbuf *top = 0, **mp = ⊤
|
|
|
|
register int off = off0, len;
|
|
|
|
register char *cp;
|
|
|
|
char *epkt;
|
|
|
|
|
|
|
|
lebuf += sizeof (struct ether_header);
|
|
|
|
cp = lebuf;
|
|
|
|
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)
|
|
|
|
return (0);
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
m->m_len = MHLEN;
|
|
|
|
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
m_freem(top);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
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 = lebuf;
|
|
|
|
}
|
|
|
|
return (top);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
1994-02-06 03:46:02 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
leioctl(ifp, cmd, data)
|
|
|
|
register struct ifnet *ifp;
|
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
1994-02-05 08:06:54 +03:00
|
|
|
register struct ifaddr *ifa;
|
|
|
|
struct le_softc *sc = &le_softc[ifp->if_unit];
|
1993-05-13 17:56:20 +04:00
|
|
|
int s = splimp(), error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
1994-02-05 08:06:54 +03:00
|
|
|
ifa = (struct ifaddr *)data;
|
1993-05-13 17:56:20 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
leinit(ifp->if_unit); /* before arpwhohas */
|
|
|
|
((struct arpcom *)ifp)->ac_ipaddr =
|
|
|
|
IA_SIN(ifa)->sin_addr;
|
|
|
|
arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NS
|
|
|
|
case AF_NS:
|
|
|
|
{
|
|
|
|
register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
|
|
|
|
|
|
|
|
if (ns_nullhost(*ina))
|
1994-02-05 08:06:54 +03:00
|
|
|
ina->x_host = *(union ns_host *)(sc->sc_addr);
|
1993-05-13 17:56:20 +04:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* The manual says we can't change the address
|
|
|
|
* while the receiver is armed,
|
|
|
|
* so reset everything
|
|
|
|
*/
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
1994-02-06 03:46:02 +03:00
|
|
|
LERDWR(sc->sc_r0, LE_STOP, sc->sc_r1->ler1_rdp);
|
1993-05-13 17:56:20 +04:00
|
|
|
bcopy((caddr_t)ina->x_host.c_host,
|
1994-02-05 08:06:54 +03:00
|
|
|
(caddr_t)sc->sc_addr, sizeof(sc->sc_addr));
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
leinit(ifp->if_unit); /* does le_setaddr() */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
leinit(ifp->if_unit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
|
|
|
ifp->if_flags & IFF_RUNNING) {
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
1994-02-06 03:46:02 +03:00
|
|
|
LERDWR(sc->sc_r0, LE_STOP, sc->sc_r1->ler1_rdp);
|
1993-05-13 17:56:20 +04:00
|
|
|
} else if (ifp->if_flags & IFF_UP &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0)
|
|
|
|
leinit(ifp->if_unit);
|
|
|
|
/*
|
|
|
|
* If the state of the promiscuous bit changes, the interface
|
|
|
|
* must be reset to effect the change.
|
|
|
|
*/
|
1994-02-05 08:06:54 +03:00
|
|
|
if (((ifp->if_flags ^ sc->sc_iflags) & IFF_PROMISC) &&
|
1993-05-13 17:56:20 +04:00
|
|
|
(ifp->if_flags & IFF_RUNNING)) {
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_iflags = ifp->if_flags;
|
|
|
|
lereset(sc);
|
1993-05-13 17:56:20 +04:00
|
|
|
lestart(ifp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
error = ether_addmulti((struct ifreq *)data, &sc->sc_ac);
|
|
|
|
goto update_multicast;
|
|
|
|
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = ether_delmulti((struct ifreq *)data, &sc->sc_ac);
|
|
|
|
update_multicast:
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware
|
|
|
|
* filter accordingly.
|
|
|
|
*/
|
|
|
|
lereset(sc);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 08:06:54 +03:00
|
|
|
leerror(sc, stat)
|
|
|
|
register struct le_softc *sc;
|
1993-05-13 17:56:20 +04:00
|
|
|
int stat;
|
|
|
|
{
|
1994-02-05 09:58:08 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
if (!ledebug)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not all transceivers implement heartbeat
|
|
|
|
* so we only log CERR once.
|
|
|
|
*/
|
1994-02-05 08:06:54 +03:00
|
|
|
if ((stat & LE_CERR) && sc->sc_cerr)
|
1993-05-13 17:56:20 +04:00
|
|
|
return;
|
|
|
|
log(LOG_WARNING,
|
1994-02-05 08:06:54 +03:00
|
|
|
"le%d: error: stat=%b\n", sc->sc_if.if_unit, stat,
|
1993-05-13 17:56:20 +04:00
|
|
|
"\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT");
|
|
|
|
}
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 08:06:54 +03:00
|
|
|
lererror(sc, msg)
|
|
|
|
register struct le_softc *sc;
|
1993-05-13 17:56:20 +04:00
|
|
|
char *msg;
|
|
|
|
{
|
|
|
|
register struct lermd *rmd;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!ledebug)
|
|
|
|
return;
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
rmd = &sc->sc_r2->ler2_rmd[sc->sc_rmd];
|
1993-05-13 17:56:20 +04:00
|
|
|
len = rmd->rmd3;
|
|
|
|
log(LOG_WARNING,
|
|
|
|
"le%d: ierror(%s): from %s: buf=%d, len=%d, rmd1=%b\n",
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_if.if_unit, msg,
|
|
|
|
len > 11 ? ether_sprintf(&sc->sc_r2->ler2_rbuf[sc->sc_rmd][6]) : "unknown",
|
|
|
|
sc->sc_rmd, len, rmd->rmd1,
|
1993-05-13 17:56:20 +04:00
|
|
|
"\20\20OWN\17ERR\16FRAM\15OFLO\14CRC\13RBUF\12STP\11ENP");
|
|
|
|
}
|
|
|
|
|
1994-02-06 03:46:02 +03:00
|
|
|
void
|
1994-02-05 08:06:54 +03:00
|
|
|
lexerror(sc)
|
|
|
|
register struct le_softc *sc;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
register struct letmd *tmd;
|
1994-02-05 08:06:54 +03:00
|
|
|
register int len;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
if (!ledebug)
|
|
|
|
return;
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
tmd = sc->sc_r2->ler2_tmd;
|
1993-05-13 17:56:20 +04:00
|
|
|
len = -tmd->tmd2;
|
|
|
|
log(LOG_WARNING,
|
|
|
|
"le%d: oerror: to %s: buf=%d, len=%d, tmd1=%b, tmd3=%b\n",
|
1994-02-05 08:06:54 +03:00
|
|
|
sc->sc_if.if_unit,
|
|
|
|
len > 5 ? ether_sprintf(&sc->sc_r2->ler2_tbuf[0][0]) : "unknown",
|
|
|
|
0, len, tmd->tmd1,
|
1993-05-13 17:56:20 +04:00
|
|
|
"\20\20OWN\17ERR\16RES\15MORE\14ONE\13DEF\12STP\11ENP",
|
|
|
|
tmd->tmd3,
|
|
|
|
"\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY");
|
|
|
|
}
|
|
|
|
#endif
|