Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.20
      1  1.20    gwr /*	$NetBSD: if_le.c,v 1.20 1995/04/26 23:19:16 gwr Exp $	*/
      2  1.12    cgd 
      3  1.16    gwr /*
      4  1.16    gwr  * LANCE Ethernet driver
      5   1.1  glass  *
      6  1.16    gwr  * Copyright (c) 1995 Gordon W. Ross
      7  1.16    gwr  * Copyright (c) 1994 Charles Hannum.
      8   1.1  glass  *
      9  1.16    gwr  * Copyright (C) 1993, Paul Richards. This software may be used, modified,
     10  1.16    gwr  *   copied, distributed, and sold, in both source and binary form provided
     11  1.16    gwr  *   that the above copyright and these terms are retained. Under no
     12  1.16    gwr  *   circumstances is the author responsible for the proper functioning
     13  1.16    gwr  *   of this software, nor does the author assume any responsibility
     14  1.16    gwr  *   for damages incurred with its use.
     15   1.1  glass  */
     16   1.1  glass 
     17   1.1  glass #include "bpfilter.h"
     18   1.1  glass 
     19   1.8  glass #include <sys/param.h>
     20   1.8  glass #include <sys/systm.h>
     21  1.16    gwr #include <sys/errno.h>
     22  1.16    gwr #include <sys/ioctl.h>
     23   1.8  glass #include <sys/mbuf.h>
     24   1.8  glass #include <sys/socket.h>
     25   1.8  glass #include <sys/syslog.h>
     26  1.16    gwr #include <sys/device.h>
     27   1.8  glass 
     28   1.8  glass #include <net/if.h>
     29  1.16    gwr #include <net/if_dl.h>
     30  1.16    gwr #include <net/if_types.h>
     31   1.8  glass #include <net/netisr.h>
     32  1.10    gwr 
     33   1.1  glass #ifdef INET
     34   1.8  glass #include <netinet/in.h>
     35   1.8  glass #include <netinet/in_systm.h>
     36   1.8  glass #include <netinet/in_var.h>
     37   1.8  glass #include <netinet/ip.h>
     38   1.8  glass #include <netinet/if_ether.h>
     39   1.1  glass #endif
     40   1.1  glass 
     41   1.1  glass #ifdef NS
     42   1.8  glass #include <netns/ns.h>
     43   1.8  glass #include <netns/ns_if.h>
     44   1.1  glass #endif
     45   1.1  glass 
     46  1.16    gwr #if NBPFILTER > 0
     47  1.16    gwr #include <net/bpf.h>
     48  1.16    gwr #include <net/bpfdesc.h>
     49   1.1  glass #endif
     50   1.1  glass 
     51   1.8  glass #include <machine/autoconf.h>
     52  1.10    gwr #include <machine/cpu.h>
     53   1.1  glass 
     54  1.20    gwr /* XXX - Yes, we DO have to deal with this bug. */
     55  1.20    gwr #define	LANCE_REVC_BUG 1
     56  1.20    gwr 
     57  1.16    gwr /* #define	LEDEBUG	1 */
     58  1.16    gwr 
     59   1.1  glass #include "if_lereg.h"
     60   1.1  glass #include "if_le.h"
     61   1.1  glass #include "if_le_subr.h"
     62   1.1  glass 
     63  1.19    gwr #define	RMD_BITS "\20\20own\17err\16fram\15oflo\14crc\13rbuf\12stp\11enp"
     64  1.19    gwr 
     65  1.16    gwr #define	ETHER_MIN_LEN	64
     66  1.16    gwr #define	ETHER_MAX_LEN	1518
     67  1.16    gwr 
     68  1.10    gwr /*
     69  1.10    gwr  * The lance has only 24 address lines.  When it accesses memory,
     70  1.10    gwr  * the high address lines are hard-wired to 0xFF, so we must:
     71  1.10    gwr  * (1) put what we want the LANCE to see above 0xFF000000, and
     72  1.10    gwr  * (2) mask our CPU addresses down to 24 bits for the LANCE.
     73  1.10    gwr  */
     74  1.16    gwr #define	LANCE_ADDR(sc,x)	((u_int)(x) & 0xFFffff)
     75   1.1  glass 
     76  1.10    gwr #ifdef PACKETSTATS
     77  1.10    gwr long	lexpacketsizes[LEMTU+1];
     78  1.10    gwr long	lerpacketsizes[LEMTU+1];
     79  1.10    gwr #endif
     80  1.10    gwr 
     81  1.10    gwr /* autoconfiguration driver */
     82  1.15    gwr void	le_attach(struct device *, struct device *, void *);
     83  1.10    gwr 
     84  1.10    gwr struct	cfdriver lecd = {
     85  1.15    gwr 	NULL, "le", le_md_match, le_attach,
     86  1.10    gwr 	DV_IFNET, sizeof(struct le_softc),
     87  1.10    gwr };
     88  1.10    gwr 
     89  1.16    gwr int leioctl __P((struct ifnet *, u_long, caddr_t));
     90  1.17    gwr void lestart __P((struct ifnet *));
     91  1.17    gwr void lewatchdog __P((/* short */));
     92  1.16    gwr static inline void lewrcsr __P((/* struct le_softc *, u_short, u_short */));
     93  1.16    gwr static inline u_short lerdcsr __P((/* struct le_softc *, u_short */));
     94  1.16    gwr void leinit __P((struct le_softc *));
     95  1.16    gwr void lememinit __P((struct le_softc *));
     96  1.16    gwr void lereset __P((struct le_softc *));
     97  1.16    gwr void lestop __P((struct le_softc *));
     98  1.16    gwr void letint __P((struct le_softc *));
     99  1.16    gwr void lerint __P((struct le_softc *));
    100  1.16    gwr void leread __P((struct le_softc *, u_char *, int));
    101  1.16    gwr struct mbuf *leget __P((u_char *, int, struct ifnet *));
    102  1.16    gwr void lesetladrf __P((struct arpcom *, u_long *));
    103  1.16    gwr #ifdef LEDEBUG
    104  1.16    gwr void recv_print __P((struct le_softc *, int));
    105  1.16    gwr void xmit_print __P((struct le_softc *, int));
    106  1.16    gwr #endif
    107  1.16    gwr 
    108  1.16    gwr /*
    109  1.16    gwr  * Inline routines to read and write the LANCE registers.
    110  1.16    gwr  */
    111  1.16    gwr 
    112  1.16    gwr static inline void
    113  1.16    gwr lewrcsr(sc, regnum, value)
    114  1.16    gwr 	struct le_softc *sc;
    115  1.16    gwr 	u_short regnum;
    116  1.16    gwr 	u_short value;
    117  1.16    gwr {
    118  1.16    gwr 	volatile struct le_regs *regs = sc->sc_regs;
    119  1.16    gwr 
    120  1.16    gwr 	regs->lereg_addr = regnum;
    121  1.16    gwr 	regs->lereg_data = value;
    122  1.16    gwr }
    123  1.16    gwr 
    124  1.16    gwr static inline u_short
    125  1.16    gwr lerdcsr(sc, regnum)
    126  1.16    gwr 	struct le_softc *sc;
    127  1.16    gwr 	u_short regnum;
    128  1.16    gwr {
    129  1.16    gwr 	volatile struct le_regs *regs = sc->sc_regs;
    130  1.16    gwr 	u_short value;
    131  1.16    gwr 
    132  1.16    gwr 	regs->lereg_addr = regnum;
    133  1.16    gwr 	value = regs->lereg_data;
    134  1.16    gwr 
    135  1.16    gwr 	return (value);
    136  1.16    gwr }
    137  1.16    gwr 
    138  1.16    gwr /*
    139  1.16    gwr  * The probe is done in if_le_subr.c:if_md_match()
    140  1.16    gwr  */
    141   1.1  glass 
    142   1.1  glass /*
    143   1.1  glass  * Interface exists: make available by filling in network interface
    144   1.1  glass  * record.  System will initialize the interface when it is ready
    145  1.16    gwr  * to accept packets.  We get the ethernet address here.
    146   1.1  glass  */
    147  1.10    gwr void
    148  1.15    gwr le_attach(parent, self, aux)
    149  1.16    gwr 	struct device *parent, *self;
    150  1.15    gwr 	void *aux;
    151  1.10    gwr {
    152  1.16    gwr 	struct le_softc *sc = (void *)self;
    153  1.16    gwr 	struct confargs *ca = aux;
    154  1.10    gwr 	struct ifnet *ifp = &sc->sc_if;
    155  1.10    gwr 	int pri;
    156  1.10    gwr 	u_int a;
    157  1.10    gwr 
    158  1.15    gwr 	le_md_attach(parent, self, aux);
    159  1.16    gwr 	printf(" hwaddr %s\n", ether_sprintf(sc->sc_enaddr));
    160   1.1  glass 
    161  1.15    gwr 	/*
    162  1.15    gwr 	 * Initialize and attach S/W interface
    163  1.15    gwr 	 */
    164  1.10    gwr 	ifp->if_unit = sc->sc_dev.dv_unit;
    165  1.15    gwr 	ifp->if_name = lecd.cd_name;
    166   1.1  glass 	ifp->if_start = lestart;
    167  1.16    gwr 	ifp->if_ioctl = leioctl;
    168  1.16    gwr 	ifp->if_watchdog = lewatchdog;
    169  1.18    gwr 	ifp->if_flags =
    170  1.18    gwr 	    IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
    171  1.18    gwr 
    172  1.18    gwr 	/* Attach the interface. */
    173  1.15    gwr 	if_attach(ifp);
    174  1.15    gwr 	ether_ifattach(ifp);
    175   1.1  glass #if NBPFILTER > 0
    176  1.18    gwr 	bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
    177   1.1  glass #endif
    178   1.1  glass }
    179   1.1  glass 
    180  1.10    gwr void
    181  1.16    gwr lereset(sc)
    182  1.16    gwr 	struct le_softc *sc;
    183  1.10    gwr {
    184  1.10    gwr 
    185  1.16    gwr 	leinit(sc);
    186  1.16    gwr }
    187  1.10    gwr 
    188  1.17    gwr void
    189  1.16    gwr lewatchdog(unit)
    190  1.16    gwr 	short unit;
    191  1.16    gwr {
    192  1.16    gwr 	struct le_softc *sc = lecd.cd_devs[unit];
    193  1.10    gwr 
    194  1.16    gwr 	log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
    195  1.16    gwr 	++sc->sc_if.if_oerrors;
    196  1.16    gwr 	lereset(sc);
    197  1.10    gwr }
    198  1.10    gwr 
    199  1.16    gwr /* LANCE initialization block set up. */
    200  1.10    gwr void
    201  1.16    gwr lememinit(sc)
    202  1.16    gwr 	register struct le_softc *sc;
    203   1.1  glass {
    204  1.16    gwr 	struct ifnet *ifp = &sc->sc_if;
    205  1.16    gwr 	int i;
    206  1.16    gwr 	void *mem;
    207  1.16    gwr 	u_long a;
    208   1.1  glass 
    209  1.16    gwr 	/*
    210  1.16    gwr 	 * At this point we assume that the memory allocated to the Lance is
    211  1.16    gwr 	 * quadword aligned.  If it isn't then the initialisation is going
    212  1.16    gwr 	 * fail later on.
    213  1.16    gwr 	 */
    214  1.16    gwr 	mem = sc->sc_mem;
    215  1.10    gwr 
    216  1.16    gwr 	sc->sc_init = mem;
    217  1.10    gwr #if NBPFILTER > 0
    218  1.16    gwr 	if (ifp->if_flags & IFF_PROMISC)
    219  1.16    gwr 		sc->sc_init->mode = LE_NORMAL | LE_PROM;
    220  1.10    gwr 	else
    221  1.10    gwr #endif
    222  1.16    gwr 		sc->sc_init->mode = LE_NORMAL;
    223  1.10    gwr 
    224  1.16    gwr 	/* Set the Ethernet address (have to byte-swap) */
    225  1.16    gwr 	for (i = 0; i < 6; i += 2) {
    226  1.16    gwr 		sc->sc_init->padr[i] = sc->sc_enaddr[i+1];
    227  1.16    gwr 		sc->sc_init->padr[i+1] = sc->sc_enaddr[i];
    228  1.16    gwr 	}
    229  1.16    gwr 	lesetladrf(&sc->sc_ac, sc->sc_init->ladrf);
    230  1.16    gwr 	mem += sizeof(struct init_block);
    231  1.16    gwr 
    232  1.16    gwr 	sc->sc_rd = mem;
    233  1.16    gwr 	a = LANCE_ADDR(sc, mem);
    234  1.16    gwr 	sc->sc_init->rdra = a;
    235  1.16    gwr 	sc->sc_init->rlen = ((a >> 16) & 0xff) | (RLEN << 13);
    236  1.16    gwr 	mem += NRBUF * sizeof(struct mds);
    237  1.16    gwr 
    238  1.16    gwr 	sc->sc_td = mem;
    239  1.16    gwr 	a = LANCE_ADDR(sc, mem);
    240  1.16    gwr 	sc->sc_init->tdra = a;
    241  1.16    gwr 	sc->sc_init->tlen = ((a >> 16) & 0xff) | (TLEN << 13);
    242  1.16    gwr 	mem += NTBUF * sizeof(struct mds);
    243  1.10    gwr 
    244  1.16    gwr 	/*
    245  1.16    gwr 	 * Set up receive ring descriptors.
    246  1.16    gwr 	 */
    247  1.16    gwr 	sc->sc_rbuf = mem;
    248  1.16    gwr 	for (i = 0; i < NRBUF; i++) {
    249  1.16    gwr 		a = LANCE_ADDR(sc, mem);
    250  1.16    gwr 		sc->sc_rd[i].addr = a;
    251  1.16    gwr 		sc->sc_rd[i].flags = ((a >> 16) & 0xff) | LE_OWN;
    252  1.16    gwr 		sc->sc_rd[i].bcnt = -BUFSIZE;
    253  1.16    gwr 		sc->sc_rd[i].mcnt = 0;
    254  1.16    gwr 		mem += BUFSIZE;
    255  1.16    gwr 	}
    256  1.10    gwr 
    257  1.16    gwr 	/*
    258  1.16    gwr 	 * Set up transmit ring descriptors.
    259  1.10    gwr 	 */
    260  1.16    gwr 	sc->sc_tbuf = mem;
    261  1.16    gwr 	for (i = 0; i < NTBUF; i++) {
    262  1.16    gwr 		a = LANCE_ADDR(sc, mem);
    263  1.16    gwr 		sc->sc_td[i].addr = a;
    264  1.16    gwr 		sc->sc_td[i].flags= ((a >> 16) & 0xff);
    265  1.16    gwr 		sc->sc_td[i].bcnt = 0xf000;
    266  1.16    gwr 		sc->sc_td[i].mcnt = 0;
    267  1.16    gwr 		mem += BUFSIZE;
    268  1.10    gwr 	}
    269  1.16    gwr 
    270  1.16    gwr #ifdef	DIAGNOSTIC
    271  1.16    gwr 	if (mem > (sc->sc_mem + MEMSIZE))
    272  1.16    gwr 		panic("lememinit: used 0x%x\n", mem - sc->sc_mem);
    273  1.16    gwr #endif
    274  1.16    gwr }
    275  1.16    gwr 
    276  1.16    gwr void
    277  1.16    gwr lestop(sc)
    278  1.16    gwr 	struct le_softc *sc;
    279  1.16    gwr {
    280  1.16    gwr 
    281  1.16    gwr 	lewrcsr(sc, 0, LE_STOP);
    282   1.1  glass }
    283   1.1  glass 
    284  1.10    gwr /*
    285  1.16    gwr  * Initialization of interface; set up initialization block
    286  1.16    gwr  * and transmit/receive descriptor rings.
    287  1.10    gwr  */
    288  1.16    gwr void
    289  1.16    gwr leinit(sc)
    290  1.16    gwr 	register struct le_softc *sc;
    291   1.1  glass {
    292  1.16    gwr 	struct ifnet *ifp = &sc->sc_if;
    293  1.10    gwr 	int s;
    294  1.16    gwr 	register int timo;
    295  1.16    gwr 	u_long a;
    296  1.16    gwr 
    297  1.16    gwr 	/* Address not known. */
    298  1.16    gwr 	if (!ifp->if_addrlist)
    299  1.16    gwr 		return;
    300  1.10    gwr 
    301  1.16    gwr 	s = splimp();
    302   1.1  glass 
    303  1.16    gwr 	/* Don't want to get in a weird state. */
    304  1.16    gwr 	lewrcsr(sc, 0, LE_STOP);
    305  1.16    gwr 	delay(100);
    306  1.16    gwr 
    307  1.16    gwr 	sc->sc_last_rd = sc->sc_last_td = sc->sc_no_td = 0;
    308  1.16    gwr 
    309  1.16    gwr 	/* Set up LANCE init block. */
    310  1.16    gwr 	lememinit(sc);
    311  1.16    gwr 
    312  1.16    gwr 	/* Set byte swapping etc. */
    313  1.16    gwr 	lewrcsr(sc, 3, LE_CONF3);
    314  1.16    gwr 
    315  1.16    gwr 	/* Give LANCE the physical address of its init block. */
    316  1.16    gwr 	a = LANCE_ADDR(sc, sc->sc_init);
    317  1.16    gwr 	lewrcsr(sc, 1, a);
    318  1.16    gwr 	lewrcsr(sc, 2, (a >> 16) & 0xff);
    319  1.16    gwr 
    320  1.16    gwr 	/* Try to initialize the LANCE. */
    321  1.16    gwr 	delay(100);
    322  1.16    gwr 	lewrcsr(sc, 0, LE_INIT);
    323  1.16    gwr 
    324  1.16    gwr 	/* Wait for initialization to finish. */
    325  1.16    gwr 	for (timo = 1000; timo; timo--)
    326  1.16    gwr 		if (lerdcsr(sc, 0) & LE_IDON)
    327  1.16    gwr 			break;
    328  1.10    gwr 
    329  1.16    gwr 	if (lerdcsr(sc, 0) & LE_IDON) {
    330  1.16    gwr 		/* Start the LANCE. */
    331  1.16    gwr 		lewrcsr(sc, 0, LE_INEA | LE_STRT | LE_IDON);
    332  1.16    gwr 		ifp->if_flags |= IFF_RUNNING;
    333  1.16    gwr 		ifp->if_flags &= ~IFF_OACTIVE;
    334  1.16    gwr 		lestart(ifp);
    335  1.16    gwr 	} else
    336  1.16    gwr 		printf("%s: card failed to initialize\n", sc->sc_dev.dv_xname);
    337  1.16    gwr 
    338  1.16    gwr 	(void) splx(s);
    339   1.1  glass }
    340   1.1  glass 
    341   1.1  glass /*
    342  1.16    gwr  * Controller interrupt.
    343   1.1  glass  */
    344  1.10    gwr int
    345  1.16    gwr leintr(vsc)
    346  1.16    gwr 	void *vsc;
    347   1.1  glass {
    348  1.16    gwr 	register struct le_softc *sc = vsc;
    349  1.16    gwr 	register u_short isr;
    350  1.16    gwr 
    351  1.16    gwr 	isr = lerdcsr(sc, 0);
    352  1.16    gwr #ifdef LEDEBUG
    353  1.16    gwr 	if (sc->sc_debug)
    354  1.16    gwr 		printf("%s: leintr entering with isr=%04x\n",
    355  1.16    gwr 		    sc->sc_dev.dv_xname, isr);
    356  1.16    gwr #endif
    357  1.16    gwr 	if ((isr & LE_INTR) == 0)
    358  1.16    gwr 		return 0;
    359  1.16    gwr 
    360  1.16    gwr 	do {
    361  1.16    gwr 		lewrcsr(sc, 0,
    362  1.16    gwr 		    isr & (LE_INEA | LE_BABL | LE_MISS | LE_MERR |
    363  1.16    gwr 			   LE_RINT | LE_TINT | LE_IDON));
    364  1.16    gwr 		if (isr & (LE_BABL | LE_CERR | LE_MISS | LE_MERR)) {
    365  1.16    gwr 			if (isr & LE_BABL) {
    366  1.16    gwr 				printf("%s: babble\n", sc->sc_dev.dv_xname);
    367  1.16    gwr 				sc->sc_if.if_oerrors++;
    368  1.16    gwr 			}
    369  1.16    gwr #if 0
    370  1.16    gwr 			if (isr & LE_CERR) {
    371  1.16    gwr 				printf("%s: collision error\n", sc->sc_dev.dv_xname);
    372  1.16    gwr 				sc->sc_if.if_collisions++;
    373  1.16    gwr 			}
    374  1.16    gwr #endif
    375  1.16    gwr 			if (isr & LE_MISS) {
    376  1.16    gwr #if 0
    377  1.16    gwr 				printf("%s: missed packet\n", sc->sc_dev.dv_xname);
    378  1.16    gwr #endif
    379  1.16    gwr 				sc->sc_if.if_ierrors++;
    380  1.16    gwr 			}
    381  1.16    gwr 			if (isr & LE_MERR) {
    382  1.16    gwr 				printf("%s: memory error\n", sc->sc_dev.dv_xname);
    383  1.16    gwr 				lereset(sc);
    384  1.16    gwr 				goto out;
    385  1.16    gwr 			}
    386  1.16    gwr 		}
    387  1.16    gwr 
    388  1.16    gwr 		if ((isr & LE_RXON) == 0) {
    389  1.16    gwr 			printf("%s: receiver disabled\n", sc->sc_dev.dv_xname);
    390  1.16    gwr 			sc->sc_if.if_ierrors++;
    391  1.16    gwr 			lereset(sc);
    392  1.16    gwr 			goto out;
    393  1.16    gwr 		}
    394  1.16    gwr 		if ((isr & LE_TXON) == 0) {
    395  1.16    gwr 			printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname);
    396  1.16    gwr 			sc->sc_if.if_oerrors++;
    397  1.16    gwr 			lereset(sc);
    398  1.16    gwr 			goto out;
    399  1.16    gwr 		}
    400  1.16    gwr 
    401  1.16    gwr 		if (isr & LE_RINT) {
    402  1.16    gwr 			/* Reset watchdog timer. */
    403  1.16    gwr 			sc->sc_if.if_timer = 0;
    404  1.16    gwr 			lerint(sc);
    405  1.16    gwr 		}
    406  1.16    gwr 		if (isr & LE_TINT) {
    407  1.16    gwr 			/* Reset watchdog timer. */
    408  1.16    gwr 			sc->sc_if.if_timer = 0;
    409  1.16    gwr 			letint(sc);
    410  1.16    gwr 		}
    411  1.16    gwr 
    412  1.16    gwr 		isr = lerdcsr(sc, 0);
    413  1.16    gwr 	} while ((isr & LE_INTR) != 0);
    414  1.16    gwr 
    415  1.16    gwr #ifdef LEDEBUG
    416  1.16    gwr 	if (sc->sc_debug)
    417  1.16    gwr 		printf("%s: leintr returning with isr=%04x\n",
    418  1.16    gwr 		    sc->sc_dev.dv_xname, isr);
    419  1.16    gwr #endif
    420   1.1  glass 
    421  1.16    gwr out:
    422  1.16    gwr 	return 1;
    423   1.1  glass }
    424   1.1  glass 
    425  1.16    gwr #define NEXTTDS \
    426  1.16    gwr 	if (++tmd == NTBUF) tmd=0, cdm=sc->sc_td; else ++cdm
    427  1.16    gwr 
    428   1.1  glass /*
    429  1.16    gwr  * Setup output on interface.
    430  1.16    gwr  * Get another datagram to send off of the interface queue, and map it to the
    431  1.16    gwr  * interface before starting the output.
    432  1.16    gwr  * Called only at splimp or interrupt level.
    433   1.1  glass  */
    434  1.17    gwr void
    435  1.10    gwr lestart(ifp)
    436  1.16    gwr 	struct ifnet *ifp;
    437   1.1  glass {
    438  1.10    gwr 	register struct le_softc *sc = lecd.cd_devs[ifp->if_unit];
    439  1.16    gwr 	register int tmd;
    440  1.16    gwr 	volatile struct mds *cdm;
    441  1.16    gwr 	struct mbuf *m0, *m;
    442  1.16    gwr 	u_char *buffer;
    443  1.16    gwr 	int len;
    444  1.10    gwr 
    445  1.16    gwr 	if ((sc->sc_if.if_flags & (IFF_RUNNING | IFF_OACTIVE)) !=
    446  1.16    gwr 	    IFF_RUNNING)
    447  1.16    gwr 		return;
    448  1.16    gwr 
    449  1.16    gwr 	tmd = sc->sc_last_td;
    450  1.16    gwr 	cdm = &sc->sc_td[tmd];
    451  1.16    gwr 
    452  1.16    gwr 	for (;;) {
    453  1.16    gwr 		if (sc->sc_no_td >= NTBUF) {
    454  1.16    gwr 			sc->sc_if.if_flags |= IFF_OACTIVE;
    455  1.16    gwr #ifdef LEDEBUG
    456  1.16    gwr 			if (sc->sc_debug)
    457  1.16    gwr 				printf("no_td = %d, last_td = %d\n", sc->sc_no_td,
    458  1.16    gwr 				    sc->sc_last_td);
    459  1.10    gwr #endif
    460  1.16    gwr 			break;
    461  1.16    gwr 		}
    462  1.10    gwr 
    463  1.16    gwr #ifdef LEDEBUG
    464  1.16    gwr 		if (cdm->flags & LE_OWN) {
    465  1.16    gwr 			sc->sc_if.if_flags |= IFF_OACTIVE;
    466  1.16    gwr 			printf("missing buffer, no_td = %d, last_td = %d\n",
    467  1.16    gwr 			    sc->sc_no_td, sc->sc_last_td);
    468  1.16    gwr 		}
    469   1.1  glass #endif
    470  1.10    gwr 
    471  1.16    gwr 		IF_DEQUEUE(&sc->sc_if.if_snd, m);
    472  1.16    gwr 		if (!m)
    473  1.16    gwr 			break;
    474  1.10    gwr 
    475  1.16    gwr 		++sc->sc_no_td;
    476  1.16    gwr 
    477  1.16    gwr 		/*
    478  1.16    gwr 		 * Copy the mbuf chain into the transmit buffer.
    479  1.16    gwr 		 */
    480  1.16    gwr 		buffer = sc->sc_tbuf + (BUFSIZE * sc->sc_last_td);
    481  1.16    gwr 		len = 0;
    482  1.16    gwr 		for (m0 = m; m; m = m->m_next) {
    483  1.16    gwr 			bcopy(mtod(m, caddr_t), buffer, m->m_len);
    484  1.16    gwr 			buffer += m->m_len;
    485  1.16    gwr 			len += m->m_len;
    486  1.16    gwr 		}
    487  1.10    gwr 
    488  1.16    gwr #ifdef LEDEBUG
    489  1.16    gwr 		if (len > ETHER_MAX_LEN)
    490  1.16    gwr 			printf("packet length %d\n", len);
    491  1.16    gwr #endif
    492  1.10    gwr 
    493  1.16    gwr #if NBPFILTER > 0
    494  1.16    gwr 		if (sc->sc_if.if_bpf)
    495  1.16    gwr 			bpf_mtap(sc->sc_if.if_bpf, m0);
    496  1.16    gwr #endif
    497  1.15    gwr 
    498  1.16    gwr 		m_freem(m0);
    499  1.16    gwr 		len = max(len, ETHER_MIN_LEN);
    500  1.15    gwr 
    501  1.16    gwr 		/*
    502  1.16    gwr 		 * Init transmit registers, and set transmit start flag.
    503  1.16    gwr 		 */
    504  1.16    gwr 		cdm->bcnt = -len;
    505  1.16    gwr 		cdm->mcnt = 0;
    506  1.16    gwr 		cdm->flags |= LE_OWN | LE_STP | LE_ENP;
    507  1.10    gwr 
    508  1.16    gwr #ifdef LEDEBUG
    509  1.16    gwr 		if (sc->sc_debug)
    510  1.16    gwr 			xmit_print(sc, sc->sc_last_td);
    511  1.16    gwr #endif
    512  1.16    gwr 
    513  1.16    gwr 		lewrcsr(sc, 0, LE_INEA | LE_TDMD);
    514  1.10    gwr 
    515  1.16    gwr 		NEXTTDS;
    516  1.10    gwr 	}
    517  1.16    gwr 
    518  1.16    gwr 	sc->sc_last_td = tmd;
    519   1.1  glass }
    520   1.1  glass 
    521  1.10    gwr void
    522  1.16    gwr letint(sc)
    523  1.16    gwr 	struct le_softc *sc;
    524  1.10    gwr {
    525  1.16    gwr 	register int tmd = (sc->sc_last_td - sc->sc_no_td + NTBUF) % NTBUF;
    526  1.16    gwr 	volatile struct mds *cdm;
    527  1.10    gwr 
    528  1.16    gwr 	cdm = &sc->sc_td[tmd];
    529  1.16    gwr 	if (cdm->flags & LE_OWN) {
    530  1.16    gwr 		/* Race condition with loop below. */
    531  1.16    gwr #ifdef LEDEBUG
    532  1.16    gwr 		if (sc->sc_debug)
    533  1.16    gwr 			printf("%s: extra tint\n", sc->sc_dev.dv_xname);
    534  1.16    gwr #endif
    535   1.1  glass 		return;
    536   1.1  glass 	}
    537  1.16    gwr 
    538  1.16    gwr 	sc->sc_if.if_flags &= ~IFF_OACTIVE;
    539  1.16    gwr 
    540  1.16    gwr 	do {
    541  1.16    gwr 		if (sc->sc_no_td <= 0)
    542  1.16    gwr 			break;
    543  1.16    gwr #ifdef LEDEBUG
    544  1.16    gwr 		if (sc->sc_debug)
    545  1.16    gwr 			printf("trans cdm = %x\n", cdm);
    546  1.16    gwr #endif
    547  1.16    gwr 		sc->sc_if.if_opackets++;
    548  1.16    gwr 		--sc->sc_no_td;
    549  1.16    gwr 		if (cdm->mcnt & (LE_TBUFF | LE_UFLO | LE_LCOL | LE_LCAR | LE_RTRY)) {
    550  1.16    gwr 			if (cdm->mcnt & LE_TBUFF)
    551  1.16    gwr 				printf("%s: transmit buffer error\n", sc->sc_dev.dv_xname);
    552  1.16    gwr 			if ((cdm->mcnt & (LE_TBUFF | LE_UFLO)) == LE_UFLO)
    553  1.16    gwr 				printf("%s: underflow\n", sc->sc_dev.dv_xname);
    554  1.16    gwr 			if (cdm->mcnt & LE_UFLO) {
    555  1.16    gwr 				lereset(sc);
    556  1.16    gwr 				return;
    557  1.16    gwr 			}
    558  1.16    gwr #if 0
    559  1.16    gwr 			if (cdm->mcnt & LE_LCOL) {
    560  1.16    gwr 				printf("%s: late collision\n", sc->sc_dev.dv_xname);
    561  1.16    gwr 				sc->sc_if.if_collisions++;
    562  1.16    gwr 			}
    563  1.16    gwr 			if (cdm->mcnt & LE_LCAR)
    564  1.16    gwr 				printf("%s: lost carrier\n", sc->sc_dev.dv_xname);
    565  1.16    gwr 			if (cdm->mcnt & LE_RTRY) {
    566  1.16    gwr 				printf("%s: excessive collisions, tdr %d\n",
    567  1.16    gwr 				    sc->sc_dev.dv_xname, cdm->flags & 0x1ff);
    568  1.16    gwr 				sc->sc_if.if_collisions += 16;
    569  1.16    gwr 			}
    570  1.16    gwr #endif
    571  1.16    gwr 		} else if (cdm->flags & LE_ONE)
    572  1.10    gwr 			sc->sc_if.if_collisions++;
    573  1.16    gwr 		else if (cdm->flags & LE_MORE)
    574  1.16    gwr 			/* Real number is unknown. */
    575  1.16    gwr 			sc->sc_if.if_collisions += 2;
    576  1.16    gwr 		NEXTTDS;
    577  1.16    gwr 	} while ((cdm->flags & LE_OWN) == 0);
    578  1.16    gwr 
    579  1.10    gwr 	lestart(&sc->sc_if);
    580   1.1  glass }
    581   1.1  glass 
    582  1.16    gwr #define NEXTRDS \
    583  1.16    gwr 	if (++rmd == NRBUF) rmd=0, cdm=sc->sc_rd; else ++cdm
    584  1.16    gwr 
    585  1.16    gwr /* only called from one place, so may as well integrate */
    586  1.10    gwr void
    587  1.10    gwr lerint(sc)
    588  1.16    gwr 	struct le_softc *sc;
    589   1.1  glass {
    590  1.16    gwr 	register int rmd = sc->sc_last_rd;
    591  1.16    gwr 	volatile struct mds *cdm;
    592   1.1  glass 
    593  1.16    gwr 	cdm = &sc->sc_rd[rmd];
    594  1.16    gwr 	if (cdm->flags & LE_OWN) {
    595  1.16    gwr 		/* Race condition with loop below. */
    596  1.16    gwr #ifdef LEDEBUG
    597  1.16    gwr 		if (sc->sc_debug)
    598  1.16    gwr 			printf("%s: extra rint\n", sc->sc_dev.dv_xname);
    599  1.16    gwr #endif
    600  1.16    gwr 		return;
    601  1.16    gwr 	}
    602   1.1  glass 
    603  1.16    gwr 	/* Process all buffers with valid data. */
    604  1.16    gwr 	do {
    605  1.19    gwr 		if (cdm->flags & LE_ERR) {
    606  1.19    gwr #ifdef	LEDEBUG
    607  1.19    gwr 			/*
    608  1.19    gwr 			 * XXX - These happen a LOT on the Sun3/50 so
    609  1.19    gwr 			 * it is really NOT appropriate to print them.
    610  1.19    gwr 			 */
    611  1.19    gwr 			printf("%s: error, cdm->flags=%b\n",
    612  1.19    gwr 				sc->sc_dev.dv_xname, cdm->flags, RMD_BITS);
    613  1.19    gwr #endif
    614  1.19    gwr 			sc->sc_if.if_ierrors++;
    615  1.16    gwr 		} else if (cdm->flags & (LE_STP | LE_ENP) != (LE_STP | LE_ENP)) {
    616   1.1  glass 			do {
    617  1.16    gwr 				cdm->mcnt = 0;
    618  1.16    gwr 				cdm->flags |= LE_OWN;
    619  1.16    gwr 				NEXTRDS;
    620  1.16    gwr 			} while ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) == 0);
    621  1.16    gwr 			sc->sc_last_rd = rmd;
    622  1.16    gwr 			printf("%s: chained buffer\n", sc->sc_dev.dv_xname);
    623  1.16    gwr 			if ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) != LE_ENP) {
    624  1.16    gwr 				lereset(sc);
    625   1.1  glass 				return;
    626   1.1  glass 			}
    627  1.10    gwr 		} else {
    628  1.16    gwr #ifdef LEDEBUG
    629  1.16    gwr 			if (sc->sc_debug)
    630  1.16    gwr 				recv_print(sc, sc->sc_last_rd);
    631  1.16    gwr #endif
    632  1.16    gwr 			leread(sc, sc->sc_rbuf + (BUFSIZE * rmd),
    633  1.16    gwr 			    (int)cdm->mcnt);
    634  1.16    gwr 			sc->sc_if.if_ipackets++;
    635  1.16    gwr 		}
    636  1.16    gwr 
    637  1.16    gwr 		cdm->bcnt = -BUFSIZE;
    638  1.16    gwr 		cdm->mcnt = 0;
    639  1.16    gwr 		cdm->flags |= LE_OWN;
    640  1.16    gwr 		NEXTRDS;
    641  1.16    gwr #ifdef LEDEBUG
    642  1.16    gwr 		if (sc->sc_debug)
    643  1.16    gwr 			printf("sc->sc_last_rd = %x, cdm = %x\n",
    644  1.16    gwr 			    sc->sc_last_rd, cdm);
    645  1.10    gwr #endif
    646  1.16    gwr 	} while ((cdm->flags & LE_OWN) == 0);
    647  1.16    gwr 
    648  1.16    gwr 	sc->sc_last_rd = rmd;
    649   1.1  glass }
    650   1.1  glass 
    651  1.16    gwr /*
    652  1.16    gwr  * Pass a packet to the higher levels.
    653  1.16    gwr  */
    654  1.10    gwr void
    655  1.16    gwr leread(sc, buf, len)
    656  1.10    gwr 	register struct le_softc *sc;
    657  1.16    gwr 	u_char *buf;
    658   1.1  glass 	int len;
    659   1.1  glass {
    660  1.16    gwr 	struct ifnet *ifp;
    661  1.10    gwr 	struct mbuf *m;
    662  1.16    gwr 	struct ether_header *eh;
    663  1.16    gwr 
    664  1.16    gwr 	len -= 4;
    665  1.16    gwr 	if (len <= 0)
    666  1.16    gwr 		return;
    667  1.20    gwr 
    668  1.20    gwr #ifdef	LANCE_REVC_BUG
    669  1.20    gwr 	/*
    670  1.20    gwr 	 * Check for unreported packet errors.  Rev C of the LANCE chip
    671  1.20    gwr 	 * has a bug which can cause "random" bytes to be prepended to
    672  1.20    gwr 	 * the start of the packet.  The work-around is to make sure that
    673  1.20    gwr 	 * the Ethernet destination address in the packet matches our
    674  1.20    gwr 	 * address (or the broadcast address).  XXX - Multicasts?
    675  1.20    gwr 	 */
    676  1.20    gwr 	{
    677  1.20    gwr 		register short *pp, *ea;
    678  1.20    gwr 		pp = (short *) buf;
    679  1.20    gwr 		ea = (short *) &sc->sc_enaddr;
    680  1.20    gwr 		if (((pp[0] != ea[0]) || (pp[1] != ea[1]) || (pp[2] != ea[2])) &&
    681  1.20    gwr 			((pp[0] != -1)    || (pp[1] != -1)    || (pp[2] != -1)   ))
    682  1.20    gwr 		{
    683  1.20    gwr 			sc->sc_if.if_ierrors++;
    684  1.20    gwr 			printf("%s: LANCE Rev C Extra Byte(s) bug; Packet punted\n",
    685  1.20    gwr 				   sc->sc_dev.dv_xname);
    686  1.20    gwr 			return;
    687  1.20    gwr 		}
    688  1.20    gwr 	}
    689  1.20    gwr #endif	/* LANCE_REVC_BUG */
    690   1.1  glass 
    691  1.16    gwr 	/* Pull packet off interface. */
    692  1.16    gwr 	ifp = &sc->sc_if;
    693  1.16    gwr 	m = leget(buf, len, ifp);
    694  1.16    gwr 	if (m == 0)
    695   1.1  glass 		return;
    696  1.10    gwr 
    697  1.16    gwr 	/* We assume that the header fit entirely in one mbuf. */
    698  1.16    gwr 	eh = mtod(m, struct ether_header *);
    699  1.10    gwr 
    700   1.1  glass #if NBPFILTER > 0
    701   1.1  glass 	/*
    702  1.16    gwr 	 * Check if there's a BPF listener on this interface.
    703  1.16    gwr 	 * If so, hand off the raw packet to BPF.
    704   1.1  glass 	 */
    705  1.10    gwr 	if (ifp->if_bpf) {
    706  1.16    gwr 		bpf_mtap(ifp->if_bpf, m);
    707  1.16    gwr 
    708  1.16    gwr 		/*
    709  1.16    gwr 		 * Note that the interface cannot be in promiscuous mode if
    710  1.16    gwr 		 * there are no BPF listeners.  And if we are in promiscuous
    711  1.16    gwr 		 * mode, we have to check if this packet is really ours.
    712  1.16    gwr 		 */
    713  1.16    gwr 		if ((ifp->if_flags & IFF_PROMISC) &&
    714  1.16    gwr 		    (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
    715  1.16    gwr 		    bcmp(eh->ether_dhost, sc->sc_enaddr,
    716  1.16    gwr 			    sizeof(eh->ether_dhost)) != 0) {
    717  1.16    gwr 			m_freem(m);
    718   1.1  glass 			return;
    719  1.16    gwr 		}
    720   1.1  glass 	}
    721   1.1  glass #endif
    722   1.1  glass 
    723  1.16    gwr 	/* We assume that the header fit entirely in one mbuf. */
    724  1.16    gwr 	m->m_pkthdr.len -= sizeof(*eh);
    725  1.16    gwr 	m->m_len -= sizeof(*eh);
    726  1.16    gwr 	m->m_data += sizeof(*eh);
    727  1.16    gwr 
    728  1.16    gwr 	ether_input(ifp, eh, m);
    729   1.1  glass }
    730   1.1  glass 
    731   1.1  glass /*
    732  1.16    gwr  * Supporting routines
    733   1.1  glass  */
    734   1.1  glass 
    735   1.1  glass /*
    736  1.16    gwr  * Pull data off an interface.
    737  1.16    gwr  * Len is length of data, with local net header stripped.
    738  1.16    gwr  * We copy the data into mbufs.  When full cluster sized units are present
    739  1.16    gwr  * we copy into clusters.
    740   1.1  glass  */
    741   1.1  glass struct mbuf *
    742  1.16    gwr leget(buf, totlen, ifp)
    743  1.16    gwr 	u_char *buf;
    744  1.16    gwr 	int totlen;
    745   1.1  glass 	struct ifnet *ifp;
    746   1.1  glass {
    747  1.16    gwr 	struct mbuf *top, **mp, *m;
    748  1.16    gwr 	int len;
    749   1.1  glass 
    750   1.1  glass 	MGETHDR(m, M_DONTWAIT, MT_DATA);
    751   1.1  glass 	if (m == 0)
    752  1.16    gwr 		return 0;
    753   1.1  glass 	m->m_pkthdr.rcvif = ifp;
    754   1.1  glass 	m->m_pkthdr.len = totlen;
    755  1.16    gwr 	len = MHLEN;
    756  1.16    gwr 	top = 0;
    757  1.16    gwr 	mp = &top;
    758   1.1  glass 
    759   1.1  glass 	while (totlen > 0) {
    760   1.1  glass 		if (top) {
    761   1.1  glass 			MGET(m, M_DONTWAIT, MT_DATA);
    762   1.1  glass 			if (m == 0) {
    763   1.1  glass 				m_freem(top);
    764  1.16    gwr 				return 0;
    765   1.1  glass 			}
    766  1.16    gwr 			len = MLEN;
    767   1.1  glass 		}
    768  1.16    gwr 		if (totlen >= MINCLSIZE) {
    769   1.1  glass 			MCLGET(m, M_DONTWAIT);
    770   1.1  glass 			if (m->m_flags & M_EXT)
    771  1.16    gwr 				len = MCLBYTES;
    772   1.1  glass 		}
    773  1.16    gwr 		m->m_len = len = min(totlen, len);
    774  1.16    gwr 		bcopy((caddr_t)buf, mtod(m, caddr_t), len);
    775  1.16    gwr 		buf += len;
    776  1.16    gwr 		totlen -= len;
    777   1.1  glass 		*mp = m;
    778   1.1  glass 		mp = &m->m_next;
    779   1.1  glass 	}
    780  1.16    gwr 
    781  1.16    gwr 	return top;
    782   1.1  glass }
    783   1.1  glass 
    784   1.1  glass /*
    785   1.1  glass  * Process an ioctl request.
    786   1.1  glass  */
    787  1.10    gwr int
    788   1.1  glass leioctl(ifp, cmd, data)
    789   1.1  glass 	register struct ifnet *ifp;
    790  1.14    gwr 	u_long cmd;
    791   1.1  glass 	caddr_t data;
    792   1.1  glass {
    793  1.16    gwr 	struct le_softc *sc = lecd.cd_devs[ifp->if_unit];
    794  1.16    gwr 	struct ifaddr *ifa = (struct ifaddr *)data;
    795  1.16    gwr 	struct ifreq *ifr = (struct ifreq *)data;
    796  1.16    gwr 	int s, error = 0;
    797  1.10    gwr 
    798  1.16    gwr 	s = splimp();
    799   1.1  glass 
    800   1.1  glass 	switch (cmd) {
    801   1.1  glass 
    802   1.1  glass 	case SIOCSIFADDR:
    803   1.1  glass 		ifp->if_flags |= IFF_UP;
    804  1.16    gwr 
    805   1.1  glass 		switch (ifa->ifa_addr->sa_family) {
    806   1.1  glass #ifdef INET
    807   1.1  glass 		case AF_INET:
    808  1.18    gwr 			leinit(sc);
    809  1.18    gwr 			arp_ifinit(&sc->sc_ac, ifa);
    810   1.1  glass 			break;
    811   1.1  glass #endif
    812   1.1  glass #ifdef NS
    813  1.16    gwr 		/* XXX - This code is probably wrong. */
    814   1.1  glass 		case AF_NS:
    815   1.1  glass 		    {
    816  1.16    gwr 			register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
    817   1.1  glass 
    818   1.1  glass 			if (ns_nullhost(*ina))
    819  1.16    gwr 				ina->x_host =
    820  1.16    gwr 				    *(union ns_host *)(sc->sc_enaddr);
    821  1.16    gwr 			else
    822  1.16    gwr 				bcopy(ina->x_host.c_host,
    823  1.16    gwr 				    sc->sc_enaddr,
    824  1.16    gwr 				    sizeof(sc->sc_enaddr));
    825  1.16    gwr 			/* Set new address. */
    826  1.16    gwr 			leinit(sc);
    827   1.1  glass 			break;
    828   1.1  glass 		    }
    829   1.1  glass #endif
    830   1.1  glass 		default:
    831  1.16    gwr 			leinit(sc);
    832   1.1  glass 			break;
    833   1.1  glass 		}
    834   1.1  glass 		break;
    835   1.1  glass 
    836   1.1  glass 	case SIOCSIFFLAGS:
    837  1.16    gwr 		/*
    838  1.16    gwr 		 * If interface is marked down and it is running, then stop it
    839  1.16    gwr 		 */
    840   1.1  glass 		if ((ifp->if_flags & IFF_UP) == 0 &&
    841  1.16    gwr 		    (ifp->if_flags & IFF_RUNNING) != 0) {
    842  1.16    gwr 			/*
    843  1.16    gwr 			 * If interface is marked down and it is running, then
    844  1.16    gwr 			 * stop it.
    845  1.16    gwr 			 */
    846  1.16    gwr 			lestop(sc);
    847   1.1  glass 			ifp->if_flags &= ~IFF_RUNNING;
    848  1.16    gwr 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
    849  1.16    gwr 		    	   (ifp->if_flags & IFF_RUNNING) == 0) {
    850  1.16    gwr 			/*
    851  1.16    gwr 			 * If interface is marked up and it is stopped, then
    852  1.16    gwr 			 * start it.
    853  1.16    gwr 			 */
    854  1.16    gwr 			leinit(sc);
    855  1.16    gwr 		} else {
    856  1.16    gwr 			/*
    857  1.16    gwr 			 * Reset the interface to pick up changes in any other
    858  1.16    gwr 			 * flags that affect hardware registers.
    859  1.16    gwr 			 */
    860  1.16    gwr 			/*lestop(sc);*/
    861  1.16    gwr 			leinit(sc);
    862  1.10    gwr 		}
    863  1.16    gwr #ifdef LEDEBUG
    864  1.16    gwr 		if (ifp->if_flags & IFF_DEBUG)
    865  1.16    gwr 			sc->sc_debug = 1;
    866  1.16    gwr 		else
    867  1.16    gwr 			sc->sc_debug = 0;
    868  1.16    gwr #endif
    869  1.10    gwr 		break;
    870  1.10    gwr 
    871  1.10    gwr 	case SIOCADDMULTI:
    872  1.16    gwr 	case SIOCDELMULTI:
    873  1.16    gwr 		error = (cmd == SIOCADDMULTI) ?
    874  1.16    gwr 		    ether_addmulti(ifr, &sc->sc_ac):
    875  1.16    gwr 		    ether_delmulti(ifr, &sc->sc_ac);
    876  1.10    gwr 
    877  1.10    gwr 		if (error == ENETRESET) {
    878  1.10    gwr 			/*
    879  1.16    gwr 			 * Multicast list has changed; set the hardware filter
    880  1.16    gwr 			 * accordingly.
    881  1.10    gwr 			 */
    882  1.16    gwr 			leinit(sc);
    883  1.10    gwr 			error = 0;
    884   1.1  glass 		}
    885   1.1  glass 		break;
    886   1.1  glass 
    887   1.1  glass 	default:
    888   1.1  glass 		error = EINVAL;
    889   1.1  glass 	}
    890  1.16    gwr 	(void) splx(s);
    891  1.16    gwr 	return error;
    892  1.16    gwr }
    893  1.16    gwr 
    894  1.16    gwr #ifdef LEDEBUG
    895  1.16    gwr void
    896  1.16    gwr recv_print(sc, no)
    897  1.16    gwr 	struct le_softc *sc;
    898  1.16    gwr 	int no;
    899  1.16    gwr {
    900  1.16    gwr 	struct mds *rmd;
    901  1.16    gwr 	int i, printed = 0;
    902  1.16    gwr 	u_short len;
    903  1.16    gwr 
    904  1.16    gwr 	rmd = &sc->sc_rd[no];
    905  1.16    gwr 	len = rmd->mcnt;
    906  1.16    gwr 	printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
    907  1.16    gwr 	    len);
    908  1.16    gwr 	printf("%s: status %x\n", sc->sc_dev.dv_xname, lerdcsr(sc, 0));
    909  1.16    gwr 	for (i = 0; i < len; i++) {
    910  1.16    gwr 		if (!printed) {
    911  1.16    gwr 			printed = 1;
    912  1.16    gwr 			printf("%s: data: ", sc->sc_dev.dv_xname);
    913  1.16    gwr 		}
    914  1.16    gwr 		printf("%x ", *(sc->sc_rbuf + (BUFSIZE*no) + i));
    915  1.16    gwr 	}
    916  1.16    gwr 	if (printed)
    917  1.16    gwr 		printf("\n");
    918  1.16    gwr }
    919  1.16    gwr 
    920  1.16    gwr void
    921  1.16    gwr xmit_print(sc, no)
    922  1.16    gwr 	struct le_softc *sc;
    923  1.16    gwr 	int no;
    924  1.16    gwr {
    925  1.16    gwr 	struct mds *rmd;
    926  1.16    gwr 	int i, printed=0;
    927  1.16    gwr 	u_short len;
    928  1.16    gwr 
    929  1.16    gwr 	rmd = &sc->sc_td[no];
    930  1.16    gwr 	len = -rmd->bcnt;
    931  1.16    gwr 	printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
    932  1.16    gwr 	    len);
    933  1.16    gwr 	printf("%s: status %x\n", sc->sc_dev.dv_xname, lerdcsr(sc, 0));
    934  1.16    gwr 	printf("%s: addr %x, flags %x, bcnt %x, mcnt %x\n",
    935  1.16    gwr 	    sc->sc_dev.dv_xname, rmd->addr, rmd->flags, rmd->bcnt, rmd->mcnt);
    936  1.16    gwr 	for (i = 0; i < len; i++)  {
    937  1.16    gwr 		if (!printed) {
    938  1.16    gwr 			printed = 1;
    939  1.16    gwr 			printf("%s: data: ", sc->sc_dev.dv_xname);
    940  1.16    gwr 		}
    941  1.16    gwr 		printf("%x ", *(sc->sc_tbuf + (BUFSIZE*no) + i));
    942  1.16    gwr 	}
    943  1.16    gwr 	if (printed)
    944  1.16    gwr 		printf("\n");
    945   1.1  glass }
    946  1.16    gwr #endif /* LEDEBUG */
    947   1.1  glass 
    948  1.16    gwr /*
    949  1.16    gwr  * Set up the logical address filter.
    950  1.16    gwr  */
    951  1.10    gwr void
    952  1.16    gwr lesetladrf(ac, af)
    953  1.16    gwr 	struct arpcom *ac;
    954  1.16    gwr 	u_long *af;
    955   1.1  glass {
    956  1.16    gwr 	struct ifnet *ifp = &ac->ac_if;
    957  1.16    gwr 	struct ether_multi *enm;
    958  1.16    gwr 	register u_char *cp, c;
    959  1.16    gwr 	register u_long crc;
    960  1.16    gwr 	register int i, len;
    961  1.16    gwr 	struct ether_multistep step;
    962   1.1  glass 
    963   1.1  glass 	/*
    964  1.16    gwr 	 * Set up multicast address filter by passing all multicast addresses
    965  1.16    gwr 	 * through a crc generator, and then using the high order 6 bits as an
    966  1.16    gwr 	 * index into the 64 bit logical address filter.  The high order bit
    967  1.16    gwr 	 * selects the word, while the rest of the bits select the bit within
    968  1.16    gwr 	 * the word.
    969   1.1  glass 	 */
    970   1.1  glass 
    971  1.16    gwr 	if (ifp->if_flags & IFF_PROMISC) {
    972  1.16    gwr 		ifp->if_flags |= IFF_ALLMULTI;
    973  1.16    gwr 		af[0] = af[1] = 0xffffffff;
    974   1.1  glass 		return;
    975  1.16    gwr 	}
    976   1.1  glass 
    977  1.16    gwr 	af[0] = af[1] = 0;
    978  1.16    gwr 	ETHER_FIRST_MULTI(step, ac, enm);
    979  1.16    gwr 	while (enm != NULL) {
    980  1.16    gwr 		if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
    981  1.16    gwr 		    sizeof(enm->enm_addrlo)) != 0) {
    982  1.16    gwr 			/*
    983  1.16    gwr 			 * We must listen to a range of multicast addresses.
    984  1.16    gwr 			 * For now, just accept all multicasts, rather than
    985  1.16    gwr 			 * trying to set only those filter bits needed to match
    986  1.16    gwr 			 * the range.  (At this time, the only use of address
    987  1.16    gwr 			 * ranges is for IP multicast routing, for which the
    988  1.16    gwr 			 * range is big enough to require all bits set.)
    989  1.16    gwr 			 */
    990  1.16    gwr 			ifp->if_flags |= IFF_ALLMULTI;
    991  1.16    gwr 			af[0] = af[1] = 0xffffffff;
    992  1.16    gwr 			return;
    993  1.16    gwr 		}
    994   1.1  glass 
    995  1.16    gwr 		cp = enm->enm_addrlo;
    996  1.16    gwr 		crc = 0xffffffff;
    997  1.16    gwr 		for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
    998  1.16    gwr 			c = *cp++;
    999  1.16    gwr 			for (i = 8; --i >= 0;) {
   1000  1.16    gwr 				if ((crc & 0x01) ^ (c & 0x01)) {
   1001  1.16    gwr 					crc >>= 1;
   1002  1.16    gwr 					crc ^= 0x6db88320 | 0x80000000;
   1003  1.16    gwr 				} else
   1004  1.16    gwr 					crc >>= 1;
   1005  1.16    gwr 				c >>= 1;
   1006  1.16    gwr 			}
   1007  1.16    gwr 		}
   1008  1.16    gwr 		/* Just want the 6 most significant bits. */
   1009  1.16    gwr 		crc >>= 26;
   1010   1.1  glass 
   1011  1.16    gwr 		/* Turn on the corresponding bit in the filter. */
   1012  1.16    gwr 		af[crc >> 5] |= 1 << ((crc & 0x1f) ^ 0);
   1013   1.1  glass 
   1014  1.16    gwr 		ETHER_NEXT_MULTI(step, enm);
   1015  1.16    gwr 	}
   1016  1.16    gwr 	ifp->if_flags &= ~IFF_ALLMULTI;
   1017   1.1  glass }
   1018