xref: /csrg-svn/sys/vax/if/if_il.c (revision 25444)
1 /*
2  * Copyright (c) 1982 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)if_il.c	6.11 (Berkeley) 11/08/85
7  */
8 
9 #include "il.h"
10 #if NIL > 0
11 
12 /*
13  * Interlan Ethernet Communications Controller interface
14  */
15 #include "../machine/pte.h"
16 
17 #include "param.h"
18 #include "systm.h"
19 #include "mbuf.h"
20 #include "buf.h"
21 #include "protosw.h"
22 #include "socket.h"
23 #include "vmmac.h"
24 #include "ioctl.h"
25 #include "errno.h"
26 
27 #include "../net/if.h"
28 #include "../net/netisr.h"
29 #include "../net/route.h"
30 
31 #ifdef	BBNNET
32 #define	INET
33 #endif
34 #ifdef INET
35 #include "../netinet/in.h"
36 #include "../netinet/in_systm.h"
37 #include "../netinet/in_var.h"
38 #include "../netinet/ip.h"
39 #include "../netinet/if_ether.h"
40 #endif
41 
42 #ifdef NS
43 #include "../netns/ns.h"
44 #include "../netns/ns_if.h"
45 #endif
46 
47 #include "../vax/cpu.h"
48 #include "../vax/mtpr.h"
49 #include "if_il.h"
50 #include "if_ilreg.h"
51 #include "if_uba.h"
52 #include "../vaxuba/ubareg.h"
53 #include "../vaxuba/ubavar.h"
54 
55 int	ilprobe(), ilattach(), ilrint(), ilcint();
56 struct	uba_device *ilinfo[NIL];
57 u_short ilstd[] = { 0 };
58 struct	uba_driver ildriver =
59 	{ ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo };
60 #define	ILUNIT(x)	minor(x)
61 int	ilinit(),iloutput(),ilioctl(),ilreset(),ilwatch();
62 
63 /*
64  * Ethernet software status per interface.
65  *
66  * Each interface is referenced by a network interface structure,
67  * is_if, which the routing code uses to locate the interface.
68  * This structure contains the output queue for the interface, its address, ...
69  * We also have, for each interface, a UBA interface structure, which
70  * contains information about the UNIBUS resources held by the interface:
71  * map registers, buffered data paths, etc.  Information is cached in this
72  * structure for use by the if_uba.c routines in running the interface
73  * efficiently.
74  */
75 struct	il_softc {
76 	struct	arpcom is_ac;		/* Ethernet common part */
77 #define	is_if	is_ac.ac_if		/* network-visible interface */
78 #define	is_addr	is_ac.ac_enaddr		/* hardware Ethernet address */
79 	struct	ifuba is_ifuba;		/* UNIBUS resources */
80 	int	is_flags;
81 #define	ILF_OACTIVE	0x1		/* output is active */
82 #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
83 #define	ILF_STATPENDING	0x4		/* stat cmd pending */
84 #define	ILF_RUNNING	0x8		/* board is running */
85 	short	is_lastcmd;		/* can't read csr, so must save it */
86 	short	is_scaninterval;	/* interval of stat collection */
87 #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
88 	struct	il_stats is_stats;	/* holds on-board statistics */
89 	struct	il_stats is_sum;	/* summation over time */
90 	int	is_ubaddr;		/* mapping registers of is_stats */
91 } il_softc[NIL];
92 
93 ilprobe(reg)
94 	caddr_t reg;
95 {
96 	register int br, cvec;		/* r11, r10 value-result */
97 	register struct ildevice *addr = (struct ildevice *)reg;
98 	register i;
99 
100 #ifdef lint
101 	br = 0; cvec = br; br = cvec;
102 	i = 0; ilrint(i); ilcint(i); ilwatch(i);
103 #endif
104 
105 	addr->il_csr = ILC_OFFLINE|IL_CIE;
106 	DELAY(100000);
107 	i = addr->il_csr;		/* clear CDONE */
108 	if (cvec > 0 && cvec != 0x200)
109 		cvec -= 4;
110 	return (1);
111 }
112 
113 /*
114  * Interface exists: make available by filling in network interface
115  * record.  System will initialize the interface when it is ready
116  * to accept packets.  A STATUS command is done to get the ethernet
117  * address and other interesting data.
118  */
119 ilattach(ui)
120 	struct uba_device *ui;
121 {
122 	register struct il_softc *is = &il_softc[ui->ui_unit];
123 	register struct ifnet *ifp = &is->is_if;
124 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
125 
126 	ifp->if_unit = ui->ui_unit;
127 	ifp->if_name = "il";
128 	ifp->if_mtu = ETHERMTU;
129 	ifp->if_flags = IFF_BROADCAST;
130 
131 	/*
132 	 * Reset the board and map the statistics
133 	 * buffer onto the Unibus.
134 	 */
135 	addr->il_csr = ILC_RESET;
136 	while ((addr->il_csr&IL_CDONE) == 0)
137 		;
138 	if (addr->il_csr&IL_STATUS)
139 		printf("il%d: reset failed, csr=%b\n", ui->ui_unit,
140 			addr->il_csr, IL_BITS);
141 
142 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
143 	    sizeof (struct il_stats), 0);
144 	addr->il_bar = is->is_ubaddr & 0xffff;
145 	addr->il_bcr = sizeof (struct il_stats);
146 	addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT;
147 	while ((addr->il_csr&IL_CDONE) == 0)
148 		;
149 	if (addr->il_csr&IL_STATUS)
150 		printf("il%d: status failed, csr=%b\n", ui->ui_unit,
151 			addr->il_csr, IL_BITS);
152 	ubarelse(ui->ui_ubanum, &is->is_ubaddr);
153 #ifdef notdef
154 	printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n",
155 		ui->ui_unit,
156 		is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff,
157 		is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff,
158 		is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff,
159 		is->is_stats.ils_module, is->is_stats.ils_firmware);
160 #endif
161  	bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)is->is_addr,
162  	    sizeof (is->is_addr));
163 	ifp->if_init = ilinit;
164 	ifp->if_output = iloutput;
165 	ifp->if_ioctl = ilioctl;
166 	ifp->if_reset = ilreset;
167 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
168 #ifdef notdef
169 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
170 #endif
171 	if_attach(ifp);
172 }
173 
174 /*
175  * Reset of interface after UNIBUS reset.
176  * If interface is on specified uba, reset its state.
177  */
178 ilreset(unit, uban)
179 	int unit, uban;
180 {
181 	register struct uba_device *ui;
182 
183 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
184 	    ui->ui_ubanum != uban)
185 		return;
186 	printf(" il%d", unit);
187 	il_softc[unit].is_if.if_flags &= ~IFF_RUNNING;
188 	il_softc[unit].is_flags &= ~ILF_RUNNING;
189 	ilinit(unit);
190 }
191 
192 /*
193  * Initialization of interface; clear recorded pending
194  * operations, and reinitialize UNIBUS usage.
195  */
196 ilinit(unit)
197 	int unit;
198 {
199 	register struct il_softc *is = &il_softc[unit];
200 	register struct uba_device *ui = ilinfo[unit];
201 	register struct ildevice *addr;
202 	register struct ifnet *ifp = &is->is_if;
203 	int s;
204 
205 	/* not yet, if address still unknown */
206 	if (ifp->if_addrlist == (struct ifaddr *)0)
207 		return;
208 	if (is->is_flags & ILF_RUNNING)
209 		return;
210 
211 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
212 		if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
213 		    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
214 			printf("il%d: can't initialize\n", unit);
215 			is->is_if.if_flags &= ~IFF_UP;
216 			return;
217 		}
218 		is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
219 		    sizeof (struct il_stats), 0);
220 	}
221 	ifp->if_watchdog = ilwatch;
222 	is->is_scaninterval = ILWATCHINTERVAL;
223 	ifp->if_timer = is->is_scaninterval;
224 	addr = (struct ildevice *)ui->ui_addr;
225 
226 	/*
227 	 * Turn off source address insertion (it's faster this way),
228 	 * and set board online.  Former doesn't work if board is
229 	 * already online (happens on ubareset), so we put it offline
230 	 * first.
231 	 */
232 	s = splimp();
233 	addr->il_csr = ILC_RESET;
234 	while ((addr->il_csr & IL_CDONE) == 0)
235 		;
236  	if (addr->il_csr & IL_STATUS) {
237  		printf("il%d failed hardware diag 0x%X\n", unit,
238  		   addr->il_csr & 0xffff);
239  		is->is_if.if_flags &= ~IFF_UP;
240  		splx(s);
241  		return;
242  	}
243 	addr->il_csr = ILC_CISA;
244 	while ((addr->il_csr & IL_CDONE) == 0)
245 		;
246 	/*
247 	 * Set board online.
248 	 * Hang receive buffer and start any pending
249 	 * writes by faking a transmit complete.
250 	 * Receive bcr is not a multiple of 8 so buffer
251 	 * chaining can't happen.
252 	 */
253 	addr->il_csr = ILC_ONLINE;
254 	while ((addr->il_csr & IL_CDONE) == 0)
255 		;
256 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
257 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
258 	addr->il_csr =
259 	    ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
260 	while ((addr->il_csr & IL_CDONE) == 0)
261 		;
262 	is->is_flags = ILF_OACTIVE;
263 	is->is_if.if_flags |= IFF_RUNNING;
264 	is->is_flags |= ILF_RUNNING;
265 	is->is_lastcmd = 0;
266 	ilcint(unit);
267 	splx(s);
268 }
269 
270 /*
271  * Start output on interface.
272  * Get another datagram to send off of the interface queue,
273  * and map it to the interface before starting the output.
274  */
275 ilstart(dev)
276 	dev_t dev;
277 {
278         int unit = ILUNIT(dev), len;
279 	struct uba_device *ui = ilinfo[unit];
280 	register struct il_softc *is = &il_softc[unit];
281 	register struct ildevice *addr;
282 	struct mbuf *m;
283 	short csr;
284 
285 	IF_DEQUEUE(&is->is_if.if_snd, m);
286 	addr = (struct ildevice *)ui->ui_addr;
287 	if (m == 0) {
288 		if ((is->is_flags & ILF_STATPENDING) == 0)
289 			return;
290 		addr->il_bar = is->is_ubaddr & 0xffff;
291 		addr->il_bcr = sizeof (struct il_stats);
292 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
293 		is->is_flags &= ~ILF_STATPENDING;
294 		goto startcmd;
295 	}
296 	len = if_wubaput(&is->is_ifuba, m);
297 	/*
298 	 * Ensure minimum packet length.
299 	 * This makes the safe assumtion that there are no virtual holes
300 	 * after the data.
301 	 * For security, it might be wise to zero out the added bytes,
302 	 * but we're mainly interested in speed at the moment.
303 	 */
304 	if (len - sizeof(struct ether_header) < ETHERMIN)
305 		len = ETHERMIN + sizeof(struct ether_header);
306 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
307 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
308 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
309 	addr->il_bcr = len;
310 	csr =
311 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
312 
313 startcmd:
314 	is->is_lastcmd = csr & IL_CMD;
315 	addr->il_csr = csr;
316 	is->is_flags |= ILF_OACTIVE;
317 }
318 
319 /*
320  * Command done interrupt.
321  */
322 ilcint(unit)
323 	int unit;
324 {
325 	register struct il_softc *is = &il_softc[unit];
326 	struct uba_device *ui = ilinfo[unit];
327 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
328 	short csr;
329 
330 	if ((is->is_flags & ILF_OACTIVE) == 0) {
331 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
332 			addr->il_csr, IL_BITS);
333 		return;
334 	}
335 
336 	csr = addr->il_csr;
337 	/*
338 	 * Hang receive buffer if it couldn't
339 	 * be done earlier (in ilrint).
340 	 */
341 	if (is->is_flags & ILF_RCVPENDING) {
342 		int s;
343 
344 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
345 		addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
346 		addr->il_csr =
347 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
348 		s = splhigh();
349 		while ((addr->il_csr & IL_CDONE) == 0)
350 			;
351 		splx(s);
352 		is->is_flags &= ~ILF_RCVPENDING;
353 	}
354 	is->is_flags &= ~ILF_OACTIVE;
355 	csr &= IL_STATUS;
356 	switch (is->is_lastcmd) {
357 
358 	case ILC_XMIT:
359 		is->is_if.if_opackets++;
360 		if (csr > ILERR_RETRIES)
361 			is->is_if.if_oerrors++;
362 		break;
363 
364 	case ILC_STAT:
365 		if (csr == ILERR_SUCCESS)
366 			iltotal(is);
367 		break;
368 	}
369 	if (is->is_ifuba.ifu_xtofree) {
370 		m_freem(is->is_ifuba.ifu_xtofree);
371 		is->is_ifuba.ifu_xtofree = 0;
372 	}
373 	ilstart(unit);
374 }
375 
376 /*
377  * Ethernet interface receiver interrupt.
378  * If input error just drop packet.
379  * Otherwise purge input buffered data path and examine
380  * packet to determine type.  If can't determine length
381  * from type, then have to drop packet.  Othewise decapsulate
382  * packet based on type and pass to type specific higher-level
383  * input routine.
384  */
385 ilrint(unit)
386 	int unit;
387 {
388 	register struct il_softc *is = &il_softc[unit];
389 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
390 	register struct il_rheader *il;
391     	struct mbuf *m;
392 	int len, off, resid, s;
393 	register struct ifqueue *inq;
394 
395 	is->is_if.if_ipackets++;
396 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
397 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
398 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
399 	len = il->ilr_length - sizeof(struct il_rheader);
400 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
401 	    len > ETHERMTU) {
402 		is->is_if.if_ierrors++;
403 #ifdef notdef
404 		if (is->is_if.if_ierrors % 100 == 0)
405 			printf("il%d: += 100 input errors\n", unit);
406 #endif
407 		goto setup;
408 	}
409 
410 	/*
411 	 * Deal with trailer protocol: if type is trailer type
412 	 * get true type from first 16-bit word past data.
413 	 * Remember that type was trailer by setting off.
414 	 */
415 	il->ilr_type = ntohs((u_short)il->ilr_type);
416 #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
417 	if (il->ilr_type >= ETHERTYPE_TRAIL &&
418 	    il->ilr_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
419 		off = (il->ilr_type - ETHERTYPE_TRAIL) * 512;
420 		if (off >= ETHERMTU)
421 			goto setup;		/* sanity */
422 		il->ilr_type = ntohs(*ildataaddr(il, off, u_short *));
423 		resid = ntohs(*(ildataaddr(il, off+2, u_short *)));
424 		if (off + resid > len)
425 			goto setup;		/* sanity */
426 		len = off + resid;
427 	} else
428 		off = 0;
429 	if (len == 0)
430 		goto setup;
431 
432 	/*
433 	 * Pull packet off interface.  Off is nonzero if packet
434 	 * has trailing header; ilget will then force this header
435 	 * information to be at the front, but we still have to drop
436 	 * the type and length which are at the front of any trailer data.
437 	 */
438 	m = if_rubaget(&is->is_ifuba, len, off, &is->is_if);
439 	if (m == 0)
440 		goto setup;
441 	if (off) {
442 		struct ifnet *ifp;
443 
444 		ifp = *(mtod(m, struct ifnet **));
445 		m->m_off += 2 * sizeof (u_short);
446 		m->m_len -= 2 * sizeof (u_short);
447 		*(mtod(m, struct ifnet **)) = ifp;
448 	}
449 	switch (il->ilr_type) {
450 
451 #ifdef INET
452 	case ETHERTYPE_IP:
453 		schednetisr(NETISR_IP);
454 		inq = &ipintrq;
455 		break;
456 
457 	case ETHERTYPE_ARP:
458 		arpinput(&is->is_ac, m);
459 		goto setup;
460 #endif
461 #ifdef NS
462 	case ETHERTYPE_NS:
463 		schednetisr(NETISR_NS);
464 		inq = &nsintrq;
465 		break;
466 
467 #endif
468 	default:
469 		m_freem(m);
470 		goto setup;
471 	}
472 
473 	s = splimp();
474 	if (IF_QFULL(inq)) {
475 		IF_DROP(inq);
476 		m_freem(m);
477 	} else
478 		IF_ENQUEUE(inq, m);
479 	splx(s);
480 
481 setup:
482 	/*
483 	 * Reset for next packet if possible.
484 	 * If waiting for transmit command completion, set flag
485 	 * and wait until command completes.
486 	 */
487 	if (is->is_flags & ILF_OACTIVE) {
488 		is->is_flags |= ILF_RCVPENDING;
489 		return;
490 	}
491 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
492 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
493 	addr->il_csr =
494 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
495 	s = splhigh();
496 	while ((addr->il_csr & IL_CDONE) == 0)
497 		;
498 	splx(s);
499 }
500 
501 /*
502  * Ethernet output routine.
503  * Encapsulate a packet of type family for the local net.
504  * Use trailer local net encapsulation if enough data in first
505  * packet leaves a multiple of 512 bytes of data in remainder.
506  */
507 iloutput(ifp, m0, dst)
508 	struct ifnet *ifp;
509 	struct mbuf *m0;
510 	struct sockaddr *dst;
511 {
512 	int type, s, error;
513  	u_char edst[6];
514 	struct in_addr idst;
515 	register struct il_softc *is = &il_softc[ifp->if_unit];
516 	register struct mbuf *m = m0;
517 	register struct ether_header *il;
518 	register int off;
519 
520 	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
521 		error = ENETDOWN;
522 		goto bad;
523 	}
524 	switch (dst->sa_family) {
525 
526 #ifdef INET
527 	case AF_INET:
528 		idst = ((struct sockaddr_in *)dst)->sin_addr;
529  		if (!arpresolve(&is->is_ac, m, &idst, edst))
530 			return (0);	/* if not yet resolved */
531 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
532 		/* need per host negotiation */
533 		if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
534 		if (off > 0 && (off & 0x1ff) == 0 &&
535 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
536 			type = ETHERTYPE_TRAIL + (off>>9);
537 			m->m_off -= 2 * sizeof (u_short);
538 			m->m_len += 2 * sizeof (u_short);
539 			*mtod(m, u_short *) = htons((u_short)ETHERTYPE_IP);
540 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
541 			goto gottrailertype;
542 		}
543 		type = ETHERTYPE_IP;
544 		off = 0;
545 		goto gottype;
546 #endif
547 #ifdef NS
548 	case AF_NS:
549 		type = ETHERTYPE_NS;
550  		bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
551 		(caddr_t)edst, sizeof (edst));
552 		off = 0;
553 		goto gottype;
554 #endif
555 
556 	case AF_UNSPEC:
557 		il = (struct ether_header *)dst->sa_data;
558  		bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst));
559 		type = il->ether_type;
560 		goto gottype;
561 
562 	default:
563 		printf("il%d: can't handle af%d\n", ifp->if_unit,
564 			dst->sa_family);
565 		error = EAFNOSUPPORT;
566 		goto bad;
567 	}
568 
569 gottrailertype:
570 	/*
571 	 * Packet to be sent as trailer: move first packet
572 	 * (control information) to end of chain.
573 	 */
574 	while (m->m_next)
575 		m = m->m_next;
576 	m->m_next = m0;
577 	m = m0->m_next;
578 	m0->m_next = 0;
579 	m0 = m;
580 
581 gottype:
582 	/*
583 	 * Add local net header.  If no space in first mbuf,
584 	 * allocate another.
585 	 */
586 	if (m->m_off > MMAXOFF ||
587 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
588 		m = m_get(M_DONTWAIT, MT_HEADER);
589 		if (m == 0) {
590 			error = ENOBUFS;
591 			goto bad;
592 		}
593 		m->m_next = m0;
594 		m->m_off = MMINOFF;
595 		m->m_len = sizeof (struct ether_header);
596 	} else {
597 		m->m_off -= sizeof (struct ether_header);
598 		m->m_len += sizeof (struct ether_header);
599 	}
600 	il = mtod(m, struct ether_header *);
601 	il->ether_type = htons((u_short)type);
602  	bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst));
603  	bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost,
604 	    sizeof(il->ether_shost));
605 
606 	/*
607 	 * Queue message on interface, and start output if interface
608 	 * not yet active.
609 	 */
610 	s = splimp();
611 	if (IF_QFULL(&ifp->if_snd)) {
612 		IF_DROP(&ifp->if_snd);
613 		splx(s);
614 		m_freem(m);
615 		return (ENOBUFS);
616 	}
617 	IF_ENQUEUE(&ifp->if_snd, m);
618 	if ((is->is_flags & ILF_OACTIVE) == 0)
619 		ilstart(ifp->if_unit);
620 	splx(s);
621 	return (0);
622 
623 bad:
624 	m_freem(m0);
625 	return (error);
626 }
627 
628 /*
629  * Watchdog routine, request statistics from board.
630  */
631 ilwatch(unit)
632 	int unit;
633 {
634 	register struct il_softc *is = &il_softc[unit];
635 	register struct ifnet *ifp = &is->is_if;
636 	int s;
637 
638 	if (is->is_flags & ILF_STATPENDING) {
639 		ifp->if_timer = is->is_scaninterval;
640 		return;
641 	}
642 	s = splimp();
643 	is->is_flags |= ILF_STATPENDING;
644 	if ((is->is_flags & ILF_OACTIVE) == 0)
645 		ilstart(ifp->if_unit);
646 	splx(s);
647 	ifp->if_timer = is->is_scaninterval;
648 }
649 
650 /*
651  * Total up the on-board statistics.
652  */
653 iltotal(is)
654 	register struct il_softc *is;
655 {
656 	register u_short *interval, *sum, *end;
657 
658 	interval = &is->is_stats.ils_frames;
659 	sum = &is->is_sum.ils_frames;
660 	end = is->is_sum.ils_fill2;
661 	while (sum < end)
662 		*sum++ += *interval++;
663 	is->is_if.if_collisions = is->is_sum.ils_collis;
664 }
665 
666 /*
667  * Process an ioctl request.
668  */
669 ilioctl(ifp, cmd, data)
670 	register struct ifnet *ifp;
671 	int cmd;
672 	caddr_t data;
673 {
674 	register struct ifaddr *ifa = (struct ifaddr *)data;
675 	register struct il_softc *is = &il_softc[ifp->if_unit];
676 	int s = splimp(), error = 0;
677 
678 	switch (cmd) {
679 
680 	case SIOCSIFADDR:
681 		ifp->if_flags |= IFF_UP;
682 		ilinit(ifp->if_unit);
683 
684 		switch (ifa->ifa_addr.sa_family) {
685 #ifdef INET
686 		case AF_INET:
687 			((struct arpcom *)ifp)->ac_ipaddr =
688 				IA_SIN(ifa)->sin_addr;
689 			arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
690 			break;
691 #endif
692 #ifdef NS
693 		case AF_NS:
694 			IA_SNS(ifa)->sns_addr.x_host =
695 				* (union ns_host *)
696 				     (is->is_addr);
697 			break;
698 #endif
699 		}
700 		break;
701 
702 	case SIOCSIFFLAGS:
703 		if ((ifp->if_flags & IFF_UP) == 0 &&
704 		    is->is_flags & ILF_RUNNING) {
705 			((struct ildevice *)
706 			   (ilinfo[ifp->if_unit]->ui_addr))->il_csr = ILC_RESET;
707 			is->is_flags &= ~ILF_RUNNING;
708 		} else if (ifp->if_flags & IFF_UP &&
709 		    (is->is_flags & ILF_RUNNING) == 0)
710 			ilinit(ifp->if_unit);
711 		break;
712 
713 	default:
714 		error = EINVAL;
715 	}
716 	splx(s);
717 	return (error);
718 }
719 #endif
720