if_el.c revision 1.54 1 /* $NetBSD: if_el.c,v 1.54 1998/07/05 06:49:13 jonathan Exp $ */
2
3 /*
4 * Copyright (c) 1994, Matthew E. Kimmel. Permission is hereby granted
5 * to use, copy, modify and distribute this software provided that both
6 * the copyright notice and this permission notice appear in all copies
7 * of the software, derivative works or modified versions, and any
8 * portions thereof.
9 */
10
11 /*
12 * 3COM Etherlink 3C501 device driver
13 */
14
15 /*
16 * Bugs/possible improvements:
17 * - Does not currently support DMA
18 * - Does not currently support multicasts
19 */
20
21 #include "opt_inet.h"
22 #include "opt_ns.h"
23 #include "bpfilter.h"
24 #include "rnd.h"
25
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/errno.h>
29 #include <sys/ioctl.h>
30 #include <sys/mbuf.h>
31 #include <sys/socket.h>
32 #include <sys/syslog.h>
33 #include <sys/device.h>
34 #if NRND > 0
35 #include <sys/rnd.h>
36 #endif
37
38 #include <net/if.h>
39 #include <net/if_dl.h>
40 #include <net/if_types.h>
41
42 #include <net/if_ether.h>
43
44 #ifdef INET
45 #include <netinet/in.h>
46 #include <netinet/in_systm.h>
47 #include <netinet/in_var.h>
48 #include <netinet/ip.h>
49 #include <netinet/if_inarp.h>
50 #endif
51
52 #ifdef NS
53 #include <netns/ns.h>
54 #include <netns/ns_if.h>
55 #endif
56
57 #if NBPFILTER > 0
58 #include <net/bpf.h>
59 #include <net/bpfdesc.h>
60 #endif
61
62 #include <machine/cpu.h>
63 #include <machine/intr.h>
64 #include <machine/bus.h>
65
66 #include <dev/isa/isavar.h>
67 #include <dev/isa/if_elreg.h>
68
69 #define ETHER_MIN_LEN 64
70 #define ETHER_MAX_LEN 1518
71 #define ETHER_ADDR_LEN 6
72
73 /* for debugging convenience */
74 #ifdef EL_DEBUG
75 #define DPRINTF(x) printf x
76 #else
77 #define DPRINTF(x)
78 #endif
79
80 /*
81 * per-line info and status
82 */
83 struct el_softc {
84 struct device sc_dev;
85 void *sc_ih;
86
87 struct ethercom sc_ethercom; /* ethernet common */
88 bus_space_tag_t sc_iot; /* bus space identifier */
89 bus_space_handle_t sc_ioh; /* i/o handle */
90
91 #if NRND > 0
92 rndsource_element_t rnd_source;
93 #endif
94 };
95
96 /*
97 * prototypes
98 */
99 int elintr __P((void *));
100 void elinit __P((struct el_softc *));
101 int elioctl __P((struct ifnet *, u_long, caddr_t));
102 void elstart __P((struct ifnet *));
103 void elwatchdog __P((struct ifnet *));
104 void elreset __P((struct el_softc *));
105 void elstop __P((struct el_softc *));
106 static int el_xmit __P((struct el_softc *));
107 void elread __P((struct el_softc *, int));
108 struct mbuf *elget __P((struct el_softc *sc, int));
109 static inline void el_hardreset __P((struct el_softc *));
110
111 int elprobe __P((struct device *, struct cfdata *, void *));
112 void elattach __P((struct device *, struct device *, void *));
113
114 struct cfattach el_ca = {
115 sizeof(struct el_softc), elprobe, elattach
116 };
117
118 /*
119 * Probe routine.
120 *
121 * See if the card is there and at the right place.
122 * (XXX - cgd -- needs help)
123 */
124 int
125 elprobe(parent, match, aux)
126 struct device *parent;
127 struct cfdata *match;
128 void *aux;
129 {
130 struct isa_attach_args *ia = aux;
131 bus_space_tag_t iot = ia->ia_iot;
132 bus_space_handle_t ioh;
133 int iobase = ia->ia_iobase;
134 u_int8_t station_addr[ETHER_ADDR_LEN];
135 u_int8_t i;
136 int rval;
137
138 rval = 0;
139
140 /* First check the base. */
141 if (iobase < 0x200 || iobase > 0x3f0)
142 return 0;
143
144 /* Map i/o space. */
145 if (bus_space_map(iot, iobase, 16, 0, &ioh))
146 return 0;
147
148 /*
149 * Now attempt to grab the station address from the PROM and see if it
150 * contains the 3com vendor code.
151 */
152 DPRINTF(("Probing 3c501 at 0x%x...\n", iobase));
153
154 /* Reset the board. */
155 DPRINTF(("Resetting board...\n"));
156 bus_space_write_1(iot, ioh, EL_AC, EL_AC_RESET);
157 delay(5);
158 bus_space_write_1(iot, ioh, EL_AC, 0);
159
160 /* Now read the address. */
161 DPRINTF(("Reading station address...\n"));
162 for (i = 0; i < ETHER_ADDR_LEN; i++) {
163 bus_space_write_1(iot, ioh, EL_GPBL, i);
164 station_addr[i] = bus_space_read_1(iot, ioh, EL_EAW);
165 }
166 DPRINTF(("Address is %s\n", ether_sprintf(station_addr)));
167
168 /*
169 * If the vendor code is ok, return a 1. We'll assume that whoever
170 * configured this system is right about the IRQ.
171 */
172 if (station_addr[0] != 0x02 || station_addr[1] != 0x60 ||
173 station_addr[2] != 0x8c) {
174 DPRINTF(("Bad vendor code.\n"));
175 goto out;
176 }
177 DPRINTF(("Vendor code ok.\n"));
178
179 ia->ia_iosize = 16;
180 ia->ia_msize = 0;
181 rval = 1;
182
183 out:
184 bus_space_unmap(iot, ioh, 16);
185 return rval;
186 }
187
188 /*
189 * Attach the interface to the kernel data structures. By the time this is
190 * called, we know that the card exists at the given I/O address. We still
191 * assume that the IRQ given is correct.
192 */
193 void
194 elattach(parent, self, aux)
195 struct device *parent, *self;
196 void *aux;
197 {
198 struct el_softc *sc = (void *)self;
199 struct isa_attach_args *ia = aux;
200 bus_space_tag_t iot = ia->ia_iot;
201 bus_space_handle_t ioh;
202 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
203 u_int8_t myaddr[ETHER_ADDR_LEN];
204 u_int8_t i;
205
206 printf("\n");
207
208 DPRINTF(("Attaching %s...\n", sc->sc_dev.dv_xname));
209
210 /* Map i/o space. */
211 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
212 printf("%s: can't map i/o space\n", self->dv_xname);
213 return;
214 }
215
216 sc->sc_iot = iot;
217 sc->sc_ioh = ioh;
218
219 /* Reset the board. */
220 bus_space_write_1(iot, ioh, EL_AC, EL_AC_RESET);
221 delay(5);
222 bus_space_write_1(iot, ioh, EL_AC, 0);
223
224 /* Now read the address. */
225 for (i = 0; i < ETHER_ADDR_LEN; i++) {
226 bus_space_write_1(iot, ioh, EL_GPBL, i);
227 myaddr[i] = bus_space_read_1(iot, ioh, EL_EAW);
228 }
229
230 /* Stop the board. */
231 elstop(sc);
232
233 /* Initialize ifnet structure. */
234 bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
235 ifp->if_softc = sc;
236 ifp->if_start = elstart;
237 ifp->if_ioctl = elioctl;
238 ifp->if_watchdog = elwatchdog;
239 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
240
241 /* Now we can attach the interface. */
242 DPRINTF(("Attaching interface...\n"));
243 if_attach(ifp);
244 ether_ifattach(ifp, myaddr);
245
246 /* Print out some information for the user. */
247 printf("%s: address %s\n", self->dv_xname, ether_sprintf(myaddr));
248
249 /* Finally, attach to bpf filter if it is present. */
250 #if NBPFILTER > 0
251 DPRINTF(("Attaching to BPF...\n"));
252 bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
253 #endif
254
255 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
256 IPL_NET, elintr, sc);
257
258 #if NRND > 0
259 DPRINTF(("Attaching to random...\n"));
260 rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname, RND_TYPE_NET);
261 #endif
262
263 DPRINTF(("elattach() finished.\n"));
264 }
265
266 /*
267 * Reset interface.
268 */
269 void
270 elreset(sc)
271 struct el_softc *sc;
272 {
273 int s;
274
275 DPRINTF(("elreset()\n"));
276 s = splnet();
277 elstop(sc);
278 elinit(sc);
279 splx(s);
280 }
281
282 /*
283 * Stop interface.
284 */
285 void
286 elstop(sc)
287 struct el_softc *sc;
288 {
289
290 bus_space_write_1(sc->sc_iot, sc->sc_ioh, EL_AC, 0);
291 }
292
293 /*
294 * Do a hardware reset of the board, and upload the ethernet address again in
295 * case the board forgets.
296 */
297 static inline void
298 el_hardreset(sc)
299 struct el_softc *sc;
300 {
301 bus_space_tag_t iot = sc->sc_iot;
302 bus_space_handle_t ioh = sc->sc_ioh;
303 int i;
304
305 bus_space_write_1(iot, ioh, EL_AC, EL_AC_RESET);
306 delay(5);
307 bus_space_write_1(iot, ioh, EL_AC, 0);
308
309 for (i = 0; i < ETHER_ADDR_LEN; i++)
310 bus_space_write_1(iot, ioh, i,
311 LLADDR(sc->sc_ethercom.ec_if.if_sadl)[i]);
312 }
313
314 /*
315 * Initialize interface.
316 */
317 void
318 elinit(sc)
319 struct el_softc *sc;
320 {
321 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
322 bus_space_tag_t iot = sc->sc_iot;
323 bus_space_handle_t ioh = sc->sc_ioh;
324
325 /* First, reset the board. */
326 el_hardreset(sc);
327
328 /* Configure rx. */
329 DPRINTF(("Configuring rx...\n"));
330 if (ifp->if_flags & IFF_PROMISC)
331 bus_space_write_1(iot, ioh, EL_RXC,
332 EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
333 EL_RXC_DOFLOW | EL_RXC_PROMISC);
334 else
335 bus_space_write_1(iot, ioh, EL_RXC,
336 EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
337 EL_RXC_DOFLOW | EL_RXC_ABROAD);
338 bus_space_write_1(iot, ioh, EL_RBC, 0);
339
340 /* Configure TX. */
341 DPRINTF(("Configuring tx...\n"));
342 bus_space_write_1(iot, ioh, EL_TXC, 0);
343
344 /* Start reception. */
345 DPRINTF(("Starting reception...\n"));
346 bus_space_write_1(iot, ioh, EL_AC, EL_AC_IRQE | EL_AC_RX);
347
348 /* Set flags appropriately. */
349 ifp->if_flags |= IFF_RUNNING;
350 ifp->if_flags &= ~IFF_OACTIVE;
351
352 /* And start output. */
353 elstart(ifp);
354 }
355
356 /*
357 * Start output on interface. Get datagrams from the queue and output them,
358 * giving the receiver a chance between datagrams. Call only from splnet or
359 * interrupt level!
360 */
361 void
362 elstart(ifp)
363 struct ifnet *ifp;
364 {
365 struct el_softc *sc = ifp->if_softc;
366 bus_space_tag_t iot = sc->sc_iot;
367 bus_space_handle_t ioh = sc->sc_ioh;
368 struct mbuf *m, *m0;
369 int s, i, off, retries;
370
371 DPRINTF(("elstart()...\n"));
372 s = splnet();
373
374 /* Don't do anything if output is active. */
375 if ((ifp->if_flags & IFF_OACTIVE) != 0) {
376 splx(s);
377 return;
378 }
379
380 ifp->if_flags |= IFF_OACTIVE;
381
382 /*
383 * The main loop. They warned me against endless loops, but would I
384 * listen? NOOO....
385 */
386 for (;;) {
387 /* Dequeue the next datagram. */
388 IF_DEQUEUE(&ifp->if_snd, m0);
389
390 /* If there's nothing to send, return. */
391 if (m0 == 0)
392 break;
393
394 #if NBPFILTER > 0
395 /* Give the packet to the bpf, if any. */
396 if (ifp->if_bpf)
397 bpf_mtap(ifp->if_bpf, m0);
398 #endif
399
400 /* Disable the receiver. */
401 bus_space_write_1(iot, ioh, EL_AC, EL_AC_HOST);
402 bus_space_write_1(iot, ioh, EL_RBC, 0);
403
404 /* Transfer datagram to board. */
405 DPRINTF(("el: xfr pkt length=%d...\n", m0->m_pkthdr.len));
406 off = EL_BUFSIZ - max(m0->m_pkthdr.len, ETHER_MIN_LEN);
407 #ifdef DIAGNOSTIC
408 if ((off & 0xffff) != off)
409 printf("%s: bogus off 0x%x\n",
410 sc->sc_dev.dv_xname, off);
411 #endif
412 bus_space_write_1(iot, ioh, EL_GPBL, off & 0xff);
413 bus_space_write_1(iot, ioh, EL_GPBH, (off >> 8) & 0xff);
414
415 /* Copy the datagram to the buffer. */
416 for (m = m0; m != 0; m = m->m_next)
417 bus_space_write_multi_1(iot, ioh, EL_BUF,
418 mtod(m, u_int8_t *), m->m_len);
419
420 m_freem(m0);
421
422 /* Now transmit the datagram. */
423 retries = 0;
424 for (;;) {
425 bus_space_write_1(iot, ioh, EL_GPBL, off & 0xff);
426 bus_space_write_1(iot, ioh, EL_GPBH, (off >> 8) & 0xff);
427 if (el_xmit(sc)) {
428 ifp->if_oerrors++;
429 break;
430 }
431 /* Check out status. */
432 i = bus_space_read_1(iot, ioh, EL_TXS);
433 DPRINTF(("tx status=0x%x\n", i));
434 if ((i & EL_TXS_READY) == 0) {
435 DPRINTF(("el: err txs=%x\n", i));
436 if (i & (EL_TXS_COLL | EL_TXS_COLL16)) {
437 ifp->if_collisions++;
438 if ((i & EL_TXC_DCOLL16) == 0 &&
439 retries < 15) {
440 retries++;
441 bus_space_write_1(iot, ioh,
442 EL_AC, EL_AC_HOST);
443 }
444 } else {
445 ifp->if_oerrors++;
446 break;
447 }
448 } else {
449 ifp->if_opackets++;
450 break;
451 }
452 }
453
454 /*
455 * Now give the card a chance to receive.
456 * Gotta love 3c501s...
457 */
458 (void)bus_space_read_1(iot, ioh, EL_AS);
459 bus_space_write_1(iot, ioh, EL_AC, EL_AC_IRQE | EL_AC_RX);
460 splx(s);
461 /* Interrupt here. */
462 s = splnet();
463 }
464
465 (void)bus_space_read_1(iot, ioh, EL_AS);
466 bus_space_write_1(iot, ioh, EL_AC, EL_AC_IRQE | EL_AC_RX);
467 ifp->if_flags &= ~IFF_OACTIVE;
468 splx(s);
469 }
470
471 /*
472 * This function actually attempts to transmit a datagram downloaded to the
473 * board. Call at splnet or interrupt, after downloading data! Returns 0 on
474 * success, non-0 on failure.
475 */
476 static int
477 el_xmit(sc)
478 struct el_softc *sc;
479 {
480 bus_space_tag_t iot = sc->sc_iot;
481 bus_space_handle_t ioh = sc->sc_ioh;
482 int i;
483
484 /*
485 * XXX
486 * This busy-waits for the tx completion. Can we get an interrupt
487 * instead?
488 */
489
490 DPRINTF(("el: xmit..."));
491 bus_space_write_1(iot, ioh, EL_AC, EL_AC_TXFRX);
492 i = 20000;
493 while ((bus_space_read_1(iot, ioh, EL_AS) & EL_AS_TXBUSY) && (i > 0))
494 i--;
495 if (i == 0) {
496 DPRINTF(("tx not ready\n"));
497 return -1;
498 }
499 DPRINTF(("%d cycles.\n", 20000 - i));
500 return 0;
501 }
502
503 /*
504 * Controller interrupt.
505 */
506 int
507 elintr(arg)
508 void *arg;
509 {
510 register struct el_softc *sc = arg;
511 bus_space_tag_t iot = sc->sc_iot;
512 bus_space_handle_t ioh = sc->sc_ioh;
513 u_int8_t rxstat;
514 int len;
515
516 DPRINTF(("elintr: "));
517
518 /* Check board status. */
519 if ((bus_space_read_1(iot, ioh, EL_AS) & EL_AS_RXBUSY) != 0) {
520 (void)bus_space_read_1(iot, ioh, EL_RXC);
521 bus_space_write_1(iot, ioh, EL_AC, EL_AC_IRQE | EL_AC_RX);
522 return 0;
523 }
524
525 for (;;) {
526 rxstat = bus_space_read_1(iot, ioh, EL_RXS);
527 if (rxstat & EL_RXS_STALE)
528 break;
529
530 /* If there's an overflow, reinit the board. */
531 if ((rxstat & EL_RXS_NOFLOW) == 0) {
532 DPRINTF(("overflow.\n"));
533 el_hardreset(sc);
534 /* Put board back into receive mode. */
535 if (sc->sc_ethercom.ec_if.if_flags & IFF_PROMISC)
536 bus_space_write_1(iot, ioh, EL_RXC,
537 EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
538 EL_RXC_DOFLOW | EL_RXC_PROMISC);
539 else
540 bus_space_write_1(iot, ioh, EL_RXC,
541 EL_RXC_AGF | EL_RXC_DSHORT | EL_RXC_DDRIB |
542 EL_RXC_DOFLOW | EL_RXC_ABROAD);
543 (void)bus_space_read_1(iot, ioh, EL_AS);
544 bus_space_write_1(iot, ioh, EL_RBC, 0);
545 break;
546 }
547
548 /* Incoming packet. */
549 len = bus_space_read_1(iot, ioh, EL_RBL);
550 len |= bus_space_read_1(iot, ioh, EL_RBH) << 8;
551 DPRINTF(("receive len=%d rxstat=%x ", len, rxstat));
552 bus_space_write_1(iot, ioh, EL_AC, EL_AC_HOST);
553
554 /* Pass data up to upper levels. */
555 elread(sc, len);
556
557 /* Is there another packet? */
558 if ((bus_space_read_1(iot, ioh, EL_AS) & EL_AS_RXBUSY) != 0)
559 break;
560
561 #if NRND > 0
562 rnd_add_uint32(&sc->rnd_source, rxstat);
563 #endif
564
565 DPRINTF(("<rescan> "));
566 }
567
568 (void)bus_space_read_1(iot, ioh, EL_RXC);
569 bus_space_write_1(iot, ioh, EL_AC, EL_AC_IRQE | EL_AC_RX);
570 return 1;
571 }
572
573 /*
574 * Pass a packet to the higher levels.
575 */
576 void
577 elread(sc, len)
578 register struct el_softc *sc;
579 int len;
580 {
581 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
582 struct mbuf *m;
583 struct ether_header *eh;
584
585 if (len <= sizeof(struct ether_header) ||
586 len > ETHER_MAX_LEN) {
587 printf("%s: invalid packet size %d; dropping\n",
588 sc->sc_dev.dv_xname, len);
589 ifp->if_ierrors++;
590 return;
591 }
592
593 /* Pull packet off interface. */
594 m = elget(sc, len);
595 if (m == 0) {
596 ifp->if_ierrors++;
597 return;
598 }
599
600 ifp->if_ipackets++;
601
602 /* We assume that the header fit entirely in one mbuf. */
603 eh = mtod(m, struct ether_header *);
604
605 #if NBPFILTER > 0
606 /*
607 * Check if there's a BPF listener on this interface.
608 * If so, hand off the raw packet to BPF.
609 */
610 if (ifp->if_bpf) {
611 bpf_mtap(ifp->if_bpf, m);
612
613 /*
614 * Note that the interface cannot be in promiscuous mode if
615 * there are no BPF listeners. And if we are in promiscuous
616 * mode, we have to check if this packet is really ours.
617 */
618 if ((ifp->if_flags & IFF_PROMISC) &&
619 (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
620 bcmp(eh->ether_dhost, LLADDR(ifp->if_sadl),
621 sizeof(eh->ether_dhost)) != 0) {
622 m_freem(m);
623 return;
624 }
625 }
626 #endif
627
628 /* We assume that the header fit entirely in one mbuf. */
629 m_adj(m, sizeof(struct ether_header));
630 ether_input(ifp, eh, m);
631 }
632
633 /*
634 * Pull read data off a interface. Len is length of data, with local net
635 * header stripped. We copy the data into mbufs. When full cluster sized
636 * units are present we copy into clusters.
637 */
638 struct mbuf *
639 elget(sc, totlen)
640 struct el_softc *sc;
641 int totlen;
642 {
643 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
644 bus_space_tag_t iot = sc->sc_iot;
645 bus_space_handle_t ioh = sc->sc_ioh;
646 struct mbuf *top, **mp, *m;
647 int len;
648
649 MGETHDR(m, M_DONTWAIT, MT_DATA);
650 if (m == 0)
651 return 0;
652 m->m_pkthdr.rcvif = ifp;
653 m->m_pkthdr.len = totlen;
654 len = MHLEN;
655 top = 0;
656 mp = ⊤
657
658 bus_space_write_1(iot, ioh, EL_GPBL, 0);
659 bus_space_write_1(iot, ioh, EL_GPBH, 0);
660
661 while (totlen > 0) {
662 if (top) {
663 MGET(m, M_DONTWAIT, MT_DATA);
664 if (m == 0) {
665 m_freem(top);
666 return 0;
667 }
668 len = MLEN;
669 }
670 if (totlen >= MINCLSIZE) {
671 MCLGET(m, M_DONTWAIT);
672 if ((m->m_flags & M_EXT) == 0) {
673 m_free(m);
674 m_freem(top);
675 return 0;
676 }
677 len = MCLBYTES;
678 }
679 m->m_len = len = min(totlen, len);
680 bus_space_read_multi_1(iot, ioh, EL_BUF, mtod(m, u_int8_t *), len);
681 totlen -= len;
682 *mp = m;
683 mp = &m->m_next;
684 }
685
686 bus_space_write_1(iot, ioh, EL_RBC, 0);
687 bus_space_write_1(iot, ioh, EL_AC, EL_AC_RX);
688
689 return top;
690 }
691
692 /*
693 * Process an ioctl request. This code needs some work - it looks pretty ugly.
694 */
695 int
696 elioctl(ifp, cmd, data)
697 register struct ifnet *ifp;
698 u_long cmd;
699 caddr_t data;
700 {
701 struct el_softc *sc = ifp->if_softc;
702 struct ifaddr *ifa = (struct ifaddr *)data;
703 int s, error = 0;
704
705 s = splnet();
706
707 switch (cmd) {
708
709 case SIOCSIFADDR:
710 ifp->if_flags |= IFF_UP;
711
712 switch (ifa->ifa_addr->sa_family) {
713 #ifdef INET
714 case AF_INET:
715 elinit(sc);
716 arp_ifinit(ifp, ifa);
717 break;
718 #endif
719 #ifdef NS
720 /* XXX - This code is probably wrong. */
721 case AF_NS:
722 {
723 register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
724
725 if (ns_nullhost(*ina))
726 ina->x_host =
727 *(union ns_host *)LLADDR(ifp->if_sadl);
728 else
729 bcopy(ina->x_host.c_host, LLADDR(ifp->if_sadl),
730 ETHER_ADDR_LEN);
731 /* Set new address. */
732 elinit(sc);
733 break;
734 }
735 #endif
736 default:
737 elinit(sc);
738 break;
739 }
740 break;
741
742 case SIOCSIFFLAGS:
743 if ((ifp->if_flags & IFF_UP) == 0 &&
744 (ifp->if_flags & IFF_RUNNING) != 0) {
745 /*
746 * If interface is marked down and it is running, then
747 * stop it.
748 */
749 elstop(sc);
750 ifp->if_flags &= ~IFF_RUNNING;
751 } else if ((ifp->if_flags & IFF_UP) != 0 &&
752 (ifp->if_flags & IFF_RUNNING) == 0) {
753 /*
754 * If interface is marked up and it is stopped, then
755 * start it.
756 */
757 elinit(sc);
758 } else {
759 /*
760 * Some other important flag might have changed, so
761 * reset.
762 */
763 elreset(sc);
764 }
765 break;
766
767 default:
768 error = EINVAL;
769 break;
770 }
771
772 splx(s);
773 return error;
774 }
775
776 /*
777 * Device timeout routine.
778 */
779 void
780 elwatchdog(ifp)
781 struct ifnet *ifp;
782 {
783 struct el_softc *sc = ifp->if_softc;
784
785 log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
786 sc->sc_ethercom.ec_if.if_oerrors++;
787
788 elreset(sc);
789 }
790