xref: /original-bsd/sys/luna68k/dev/if_le.c (revision 68d9582f)
1 /*
2  * Copyright (c) 1982, 1990, 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)if_le.c	7.1 (Berkeley) 06/15/92
8  */
9 
10 #include "le.h"
11 #if NLE > 0
12 
13 #include "bpfilter.h"
14 
15 /*
16  * AMD 7990 LANCE
17  *
18  * This driver will generate and accept tailer encapsulated packets even
19  * though it buys us nothing.  The motivation was to avoid incompatibilities
20  * with VAXen, SUNs, and others that handle and benefit from them.
21  * This reasoning is dubious.
22  */
23 #include "sys/param.h"
24 #include "sys/proc.h"
25 #include "sys/systm.h"
26 #include "sys/mbuf.h"
27 #include "sys/buf.h"
28 #include "sys/protosw.h"
29 #include "sys/socket.h"
30 #include "sys/syslog.h"
31 #include "sys/ioctl.h"
32 #include "sys/errno.h"
33 
34 #include "net/if.h"
35 #include "net/netisr.h"
36 #include "net/route.h"
37 
38 #ifdef INET
39 #include "netinet/in.h"
40 #include "netinet/in_systm.h"
41 #include "netinet/in_var.h"
42 #include "netinet/ip.h"
43 #include "netinet/if_ether.h"
44 #endif
45 
46 #ifdef NS
47 #include "netns/ns.h"
48 #include "netns/ns_if.h"
49 #endif
50 
51 #ifdef ISO
52 extern	char all_es_snpa[], all_is_snpa[], all_l1is_snpa[], all_l2is_snpa[];
53 #endif
54 
55 #include "../include/cpu.h"
56 #include "../include/mtpr.h"
57 #include "device.h"
58 #include "if_lereg.h"
59 
60 #if NBPFILTER > 0
61 #include "../net/bpf.h"
62 #include "../net/bpfdesc.h"
63 char hprmp_multi[] = { 9, 0, 9, 0, 0, 4};
64 #endif
65 
66 
67 int	leattach();
68 struct	driver ledriver = {
69 	leattach, "le",
70 };
71 
72 int	ledebug = 0;		/* console error messages */
73 
74 int	leintr(), leinit(), leioctl(), lestart(), ether_output();
75 struct	mbuf *m_devget();
76 extern	struct ifnet loif;
77 
78 /*
79  * Ethernet software status per interface.
80  *
81  * Each interface is referenced by a network interface structure,
82  * le_if, which the routing code uses to locate the interface.
83  * This structure contains the output queue for the interface, its address, ...
84  */
85 struct	le_softc {
86 	struct	arpcom sc_ac;	/* common Ethernet structures */
87 #define	sc_if	sc_ac.ac_if	/* network-visible interface */
88 #define	sc_addr	sc_ac.ac_enaddr	/* hardware Ethernet address */
89 	struct	lereg1 *sc_r1;	/* LANCE registers */
90 	struct	lereg2 *sc_r2;	/* dual-port RAM */
91 	int	sc_rmd;		/* predicted next rmd to process */
92 	int	sc_runt;
93 	int	sc_jab;
94 	int	sc_merr;
95 	int	sc_babl;
96 	int	sc_cerr;
97 	int	sc_miss;
98 	int	sc_xint;
99 	int	sc_xown;
100 	int	sc_uflo;
101 	int	sc_rxlen;
102 	int	sc_rxoff;
103 	int	sc_txoff;
104 	int	sc_busy;
105 	short	sc_iflags;
106 	caddr_t sc_bpf;
107 	int	sc_tmd;		/* predicted next tmd to process */
108 	int	sc_txcnt;	/* transmissions in progress */
109 	int	sc_txbad;
110 	int	sc_txbusy;
111 } le_softc[NLE];
112 
113 /* access LANCE registers */
114 #define	LERDWR(cntl, src, dst)	(dst) = (src)
115 
116 #define LE_IPL		3
117 
118 /*
119  * Interface exists: make available by filling in network interface
120  * record.  System will initialize the interface when it is ready
121  * to accept packets.
122  */
123 leattach(hd)
124 	struct hp_device *hd;
125 {
126 	register struct lereg2 *ler2;
127 	struct lereg2 *lemem = (struct lereg2 *) 0;
128 	struct le_softc *le = &le_softc[hd->hp_unit];
129 	struct ifnet *ifp = &le->sc_if;
130 	char *cp;
131 	int i;
132 
133 	le->sc_r1 = (struct lereg1 *) hd->hp_addr;
134 	ler2 = le->sc_r2 = (struct lereg2 *) 0x71000000;
135 
136 	hd->hp_ipl = LE_IPL;
137 
138 	/*
139 	 * Read the ethernet address off the board, one nibble at a time.
140 	 */
141 #ifdef NOROM
142 	cp = "00000a02456c";
143 #else
144 	cp = (char *) 0x4101FFE0;
145 #endif
146 	for (i = 0; i < sizeof(le->sc_addr); i++) {
147 		le->sc_addr[i]  = (*cp < 'A' ? (*cp & 0xF) : (*cp & 0xF) + 9) << 4;
148 		cp++;
149 		le->sc_addr[i] |= (*cp < 'A' ? (*cp & 0xF) : (*cp & 0xF) + 9);
150 		cp++;
151 	}
152 	printf("le%d: hardware address %s\n", hd->hp_unit,
153 		ether_sprintf(le->sc_addr));
154 
155 	/*
156 	 * Setup for transmit/receive
157 	 */
158 	ler2->ler2_mode = LE_MODE;
159 #if defined(ISO) || NBPFILTER > 0
160 	ler2->ler2_ladrf0 = 0xffffffff;
161 	ler2->ler2_ladrf1 = 0xffffffff;
162 #else
163 	ler2->ler2_ladrf0 = 0;
164 	ler2->ler2_ladrf1 = 0;
165 #endif
166 	ler2->ler2_rlen = LE_RLEN;
167 	ler2->ler2_rdra = (int)lemem->ler2_rmd;
168 	ler2->ler2_tlen = LE_TLEN;
169 	ler2->ler2_tdra = (int)lemem->ler2_tmd;
170 
171 	ifp->if_unit = hd->hp_unit;
172 	ifp->if_name = "le";
173 	ifp->if_mtu = ETHERMTU;
174 	ifp->if_init = leinit;
175 	ifp->if_ioctl = leioctl;
176 	ifp->if_output = ether_output;
177 	ifp->if_start = lestart;
178 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
179 #if NBPFILTER > 0
180 	bpfattach(&le->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
181 #endif
182 	if_attach(ifp);
183 	return (1);
184 }
185 
186 ledrinit(ler2, le)
187 	register struct lereg2 *ler2;
188 	register struct le_softc *le;
189 {
190 	register struct lereg2 *lemem = (struct lereg2 *) 0;
191 	register int i;
192 
193 	ler2->ler2_padr[0] = le->sc_addr[1];
194 	ler2->ler2_padr[1] = le->sc_addr[0];
195 	ler2->ler2_padr[2] = le->sc_addr[3];
196 	ler2->ler2_padr[3] = le->sc_addr[2];
197 	ler2->ler2_padr[4] = le->sc_addr[5];
198 	ler2->ler2_padr[5] = le->sc_addr[4];
199 	for (i = 0; i < LERBUF; i++) {
200 		ler2->ler2_rmd[i].rmd0 = (int)lemem->ler2_rbuf[i];
201 		ler2->ler2_rmd[i].rmd1 = LE_OWN;
202 		ler2->ler2_rmd[i].rmd2 = -LEMTU;
203 		ler2->ler2_rmd[i].rmd3 = 0;
204 	}
205 	for (i = 0; i < LETBUF; i++) {
206 		ler2->ler2_tmd[i].tmd0 = (int)lemem->ler2_tbuf[i];
207 		ler2->ler2_tmd[i].tmd1 = 0;
208 		ler2->ler2_tmd[i].tmd2 = 0;
209 		ler2->ler2_tmd[i].tmd3 = 0;
210 	}
211 }
212 
213 lereset(unit)
214 	register int unit;
215 {
216 	register struct le_softc *le = &le_softc[unit];
217 	register struct lereg1 *ler1 = le->sc_r1;
218 	register struct lereg2 *lemem = (struct lereg2 *) 0;
219 	register int timo = 100000;
220 	register int stat;
221 
222 #ifdef lint
223 	stat = unit;
224 #endif
225 #if NBPFILTER > 0
226 	if (le->sc_if.if_flags & IFF_PROMISC)
227 		/* set the promiscuous bit */
228 		le->sc_r2->ler2_mode = LE_MODE|0x8000;
229 	else
230 		le->sc_r2->ler2_mode = LE_MODE;
231 #endif
232 	LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
233 	LERDWR(ler0, LE_STOP, ler1->ler1_rdp);
234 	ledrinit(le->sc_r2, le);
235 	le->sc_txcnt = le->sc_tmd = le->sc_rmd = 0;
236 	LERDWR(ler0, LE_CSR1, ler1->ler1_rap);
237 	LERDWR(ler0, (int)&lemem->ler2_mode, ler1->ler1_rdp);
238 	LERDWR(ler0, LE_CSR2, ler1->ler1_rap);
239 	LERDWR(ler0, 0, ler1->ler1_rdp);
240 	LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
241 	LERDWR(ler0, LE_INIT, ler1->ler1_rdp);
242 	do {
243 		if (--timo == 0) {
244 			printf("le%d: init timeout, stat = 0x%x\n",
245 			       unit, stat);
246 			break;
247 		}
248 		LERDWR(ler0, ler1->ler1_rdp, stat);
249 	} while ((stat & LE_IDON) == 0);
250 	LERDWR(ler0, LE_STOP, ler1->ler1_rdp);
251 	LERDWR(ler0, LE_CSR3, ler1->ler1_rap);
252 	LERDWR(ler0, LE_BSWP, ler1->ler1_rdp);
253 	LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
254 	LERDWR(ler0, LE_STRT | LE_INEA, ler1->ler1_rdp);
255 	le->sc_if.if_flags &= ~IFF_OACTIVE;
256 }
257 
258 /*
259  * Initialization of interface
260  */
261 leinit(unit)
262 	int unit;
263 {
264 	register struct ifnet *ifp = &le_softc[unit].sc_if;
265 	register struct ifaddr *ifa;
266 	int s;
267 
268 	/* not yet, if address still unknown */
269 	for (ifa = ifp->if_addrlist;; ifa = ifa->ifa_next)
270 		if (ifa == 0)
271 			return;
272 		else if (ifa->ifa_addr && ifa->ifa_addr->sa_family != AF_LINK)
273 			break;
274 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
275 		s = splimp();
276 		ifp->if_flags |= IFF_RUNNING;
277 		lereset(unit);
278 	        (void) lestart(ifp);
279 		splx(s);
280 	}
281 }
282 
283 /*
284  * Start output on interface.  Get another datagram to send
285  * off of the interface queue, and copy it to the interface
286  * before starting the output.
287  */
288 lestart(ifp)
289 	struct ifnet *ifp;
290 {
291 	register struct le_softc *le = &le_softc[ifp->if_unit];
292 	register struct letmd *tmd;
293 	register struct mbuf *m;
294 	int len;
295 
296 again:
297 	if ((le->sc_if.if_flags & IFF_RUNNING) == 0)
298 		return (0);
299 	IF_DEQUEUE(&le->sc_if.if_snd, m);
300 	if (m == 0)
301 		return (0);
302 	tmd = le->sc_r2->ler2_tmd + le->sc_tmd;
303 	if (tmd->tmd1 & LE_OWN)
304 		return (le->sc_txbusy++, 0);
305 	len = leput(le->sc_r2->ler2_tbuf[le->sc_tmd], m);
306 #if NBPFILTER > 0
307 	/*
308 	 * If bpf is listening on this interface, let it
309 	 * see the packet before we commit it to the wire.
310 	 */
311 	if (le->sc_bpf)
312                 bpf_tap(le->sc_bpf, le->sc_r2->ler2_tbuf[le->sc_tmd], len);
313 #endif
314 	tmd->tmd3 = 0;
315 	tmd->tmd2 = -len;
316 	if (++le->sc_tmd >= LETBUF)
317 		le->sc_tmd = 0;
318 	if (++le->sc_txcnt >= LETBUF) {
319 		le->sc_txcnt = LETBUF;
320 		le->sc_if.if_flags |= IFF_OACTIVE;
321 		tmd->tmd1 = LE_OWN | LE_STP | LE_ENP;
322 	} else {
323 		tmd->tmd1 = LE_OWN | LE_STP | LE_ENP;
324 		goto again;
325 	}
326 	return (0);
327 }
328 
329 void
330 _leintr()
331 {
332 	register int i;
333 
334 	for (i = 0; i < NLE; i++) {
335 		leintr(i);
336 	}
337 }
338 
339 int
340 leintr(unit)
341 	register int unit;
342 {
343 	register struct le_softc *le = &le_softc[unit];
344 	register struct lereg1 *ler1;
345 	register int stat;
346 
347 	ler1 = le->sc_r1;
348 	LERDWR(ler0, ler1->ler1_rdp, stat);
349 	if (stat & LE_SERR) {
350 		leerror(unit, stat);
351 		if (stat & LE_MERR) {
352 			le->sc_merr++;
353 			lereset(unit);
354 			return(1);
355 		}
356 		if (stat & LE_BABL)
357 			le->sc_babl++;
358 		if (stat & LE_CERR)
359 			le->sc_cerr++;
360 		if (stat & LE_MISS)
361 			le->sc_miss++;
362 		LERDWR(ler0, LE_BABL|LE_CERR|LE_MISS|LE_INEA, ler1->ler1_rdp);
363 	}
364 	if ((stat & LE_RXON) == 0) {
365 		le->sc_rxoff++;
366 		lereset(unit);
367 		return(1);
368 	}
369 	if ((stat & LE_TXON) == 0) {
370 		le->sc_txoff++;
371 		lereset(unit);
372 		return(1);
373 	}
374 	if (stat & LE_RINT) {
375 		/* interrupt is cleared in lerint */
376 		lerint(unit);
377 	}
378 	if (stat & LE_TINT) {
379 		LERDWR(ler0, LE_TINT|LE_INEA, ler1->ler1_rdp);
380 		lexint(unit);
381 	}
382 	return(1);
383 }
384 
385 /*
386  * Ethernet interface transmitter interrupt.
387  * Start another output if more data to send.
388  */
389 lexint(unit)
390 	register int unit;
391 {
392 	register struct le_softc *le = &le_softc[unit];
393 	register struct letmd *tmd;
394 	int i, loopcount = 0;
395 
396 	if (le->sc_txcnt == 0) {
397 		le->sc_xint++;
398 		return;
399 	}
400 again:
401 	if ((i = le->sc_tmd - le->sc_txcnt) < 0) i += LETBUF;
402 	tmd = le->sc_r2->ler2_tmd + i;
403 	if (tmd->tmd1 & LE_OWN) {
404 		if (loopcount)
405 			goto out;
406 		le->sc_xown++;
407 		return;
408 	}
409 	if (tmd->tmd1 & LE_ERR) {
410 err:
411 		lexerror(unit);
412 		le->sc_if.if_oerrors++;
413 		if (tmd->tmd3 & (LE_TBUFF|LE_UFLO)) {
414 			le->sc_uflo++;
415 			lereset(unit);
416 		}
417 		else if (tmd->tmd3 & LE_LCOL)
418 			le->sc_if.if_collisions++;
419 		else if (tmd->tmd3 & LE_RTRY)
420 			le->sc_if.if_collisions += 16;
421 	}
422 	else if (tmd->tmd3 & LE_TBUFF)
423 		/* XXX documentation says BUFF not included in ERR */
424 		goto err;
425 	else if (tmd->tmd1 & LE_ONE)
426 		le->sc_if.if_collisions++;
427 	else if (tmd->tmd1 & LE_MORE)
428 		/* what is the real number? */
429 		le->sc_if.if_collisions += 2;
430 	else
431 		le->sc_if.if_opackets++;
432 	loopcount++;
433 	if (--le->sc_txcnt > 0)
434 		goto again;
435 	if (le->sc_txcnt < 0) {
436 		le->sc_txbad++;
437 		le->sc_txcnt = 0;
438 	}
439 out:
440 	le->sc_if.if_flags &= ~IFF_OACTIVE;
441 	(void) lestart(&le->sc_if);
442 }
443 
444 #define	LENEXTRMP \
445 	if (++bix == LERBUF) bix = 0, rmd = le->sc_r2->ler2_rmd; else ++rmd
446 
447 /*
448  * Ethernet interface receiver interrupt.
449  * If input error just drop packet.
450  * Decapsulate packet based on type and pass to type specific
451  * higher-level input routine.
452  */
453 lerint(unit)
454 	int unit;
455 {
456 	register struct le_softc *le = &le_softc[unit];
457 	register int bix = le->sc_rmd;
458 	register struct lermd *rmd = &le->sc_r2->ler2_rmd[bix];
459 
460 	/*
461 	 * Out of sync with hardware, should never happen?
462 	 */
463 	if (rmd->rmd1 & LE_OWN) {
464 		LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
465 		return;
466 	}
467 
468 	/*
469 	 * Process all buffers with valid data
470 	 */
471 	while ((rmd->rmd1 & LE_OWN) == 0) {
472 		int len = rmd->rmd3;
473 
474 		/* Clear interrupt to avoid race condition */
475 		LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
476 
477 		if (rmd->rmd1 & LE_ERR) {
478 			le->sc_rmd = bix;
479 			lererror(unit, "bad packet");
480 			le->sc_if.if_ierrors++;
481 		} else if ((rmd->rmd1 & (LE_STP|LE_ENP)) != (LE_STP|LE_ENP)) {
482 			/*
483 			 * Find the end of the packet so we can see how long
484 			 * it was.  We still throw it away.
485 			 */
486 			do {
487 				LERDWR(le->sc_r0, LE_RINT|LE_INEA,
488 				       le->sc_r1->ler1_rdp);
489 				rmd->rmd3 = 0;
490 				rmd->rmd1 = LE_OWN;
491 				LENEXTRMP;
492 			} while (!(rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)));
493 			le->sc_rmd = bix;
494 			lererror(unit, "chained buffer");
495 			le->sc_rxlen++;
496 			/*
497 			 * If search terminated without successful completion
498 			 * we reset the hardware (conservative).
499 			 */
500 			if ((rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)) !=
501 			    LE_ENP) {
502 				lereset(unit);
503 				return;
504 			}
505 		} else
506 			leread(unit, le->sc_r2->ler2_rbuf[bix], len);
507 		rmd->rmd3 = 0;
508 		rmd->rmd1 = LE_OWN;
509 		LENEXTRMP;
510 	}
511 	le->sc_rmd = bix;
512 }
513 
514 leread(unit, buf, len)
515 	int unit;
516 	char *buf;
517 	int len;
518 {
519 	register struct le_softc *le = &le_softc[unit];
520 	register struct ether_header *et;
521     	struct mbuf *m;
522 	int off, resid;
523 
524 	le->sc_if.if_ipackets++;
525 	et = (struct ether_header *)buf;
526 	et->ether_type = ntohs((u_short)et->ether_type);
527 	/* adjust input length to account for header and CRC */
528 	len = len - sizeof(struct ether_header) - 4;
529 
530 #define	ledataaddr(et, off, type)	((type)(((caddr_t)((et)+1)+(off))))
531 	if (et->ether_type >= ETHERTYPE_TRAIL &&
532 	    et->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
533 		off = (et->ether_type - ETHERTYPE_TRAIL) * 512;
534 		if (off >= ETHERMTU)
535 			return;		/* sanity */
536 		et->ether_type = ntohs(*ledataaddr(et, off, u_short *));
537 		resid = ntohs(*(ledataaddr(et, off+2, u_short *)));
538 		if (off + resid > len)
539 			return;		/* sanity */
540 		len = off + resid;
541 	} else
542 		off = 0;
543 
544 	if (len <= 0) {
545 		if (ledebug)
546 			log(LOG_WARNING,
547 			    "le%d: ierror(runt packet): from %s: len=%d\n",
548 			    unit, ether_sprintf(et->ether_shost), len);
549 		le->sc_runt++;
550 		le->sc_if.if_ierrors++;
551 		return;
552 	}
553 #if NBPFILTER > 0
554 	/*
555 	 * Check if there's a bpf filter listening on this interface.
556 	 * If so, hand off the raw packet to bpf, which must deal with
557 	 * trailers in its own way.
558 	 */
559 	if (le->sc_bpf)
560 		bpf_tap(le->sc_bpf, buf, len + sizeof(struct ether_header));
561 #endif
562 #if defined(ISO) || NBPFILTER > 0
563 	/*
564 	 * Note that the interface cannot be in promiscuous mode if
565 	 * there are no bpf listeners.  If we are in promiscuous
566 	 * mode, we have to check if this packet is really ours.
567 	 * However, there may be appropriate multicate addresses involved
568 	 */
569 #define NOT_TO(p) (bcmp(et->ether_dhost, p, sizeof(et->ether_dhost)) != 0)
570 	if (et->ether_dhost[0] & 1) {
571 		if (NOT_TO(etherbroadcastaddr) && NOT_TO(hprmp_multi)
572 #ifdef ISO
573 		    && NOT_TO(all_es_snpa) && NOT_TO(all_is_snpa)
574 		    && NOT_TO(all_l1is_snpa) && NOT_TO(all_l2is_snpa)
575 #endif
576 		     ) return;
577 	} else if ((le->sc_if.if_flags & IFF_PROMISC) && NOT_TO(le->sc_addr))
578 		return;
579 #endif
580 	/*
581 	 * Pull packet off interface.  Off is nonzero if packet
582 	 * has trailing header; m_devget will then force this header
583 	 * information to be at the front, but we still have to drop
584 	 * the type and length which are at the front of any trailer data.
585 	 */
586 	m = m_devget((char *)(et + 1), len, off, &le->sc_if, 0);
587 	if (m == 0)
588 		return;
589 	ether_input(&le->sc_if, et, m);
590 }
591 
592 /*
593  * Routine to copy from mbuf chain to transmit
594  * buffer in board local memory.
595  */
596 leput(lebuf, m)
597 	register char *lebuf;
598 	register struct mbuf *m;
599 {
600 	register struct mbuf *mp;
601 	register int len, tlen = 0;
602 
603 	for (mp = m; mp; mp = mp->m_next) {
604 		len = mp->m_len;
605 		if (len == 0)
606 			continue;
607 		tlen += len;
608 		bcopy(mtod(mp, char *), lebuf, len);
609 		lebuf += len;
610 	}
611 	m_freem(m);
612 	if (tlen < LEMINSIZE) {
613 		bzero(lebuf, LEMINSIZE - tlen);
614 		tlen = LEMINSIZE;
615 	}
616 	return(tlen);
617 }
618 
619 /*
620  * Process an ioctl request.
621  */
622 leioctl(ifp, cmd, data)
623 	register struct ifnet *ifp;
624 	int cmd;
625 	caddr_t data;
626 {
627 	register struct ifaddr *ifa = (struct ifaddr *)data;
628 	struct le_softc *le = &le_softc[ifp->if_unit];
629 	struct lereg1 *ler1 = le->sc_r1;
630 	int s = splimp(), error = 0;
631 
632 	switch (cmd) {
633 
634 	case SIOCSIFADDR:
635 		ifp->if_flags |= IFF_UP;
636 		switch (ifa->ifa_addr->sa_family) {
637 #ifdef INET
638 		case AF_INET:
639 			leinit(ifp->if_unit);	/* before arpwhohas */
640 			((struct arpcom *)ifp)->ac_ipaddr =
641 				IA_SIN(ifa)->sin_addr;
642 			arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
643 			break;
644 #endif
645 #ifdef NS
646 		case AF_NS:
647 		    {
648 			register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
649 
650 			if (ns_nullhost(*ina))
651 				ina->x_host = *(union ns_host *)(le->sc_addr);
652 			else {
653 				/*
654 				 * The manual says we can't change the address
655 				 * while the receiver is armed,
656 				 * so reset everything
657 				 */
658 				ifp->if_flags &= ~IFF_RUNNING;
659 				LERDWR(le->sc_r0, LE_STOP, ler1->ler1_rdp);
660 				bcopy((caddr_t)ina->x_host.c_host,
661 				    (caddr_t)le->sc_addr, sizeof(le->sc_addr));
662 			}
663 			leinit(ifp->if_unit); /* does le_setaddr() */
664 			break;
665 		    }
666 #endif
667 		default:
668 			leinit(ifp->if_unit);
669 			break;
670 		}
671 		break;
672 
673 	case SIOCSIFFLAGS:
674 		if ((ifp->if_flags & IFF_UP) == 0 &&
675 		    ifp->if_flags & IFF_RUNNING) {
676 			LERDWR(le->sc_r0, LE_STOP, ler1->ler1_rdp);
677 			ifp->if_flags &= ~IFF_RUNNING;
678 		} else if (ifp->if_flags & IFF_UP &&
679 		    (ifp->if_flags & IFF_RUNNING) == 0)
680 			leinit(ifp->if_unit);
681 		/*
682 		 * If the state of the promiscuous bit changes, the interface
683 		 * must be reset to effect the change.
684 		 */
685 		if (((ifp->if_flags ^ le->sc_iflags) & IFF_PROMISC) &&
686 		    (ifp->if_flags & IFF_RUNNING)) {
687 			le->sc_iflags = ifp->if_flags;
688 			lereset(ifp->if_unit);
689 			lestart(ifp);
690 		}
691 		break;
692 
693 	default:
694 		error = EINVAL;
695 	}
696 	splx(s);
697 	return (error);
698 }
699 
700 leerror(unit, stat)
701 	int unit;
702 	int stat;
703 {
704 	if (!ledebug)
705 		return;
706 
707 	/*
708 	 * Not all transceivers implement heartbeat
709 	 * so we only log CERR once.
710 	 */
711 	if ((stat & LE_CERR) && le_softc[unit].sc_cerr)
712 		return;
713 	log(LOG_WARNING,
714 	    "le%d: error: stat=%b\n", unit,
715 	    stat,
716 	    "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT");
717 }
718 
719 lererror(unit, msg)
720 	int unit;
721 	char *msg;
722 {
723 	register struct le_softc *le = &le_softc[unit];
724 	register struct lermd *rmd;
725 	int len;
726 
727 	if (!ledebug)
728 		return;
729 
730 	rmd = &le->sc_r2->ler2_rmd[le->sc_rmd];
731 	len = rmd->rmd3;
732 	log(LOG_WARNING,
733 	    "le%d: ierror(%s): from %s: buf=%d, len=%d, rmd1=%b\n",
734 	    unit, msg,
735 	    len > 11 ?
736 		ether_sprintf((u_char *)&le->sc_r2->ler2_rbuf[le->sc_rmd][6]) :
737 		"unknown",
738 	    le->sc_rmd, len,
739 	    rmd->rmd1,
740 	    "\20\20OWN\17ERR\16FRAM\15OFLO\14CRC\13RBUF\12STP\11ENP");
741 }
742 
743 lexerror(unit)
744 	int unit;
745 {
746 	register struct le_softc *le = &le_softc[unit];
747 	register struct letmd *tmd;
748 	int len;
749 
750 	if (!ledebug)
751 		return;
752 
753 	tmd = le->sc_r2->ler2_tmd;
754 	len = -tmd->tmd2;
755 	log(LOG_WARNING,
756 	    "le%d: oerror: to %s: buf=%d, len=%d, tmd1=%b, tmd3=%b\n",
757 	    unit,
758 	    len > 5 ?
759 		ether_sprintf((u_char *)&le->sc_r2->ler2_tbuf[0][0]) :
760 		"unknown",
761 	    0, len,
762 	    tmd->tmd1,
763 	    "\20\20OWN\17ERR\16RES\15MORE\14ONE\13DEF\12STP\11ENP",
764 	    tmd->tmd3,
765 	    "\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY");
766 }
767 #endif
768