Rename flags; clean up a bit.

This commit is contained in:
mycroft 1994-07-05 21:20:20 +00:00
parent c5bedb0aa6
commit 668c4747b3
4 changed files with 394 additions and 398 deletions

View File

@ -10,7 +10,7 @@
* of this software, nor does the author assume any responsibility * of this software, nor does the author assume any responsibility
* for damages incurred with its use. * for damages incurred with its use.
* *
* $Id: if_le.c,v 1.6 1994/07/02 04:13:16 mycroft Exp $ * $Id: if_le.c,v 1.7 1994/07/05 21:20:20 mycroft Exp $
*/ */
#include "bpfilter.h" #include "bpfilter.h"
@ -93,24 +93,24 @@ struct le_softc {
}; };
int leintr __P((struct le_softc *)); int leintr __P((struct le_softc *));
int le_ioctl __P((struct ifnet *, int, caddr_t)); int leioctl __P((struct ifnet *, int, caddr_t));
int le_start __P((struct ifnet *)); int lestart __P((struct ifnet *));
int le_watchdog __P((/* short */)); int lewatchdog __P((/* short */));
static inline void lewrcsr __P((/* struct le_softc *, u_short, u_short */)); static inline void lewrcsr __P((/* struct le_softc *, u_short, u_short */));
static inline u_short lerdcsr __P((/* struct le_softc *, u_short */)); static inline u_short lerdcsr __P((/* struct le_softc *, u_short */));
void le_init __P((struct le_softc *)); void leinit __P((struct le_softc *));
void init_mem __P((struct le_softc *)); void lememinit __P((struct le_softc *));
void le_reset __P((struct le_softc *)); void lereset __P((struct le_softc *));
void le_stop __P((struct le_softc *)); void lestop __P((struct le_softc *));
void le_tint __P((struct le_softc *)); void letint __P((struct le_softc *));
void le_rint __P((struct le_softc *)); void lerint __P((struct le_softc *));
void le_read __P((struct le_softc *, u_char *, int)); void leread __P((struct le_softc *, u_char *, int));
struct mbuf *le_get __P((u_char *, int, struct ifnet *)); struct mbuf *leget __P((u_char *, int, struct ifnet *));
#ifdef LEDEBUG #ifdef LEDEBUG
void recv_print __P((struct le_softc *, int)); void recv_print __P((struct le_softc *, int));
void xmit_print __P((struct le_softc *, int)); void xmit_print __P((struct le_softc *, int));
#endif #endif
void le_setladrf __P((struct arpcom *, u_long *)); void lesetladrf __P((struct arpcom *, u_long *));
int leprobe(); int leprobe();
int depca_probe __P((struct le_softc *, struct isa_attach_args *)); int depca_probe __P((struct le_softc *, struct isa_attach_args *));
@ -349,10 +349,10 @@ lance_probe(sc)
int type; int type;
/* Stop the LANCE chip and put it in a known state. */ /* Stop the LANCE chip and put it in a known state. */
lewrcsr(sc, 0, STOP); lewrcsr(sc, 0, LE_STOP);
delay(100); delay(100);
if (lerdcsr(sc, 0) != STOP) if (lerdcsr(sc, 0) != LE_STOP)
return 0; return 0;
/* /*
@ -372,7 +372,7 @@ lance_probe(sc)
break; break;
} }
lewrcsr(sc, 3, sc->sc_card == DEPCA ? ACON : 0); lewrcsr(sc, 3, sc->sc_card == DEPCA ? LE_ACON : 0);
return type; return type;
} }
@ -393,9 +393,9 @@ leattach(parent, self, aux)
ifp->if_unit = sc->sc_dev.dv_unit; ifp->if_unit = sc->sc_dev.dv_unit;
ifp->if_name = lecd.cd_name; ifp->if_name = lecd.cd_name;
ifp->if_output = ether_output; ifp->if_output = ether_output;
ifp->if_start = le_start; ifp->if_start = lestart;
ifp->if_ioctl = le_ioctl; ifp->if_ioctl = leioctl;
ifp->if_watchdog = le_watchdog; ifp->if_watchdog = lewatchdog;
ifp->if_flags = ifp->if_flags =
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
@ -421,32 +421,31 @@ leattach(parent, self, aux)
} }
void void
le_reset(sc) lereset(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
log(LOG_NOTICE, "%s: reset\n", sc->sc_dev.dv_xname); leinit(sc);
le_init(sc);
} }
int int
le_watchdog(unit) lewatchdog(unit)
short unit; short unit;
{ {
struct le_softc *sc = lecd.cd_devs[unit]; struct le_softc *sc = lecd.cd_devs[unit];
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
++sc->sc_arpcom.ac_if.if_oerrors; ++sc->sc_arpcom.ac_if.if_oerrors;
le_reset(sc); lereset(sc);
} }
#define LANCE_ADDR(sc, a) \ #define LANCE_ADDR(sc, a) \
(sc->sc_card == DEPCA ? ((u_long)(a) - (u_long)sc->sc_mem) : kvtop(a)) (sc->sc_card == DEPCA ? ((u_long)(a) - (u_long)sc->sc_mem) : kvtop(a))
/* Lance initialisation block set up. */ /* LANCE initialization block set up. */
void void
init_mem(sc) lememinit(sc)
struct le_softc *sc; register struct le_softc *sc;
{ {
struct ifnet *ifp = &sc->sc_arpcom.ac_if; struct ifnet *ifp = &sc->sc_arpcom.ac_if;
int i; int i;
@ -458,22 +457,18 @@ init_mem(sc)
* quadword aligned. If it isn't then the initialisation is going * quadword aligned. If it isn't then the initialisation is going
* fail later on. * fail later on.
*/ */
/*
* Set up lance initialisation block.
*/
mem = sc->sc_mem; mem = sc->sc_mem;
sc->sc_init = mem; sc->sc_init = mem;
#if NBPFILTER > 0 #if NBPFILTER > 0
if (ifp->if_flags & IFF_PROMISC) if (ifp->if_flags & IFF_PROMISC)
sc->sc_init->mode = PROM; sc->sc_init->mode = LE_NORMAL | LE_PROM;
else else
#endif #endif
sc->sc_init->mode = 0; sc->sc_init->mode = LE_NORMAL;
for (i = 0; i < ETHER_ADDR_LEN; i++) for (i = 0; i < ETHER_ADDR_LEN; i++)
sc->sc_init->padr[i] = sc->sc_arpcom.ac_enaddr[i]; sc->sc_init->padr[i] = sc->sc_arpcom.ac_enaddr[i];
le_setladrf(&sc->sc_arpcom, sc->sc_init->ladrf); lesetladrf(&sc->sc_arpcom, sc->sc_init->ladrf);
mem += sizeof(struct init_block); mem += sizeof(struct init_block);
sc->sc_rd = mem; sc->sc_rd = mem;
@ -495,7 +490,7 @@ init_mem(sc)
for (i = 0; i < NRBUF; i++) { for (i = 0; i < NRBUF; i++) {
a = LANCE_ADDR(sc, mem); a = LANCE_ADDR(sc, mem);
sc->sc_rd[i].addr = a; sc->sc_rd[i].addr = a;
sc->sc_rd[i].flags = ((a >> 16) & 0xff) | OWN; sc->sc_rd[i].flags = ((a >> 16) & 0xff) | LE_OWN;
sc->sc_rd[i].bcnt = -BUFSIZE; sc->sc_rd[i].bcnt = -BUFSIZE;
sc->sc_rd[i].mcnt = 0; sc->sc_rd[i].mcnt = 0;
mem += BUFSIZE; mem += BUFSIZE;
@ -516,11 +511,11 @@ init_mem(sc)
} }
void void
le_stop(sc) lestop(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
lewrcsr(sc, 0, STOP); lewrcsr(sc, 0, LE_STOP);
} }
/* /*
@ -528,54 +523,52 @@ le_stop(sc)
* and transmit/receive descriptor rings. * and transmit/receive descriptor rings.
*/ */
void void
le_init(sc) leinit(sc)
struct le_softc *sc; register struct le_softc *sc;
{ {
struct ifnet *ifp = &sc->sc_arpcom.ac_if; struct ifnet *ifp = &sc->sc_arpcom.ac_if;
int s; int s;
register i; register int timo;
u_long a; u_long a;
/* Address not known. */ /* Address not known. */
if (!ifp->if_addrlist) if (!ifp->if_addrlist)
return; return;
s = splimp(); s = splimp();
/* /* Don't want to get in a weird state. */
* Lance must be stopped to access registers. lestop(sc);
*/
le_stop(sc);
sc->sc_last_rd = sc->sc_last_td = sc->sc_no_td = 0; sc->sc_last_rd = sc->sc_last_td = sc->sc_no_td = 0;
/* Set up lance's memory area. */ /* Set up LANCE init block. */
init_mem(sc); lememinit(sc);
/* No byte swapping etc. */ /* No byte swapping etc. */
lewrcsr(sc, 3, sc->sc_card == DEPCA ? ACON : 0); lewrcsr(sc, 3, sc->sc_card == DEPCA ? LE_ACON : 0);
/* Give lance the physical address of its init block. */ /* Give LANCE the physical address of its init block. */
a = LANCE_ADDR(sc, sc->sc_init); a = LANCE_ADDR(sc, sc->sc_init);
lewrcsr(sc, 1, a); lewrcsr(sc, 1, a);
lewrcsr(sc, 2, (a >> 16) & 0xff); lewrcsr(sc, 2, (a >> 16) & 0xff);
/* OK, let's try and initialise the Lance. */ /* Try to initialize the LANCE. */
lewrcsr(sc, 0, INIT); lewrcsr(sc, 0, LE_INIT);
/* Wait for initialisation to finish. */ /* Wait for initialization to finish. */
for (i = 0; i < 1000; i++) for (timo = 1000; timo; timo--)
if (lerdcsr(sc, 0) & IDON) if (lerdcsr(sc, 0) & LE_IDON)
break; break;
if (lerdcsr(sc, 0) & IDON) { if (lerdcsr(sc, 0) & LE_IDON) {
/* Start the lance. */ /* Start the LANCE. */
lewrcsr(sc, 0, INEA | STRT | IDON); lewrcsr(sc, 0, LE_INEA | LE_STRT | LE_IDON);
ifp->if_flags |= IFF_RUNNING; ifp->if_flags |= IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE; ifp->if_flags &= ~IFF_OACTIVE;
le_start(ifp); lestart(ifp);
} else } else
printf("%s: card failed to initialise\n", sc->sc_dev.dv_xname); printf("%s: card failed to initialize\n", sc->sc_dev.dv_xname);
(void) splx(s); (void) splx(s);
} }
@ -587,7 +580,7 @@ le_init(sc)
* Called only at splimp or interrupt level. * Called only at splimp or interrupt level.
*/ */
int int
le_start(ifp) lestart(ifp)
struct ifnet *ifp; struct ifnet *ifp;
{ {
register struct le_softc *sc = lecd.cd_devs[ifp->if_unit]; register struct le_softc *sc = lecd.cd_devs[ifp->if_unit];
@ -614,7 +607,7 @@ outloop:
cdm = &sc->sc_td[sc->sc_last_td]; cdm = &sc->sc_td[sc->sc_last_td];
#if 0 /* XXX redundant */ #if 0 /* XXX redundant */
if (cdm->flags & OWN) if (cdm->flags & LE_OWN)
return; return;
#endif #endif
@ -648,14 +641,14 @@ outloop:
*/ */
cdm->bcnt = -len; cdm->bcnt = -len;
cdm->mcnt = 0; cdm->mcnt = 0;
cdm->flags |= OWN | STP | ENP; cdm->flags |= LE_OWN | LE_STP | LE_ENP;
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
xmit_print(sc, sc->sc_last_td); xmit_print(sc, sc->sc_last_td);
#endif #endif
lewrcsr(sc, 0, INEA | TDMD); lewrcsr(sc, 0, LE_INEA | LE_TDMD);
/* possible more packets */ /* possible more packets */
if (++sc->sc_last_td >= NTBUF) if (++sc->sc_last_td >= NTBUF)
@ -663,7 +656,6 @@ outloop:
goto outloop; goto outloop;
} }
/* /*
* Controller interrupt. * Controller interrupt.
*/ */
@ -671,7 +663,7 @@ int
leintr(sc) leintr(sc)
register struct le_softc *sc; register struct le_softc *sc;
{ {
u_short isr; register u_short isr;
isr = lerdcsr(sc, 0); isr = lerdcsr(sc, 0);
#ifdef LEDEBUG #ifdef LEDEBUG
@ -679,7 +671,7 @@ leintr(sc)
printf("%s: leintr entering with isr=%04x\n", printf("%s: leintr entering with isr=%04x\n",
sc->sc_dev.dv_xname, isr); sc->sc_dev.dv_xname, isr);
#endif #endif
if ((isr & INTR) == 0) if ((isr & LE_INTR) == 0)
return 0; return 0;
if (sc->sc_card == DEPCA) if (sc->sc_card == DEPCA)
@ -687,55 +679,56 @@ leintr(sc)
do { do {
lewrcsr(sc, 0, lewrcsr(sc, 0,
isr & (INEA | BABL | MISS | MERR | RINT | TINT | IDON)); isr & (LE_INEA | LE_BABL | LE_MISS | LE_MERR |
if (isr & (BABL | CERR | MISS | MERR)) { LE_RINT | LE_TINT | LE_IDON));
if (isr & BABL){ if (isr & (LE_BABL | LE_CERR | LE_MISS | LE_MERR)) {
if (isr & LE_BABL) {
printf("%s: BABL\n", sc->sc_dev.dv_xname); printf("%s: BABL\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_oerrors++; sc->sc_arpcom.ac_if.if_oerrors++;
} }
#if 0 #if 0
if (isr & CERR) { if (isr & LE_CERR) {
printf("%s: CERR\n", sc->sc_dev.dv_xname); printf("%s: CERR\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_collisions++; sc->sc_arpcom.ac_if.if_collisions++;
} }
#endif #endif
if (isr & MISS) { if (isr & LE_MISS) {
printf("%s: MISS\n", sc->sc_dev.dv_xname); printf("%s: MISS\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_ierrors++; sc->sc_arpcom.ac_if.if_ierrors++;
} }
if (isr & MERR) { if (isr & LE_MERR) {
printf("%s: MERR\n", sc->sc_dev.dv_xname); printf("%s: MERR\n", sc->sc_dev.dv_xname);
le_reset(sc); lereset(sc);
goto out; goto out;
} }
} }
if ((isr & RXON) == 0) { if ((isr & LE_RXON) == 0) {
printf("%s: receiver disabled\n", sc->sc_dev.dv_xname); printf("%s: receiver disabled\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_ierrors++; sc->sc_arpcom.ac_if.if_ierrors++;
le_reset(sc); lereset(sc);
goto out; goto out;
} }
if ((isr & TXON) == 0) { if ((isr & LE_TXON) == 0) {
printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname); printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_oerrors++; sc->sc_arpcom.ac_if.if_oerrors++;
le_reset(sc); lereset(sc);
goto out; goto out;
} }
if (isr & RINT) { if (isr & LE_RINT) {
/* Reset watchdog timer. */ /* Reset watchdog timer. */
sc->sc_arpcom.ac_if.if_timer = 0; sc->sc_arpcom.ac_if.if_timer = 0;
le_rint(sc); lerint(sc);
} }
if (isr & TINT) { if (isr & LE_TINT) {
/* Reset watchdog timer. */ /* Reset watchdog timer. */
sc->sc_arpcom.ac_if.if_timer = 0; sc->sc_arpcom.ac_if.if_timer = 0;
le_tint(sc); letint(sc);
} }
isr = lerdcsr(sc, 0); isr = lerdcsr(sc, 0);
} while ((isr & INTR) != 0); } while ((isr & LE_INTR) != 0);
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
@ -753,13 +746,13 @@ out:
if (++tmd == NTBUF) tmd=0, cdm=sc->sc_td; else ++cdm if (++tmd == NTBUF) tmd=0, cdm=sc->sc_td; else ++cdm
void void
le_tint(sc) letint(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
register int tmd = (sc->sc_last_td - sc->sc_no_td + NTBUF) % NTBUF; register int tmd = (sc->sc_last_td - sc->sc_no_td + NTBUF) % NTBUF;
struct mds *cdm = &sc->sc_td[tmd]; struct mds *cdm = &sc->sc_td[tmd];
if (cdm->flags & OWN) { if (cdm->flags & LE_OWN) {
/* Race condition with loop below. */ /* Race condition with loop below. */
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
@ -779,23 +772,23 @@ le_tint(sc)
#endif #endif
sc->sc_arpcom.ac_if.if_opackets++; sc->sc_arpcom.ac_if.if_opackets++;
--sc->sc_no_td; --sc->sc_no_td;
if (cdm->flags & (TBUFF | UFLO | LCOL | LCAR | RTRY)) { if (cdm->flags & (LE_TBUFF | LE_UFLO | LE_LCOL | LE_LCAR | LE_RTRY)) {
if (cdm->flags & TBUFF) if (cdm->flags & LE_TBUFF)
printf("%s: TBUFF\n", sc->sc_dev.dv_xname); printf("%s: TBUFF\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (TBUFF | UFLO)) == UFLO) if ((cdm->flags & (LE_TBUFF | LE_UFLO)) == LE_UFLO)
printf("%s: UFLO\n", sc->sc_dev.dv_xname); printf("%s: UFLO\n", sc->sc_dev.dv_xname);
if (cdm->flags & UFLO) { if (cdm->flags & LE_UFLO) {
le_reset(sc); lereset(sc);
return; return;
} }
#if 0 #if 0
if (cdm->flags & LCOL) { if (cdm->flags & LE_LCOL) {
printf("%s: late collision\n", sc->sc_dev.dv_xname); printf("%s: late collision\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_collisions++; sc->sc_arpcom.ac_if.if_collisions++;
} }
if (cdm->flags & LCAR) if (cdm->flags & LE_LCAR)
printf("%s: lost carrier\n", sc->sc_dev.dv_xname); printf("%s: lost carrier\n", sc->sc_dev.dv_xname);
if (cdm->flags & RTRY) { if (cdm->flags & LE_RTRY) {
printf("%s: excessive collisions, tdr %d\n", printf("%s: excessive collisions, tdr %d\n",
sc->sc_dev.dv_xname, cdm->flags & 0x1ff); sc->sc_dev.dv_xname, cdm->flags & 0x1ff);
sc->sc_arpcom.ac_if.if_collisions++; sc->sc_arpcom.ac_if.if_collisions++;
@ -803,9 +796,9 @@ le_tint(sc)
#endif #endif
} }
NEXTTDS; NEXTTDS;
} while ((cdm->flags & OWN) == 0); } while ((cdm->flags & LE_OWN) == 0);
le_start(&sc->sc_arpcom.ac_if); lestart(&sc->sc_arpcom.ac_if);
} }
#define NEXTRDS \ #define NEXTRDS \
@ -813,13 +806,13 @@ le_tint(sc)
/* only called from one place, so may as well integrate */ /* only called from one place, so may as well integrate */
void void
le_rint(sc) lerint(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
register int rmd = sc->sc_last_rd; register int rmd = sc->sc_last_rd;
struct mds *cdm = &sc->sc_rd[rmd]; struct mds *cdm = &sc->sc_rd[rmd];
if (cdm->flags & OWN) { if (cdm->flags & LE_OWN) {
/* Race condition with loop below. */ /* Race condition with loop below. */
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
@ -830,25 +823,25 @@ le_rint(sc)
/* Process all buffers with valid data. */ /* Process all buffers with valid data. */
do { do {
if (cdm->flags & (FRAM | OFLO | CRC | RBUFF)) { if (cdm->flags & (LE_FRAM | LE_OFLO | LE_CRC | LE_RBUFF)) {
if ((cdm->flags & (FRAM | OFLO | ENP)) == (FRAM | ENP)) if ((cdm->flags & (LE_FRAM | LE_OFLO | LE_ENP)) == (LE_FRAM | LE_ENP))
printf("%s: FRAM\n", sc->sc_dev.dv_xname); printf("%s: FRAM\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (OFLO | ENP)) == OFLO) if ((cdm->flags & (LE_OFLO | LE_ENP)) == LE_OFLO)
printf("%s: OFLO\n", sc->sc_dev.dv_xname); printf("%s: OFLO\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (CRC | OFLO | ENP)) == (CRC | ENP)) if ((cdm->flags & (LE_CRC | LE_OFLO | LE_ENP)) == (LE_CRC | LE_ENP))
printf("%s: CRC\n", sc->sc_dev.dv_xname); printf("%s: CRC\n", sc->sc_dev.dv_xname);
if (cdm->flags & RBUFF) if (cdm->flags & LE_RBUFF)
printf("%s: RBUFF\n", sc->sc_dev.dv_xname); printf("%s: RBUFF\n", sc->sc_dev.dv_xname);
} else if (cdm->flags & (STP | ENP) != (STP | ENP)) { } else if (cdm->flags & (LE_STP | LE_ENP) != (LE_STP | LE_ENP)) {
do { do {
cdm->mcnt = 0; cdm->mcnt = 0;
cdm->flags |= OWN; cdm->flags |= LE_OWN;
NEXTRDS; NEXTRDS;
} while ((cdm->flags & (OWN | ERR | STP | ENP)) == 0); } while ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) == 0);
sc->sc_last_rd = rmd; sc->sc_last_rd = rmd;
printf("%s: chained buffer\n", sc->sc_dev.dv_xname); printf("%s: chained buffer\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (OWN | ERR | STP | ENP)) != ENP) { if ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) != LE_ENP) {
le_reset(sc); lereset(sc);
return; return;
} }
} else { } else {
@ -856,31 +849,30 @@ le_rint(sc)
if (sc->sc_debug) if (sc->sc_debug)
recv_print(sc, sc->sc_last_rd); recv_print(sc, sc->sc_last_rd);
#endif #endif
le_read(sc, sc->sc_rbuf + (BUFSIZE * rmd), leread(sc, sc->sc_rbuf + (BUFSIZE * rmd),
(int)cdm->mcnt); (int)cdm->mcnt);
sc->sc_arpcom.ac_if.if_ipackets++; sc->sc_arpcom.ac_if.if_ipackets++;
} }
cdm->mcnt = 0; cdm->mcnt = 0;
cdm->flags |= OWN; cdm->flags |= LE_OWN;
NEXTRDS; NEXTRDS;
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
printf("sc->sc_last_rd = %x, cdm = %x\n", printf("sc->sc_last_rd = %x, cdm = %x\n",
sc->sc_last_rd, cdm); sc->sc_last_rd, cdm);
#endif #endif
} while ((cdm->flags & OWN) == 0); } while ((cdm->flags & LE_OWN) == 0);
sc->sc_last_rd = rmd; sc->sc_last_rd = rmd;
} /* le_rint */ }
/* /*
* Pass a packet to the higher levels. * Pass a packet to the higher levels.
*/ */
void void
le_read(sc, buf, len) leread(sc, buf, len)
struct le_softc *sc; register struct le_softc *sc;
u_char *buf; u_char *buf;
int len; int len;
{ {
@ -893,14 +885,14 @@ le_read(sc, buf, len)
return; return;
/* Pull packet off interface. */ /* Pull packet off interface. */
m = le_get(buf, len, &sc->sc_arpcom.ac_if); m = leget(buf, len, &sc->sc_arpcom.ac_if);
if (m == 0) if (m == 0)
return; return;
#if NBPFILTER > 0 #if NBPFILTER > 0
/* /*
* Check if there's a BPF listener on this interface. * Check if there's a BPF listener on this interface.
* If so, hand off the raw packet to bpf. * If so, hand off the raw packet to BPF.
*/ */
if (sc->sc_arpcom.ac_if.if_bpf) { if (sc->sc_arpcom.ac_if.if_bpf) {
bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m); bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m);
@ -934,7 +926,7 @@ le_read(sc, buf, len)
* we copy into clusters. * we copy into clusters.
*/ */
struct mbuf * struct mbuf *
le_get(buf, totlen, ifp) leget(buf, totlen, ifp)
u_char *buf; u_char *buf;
int totlen; int totlen;
struct ifnet *ifp; struct ifnet *ifp;
@ -1000,8 +992,8 @@ le_get(buf, totlen, ifp)
* Process an ioctl request. * Process an ioctl request.
*/ */
int int
le_ioctl(ifp, cmd, data) leioctl(ifp, cmd, data)
struct ifnet *ifp; register struct ifnet *ifp;
int cmd; int cmd;
caddr_t data; caddr_t data;
{ {
@ -1020,7 +1012,7 @@ le_ioctl(ifp, cmd, data)
switch (ifa->ifa_addr->sa_family) { switch (ifa->ifa_addr->sa_family) {
#ifdef INET #ifdef INET
case AF_INET: case AF_INET:
le_init(sc); /* before arpwhohas */ leinit(sc); /* before arpwhohas */
/* /*
* See if another station has *our* IP address. * See if another station has *our* IP address.
* i.e.: There is an address conflict! If a * i.e.: There is an address conflict! If a
@ -1040,21 +1032,17 @@ le_ioctl(ifp, cmd, data)
if (ns_nullhost(*ina)) if (ns_nullhost(*ina))
ina->x_host = ina->x_host =
*(union ns_host *)(sc->sc_arpcom.ac_enaddr); *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
else { else
/*
*
*/
bcopy(ina->x_host.c_host, bcopy(ina->x_host.c_host,
sc->sc_arpcom.ac_enaddr, sc->sc_arpcom.ac_enaddr,
sizeof(sc->sc_arpcom.ac_enaddr)); sizeof(sc->sc_arpcom.ac_enaddr));
}
/* Set new address. */ /* Set new address. */
le_init(sc); leinit(sc);
break; break;
} }
#endif #endif
default: default:
le_init(sc); leinit(sc);
break; break;
} }
break; break;
@ -1069,7 +1057,7 @@ le_ioctl(ifp, cmd, data)
* If interface is marked down and it is running, then * If interface is marked down and it is running, then
* stop it. * stop it.
*/ */
le_stop(sc); lestop(sc);
ifp->if_flags &= ~IFF_RUNNING; ifp->if_flags &= ~IFF_RUNNING;
} else if ((ifp->if_flags & IFF_UP) != 0 && } else if ((ifp->if_flags & IFF_UP) != 0 &&
(ifp->if_flags & IFF_RUNNING) == 0) { (ifp->if_flags & IFF_RUNNING) == 0) {
@ -1077,14 +1065,14 @@ le_ioctl(ifp, cmd, data)
* If interface is marked up and it is stopped, then * If interface is marked up and it is stopped, then
* start it. * start it.
*/ */
le_init(sc); leinit(sc);
} else { } else {
/* /*
* Reset the interface to pick up changes in any other * Reset the interface to pick up changes in any other
* flags that affect hardware registers. * flags that affect hardware registers.
*/ */
/*le_stop(sc);*/ /*lestop(sc);*/
le_init(sc); leinit(sc);
} }
#ifdef LEDEBUG #ifdef LEDEBUG
if (ifp->if_flags & IFF_DEBUG) if (ifp->if_flags & IFF_DEBUG)
@ -1105,7 +1093,7 @@ le_ioctl(ifp, cmd, data)
* Multicast list has changed; set the hardware filter * Multicast list has changed; set the hardware filter
* accordingly. * accordingly.
*/ */
le_init(sc); leinit(sc);
error = 0; error = 0;
} }
break; break;
@ -1175,7 +1163,7 @@ xmit_print(sc, no)
* Set up the logical address filter. * Set up the logical address filter.
*/ */
void void
le_setladrf(ac, af) lesetladrf(ac, af)
struct arpcom *ac; struct arpcom *ac;
u_long *af; u_long *af;
{ {

View File

@ -10,15 +10,15 @@
* of this software, nor does the author assume any responsibility * of this software, nor does the author assume any responsibility
* for damages incurred with its use. * for damages incurred with its use.
* *
* $Id: if_lereg.h,v 1.1 1994/07/01 20:25:27 mycroft Exp $ * $Id: if_lereg.h,v 1.2 1994/07/05 21:20:22 mycroft Exp $
*/ */
/* Declarations specific to this driver */ /* Declarations specific to this driver */
#define NTBUF 2 #define NTBUF 2
#define TLEN 1 #define TLEN 1
#define NRBUF 8 #define NRBUF 8
#define RLEN 3 #define RLEN 3
#define BUFSIZE 1518 #define BUFSIZE 1518
/* Board types */ /* Board types */
#define BICC 1 #define BICC 1
@ -38,51 +38,59 @@
#define PCnet_ISA 2 #define PCnet_ISA 2
#define PCnet_ISA_MASK 0x0000 #define PCnet_ISA_MASK 0x0000
/* Control and status register 0 flags */ /*
#define ERR 0x8000 * Control and status bits
#define BABL 0x4000 */
#define CERR 0x2000 #define LE_SERR 0x8000
#define MISS 0x1000 #define LE_BABL 0x4000
#define MERR 0x0800 #define LE_CERR 0x2000
#define RINT 0x0400 #define LE_MISS 0x1000
#define TINT 0x0200 #define LE_MERR 0x0800
#define IDON 0x0100 #define LE_RINT 0x0400
#define INTR 0x0080 #define LE_TINT 0x0200
#define INEA 0x0040 #define LE_IDON 0x0100
#define RXON 0x0020 #define LE_INTR 0x0080
#define TXON 0x0010 #define LE_INEA 0x0040
#define TDMD 0x0008 #define LE_RXON 0x0020
#define STOP 0x0004 #define LE_TXON 0x0010
#define STRT 0x0002 #define LE_TDMD 0x0008
#define INIT 0x0001 #define LE_STOP 0x0004
#define LE_STRT 0x0002
#define LE_INIT 0x0001
/* Coontrol and status register 3 flags */ #define LE_BSWP 0x0004
#define BSWP 0x0004 #define LE_ACON 0x0002
#define ACON 0x0002 #define LE_BCON 0x0001
#define BCON 0x0001
/* Initialisation block (must be on word boundary) */ /*
* LANCE initialization block
*/
struct init_block { struct init_block {
u_short mode; /* Mode register */ u_short mode; /* mode register */
u_char padr[6]; /* Ethernet address */ u_char padr[6]; /* ethernet address */
u_long ladrf[2]; /* Logical address filter (multicast) */ u_long ladrf[2]; /* logical address filter (multicast) */
u_short rdra; /* Low order pointer to receive ring */ u_short rdra; /* low order pointer to receive ring */
u_short rlen; /* High order pointer and no. rings */ u_short rlen; /* high order pointer and no. rings */
u_short tdra; /* Low order pointer to transmit ring */ u_short tdra; /* low order pointer to transmit ring */
u_short tlen; /* High order pointer and no rings */ u_short tlen; /* high order pointer and no rings */
}; };
/* Mode settings */ /*
#define PROM 0x8000 /* Promiscuous */ * Mode bits -- init_block
#define INTL 0x0040 /* Internal loopback */ */
#define DRTY 0x0020 /* Disable retry */ #define LE_PROM 0x8000 /* promiscuous */
#define COLL 0x0010 /* Force collision */ #define LE_INTL 0x0040 /* internal loopback */
#define DTCR 0x0008 /* Disable transmit crc */ #define LE_DRTY 0x0020 /* disable retry */
#define LOOP 0x0004 /* Loop back */ #define LE_COLL 0x0010 /* force collision */
#define DTX 0x0002 /* Disable transmitter */ #define LE_DTCR 0x0008 /* disable transmit crc */
#define DRX 0x0001 /* Disable receiver */ #define LE_LOOP 0x0004 /* loopback */
#define LE_DTX 0x0002 /* disable transmitter */
#define LE_DRX 0x0001 /* disable receiver */
#define LE_NORMAL 0x0000
/* Message descriptor structure */ /*
* Message descriptor
*/
struct mds { struct mds {
u_short addr; u_short addr;
u_short flags; u_short flags;
@ -90,27 +98,29 @@ struct mds {
u_short mcnt; u_short mcnt;
}; };
/* Receive ring status flags */ /* Message descriptor flags */
#define OWN 0x8000 /* Owner bit, 0=host, 1=Lance */ #define LE_OWN 0x8000 /* owner bit, 0=host, 1=LANCE */
#define MDERR 0x4000 /* Error */ #define LE_ERR 0x4000 /* error */
#define FRAM 0x2000 /* Framing error error */ #define LE_STP 0x0200 /* start of packet */
#define OFLO 0x1000 /* Silo overflow */ #define LE_ENP 0x0100 /* end of packet */
#define CRC 0x0800 /* CRC error */
#define RBUFF 0x0400 /* Buffer error */
#define STP 0x0200 /* Start of packet */
#define ENP 0x0100 /* End of packet */
/* Transmit ring flags */ /* Receive ring status flags */
#define MORE 0x1000 /* More than 1 retry */ #define LE_FRAM 0x2000 /* framing error error */
#define ONE 0x0800 /* One retry */ #define LE_OFLO 0x1000 /* silo overflow */
#define DEF 0x0400 /* Deferred transmit */ #define LE_CRC 0x0800 /* CRC error */
#define LE_RBUFF 0x0400 /* buffer error */
/* Transmit ring status flags */
#define LE_MORE 0x1000 /* more than 1 retry */
#define LE_ONE 0x0800 /* one retry */
#define LE_DEF 0x0400 /* deferred transmit */
/* Transmit errors */ /* Transmit errors */
#define TBUFF 0x8000 /* Buffer error */ #define LE_TBUFF 0x8000 /* buffer error */
#define UFLO 0x4000 /* Silo underflow */ #define LE_UFLO 0x4000 /* silo underflow */
#define LCOL 0x1000 /* Late collision */ #define LE_LCOL 0x1000 /* late collision */
#define LCAR 0x0800 /* Loss of carrier */ #define LE_LCAR 0x0800 /* loss of carrier */
#define RTRY 0x0400 /* Tried 16 times */ #define LE_RTRY 0x0400 /* tried 16 times */
/* DEPCA-specific definitions */ /* DEPCA-specific definitions */

View File

@ -10,7 +10,7 @@
* of this software, nor does the author assume any responsibility * of this software, nor does the author assume any responsibility
* for damages incurred with its use. * for damages incurred with its use.
* *
* $Id: if_le.c,v 1.6 1994/07/02 04:13:16 mycroft Exp $ * $Id: if_le.c,v 1.7 1994/07/05 21:20:20 mycroft Exp $
*/ */
#include "bpfilter.h" #include "bpfilter.h"
@ -93,24 +93,24 @@ struct le_softc {
}; };
int leintr __P((struct le_softc *)); int leintr __P((struct le_softc *));
int le_ioctl __P((struct ifnet *, int, caddr_t)); int leioctl __P((struct ifnet *, int, caddr_t));
int le_start __P((struct ifnet *)); int lestart __P((struct ifnet *));
int le_watchdog __P((/* short */)); int lewatchdog __P((/* short */));
static inline void lewrcsr __P((/* struct le_softc *, u_short, u_short */)); static inline void lewrcsr __P((/* struct le_softc *, u_short, u_short */));
static inline u_short lerdcsr __P((/* struct le_softc *, u_short */)); static inline u_short lerdcsr __P((/* struct le_softc *, u_short */));
void le_init __P((struct le_softc *)); void leinit __P((struct le_softc *));
void init_mem __P((struct le_softc *)); void lememinit __P((struct le_softc *));
void le_reset __P((struct le_softc *)); void lereset __P((struct le_softc *));
void le_stop __P((struct le_softc *)); void lestop __P((struct le_softc *));
void le_tint __P((struct le_softc *)); void letint __P((struct le_softc *));
void le_rint __P((struct le_softc *)); void lerint __P((struct le_softc *));
void le_read __P((struct le_softc *, u_char *, int)); void leread __P((struct le_softc *, u_char *, int));
struct mbuf *le_get __P((u_char *, int, struct ifnet *)); struct mbuf *leget __P((u_char *, int, struct ifnet *));
#ifdef LEDEBUG #ifdef LEDEBUG
void recv_print __P((struct le_softc *, int)); void recv_print __P((struct le_softc *, int));
void xmit_print __P((struct le_softc *, int)); void xmit_print __P((struct le_softc *, int));
#endif #endif
void le_setladrf __P((struct arpcom *, u_long *)); void lesetladrf __P((struct arpcom *, u_long *));
int leprobe(); int leprobe();
int depca_probe __P((struct le_softc *, struct isa_attach_args *)); int depca_probe __P((struct le_softc *, struct isa_attach_args *));
@ -349,10 +349,10 @@ lance_probe(sc)
int type; int type;
/* Stop the LANCE chip and put it in a known state. */ /* Stop the LANCE chip and put it in a known state. */
lewrcsr(sc, 0, STOP); lewrcsr(sc, 0, LE_STOP);
delay(100); delay(100);
if (lerdcsr(sc, 0) != STOP) if (lerdcsr(sc, 0) != LE_STOP)
return 0; return 0;
/* /*
@ -372,7 +372,7 @@ lance_probe(sc)
break; break;
} }
lewrcsr(sc, 3, sc->sc_card == DEPCA ? ACON : 0); lewrcsr(sc, 3, sc->sc_card == DEPCA ? LE_ACON : 0);
return type; return type;
} }
@ -393,9 +393,9 @@ leattach(parent, self, aux)
ifp->if_unit = sc->sc_dev.dv_unit; ifp->if_unit = sc->sc_dev.dv_unit;
ifp->if_name = lecd.cd_name; ifp->if_name = lecd.cd_name;
ifp->if_output = ether_output; ifp->if_output = ether_output;
ifp->if_start = le_start; ifp->if_start = lestart;
ifp->if_ioctl = le_ioctl; ifp->if_ioctl = leioctl;
ifp->if_watchdog = le_watchdog; ifp->if_watchdog = lewatchdog;
ifp->if_flags = ifp->if_flags =
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
@ -421,32 +421,31 @@ leattach(parent, self, aux)
} }
void void
le_reset(sc) lereset(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
log(LOG_NOTICE, "%s: reset\n", sc->sc_dev.dv_xname); leinit(sc);
le_init(sc);
} }
int int
le_watchdog(unit) lewatchdog(unit)
short unit; short unit;
{ {
struct le_softc *sc = lecd.cd_devs[unit]; struct le_softc *sc = lecd.cd_devs[unit];
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
++sc->sc_arpcom.ac_if.if_oerrors; ++sc->sc_arpcom.ac_if.if_oerrors;
le_reset(sc); lereset(sc);
} }
#define LANCE_ADDR(sc, a) \ #define LANCE_ADDR(sc, a) \
(sc->sc_card == DEPCA ? ((u_long)(a) - (u_long)sc->sc_mem) : kvtop(a)) (sc->sc_card == DEPCA ? ((u_long)(a) - (u_long)sc->sc_mem) : kvtop(a))
/* Lance initialisation block set up. */ /* LANCE initialization block set up. */
void void
init_mem(sc) lememinit(sc)
struct le_softc *sc; register struct le_softc *sc;
{ {
struct ifnet *ifp = &sc->sc_arpcom.ac_if; struct ifnet *ifp = &sc->sc_arpcom.ac_if;
int i; int i;
@ -458,22 +457,18 @@ init_mem(sc)
* quadword aligned. If it isn't then the initialisation is going * quadword aligned. If it isn't then the initialisation is going
* fail later on. * fail later on.
*/ */
/*
* Set up lance initialisation block.
*/
mem = sc->sc_mem; mem = sc->sc_mem;
sc->sc_init = mem; sc->sc_init = mem;
#if NBPFILTER > 0 #if NBPFILTER > 0
if (ifp->if_flags & IFF_PROMISC) if (ifp->if_flags & IFF_PROMISC)
sc->sc_init->mode = PROM; sc->sc_init->mode = LE_NORMAL | LE_PROM;
else else
#endif #endif
sc->sc_init->mode = 0; sc->sc_init->mode = LE_NORMAL;
for (i = 0; i < ETHER_ADDR_LEN; i++) for (i = 0; i < ETHER_ADDR_LEN; i++)
sc->sc_init->padr[i] = sc->sc_arpcom.ac_enaddr[i]; sc->sc_init->padr[i] = sc->sc_arpcom.ac_enaddr[i];
le_setladrf(&sc->sc_arpcom, sc->sc_init->ladrf); lesetladrf(&sc->sc_arpcom, sc->sc_init->ladrf);
mem += sizeof(struct init_block); mem += sizeof(struct init_block);
sc->sc_rd = mem; sc->sc_rd = mem;
@ -495,7 +490,7 @@ init_mem(sc)
for (i = 0; i < NRBUF; i++) { for (i = 0; i < NRBUF; i++) {
a = LANCE_ADDR(sc, mem); a = LANCE_ADDR(sc, mem);
sc->sc_rd[i].addr = a; sc->sc_rd[i].addr = a;
sc->sc_rd[i].flags = ((a >> 16) & 0xff) | OWN; sc->sc_rd[i].flags = ((a >> 16) & 0xff) | LE_OWN;
sc->sc_rd[i].bcnt = -BUFSIZE; sc->sc_rd[i].bcnt = -BUFSIZE;
sc->sc_rd[i].mcnt = 0; sc->sc_rd[i].mcnt = 0;
mem += BUFSIZE; mem += BUFSIZE;
@ -516,11 +511,11 @@ init_mem(sc)
} }
void void
le_stop(sc) lestop(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
lewrcsr(sc, 0, STOP); lewrcsr(sc, 0, LE_STOP);
} }
/* /*
@ -528,54 +523,52 @@ le_stop(sc)
* and transmit/receive descriptor rings. * and transmit/receive descriptor rings.
*/ */
void void
le_init(sc) leinit(sc)
struct le_softc *sc; register struct le_softc *sc;
{ {
struct ifnet *ifp = &sc->sc_arpcom.ac_if; struct ifnet *ifp = &sc->sc_arpcom.ac_if;
int s; int s;
register i; register int timo;
u_long a; u_long a;
/* Address not known. */ /* Address not known. */
if (!ifp->if_addrlist) if (!ifp->if_addrlist)
return; return;
s = splimp(); s = splimp();
/* /* Don't want to get in a weird state. */
* Lance must be stopped to access registers. lestop(sc);
*/
le_stop(sc);
sc->sc_last_rd = sc->sc_last_td = sc->sc_no_td = 0; sc->sc_last_rd = sc->sc_last_td = sc->sc_no_td = 0;
/* Set up lance's memory area. */ /* Set up LANCE init block. */
init_mem(sc); lememinit(sc);
/* No byte swapping etc. */ /* No byte swapping etc. */
lewrcsr(sc, 3, sc->sc_card == DEPCA ? ACON : 0); lewrcsr(sc, 3, sc->sc_card == DEPCA ? LE_ACON : 0);
/* Give lance the physical address of its init block. */ /* Give LANCE the physical address of its init block. */
a = LANCE_ADDR(sc, sc->sc_init); a = LANCE_ADDR(sc, sc->sc_init);
lewrcsr(sc, 1, a); lewrcsr(sc, 1, a);
lewrcsr(sc, 2, (a >> 16) & 0xff); lewrcsr(sc, 2, (a >> 16) & 0xff);
/* OK, let's try and initialise the Lance. */ /* Try to initialize the LANCE. */
lewrcsr(sc, 0, INIT); lewrcsr(sc, 0, LE_INIT);
/* Wait for initialisation to finish. */ /* Wait for initialization to finish. */
for (i = 0; i < 1000; i++) for (timo = 1000; timo; timo--)
if (lerdcsr(sc, 0) & IDON) if (lerdcsr(sc, 0) & LE_IDON)
break; break;
if (lerdcsr(sc, 0) & IDON) { if (lerdcsr(sc, 0) & LE_IDON) {
/* Start the lance. */ /* Start the LANCE. */
lewrcsr(sc, 0, INEA | STRT | IDON); lewrcsr(sc, 0, LE_INEA | LE_STRT | LE_IDON);
ifp->if_flags |= IFF_RUNNING; ifp->if_flags |= IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE; ifp->if_flags &= ~IFF_OACTIVE;
le_start(ifp); lestart(ifp);
} else } else
printf("%s: card failed to initialise\n", sc->sc_dev.dv_xname); printf("%s: card failed to initialize\n", sc->sc_dev.dv_xname);
(void) splx(s); (void) splx(s);
} }
@ -587,7 +580,7 @@ le_init(sc)
* Called only at splimp or interrupt level. * Called only at splimp or interrupt level.
*/ */
int int
le_start(ifp) lestart(ifp)
struct ifnet *ifp; struct ifnet *ifp;
{ {
register struct le_softc *sc = lecd.cd_devs[ifp->if_unit]; register struct le_softc *sc = lecd.cd_devs[ifp->if_unit];
@ -614,7 +607,7 @@ outloop:
cdm = &sc->sc_td[sc->sc_last_td]; cdm = &sc->sc_td[sc->sc_last_td];
#if 0 /* XXX redundant */ #if 0 /* XXX redundant */
if (cdm->flags & OWN) if (cdm->flags & LE_OWN)
return; return;
#endif #endif
@ -648,14 +641,14 @@ outloop:
*/ */
cdm->bcnt = -len; cdm->bcnt = -len;
cdm->mcnt = 0; cdm->mcnt = 0;
cdm->flags |= OWN | STP | ENP; cdm->flags |= LE_OWN | LE_STP | LE_ENP;
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
xmit_print(sc, sc->sc_last_td); xmit_print(sc, sc->sc_last_td);
#endif #endif
lewrcsr(sc, 0, INEA | TDMD); lewrcsr(sc, 0, LE_INEA | LE_TDMD);
/* possible more packets */ /* possible more packets */
if (++sc->sc_last_td >= NTBUF) if (++sc->sc_last_td >= NTBUF)
@ -663,7 +656,6 @@ outloop:
goto outloop; goto outloop;
} }
/* /*
* Controller interrupt. * Controller interrupt.
*/ */
@ -671,7 +663,7 @@ int
leintr(sc) leintr(sc)
register struct le_softc *sc; register struct le_softc *sc;
{ {
u_short isr; register u_short isr;
isr = lerdcsr(sc, 0); isr = lerdcsr(sc, 0);
#ifdef LEDEBUG #ifdef LEDEBUG
@ -679,7 +671,7 @@ leintr(sc)
printf("%s: leintr entering with isr=%04x\n", printf("%s: leintr entering with isr=%04x\n",
sc->sc_dev.dv_xname, isr); sc->sc_dev.dv_xname, isr);
#endif #endif
if ((isr & INTR) == 0) if ((isr & LE_INTR) == 0)
return 0; return 0;
if (sc->sc_card == DEPCA) if (sc->sc_card == DEPCA)
@ -687,55 +679,56 @@ leintr(sc)
do { do {
lewrcsr(sc, 0, lewrcsr(sc, 0,
isr & (INEA | BABL | MISS | MERR | RINT | TINT | IDON)); isr & (LE_INEA | LE_BABL | LE_MISS | LE_MERR |
if (isr & (BABL | CERR | MISS | MERR)) { LE_RINT | LE_TINT | LE_IDON));
if (isr & BABL){ if (isr & (LE_BABL | LE_CERR | LE_MISS | LE_MERR)) {
if (isr & LE_BABL) {
printf("%s: BABL\n", sc->sc_dev.dv_xname); printf("%s: BABL\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_oerrors++; sc->sc_arpcom.ac_if.if_oerrors++;
} }
#if 0 #if 0
if (isr & CERR) { if (isr & LE_CERR) {
printf("%s: CERR\n", sc->sc_dev.dv_xname); printf("%s: CERR\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_collisions++; sc->sc_arpcom.ac_if.if_collisions++;
} }
#endif #endif
if (isr & MISS) { if (isr & LE_MISS) {
printf("%s: MISS\n", sc->sc_dev.dv_xname); printf("%s: MISS\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_ierrors++; sc->sc_arpcom.ac_if.if_ierrors++;
} }
if (isr & MERR) { if (isr & LE_MERR) {
printf("%s: MERR\n", sc->sc_dev.dv_xname); printf("%s: MERR\n", sc->sc_dev.dv_xname);
le_reset(sc); lereset(sc);
goto out; goto out;
} }
} }
if ((isr & RXON) == 0) { if ((isr & LE_RXON) == 0) {
printf("%s: receiver disabled\n", sc->sc_dev.dv_xname); printf("%s: receiver disabled\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_ierrors++; sc->sc_arpcom.ac_if.if_ierrors++;
le_reset(sc); lereset(sc);
goto out; goto out;
} }
if ((isr & TXON) == 0) { if ((isr & LE_TXON) == 0) {
printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname); printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_oerrors++; sc->sc_arpcom.ac_if.if_oerrors++;
le_reset(sc); lereset(sc);
goto out; goto out;
} }
if (isr & RINT) { if (isr & LE_RINT) {
/* Reset watchdog timer. */ /* Reset watchdog timer. */
sc->sc_arpcom.ac_if.if_timer = 0; sc->sc_arpcom.ac_if.if_timer = 0;
le_rint(sc); lerint(sc);
} }
if (isr & TINT) { if (isr & LE_TINT) {
/* Reset watchdog timer. */ /* Reset watchdog timer. */
sc->sc_arpcom.ac_if.if_timer = 0; sc->sc_arpcom.ac_if.if_timer = 0;
le_tint(sc); letint(sc);
} }
isr = lerdcsr(sc, 0); isr = lerdcsr(sc, 0);
} while ((isr & INTR) != 0); } while ((isr & LE_INTR) != 0);
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
@ -753,13 +746,13 @@ out:
if (++tmd == NTBUF) tmd=0, cdm=sc->sc_td; else ++cdm if (++tmd == NTBUF) tmd=0, cdm=sc->sc_td; else ++cdm
void void
le_tint(sc) letint(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
register int tmd = (sc->sc_last_td - sc->sc_no_td + NTBUF) % NTBUF; register int tmd = (sc->sc_last_td - sc->sc_no_td + NTBUF) % NTBUF;
struct mds *cdm = &sc->sc_td[tmd]; struct mds *cdm = &sc->sc_td[tmd];
if (cdm->flags & OWN) { if (cdm->flags & LE_OWN) {
/* Race condition with loop below. */ /* Race condition with loop below. */
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
@ -779,23 +772,23 @@ le_tint(sc)
#endif #endif
sc->sc_arpcom.ac_if.if_opackets++; sc->sc_arpcom.ac_if.if_opackets++;
--sc->sc_no_td; --sc->sc_no_td;
if (cdm->flags & (TBUFF | UFLO | LCOL | LCAR | RTRY)) { if (cdm->flags & (LE_TBUFF | LE_UFLO | LE_LCOL | LE_LCAR | LE_RTRY)) {
if (cdm->flags & TBUFF) if (cdm->flags & LE_TBUFF)
printf("%s: TBUFF\n", sc->sc_dev.dv_xname); printf("%s: TBUFF\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (TBUFF | UFLO)) == UFLO) if ((cdm->flags & (LE_TBUFF | LE_UFLO)) == LE_UFLO)
printf("%s: UFLO\n", sc->sc_dev.dv_xname); printf("%s: UFLO\n", sc->sc_dev.dv_xname);
if (cdm->flags & UFLO) { if (cdm->flags & LE_UFLO) {
le_reset(sc); lereset(sc);
return; return;
} }
#if 0 #if 0
if (cdm->flags & LCOL) { if (cdm->flags & LE_LCOL) {
printf("%s: late collision\n", sc->sc_dev.dv_xname); printf("%s: late collision\n", sc->sc_dev.dv_xname);
sc->sc_arpcom.ac_if.if_collisions++; sc->sc_arpcom.ac_if.if_collisions++;
} }
if (cdm->flags & LCAR) if (cdm->flags & LE_LCAR)
printf("%s: lost carrier\n", sc->sc_dev.dv_xname); printf("%s: lost carrier\n", sc->sc_dev.dv_xname);
if (cdm->flags & RTRY) { if (cdm->flags & LE_RTRY) {
printf("%s: excessive collisions, tdr %d\n", printf("%s: excessive collisions, tdr %d\n",
sc->sc_dev.dv_xname, cdm->flags & 0x1ff); sc->sc_dev.dv_xname, cdm->flags & 0x1ff);
sc->sc_arpcom.ac_if.if_collisions++; sc->sc_arpcom.ac_if.if_collisions++;
@ -803,9 +796,9 @@ le_tint(sc)
#endif #endif
} }
NEXTTDS; NEXTTDS;
} while ((cdm->flags & OWN) == 0); } while ((cdm->flags & LE_OWN) == 0);
le_start(&sc->sc_arpcom.ac_if); lestart(&sc->sc_arpcom.ac_if);
} }
#define NEXTRDS \ #define NEXTRDS \
@ -813,13 +806,13 @@ le_tint(sc)
/* only called from one place, so may as well integrate */ /* only called from one place, so may as well integrate */
void void
le_rint(sc) lerint(sc)
struct le_softc *sc; struct le_softc *sc;
{ {
register int rmd = sc->sc_last_rd; register int rmd = sc->sc_last_rd;
struct mds *cdm = &sc->sc_rd[rmd]; struct mds *cdm = &sc->sc_rd[rmd];
if (cdm->flags & OWN) { if (cdm->flags & LE_OWN) {
/* Race condition with loop below. */ /* Race condition with loop below. */
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
@ -830,25 +823,25 @@ le_rint(sc)
/* Process all buffers with valid data. */ /* Process all buffers with valid data. */
do { do {
if (cdm->flags & (FRAM | OFLO | CRC | RBUFF)) { if (cdm->flags & (LE_FRAM | LE_OFLO | LE_CRC | LE_RBUFF)) {
if ((cdm->flags & (FRAM | OFLO | ENP)) == (FRAM | ENP)) if ((cdm->flags & (LE_FRAM | LE_OFLO | LE_ENP)) == (LE_FRAM | LE_ENP))
printf("%s: FRAM\n", sc->sc_dev.dv_xname); printf("%s: FRAM\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (OFLO | ENP)) == OFLO) if ((cdm->flags & (LE_OFLO | LE_ENP)) == LE_OFLO)
printf("%s: OFLO\n", sc->sc_dev.dv_xname); printf("%s: OFLO\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (CRC | OFLO | ENP)) == (CRC | ENP)) if ((cdm->flags & (LE_CRC | LE_OFLO | LE_ENP)) == (LE_CRC | LE_ENP))
printf("%s: CRC\n", sc->sc_dev.dv_xname); printf("%s: CRC\n", sc->sc_dev.dv_xname);
if (cdm->flags & RBUFF) if (cdm->flags & LE_RBUFF)
printf("%s: RBUFF\n", sc->sc_dev.dv_xname); printf("%s: RBUFF\n", sc->sc_dev.dv_xname);
} else if (cdm->flags & (STP | ENP) != (STP | ENP)) { } else if (cdm->flags & (LE_STP | LE_ENP) != (LE_STP | LE_ENP)) {
do { do {
cdm->mcnt = 0; cdm->mcnt = 0;
cdm->flags |= OWN; cdm->flags |= LE_OWN;
NEXTRDS; NEXTRDS;
} while ((cdm->flags & (OWN | ERR | STP | ENP)) == 0); } while ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) == 0);
sc->sc_last_rd = rmd; sc->sc_last_rd = rmd;
printf("%s: chained buffer\n", sc->sc_dev.dv_xname); printf("%s: chained buffer\n", sc->sc_dev.dv_xname);
if ((cdm->flags & (OWN | ERR | STP | ENP)) != ENP) { if ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) != LE_ENP) {
le_reset(sc); lereset(sc);
return; return;
} }
} else { } else {
@ -856,31 +849,30 @@ le_rint(sc)
if (sc->sc_debug) if (sc->sc_debug)
recv_print(sc, sc->sc_last_rd); recv_print(sc, sc->sc_last_rd);
#endif #endif
le_read(sc, sc->sc_rbuf + (BUFSIZE * rmd), leread(sc, sc->sc_rbuf + (BUFSIZE * rmd),
(int)cdm->mcnt); (int)cdm->mcnt);
sc->sc_arpcom.ac_if.if_ipackets++; sc->sc_arpcom.ac_if.if_ipackets++;
} }
cdm->mcnt = 0; cdm->mcnt = 0;
cdm->flags |= OWN; cdm->flags |= LE_OWN;
NEXTRDS; NEXTRDS;
#ifdef LEDEBUG #ifdef LEDEBUG
if (sc->sc_debug) if (sc->sc_debug)
printf("sc->sc_last_rd = %x, cdm = %x\n", printf("sc->sc_last_rd = %x, cdm = %x\n",
sc->sc_last_rd, cdm); sc->sc_last_rd, cdm);
#endif #endif
} while ((cdm->flags & OWN) == 0); } while ((cdm->flags & LE_OWN) == 0);
sc->sc_last_rd = rmd; sc->sc_last_rd = rmd;
} /* le_rint */ }
/* /*
* Pass a packet to the higher levels. * Pass a packet to the higher levels.
*/ */
void void
le_read(sc, buf, len) leread(sc, buf, len)
struct le_softc *sc; register struct le_softc *sc;
u_char *buf; u_char *buf;
int len; int len;
{ {
@ -893,14 +885,14 @@ le_read(sc, buf, len)
return; return;
/* Pull packet off interface. */ /* Pull packet off interface. */
m = le_get(buf, len, &sc->sc_arpcom.ac_if); m = leget(buf, len, &sc->sc_arpcom.ac_if);
if (m == 0) if (m == 0)
return; return;
#if NBPFILTER > 0 #if NBPFILTER > 0
/* /*
* Check if there's a BPF listener on this interface. * Check if there's a BPF listener on this interface.
* If so, hand off the raw packet to bpf. * If so, hand off the raw packet to BPF.
*/ */
if (sc->sc_arpcom.ac_if.if_bpf) { if (sc->sc_arpcom.ac_if.if_bpf) {
bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m); bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m);
@ -934,7 +926,7 @@ le_read(sc, buf, len)
* we copy into clusters. * we copy into clusters.
*/ */
struct mbuf * struct mbuf *
le_get(buf, totlen, ifp) leget(buf, totlen, ifp)
u_char *buf; u_char *buf;
int totlen; int totlen;
struct ifnet *ifp; struct ifnet *ifp;
@ -1000,8 +992,8 @@ le_get(buf, totlen, ifp)
* Process an ioctl request. * Process an ioctl request.
*/ */
int int
le_ioctl(ifp, cmd, data) leioctl(ifp, cmd, data)
struct ifnet *ifp; register struct ifnet *ifp;
int cmd; int cmd;
caddr_t data; caddr_t data;
{ {
@ -1020,7 +1012,7 @@ le_ioctl(ifp, cmd, data)
switch (ifa->ifa_addr->sa_family) { switch (ifa->ifa_addr->sa_family) {
#ifdef INET #ifdef INET
case AF_INET: case AF_INET:
le_init(sc); /* before arpwhohas */ leinit(sc); /* before arpwhohas */
/* /*
* See if another station has *our* IP address. * See if another station has *our* IP address.
* i.e.: There is an address conflict! If a * i.e.: There is an address conflict! If a
@ -1040,21 +1032,17 @@ le_ioctl(ifp, cmd, data)
if (ns_nullhost(*ina)) if (ns_nullhost(*ina))
ina->x_host = ina->x_host =
*(union ns_host *)(sc->sc_arpcom.ac_enaddr); *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
else { else
/*
*
*/
bcopy(ina->x_host.c_host, bcopy(ina->x_host.c_host,
sc->sc_arpcom.ac_enaddr, sc->sc_arpcom.ac_enaddr,
sizeof(sc->sc_arpcom.ac_enaddr)); sizeof(sc->sc_arpcom.ac_enaddr));
}
/* Set new address. */ /* Set new address. */
le_init(sc); leinit(sc);
break; break;
} }
#endif #endif
default: default:
le_init(sc); leinit(sc);
break; break;
} }
break; break;
@ -1069,7 +1057,7 @@ le_ioctl(ifp, cmd, data)
* If interface is marked down and it is running, then * If interface is marked down and it is running, then
* stop it. * stop it.
*/ */
le_stop(sc); lestop(sc);
ifp->if_flags &= ~IFF_RUNNING; ifp->if_flags &= ~IFF_RUNNING;
} else if ((ifp->if_flags & IFF_UP) != 0 && } else if ((ifp->if_flags & IFF_UP) != 0 &&
(ifp->if_flags & IFF_RUNNING) == 0) { (ifp->if_flags & IFF_RUNNING) == 0) {
@ -1077,14 +1065,14 @@ le_ioctl(ifp, cmd, data)
* If interface is marked up and it is stopped, then * If interface is marked up and it is stopped, then
* start it. * start it.
*/ */
le_init(sc); leinit(sc);
} else { } else {
/* /*
* Reset the interface to pick up changes in any other * Reset the interface to pick up changes in any other
* flags that affect hardware registers. * flags that affect hardware registers.
*/ */
/*le_stop(sc);*/ /*lestop(sc);*/
le_init(sc); leinit(sc);
} }
#ifdef LEDEBUG #ifdef LEDEBUG
if (ifp->if_flags & IFF_DEBUG) if (ifp->if_flags & IFF_DEBUG)
@ -1105,7 +1093,7 @@ le_ioctl(ifp, cmd, data)
* Multicast list has changed; set the hardware filter * Multicast list has changed; set the hardware filter
* accordingly. * accordingly.
*/ */
le_init(sc); leinit(sc);
error = 0; error = 0;
} }
break; break;
@ -1175,7 +1163,7 @@ xmit_print(sc, no)
* Set up the logical address filter. * Set up the logical address filter.
*/ */
void void
le_setladrf(ac, af) lesetladrf(ac, af)
struct arpcom *ac; struct arpcom *ac;
u_long *af; u_long *af;
{ {

View File

@ -10,15 +10,15 @@
* of this software, nor does the author assume any responsibility * of this software, nor does the author assume any responsibility
* for damages incurred with its use. * for damages incurred with its use.
* *
* $Id: if_lereg.h,v 1.1 1994/07/01 20:25:27 mycroft Exp $ * $Id: if_lereg.h,v 1.2 1994/07/05 21:20:22 mycroft Exp $
*/ */
/* Declarations specific to this driver */ /* Declarations specific to this driver */
#define NTBUF 2 #define NTBUF 2
#define TLEN 1 #define TLEN 1
#define NRBUF 8 #define NRBUF 8
#define RLEN 3 #define RLEN 3
#define BUFSIZE 1518 #define BUFSIZE 1518
/* Board types */ /* Board types */
#define BICC 1 #define BICC 1
@ -38,51 +38,59 @@
#define PCnet_ISA 2 #define PCnet_ISA 2
#define PCnet_ISA_MASK 0x0000 #define PCnet_ISA_MASK 0x0000
/* Control and status register 0 flags */ /*
#define ERR 0x8000 * Control and status bits
#define BABL 0x4000 */
#define CERR 0x2000 #define LE_SERR 0x8000
#define MISS 0x1000 #define LE_BABL 0x4000
#define MERR 0x0800 #define LE_CERR 0x2000
#define RINT 0x0400 #define LE_MISS 0x1000
#define TINT 0x0200 #define LE_MERR 0x0800
#define IDON 0x0100 #define LE_RINT 0x0400
#define INTR 0x0080 #define LE_TINT 0x0200
#define INEA 0x0040 #define LE_IDON 0x0100
#define RXON 0x0020 #define LE_INTR 0x0080
#define TXON 0x0010 #define LE_INEA 0x0040
#define TDMD 0x0008 #define LE_RXON 0x0020
#define STOP 0x0004 #define LE_TXON 0x0010
#define STRT 0x0002 #define LE_TDMD 0x0008
#define INIT 0x0001 #define LE_STOP 0x0004
#define LE_STRT 0x0002
#define LE_INIT 0x0001
/* Coontrol and status register 3 flags */ #define LE_BSWP 0x0004
#define BSWP 0x0004 #define LE_ACON 0x0002
#define ACON 0x0002 #define LE_BCON 0x0001
#define BCON 0x0001
/* Initialisation block (must be on word boundary) */ /*
* LANCE initialization block
*/
struct init_block { struct init_block {
u_short mode; /* Mode register */ u_short mode; /* mode register */
u_char padr[6]; /* Ethernet address */ u_char padr[6]; /* ethernet address */
u_long ladrf[2]; /* Logical address filter (multicast) */ u_long ladrf[2]; /* logical address filter (multicast) */
u_short rdra; /* Low order pointer to receive ring */ u_short rdra; /* low order pointer to receive ring */
u_short rlen; /* High order pointer and no. rings */ u_short rlen; /* high order pointer and no. rings */
u_short tdra; /* Low order pointer to transmit ring */ u_short tdra; /* low order pointer to transmit ring */
u_short tlen; /* High order pointer and no rings */ u_short tlen; /* high order pointer and no rings */
}; };
/* Mode settings */ /*
#define PROM 0x8000 /* Promiscuous */ * Mode bits -- init_block
#define INTL 0x0040 /* Internal loopback */ */
#define DRTY 0x0020 /* Disable retry */ #define LE_PROM 0x8000 /* promiscuous */
#define COLL 0x0010 /* Force collision */ #define LE_INTL 0x0040 /* internal loopback */
#define DTCR 0x0008 /* Disable transmit crc */ #define LE_DRTY 0x0020 /* disable retry */
#define LOOP 0x0004 /* Loop back */ #define LE_COLL 0x0010 /* force collision */
#define DTX 0x0002 /* Disable transmitter */ #define LE_DTCR 0x0008 /* disable transmit crc */
#define DRX 0x0001 /* Disable receiver */ #define LE_LOOP 0x0004 /* loopback */
#define LE_DTX 0x0002 /* disable transmitter */
#define LE_DRX 0x0001 /* disable receiver */
#define LE_NORMAL 0x0000
/* Message descriptor structure */ /*
* Message descriptor
*/
struct mds { struct mds {
u_short addr; u_short addr;
u_short flags; u_short flags;
@ -90,27 +98,29 @@ struct mds {
u_short mcnt; u_short mcnt;
}; };
/* Receive ring status flags */ /* Message descriptor flags */
#define OWN 0x8000 /* Owner bit, 0=host, 1=Lance */ #define LE_OWN 0x8000 /* owner bit, 0=host, 1=LANCE */
#define MDERR 0x4000 /* Error */ #define LE_ERR 0x4000 /* error */
#define FRAM 0x2000 /* Framing error error */ #define LE_STP 0x0200 /* start of packet */
#define OFLO 0x1000 /* Silo overflow */ #define LE_ENP 0x0100 /* end of packet */
#define CRC 0x0800 /* CRC error */
#define RBUFF 0x0400 /* Buffer error */
#define STP 0x0200 /* Start of packet */
#define ENP 0x0100 /* End of packet */
/* Transmit ring flags */ /* Receive ring status flags */
#define MORE 0x1000 /* More than 1 retry */ #define LE_FRAM 0x2000 /* framing error error */
#define ONE 0x0800 /* One retry */ #define LE_OFLO 0x1000 /* silo overflow */
#define DEF 0x0400 /* Deferred transmit */ #define LE_CRC 0x0800 /* CRC error */
#define LE_RBUFF 0x0400 /* buffer error */
/* Transmit ring status flags */
#define LE_MORE 0x1000 /* more than 1 retry */
#define LE_ONE 0x0800 /* one retry */
#define LE_DEF 0x0400 /* deferred transmit */
/* Transmit errors */ /* Transmit errors */
#define TBUFF 0x8000 /* Buffer error */ #define LE_TBUFF 0x8000 /* buffer error */
#define UFLO 0x4000 /* Silo underflow */ #define LE_UFLO 0x4000 /* silo underflow */
#define LCOL 0x1000 /* Late collision */ #define LE_LCOL 0x1000 /* late collision */
#define LCAR 0x0800 /* Loss of carrier */ #define LE_LCAR 0x0800 /* loss of carrier */
#define RTRY 0x0400 /* Tried 16 times */ #define LE_RTRY 0x0400 /* tried 16 times */
/* DEPCA-specific definitions */ /* DEPCA-specific definitions */