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