Home | History | Annotate | Line # | Download | only in qbus
if_il.c revision 1.8
      1 /*	$NetBSD: if_il.c,v 1.8 2002/10/02 16:52:27 thorpej Exp $	*/
      2 /*
      3  * Copyright (c) 1982, 1986 Regents of the University of California.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by the University of
     17  *	California, Berkeley and its contributors.
     18  * 4. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)if_il.c	7.8 (Berkeley) 12/16/90
     35  */
     36 
     37 /*
     38  * Interlan Ethernet Communications Controller interface
     39  */
     40 
     41 #include <sys/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: if_il.c,v 1.8 2002/10/02 16:52:27 thorpej Exp $");
     43 
     44 #include "opt_inet.h"
     45 #include "opt_ns.h"
     46 
     47 #include <sys/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/mbuf.h>
     50 #include <sys/buf.h>
     51 #include <sys/protosw.h>
     52 #include <sys/socket.h>
     53 #include <sys/ioctl.h>
     54 #include <sys/errno.h>
     55 #include <sys/syslog.h>
     56 #include <sys/device.h>
     57 
     58 #include <net/if.h>
     59 #include <net/if_ether.h>
     60 #include <net/if_dl.h>
     61 
     62 #ifdef INET
     63 #include <netinet/in.h>
     64 #endif
     65 
     66 #ifdef NS
     67 #include <netns/ns.h>
     68 #include <netns/ns_if.h>
     69 #endif
     70 
     71 #include <machine/bus.h>
     72 
     73 #include <dev/qbus/ubareg.h>
     74 #include <dev/qbus/ubavar.h>
     75 #include <dev/qbus/if_uba.h>
     76 
     77 #include <dev/qbus/if_il.h>
     78 #include <dev/qbus/if_ilreg.h>
     79 
     80 /*
     81  * Ethernet software status per interface.
     82  *
     83  * Each interface is referenced by a network interface structure,
     84  * is_if, which the routing code uses to locate the interface.
     85  * This structure contains the output queue for the interface, its address, ...
     86  * We also have, for each interface, a UBA interface structure, which
     87  * contains information about the UNIBUS resources held by the interface:
     88  * map registers, buffered data paths, etc.  Information is cached in this
     89  * structure for use by the if_uba.c routines in running the interface
     90  * efficiently.
     91  */
     92 
     93 struct	il_softc {
     94 	struct	device sc_dev;		/* Configuration common part */
     95 	struct	ethercom sc_ec;		/* Ethernet common part */
     96 #define	sc_if	sc_ec.ec_if		/* network-visible interface */
     97 	struct	evcnt sc_cintrcnt;	/* Command interrupts */
     98 	struct  evcnt sc_rintrcnt;	/* Receive interrupts */
     99 	bus_space_tag_t sc_iot;
    100 	bus_addr_t sc_ioh;
    101 	bus_dma_tag_t sc_dmat;
    102 	struct	ubinfo sc_ui;
    103 
    104 	struct	ifuba sc_ifuba;		/* UNIBUS resources */
    105 	int	sc_flags;
    106 #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
    107 #define	ILF_STATPENDING	0x4		/* stat cmd pending */
    108 #define	ILF_RUNNING	0x8		/* board is running */
    109 #define	ILF_SETADDR	0x10		/* physical address is changed */
    110 	short	sc_lastcmd;		/* can't read csr, so must save it */
    111 	short	sc_scaninterval;	/* interval of stat collection */
    112 #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
    113 	union {
    114 	    struct	il_stats isu_stats;	/* holds on-board statistics */
    115 	    struct	ether_addr isu_maddrs[63];	/* multicast addrs */
    116 	}	sc_isu;
    117 #define sc_stats	sc_isu.isu_stats
    118 #define sc_maddrs	sc_isu.isu_maddrs
    119 	struct	il_stats sc_sum;	/* summation over time */
    120 	int	sc_ubaddr;		/* mapping registers of is_stats */
    121 };
    122 
    123 static	int ilmatch(struct device *, struct cfdata *, void *);
    124 static	void ilattach(struct device *, struct device *, void *);
    125 static	void ilcint(void *);
    126 static	void ilrint(void *);
    127 static	void ilreset(struct device *);
    128 static	int ilwait(struct il_softc *, char *);
    129 static	int ilinit(struct ifnet *);
    130 static	void ilstart(struct ifnet *);
    131 static	void ilwatch(struct ifnet *);
    132 static	void iltotal(struct il_softc *);
    133 static	void ilstop(struct ifnet *, int);
    134 
    135 CFATTACH_DECL(il, sizeof(struct il_softc),
    136     ilmatch, ilattach, NULL, NULL);
    137 
    138 #define IL_WCSR(csr, val) \
    139 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
    140 #define IL_RCSR(csr) \
    141 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
    142 #define LOWORD(x)	((int)(x) & 0xffff)
    143 #define HIWORD(x)	(((int)(x) >> 16) & 0x3)
    144 
    145 int
    146 ilmatch(struct device *parent, struct cfdata *cf, void *aux)
    147 {
    148 	struct uba_attach_args *ua = aux;
    149 	volatile int i;
    150 
    151 	bus_space_write_2(ua->ua_iot, ua->ua_ioh, IL_CSR, ILC_OFFLINE|IL_CIE);
    152 	DELAY(100000);
    153 	i = bus_space_read_2(ua->ua_iot, ua->ua_ioh, IL_CSR); /* clear CDONE */
    154 
    155 	return 1;
    156 }
    157 
    158 /*
    159  * Interface exists: make available by filling in network interface
    160  * record.  System will initialize the interface when it is ready
    161  * to accept packets.  A STATUS command is done to get the ethernet
    162  * address and other interesting data.
    163  */
    164 void
    165 ilattach(struct device *parent, struct device *self, void *aux)
    166 {
    167 	struct uba_attach_args *ua = aux;
    168 	struct il_softc *sc = (struct il_softc *)self;
    169 	struct ifnet *ifp = &sc->sc_if;
    170 	int error;
    171 
    172 	sc->sc_iot = ua->ua_iot;
    173 	sc->sc_ioh = ua->ua_ioh;
    174 	sc->sc_dmat = ua->ua_dmat;
    175 
    176 	/*
    177 	 * Map interrupt vectors and reset function.
    178 	 */
    179 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec, ilcint,
    180 	    sc, &sc->sc_cintrcnt);
    181 	evcnt_attach_dynamic(&sc->sc_cintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    182 	    sc->sc_dev.dv_xname, "intr");
    183 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec-4, ilrint,
    184 	    sc, &sc->sc_rintrcnt);
    185 	evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    186 	    sc->sc_dev.dv_xname, "intr");
    187 	uba_reset_establish(ilreset, &sc->sc_dev);
    188 
    189 	/*
    190 	 * Reset the board and map the statistics
    191 	 * buffer onto the Unibus.
    192 	 */
    193 	IL_WCSR(IL_CSR, ILC_RESET);
    194 	(void)ilwait(sc, "reset");
    195 	sc->sc_ui.ui_size = sizeof(struct il_stats);
    196 	sc->sc_ui.ui_vaddr = (caddr_t)&sc->sc_stats;
    197 	if ((error = uballoc((struct uba_softc *)parent, &sc->sc_ui, 0)))
    198 		return printf(": failed uballoc, error = %d\n", error);
    199 
    200 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    201 	IL_WCSR(IL_BCR, sizeof(struct il_stats));
    202 	IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT);
    203 	(void)ilwait(sc, "status");
    204 	ubfree((struct uba_softc *)parent, &sc->sc_ui);
    205 	printf("%s: module=%s firmware=%s\n", sc->sc_dev.dv_xname,
    206 		sc->sc_stats.ils_module, sc->sc_stats.ils_firmware);
    207 	printf("%s: hardware address %s\n", sc->sc_dev.dv_xname,
    208 		ether_sprintf(sc->sc_stats.ils_addr));
    209 
    210 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
    211 	ifp->if_softc = sc;
    212 	ifp->if_flags = IFF_BROADCAST;
    213 	ifp->if_init = ilinit;
    214 	ifp->if_stop = ilstop;
    215 	ifp->if_ioctl = ether_ioctl;
    216 	ifp->if_start = ilstart;
    217 	ifp->if_watchdog = ilwatch;
    218 	IFQ_SET_READY(&ifp->if_snd);
    219 
    220 	if_attach(ifp);
    221 	ether_ifattach(ifp, sc->sc_stats.ils_addr);
    222 }
    223 
    224 void
    225 ilstop(struct ifnet *ifp, int a)
    226 {
    227 	struct il_softc *sc = ifp->if_softc;
    228 
    229 	IL_WCSR(IL_CSR, ILC_RESET);
    230 }
    231 
    232 
    233 int
    234 ilwait(struct il_softc *sc, char *op)
    235 {
    236 
    237 	while ((IL_RCSR(IL_CSR)&IL_CDONE) == 0)
    238 		;
    239 	if (IL_RCSR(IL_CSR)&IL_STATUS) {
    240 		char bits[64];
    241 
    242 		printf("%s: %s failed, csr=%s\n", sc->sc_dev.dv_xname, op,
    243 		    bitmask_snprintf(IL_RCSR(IL_CSR), IL_BITS, bits,
    244 		    sizeof(bits)));
    245 		return (-1);
    246 	}
    247 	return (0);
    248 }
    249 
    250 /*
    251  * Reset of interface after UNIBUS reset.
    252  * If interface is on specified uba, reset its state.
    253  */
    254 void
    255 ilreset(struct device *dev)
    256 {
    257 	struct il_softc *sc = (void *)dev;
    258 
    259 	printf(" %s", sc->sc_dev.dv_xname);
    260 	sc->sc_if.if_flags &= ~IFF_RUNNING;
    261 	sc->sc_flags &= ~ILF_RUNNING;
    262 	ilinit(&sc->sc_if);
    263 }
    264 
    265 /*
    266  * Initialization of interface; clear recorded pending
    267  * operations, and reinitialize UNIBUS usage.
    268  */
    269 int
    270 ilinit(struct ifnet *ifp)
    271 {
    272 	struct il_softc *sc = ifp->if_softc;
    273 	int s;
    274 
    275 	if (sc->sc_flags & ILF_RUNNING)
    276 		return 0;
    277 
    278 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
    279 		if (if_ubainit(&sc->sc_ifuba, (void *)sc->sc_dev.dv_parent,
    280 		    ETHER_MAX_LEN)) {
    281 			printf("%s: can't initialize\n", sc->sc_dev.dv_xname);
    282 			sc->sc_if.if_flags &= ~IFF_UP;
    283 			return 0;
    284 		}
    285 		sc->sc_ui.ui_size = sizeof(sc->sc_isu);
    286 		sc->sc_ui.ui_vaddr = (caddr_t)&sc->sc_isu;
    287 		uballoc((void *)sc->sc_dev.dv_parent, &sc->sc_ui, 0);
    288 	}
    289 	sc->sc_scaninterval = ILWATCHINTERVAL;
    290 	ifp->if_timer = sc->sc_scaninterval;
    291 
    292 	/*
    293 	 * Turn off source address insertion (it's faster this way),
    294 	 * and set board online.  Former doesn't work if board is
    295 	 * already online (happens on ubareset), so we put it offline
    296 	 * first.
    297 	 */
    298 	s = splnet();
    299 	IL_WCSR(IL_CSR, ILC_RESET);
    300 	if (ilwait(sc, "hardware diag")) {
    301  		sc->sc_if.if_flags &= ~IFF_UP;
    302  		splx(s);
    303  		return 0;
    304  	}
    305 	IL_WCSR(IL_CSR, ILC_CISA);
    306 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    307 		;
    308 	/*
    309 	 * If we must reprogram this board's physical ethernet
    310 	 * address (as for secondary XNS interfaces), we do so
    311 	 * before putting it on line, and starting receive requests.
    312 	 * If you try this on an older 1010 board, it will total
    313 	 * wedge the board.
    314 	 */
    315 	if (sc->sc_flags & ILF_SETADDR) {
    316 		bcopy((caddr_t)LLADDR(ifp->if_sadl),
    317 		    (caddr_t)&sc->sc_isu, ETHER_ADDR_LEN);
    318 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    319 		IL_WCSR(IL_BCR, ETHER_ADDR_LEN);
    320 		IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_LDPA);
    321 		if (ilwait(sc, "setaddr"))
    322 			return 0;
    323 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    324 		IL_WCSR(IL_BCR, sizeof (struct il_stats));
    325 		IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT);
    326 		if (ilwait(sc, "verifying setaddr"))
    327 			return 0;
    328 		if (memcmp((caddr_t)sc->sc_stats.ils_addr,
    329 		    (caddr_t)LLADDR(ifp->if_sadl), ETHER_ADDR_LEN) != 0) {
    330 			printf("%s: setaddr didn't work\n",
    331 			    sc->sc_dev.dv_xname);
    332 			return 0;
    333 		}
    334 	}
    335 #ifdef MULTICAST
    336 	if (is->is_if.if_flags & IFF_PROMISC) {
    337 		addr->il_csr = ILC_PRMSC;
    338 		if (ilwait(ui, "all multi"))
    339 			return 0;
    340 	} else if (is->is_if.if_flags & IFF_ALLMULTI) {
    341 	too_many_multis:
    342 		addr->il_csr = ILC_ALLMC;
    343 		if (ilwait(ui, "all multi"))
    344 			return 0;
    345 	else {
    346 		int i;
    347 		register struct ether_addr *ep = is->is_maddrs;
    348 		struct ether_multi *enm;
    349 		struct ether_multistep step;
    350 		/*
    351 		 * Step through our list of multicast addresses.  If we have
    352 		 * too many multicast addresses, or if we have to listen to
    353 		 * a range of multicast addresses, turn on reception of all
    354 		 * multicasts.
    355 		 */
    356 		i = 0;
    357 		ETHER_FIRST_MULTI(step, &is->is_ac, enm);
    358 		while (enm != NULL) {
    359 			if (++i > 63 && k != 0) {
    360 				break;
    361 			}
    362 			*ep++ = *(struct ether_addr *)enm->enm_addrlo;
    363 			ETHER_NEXT_MULTI(step, enm);
    364 		}
    365 		if (i = 0) {
    366 			/* no multicasts! */
    367 		} else if (i <= 63) {
    368 			addr->il_bar = is->is_ubaddr & 0xffff;
    369 			addr->il_bcr = i * sizeof (struct ether_addr);
    370 			addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|
    371 						LC_LDGRPS;
    372 			if (ilwait(ui, "load multi"))
    373 				return;
    374 		} else {
    375 		    is->is_if.if_flags |= IFF_ALLMULTI;
    376 		    goto too_many_multis;
    377 		}
    378 	}
    379 #endif /* MULTICAST */
    380 	/*
    381 	 * Set board online.
    382 	 * Hang receive buffer and start any pending
    383 	 * writes by faking a transmit complete.
    384 	 * Receive bcr is not a multiple of 8 so buffer
    385 	 * chaining can't happen.
    386 	 */
    387 	IL_WCSR(IL_CSR, ILC_ONLINE);
    388 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    389 		;
    390 
    391 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
    392 	IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
    393 	IL_WCSR(IL_CSR,
    394 	    ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE);
    395 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    396 		;
    397 	ifp->if_flags |= IFF_RUNNING | IFF_OACTIVE;
    398 	sc->sc_flags |= ILF_RUNNING;
    399 	sc->sc_lastcmd = 0;
    400 	ilcint(sc);
    401 	splx(s);
    402 	return 0;
    403 }
    404 
    405 /*
    406  * Start output on interface.
    407  * Get another datagram to send off of the interface queue,
    408  * and map it to the interface before starting the output.
    409  */
    410 void
    411 ilstart(struct ifnet *ifp)
    412 {
    413 	struct il_softc *sc = ifp->if_softc;
    414         int len;
    415 	struct mbuf *m;
    416 	short csr;
    417 
    418 	IFQ_DEQUEUE(&ifp->if_snd, m);
    419 	if (m == 0) {
    420 		if ((sc->sc_flags & ILF_STATPENDING) == 0)
    421 			return;
    422 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    423 		IL_WCSR(IL_BCR, sizeof (struct il_stats));
    424 		csr = ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
    425 		sc->sc_flags &= ~ILF_STATPENDING;
    426 		goto startcmd;
    427 	}
    428 	len = if_wubaput(&sc->sc_ifuba, m);
    429 	/*
    430 	 * Ensure minimum packet length.
    431 	 * This makes the safe assumtion that there are no virtual holes
    432 	 * after the data.
    433 	 * For security, it might be wise to zero out the added bytes,
    434 	 * but we're mainly interested in speed at the moment.
    435 	 */
    436 	if (len - sizeof(struct ether_header) < ETHERMIN)
    437 		len = ETHERMIN + sizeof(struct ether_header);
    438 #ifdef notdef
    439 	if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
    440 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
    441 #endif
    442 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_w.ifrw_info));
    443 	IL_WCSR(IL_BCR, len);
    444 	csr =
    445 	  ((sc->sc_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
    446 
    447 startcmd:
    448 	sc->sc_lastcmd = csr & IL_CMD;
    449 	IL_WCSR(IL_CSR, csr);
    450 	ifp->if_flags |= IFF_OACTIVE;
    451 	return;
    452 }
    453 
    454 /*
    455  * Command done interrupt.
    456  */
    457 void
    458 ilcint(void *arg)
    459 {
    460 	struct il_softc *sc = arg;
    461 	short csr;
    462 
    463 	if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0) {
    464 		char bits[64];
    465 
    466 		printf("%s: stray xmit interrupt, csr=%s\n",
    467 		    sc->sc_dev.dv_xname,
    468 		    bitmask_snprintf(IL_RCSR(IL_CSR), IL_BITS, bits,
    469 		    sizeof(bits)));
    470 		return;
    471 	}
    472 
    473 	csr = IL_RCSR(IL_CSR);
    474 	/*
    475 	 * Hang receive buffer if it couldn't
    476 	 * be done earlier (in ilrint).
    477 	 */
    478 	if (sc->sc_flags & ILF_RCVPENDING) {
    479 		int s;
    480 
    481 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
    482 		IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
    483 		IL_WCSR(IL_CSR,
    484 		  ((sc->sc_ifuba.ifu_r.ifrw_info>>2) & IL_EUA)|ILC_RCV|IL_RIE);
    485 		s = splhigh();
    486 		while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    487 			;
    488 		splx(s);
    489 		sc->sc_flags &= ~ILF_RCVPENDING;
    490 	}
    491 	sc->sc_if.if_flags &= ~IFF_OACTIVE;
    492 	csr &= IL_STATUS;
    493 	switch (sc->sc_lastcmd) {
    494 
    495 	case ILC_XMIT:
    496 		sc->sc_if.if_opackets++;
    497 		if (csr > ILERR_RETRIES)
    498 			sc->sc_if.if_oerrors++;
    499 		break;
    500 
    501 	case ILC_STAT:
    502 		if (csr == ILERR_SUCCESS)
    503 			iltotal(sc);
    504 		break;
    505 	}
    506 	if_wubaend(&sc->sc_ifuba);
    507 	ilstart(&sc->sc_if);
    508 }
    509 
    510 /*
    511  * Ethernet interface receiver interrupt.
    512  * If input error just drop packet.
    513  * Otherwise purge input buffered data path and examine
    514  * packet to determine type.  If can't determine length
    515  * from type, then have to drop packet.  Othewise decapsulate
    516  * packet based on type and pass to type specific higher-level
    517  * input routine.
    518  */
    519 void
    520 ilrint(void *arg)
    521 {
    522 	struct il_softc *sc = arg;
    523 	struct il_rheader *il;
    524     	struct mbuf *m;
    525 	int len, s;
    526 
    527 	sc->sc_if.if_ipackets++;
    528 #ifdef notyet
    529 	if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
    530 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
    531 #endif
    532 	il = (struct il_rheader *)(sc->sc_ifuba.ifu_r.ifrw_addr);
    533 	len = il->ilr_length - sizeof(struct il_rheader);
    534 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
    535 	    len > ETHERMTU) {
    536 		sc->sc_if.if_ierrors++;
    537 #ifdef notdef
    538 		if (sc->sc_if.if_ierrors % 100 == 0)
    539 			printf("il%d: += 100 input errors\n", unit);
    540 #endif
    541 		goto setup;
    542 	}
    543 
    544 	if (len == 0)
    545 		goto setup;
    546 
    547 	/*
    548 	 * Pull packet off interface.
    549 	 */
    550 	m = if_rubaget(&sc->sc_ifuba, &sc->sc_if, len);
    551 	if (m == NULL)
    552 		goto setup;
    553 
    554 	/* Shave off status hdr */
    555 	m_adj(m, 4);
    556 	(*sc->sc_if.if_input)(&sc->sc_if, m);
    557 setup:
    558 	/*
    559 	 * Reset for next packet if possible.
    560 	 * If waiting for transmit command completion, set flag
    561 	 * and wait until command completes.
    562 	 */
    563 	if (sc->sc_if.if_flags & IFF_OACTIVE) {
    564 		sc->sc_flags |= ILF_RCVPENDING;
    565 		return;
    566 	}
    567 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
    568 	IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
    569 	IL_WCSR(IL_CSR,
    570 	    ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE);
    571 	s = splhigh();
    572 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    573 		;
    574 	splx(s);
    575 }
    576 /*
    577  * Watchdog routine, request statistics from board.
    578  */
    579 void
    580 ilwatch(struct ifnet *ifp)
    581 {
    582 	struct il_softc *sc = ifp->if_softc;
    583 	int s;
    584 
    585 	if (sc->sc_flags & ILF_STATPENDING) {
    586 		ifp->if_timer = sc->sc_scaninterval;
    587 		return;
    588 	}
    589 	s = splnet();
    590 	sc->sc_flags |= ILF_STATPENDING;
    591 	if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0)
    592 		ilstart(ifp);
    593 	splx(s);
    594 	ifp->if_timer = sc->sc_scaninterval;
    595 }
    596 
    597 /*
    598  * Total up the on-board statistics.
    599  */
    600 void
    601 iltotal(struct il_softc *sc)
    602 {
    603 	struct ifnet *ifp = &sc->sc_if;
    604 	u_short *interval, *sum, *end;
    605 
    606 	interval = &sc->sc_stats.ils_frames;
    607 	sum = &sc->sc_sum.ils_frames;
    608 	end = sc->sc_sum.ils_fill2;
    609 	while (sum < end)
    610 		*sum++ += *interval++;
    611 	sc->sc_if.if_collisions = sc->sc_sum.ils_collis;
    612 	if ((sc->sc_flags & ILF_SETADDR) &&
    613 	    (memcmp((caddr_t)sc->sc_stats.ils_addr, LLADDR(ifp->if_sadl),
    614 		    ETHER_ADDR_LEN) != 0)) {
    615 		log(LOG_ERR, "%s: physaddr reverted\n", sc->sc_dev.dv_xname);
    616 		sc->sc_flags &= ~ILF_RUNNING;
    617 		ilinit(&sc->sc_if);
    618 	}
    619 }
    620 
    621 #ifdef notyet
    622 /*
    623  * set ethernet address for unit
    624  */
    625 void
    626 il_setaddr(u_char *physaddr, struct il_softc *sc)
    627 {
    628 	if (! (sc->sc_flags & ILF_RUNNING))
    629 		return;
    630 
    631 	bcopy((caddr_t)physaddr, (caddr_t)is->is_addr, sizeof is->is_addr);
    632 	sc->sc_flags &= ~ILF_RUNNING;
    633 	sc->sc_flags |= ILF_SETADDR;
    634 	ilinit(&sc->sc_if);
    635 }
    636 #endif
    637