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