xref: /netbsd-src/sys/dev/qbus/if_il.c (revision 08c81a9c2dc8c7300e893321eb65c0925d60871c)
1 /*	$NetBSD: if_il.c,v 1.5 2002/05/22 16:03:17 wiz 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.5 2002/05/22 16:03:17 wiz 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 struct	cfattach il_ca = {
136 	sizeof(struct il_softc), ilmatch, ilattach
137 };
138 
139 #define IL_WCSR(csr, val) \
140 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
141 #define IL_RCSR(csr) \
142 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
143 #define LOWORD(x)	((int)(x) & 0xffff)
144 #define HIWORD(x)	(((int)(x) >> 16) & 0x3)
145 
146 int
147 ilmatch(struct device *parent, struct cfdata *cf, void *aux)
148 {
149 	struct uba_attach_args *ua = aux;
150 	volatile int i;
151 
152 	bus_space_write_2(ua->ua_iot, ua->ua_ioh, IL_CSR, ILC_OFFLINE|IL_CIE);
153 	DELAY(100000);
154 	i = bus_space_read_2(ua->ua_iot, ua->ua_ioh, IL_CSR); /* clear CDONE */
155 
156 	return 1;
157 }
158 
159 /*
160  * Interface exists: make available by filling in network interface
161  * record.  System will initialize the interface when it is ready
162  * to accept packets.  A STATUS command is done to get the ethernet
163  * address and other interesting data.
164  */
165 void
166 ilattach(struct device *parent, struct device *self, void *aux)
167 {
168 	struct uba_attach_args *ua = aux;
169 	struct il_softc *sc = (struct il_softc *)self;
170 	struct ifnet *ifp = &sc->sc_if;
171 	int error;
172 
173 	sc->sc_iot = ua->ua_iot;
174 	sc->sc_ioh = ua->ua_ioh;
175 	sc->sc_dmat = ua->ua_dmat;
176 
177 	/*
178 	 * Map interrupt vectors and reset function.
179 	 */
180 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec, ilcint,
181 	    sc, &sc->sc_cintrcnt);
182 	evcnt_attach_dynamic(&sc->sc_cintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
183 	    sc->sc_dev.dv_xname, "intr");
184 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec-4, ilrint,
185 	    sc, &sc->sc_rintrcnt);
186 	evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
187 	    sc->sc_dev.dv_xname, "intr");
188 	uba_reset_establish(ilreset, &sc->sc_dev);
189 
190 	/*
191 	 * Reset the board and map the statistics
192 	 * buffer onto the Unibus.
193 	 */
194 	IL_WCSR(IL_CSR, ILC_RESET);
195 	(void)ilwait(sc, "reset");
196 	sc->sc_ui.ui_size = sizeof(struct il_stats);
197 	sc->sc_ui.ui_vaddr = (caddr_t)&sc->sc_stats;
198 	if ((error = uballoc((struct uba_softc *)parent, &sc->sc_ui, 0)))
199 		return printf(": failed uballoc, error = %d\n", error);
200 
201 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
202 	IL_WCSR(IL_BCR, sizeof(struct il_stats));
203 	IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT);
204 	(void)ilwait(sc, "status");
205 	ubfree((struct uba_softc *)parent, &sc->sc_ui);
206 	printf("%s: module=%s firmware=%s\n", sc->sc_dev.dv_xname,
207 		sc->sc_stats.ils_module, sc->sc_stats.ils_firmware);
208 	printf("%s: hardware address %s\n", sc->sc_dev.dv_xname,
209 		ether_sprintf(sc->sc_stats.ils_addr));
210 
211 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
212 	ifp->if_softc = sc;
213 	ifp->if_flags = IFF_BROADCAST;
214 	ifp->if_init = ilinit;
215 	ifp->if_stop = ilstop;
216 	ifp->if_ioctl = ether_ioctl;
217 	ifp->if_start = ilstart;
218 	ifp->if_watchdog = ilwatch;
219 	IFQ_SET_READY(&ifp->if_snd);
220 
221 	if_attach(ifp);
222 	ether_ifattach(ifp, sc->sc_stats.ils_addr);
223 }
224 
225 void
226 ilstop(struct ifnet *ifp, int a)
227 {
228 	struct il_softc *sc = ifp->if_softc;
229 
230 	IL_WCSR(IL_CSR, ILC_RESET);
231 }
232 
233 
234 int
235 ilwait(struct il_softc *sc, char *op)
236 {
237 
238 	while ((IL_RCSR(IL_CSR)&IL_CDONE) == 0)
239 		;
240 	if (IL_RCSR(IL_CSR)&IL_STATUS) {
241 		char bits[64];
242 
243 		printf("%s: %s failed, csr=%s\n", sc->sc_dev.dv_xname, op,
244 		    bitmask_snprintf(IL_RCSR(IL_CSR), IL_BITS, bits,
245 		    sizeof(bits)));
246 		return (-1);
247 	}
248 	return (0);
249 }
250 
251 /*
252  * Reset of interface after UNIBUS reset.
253  * If interface is on specified uba, reset its state.
254  */
255 void
256 ilreset(struct device *dev)
257 {
258 	struct il_softc *sc = (void *)dev;
259 
260 	printf(" %s", sc->sc_dev.dv_xname);
261 	sc->sc_if.if_flags &= ~IFF_RUNNING;
262 	sc->sc_flags &= ~ILF_RUNNING;
263 	ilinit(&sc->sc_if);
264 }
265 
266 /*
267  * Initialization of interface; clear recorded pending
268  * operations, and reinitialize UNIBUS usage.
269  */
270 int
271 ilinit(struct ifnet *ifp)
272 {
273 	struct il_softc *sc = ifp->if_softc;
274 	int s;
275 
276 	if (sc->sc_flags & ILF_RUNNING)
277 		return 0;
278 
279 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
280 		if (if_ubainit(&sc->sc_ifuba, (void *)sc->sc_dev.dv_parent,
281 		    ETHER_MAX_LEN)) {
282 			printf("%s: can't initialize\n", sc->sc_dev.dv_xname);
283 			sc->sc_if.if_flags &= ~IFF_UP;
284 			return 0;
285 		}
286 		sc->sc_ui.ui_size = sizeof(sc->sc_isu);
287 		sc->sc_ui.ui_vaddr = (caddr_t)&sc->sc_isu;
288 		uballoc((void *)sc->sc_dev.dv_parent, &sc->sc_ui, 0);
289 	}
290 	sc->sc_scaninterval = ILWATCHINTERVAL;
291 	ifp->if_timer = sc->sc_scaninterval;
292 
293 	/*
294 	 * Turn off source address insertion (it's faster this way),
295 	 * and set board online.  Former doesn't work if board is
296 	 * already online (happens on ubareset), so we put it offline
297 	 * first.
298 	 */
299 	s = splnet();
300 	IL_WCSR(IL_CSR, ILC_RESET);
301 	if (ilwait(sc, "hardware diag")) {
302  		sc->sc_if.if_flags &= ~IFF_UP;
303  		splx(s);
304  		return 0;
305  	}
306 	IL_WCSR(IL_CSR, ILC_CISA);
307 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
308 		;
309 	/*
310 	 * If we must reprogram this board's physical ethernet
311 	 * address (as for secondary XNS interfaces), we do so
312 	 * before putting it on line, and starting receive requests.
313 	 * If you try this on an older 1010 board, it will total
314 	 * wedge the board.
315 	 */
316 	if (sc->sc_flags & ILF_SETADDR) {
317 		bcopy((caddr_t)LLADDR(ifp->if_sadl),
318 		    (caddr_t)&sc->sc_isu, ETHER_ADDR_LEN);
319 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
320 		IL_WCSR(IL_BCR, ETHER_ADDR_LEN);
321 		IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_LDPA);
322 		if (ilwait(sc, "setaddr"))
323 			return 0;
324 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
325 		IL_WCSR(IL_BCR, sizeof (struct il_stats));
326 		IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT);
327 		if (ilwait(sc, "verifying setaddr"))
328 			return 0;
329 		if (memcmp((caddr_t)sc->sc_stats.ils_addr,
330 		    (caddr_t)LLADDR(ifp->if_sadl), ETHER_ADDR_LEN) != 0) {
331 			printf("%s: setaddr didn't work\n",
332 			    sc->sc_dev.dv_xname);
333 			return 0;
334 		}
335 	}
336 #ifdef MULTICAST
337 	if (is->is_if.if_flags & IFF_PROMISC) {
338 		addr->il_csr = ILC_PRMSC;
339 		if (ilwait(ui, "all multi"))
340 			return 0;
341 	} else if (is->is_if.if_flags & IFF_ALLMULTI) {
342 	too_many_multis:
343 		addr->il_csr = ILC_ALLMC;
344 		if (ilwait(ui, "all multi"))
345 			return 0;
346 	else {
347 		int i;
348 		register struct ether_addr *ep = is->is_maddrs;
349 		struct ether_multi *enm;
350 		struct ether_multistep step;
351 		/*
352 		 * Step through our list of multicast addresses.  If we have
353 		 * too many multicast addresses, or if we have to listen to
354 		 * a range of multicast addresses, turn on reception of all
355 		 * multicasts.
356 		 */
357 		i = 0;
358 		ETHER_FIRST_MULTI(step, &is->is_ac, enm);
359 		while (enm != NULL) {
360 			if (++i > 63 && k != 0) {
361 				break;
362 			}
363 			*ep++ = *(struct ether_addr *)enm->enm_addrlo;
364 			ETHER_NEXT_MULTI(step, enm);
365 		}
366 		if (i = 0) {
367 			/* no multicasts! */
368 		} else if (i <= 63) {
369 			addr->il_bar = is->is_ubaddr & 0xffff;
370 			addr->il_bcr = i * sizeof (struct ether_addr);
371 			addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|
372 						LC_LDGRPS;
373 			if (ilwait(ui, "load multi"))
374 				return;
375 		} else {
376 		    is->is_if.if_flags |= IFF_ALLMULTI;
377 		    goto too_many_multis;
378 		}
379 	}
380 #endif /* MULTICAST */
381 	/*
382 	 * Set board online.
383 	 * Hang receive buffer and start any pending
384 	 * writes by faking a transmit complete.
385 	 * Receive bcr is not a multiple of 8 so buffer
386 	 * chaining can't happen.
387 	 */
388 	IL_WCSR(IL_CSR, ILC_ONLINE);
389 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
390 		;
391 
392 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
393 	IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
394 	IL_WCSR(IL_CSR,
395 	    ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE);
396 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
397 		;
398 	ifp->if_flags |= IFF_RUNNING | IFF_OACTIVE;
399 	sc->sc_flags |= ILF_RUNNING;
400 	sc->sc_lastcmd = 0;
401 	ilcint(sc);
402 	splx(s);
403 	return 0;
404 }
405 
406 /*
407  * Start output on interface.
408  * Get another datagram to send off of the interface queue,
409  * and map it to the interface before starting the output.
410  */
411 void
412 ilstart(struct ifnet *ifp)
413 {
414 	struct il_softc *sc = ifp->if_softc;
415         int len;
416 	struct mbuf *m;
417 	short csr;
418 
419 	IFQ_DEQUEUE(&ifp->if_snd, m);
420 	if (m == 0) {
421 		if ((sc->sc_flags & ILF_STATPENDING) == 0)
422 			return;
423 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
424 		IL_WCSR(IL_BCR, sizeof (struct il_stats));
425 		csr = ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
426 		sc->sc_flags &= ~ILF_STATPENDING;
427 		goto startcmd;
428 	}
429 	len = if_wubaput(&sc->sc_ifuba, m);
430 	/*
431 	 * Ensure minimum packet length.
432 	 * This makes the safe assumtion that there are no virtual holes
433 	 * after the data.
434 	 * For security, it might be wise to zero out the added bytes,
435 	 * but we're mainly interested in speed at the moment.
436 	 */
437 	if (len - sizeof(struct ether_header) < ETHERMIN)
438 		len = ETHERMIN + sizeof(struct ether_header);
439 #ifdef notdef
440 	if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
441 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
442 #endif
443 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_w.ifrw_info));
444 	IL_WCSR(IL_BCR, len);
445 	csr =
446 	  ((sc->sc_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
447 
448 startcmd:
449 	sc->sc_lastcmd = csr & IL_CMD;
450 	IL_WCSR(IL_CSR, csr);
451 	ifp->if_flags |= IFF_OACTIVE;
452 	return;
453 }
454 
455 /*
456  * Command done interrupt.
457  */
458 void
459 ilcint(void *arg)
460 {
461 	struct il_softc *sc = arg;
462 	short csr;
463 
464 	if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0) {
465 		char bits[64];
466 
467 		printf("%s: stray xmit interrupt, csr=%s\n",
468 		    sc->sc_dev.dv_xname,
469 		    bitmask_snprintf(IL_RCSR(IL_CSR), IL_BITS, bits,
470 		    sizeof(bits)));
471 		return;
472 	}
473 
474 	csr = IL_RCSR(IL_CSR);
475 	/*
476 	 * Hang receive buffer if it couldn't
477 	 * be done earlier (in ilrint).
478 	 */
479 	if (sc->sc_flags & ILF_RCVPENDING) {
480 		int s;
481 
482 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
483 		IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
484 		IL_WCSR(IL_CSR,
485 		  ((sc->sc_ifuba.ifu_r.ifrw_info>>2) & IL_EUA)|ILC_RCV|IL_RIE);
486 		s = splhigh();
487 		while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
488 			;
489 		splx(s);
490 		sc->sc_flags &= ~ILF_RCVPENDING;
491 	}
492 	sc->sc_if.if_flags &= ~IFF_OACTIVE;
493 	csr &= IL_STATUS;
494 	switch (sc->sc_lastcmd) {
495 
496 	case ILC_XMIT:
497 		sc->sc_if.if_opackets++;
498 		if (csr > ILERR_RETRIES)
499 			sc->sc_if.if_oerrors++;
500 		break;
501 
502 	case ILC_STAT:
503 		if (csr == ILERR_SUCCESS)
504 			iltotal(sc);
505 		break;
506 	}
507 	if_wubaend(&sc->sc_ifuba);
508 	ilstart(&sc->sc_if);
509 }
510 
511 /*
512  * Ethernet interface receiver interrupt.
513  * If input error just drop packet.
514  * Otherwise purge input buffered data path and examine
515  * packet to determine type.  If can't determine length
516  * from type, then have to drop packet.  Othewise decapsulate
517  * packet based on type and pass to type specific higher-level
518  * input routine.
519  */
520 void
521 ilrint(void *arg)
522 {
523 	struct il_softc *sc = arg;
524 	struct il_rheader *il;
525     	struct mbuf *m;
526 	int len, s;
527 
528 	sc->sc_if.if_ipackets++;
529 #ifdef notyet
530 	if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
531 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
532 #endif
533 	il = (struct il_rheader *)(sc->sc_ifuba.ifu_r.ifrw_addr);
534 	len = il->ilr_length - sizeof(struct il_rheader);
535 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
536 	    len > ETHERMTU) {
537 		sc->sc_if.if_ierrors++;
538 #ifdef notdef
539 		if (sc->sc_if.if_ierrors % 100 == 0)
540 			printf("il%d: += 100 input errors\n", unit);
541 #endif
542 		goto setup;
543 	}
544 
545 	if (len == 0)
546 		goto setup;
547 
548 	/*
549 	 * Pull packet off interface.
550 	 */
551 	m = if_rubaget(&sc->sc_ifuba, &sc->sc_if, len);
552 	if (m == NULL)
553 		goto setup;
554 
555 	/* Shave off status hdr */
556 	m_adj(m, 4);
557 	(*sc->sc_if.if_input)(&sc->sc_if, m);
558 setup:
559 	/*
560 	 * Reset for next packet if possible.
561 	 * If waiting for transmit command completion, set flag
562 	 * and wait until command completes.
563 	 */
564 	if (sc->sc_if.if_flags & IFF_OACTIVE) {
565 		sc->sc_flags |= ILF_RCVPENDING;
566 		return;
567 	}
568 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
569 	IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
570 	IL_WCSR(IL_CSR,
571 	    ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE);
572 	s = splhigh();
573 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
574 		;
575 	splx(s);
576 }
577 /*
578  * Watchdog routine, request statistics from board.
579  */
580 void
581 ilwatch(struct ifnet *ifp)
582 {
583 	struct il_softc *sc = ifp->if_softc;
584 	int s;
585 
586 	if (sc->sc_flags & ILF_STATPENDING) {
587 		ifp->if_timer = sc->sc_scaninterval;
588 		return;
589 	}
590 	s = splnet();
591 	sc->sc_flags |= ILF_STATPENDING;
592 	if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0)
593 		ilstart(ifp);
594 	splx(s);
595 	ifp->if_timer = sc->sc_scaninterval;
596 }
597 
598 /*
599  * Total up the on-board statistics.
600  */
601 void
602 iltotal(struct il_softc *sc)
603 {
604 	struct ifnet *ifp = &sc->sc_if;
605 	u_short *interval, *sum, *end;
606 
607 	interval = &sc->sc_stats.ils_frames;
608 	sum = &sc->sc_sum.ils_frames;
609 	end = sc->sc_sum.ils_fill2;
610 	while (sum < end)
611 		*sum++ += *interval++;
612 	sc->sc_if.if_collisions = sc->sc_sum.ils_collis;
613 	if ((sc->sc_flags & ILF_SETADDR) &&
614 	    (memcmp((caddr_t)sc->sc_stats.ils_addr, LLADDR(ifp->if_sadl),
615 		    ETHER_ADDR_LEN) != 0)) {
616 		log(LOG_ERR, "%s: physaddr reverted\n", sc->sc_dev.dv_xname);
617 		sc->sc_flags &= ~ILF_RUNNING;
618 		ilinit(&sc->sc_if);
619 	}
620 }
621 
622 #ifdef notyet
623 /*
624  * set ethernet address for unit
625  */
626 void
627 il_setaddr(u_char *physaddr, struct il_softc *sc)
628 {
629 	if (! (sc->sc_flags & ILF_RUNNING))
630 		return;
631 
632 	bcopy((caddr_t)physaddr, (caddr_t)is->is_addr, sizeof is->is_addr);
633 	sc->sc_flags &= ~ILF_RUNNING;
634 	sc->sc_flags |= ILF_SETADDR;
635 	ilinit(&sc->sc_if);
636 }
637 #endif
638