xref: /netbsd-src/sys/arch/macppc/dev/am79c950.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: am79c950.c,v 1.40 2018/06/26 06:47:58 msaitoh Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 David Huang <khym@bga.com>
5  * All rights reserved.
6  *
7  * Portions of this code are based on code by Denton Gentry <denny1@home.com>,
8  * Charles M. Hannum, Yanagisawa Takeshi <yanagisw@aa.ap.titech.ac.jp>, and
9  * Jason R. Thorpe.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  */
31 
32 /*
33  * Driver for the AMD Am79C940 (MACE) ethernet chip, used for onboard
34  * ethernet on the Centris/Quadra 660av and Quadra 840av.
35  */
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: am79c950.c,v 1.40 2018/06/26 06:47:58 msaitoh Exp $");
39 
40 #include "opt_inet.h"
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/mbuf.h>
45 #include <sys/buf.h>
46 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <sys/syslog.h>
49 #include <sys/ioctl.h>
50 #include <sys/errno.h>
51 #include <sys/device.h>
52 
53 #include <net/if.h>
54 #include <net/if_dl.h>
55 #include <net/if_ether.h>
56 #include <net/if_media.h>
57 #include <net/bpf.h>
58 
59 #ifdef INET
60 #include <netinet/in.h>
61 #include <netinet/if_inarp.h>
62 #include <netinet/in_systm.h>
63 #include <netinet/in_var.h>
64 #include <netinet/ip.h>
65 #endif
66 
67 #include <sys/bus.h>
68 
69 #include <macppc/dev/am79c950reg.h>
70 #include <macppc/dev/if_mcvar.h>
71 
72 hide void	mcwatchdog(struct ifnet *);
73 hide int	mcinit(struct mc_softc *sc);
74 hide int	mcstop(struct mc_softc *sc);
75 hide int	mcioctl(struct ifnet *ifp, u_long cmd, void *data);
76 hide void	mcstart(struct ifnet *ifp);
77 hide void	mcreset(struct mc_softc *sc);
78 
79 integrate u_int	maceput(struct mc_softc *sc, struct mbuf *m0);
80 integrate void	mc_tint(struct mc_softc *sc);
81 integrate void	mace_read(struct mc_softc *, uint8_t *, int);
82 integrate struct mbuf *mace_get(struct mc_softc *, uint8_t *, int);
83 static void mace_calcladrf(struct ethercom *ac, u_int8_t *af);
84 static inline u_int16_t ether_cmp(void *, void *);
85 static int mc_mediachange(struct ifnet *);
86 static void mc_mediastatus(struct ifnet *, struct ifmediareq *);
87 
88 /*
89  * Compare two Ether/802 addresses for equality, inlined and
90  * unrolled for speed.  Use this like memcmp().
91  *
92  * XXX: Add <machine/inlines.h> for stuff like this?
93  * XXX: or maybe add it to libkern.h instead?
94  *
95  * "I'd love to have an inline assembler version of this."
96  * XXX: Who wanted that? mycroft?  I wrote one, but this
97  * version in C is as good as hand-coded assembly. -gwr
98  *
99  * Please do NOT tweak this without looking at the actual
100  * assembly code generated before and after your tweaks!
101  */
102 static inline u_int16_t
103 ether_cmp(void *one, void *two)
104 {
105 	register u_int16_t *a = (u_short *) one;
106 	register u_int16_t *b = (u_short *) two;
107 	register u_int16_t diff;
108 
109 #ifdef	m68k
110 	/*
111 	 * The post-increment-pointer form produces the best
112 	 * machine code for m68k.  This was carefully tuned
113 	 * so it compiles to just 8 short (2-byte) op-codes!
114 	 */
115 	diff  = *a++ - *b++;
116 	diff |= *a++ - *b++;
117 	diff |= *a++ - *b++;
118 #else
119 	/*
120 	 * Most modern CPUs do better with a single expresion.
121 	 * Note that short-cut evaluation is NOT helpful here,
122 	 * because it just makes the code longer, not faster!
123 	 */
124 	diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]);
125 #endif
126 
127 	return (diff);
128 }
129 
130 #define ETHER_CMP	ether_cmp
131 
132 /*
133  * Interface exists: make available by filling in network interface
134  * record.  System will initialize the interface when it is ready
135  * to accept packets.
136  */
137 int
138 mcsetup(struct mc_softc *sc, u_int8_t *lladdr)
139 {
140 	struct ifnet *ifp = &sc->sc_if;
141 
142 	/* reset the chip and disable all interrupts */
143 	NIC_PUT(sc, MACE_BIUCC, SWRST);
144 	DELAY(100);
145 	NIC_PUT(sc, MACE_IMR, ~0);
146 
147 	memcpy(sc->sc_enaddr, lladdr, ETHER_ADDR_LEN);
148 	printf(": address %s\n", ether_sprintf(lladdr));
149 
150 	memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
151 	ifp->if_softc = sc;
152 	ifp->if_ioctl = mcioctl;
153 	ifp->if_start = mcstart;
154 	ifp->if_flags =
155 	    IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
156 	ifp->if_watchdog = mcwatchdog;
157 
158 	/* initialize ifmedia structures */
159 	ifmedia_init(&sc->sc_media, 0, mc_mediachange, mc_mediastatus);
160 	ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
161 	ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
162 
163 	if_attach(ifp);
164 	if_deferred_start_init(ifp, NULL);
165 	ether_ifattach(ifp, lladdr);
166 
167 	return (0);
168 }
169 
170 hide int
171 mcioctl(struct ifnet *ifp, u_long cmd, void *data)
172 {
173 	struct mc_softc *sc = ifp->if_softc;
174 	struct ifaddr *ifa;
175 	struct ifreq *ifr;
176 
177 	int	s = splnet(), err = 0;
178 
179 	switch (cmd) {
180 
181 	case SIOCINITIFADDR:
182 		ifa = (struct ifaddr *)data;
183 		ifp->if_flags |= IFF_UP;
184 		mcinit(sc);
185 		switch (ifa->ifa_addr->sa_family) {
186 #ifdef INET
187 		case AF_INET:
188 			arp_ifinit(ifp, ifa);
189 			break;
190 #endif
191 		default:
192 			break;
193 		}
194 		break;
195 
196 	case SIOCSIFFLAGS:
197 		if ((err = ifioctl_common(ifp, cmd, data)) != 0)
198 			break;
199 		/* XXX see the comment in ed_ioctl() about code re-use */
200 		if ((ifp->if_flags & IFF_UP) == 0 &&
201 		    (ifp->if_flags & IFF_RUNNING) != 0) {
202 			/*
203 			 * If interface is marked down and it is running,
204 			 * then stop it.
205 			 */
206 			mcstop(sc);
207 			ifp->if_flags &= ~IFF_RUNNING;
208 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
209 		    (ifp->if_flags & IFF_RUNNING) == 0) {
210 			/*
211 			 * If interface is marked up and it is stopped,
212 			 * then start it.
213 			 */
214 			(void)mcinit(sc);
215 		} else {
216 			/*
217 			 * reset the interface to pick up any other changes
218 			 * in flags
219 			 */
220 			mcreset(sc);
221 			mcstart(ifp);
222 		}
223 		break;
224 
225 	case SIOCADDMULTI:
226 	case SIOCDELMULTI:
227 		if ((err = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
228 			/*
229 			 * Multicast list has changed; set the hardware
230 			 * filter accordingly. But remember UP flag!
231 			 */
232 			if (ifp->if_flags & IFF_RUNNING)
233 				mcreset(sc);
234 			err = 0;
235 		}
236 		break;
237 
238 	case SIOCGIFMEDIA:
239 	case SIOCSIFMEDIA:
240 		ifr = (struct ifreq *) data;
241 		err = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
242 		break;
243 
244 	default:
245 		err = ether_ioctl(ifp, cmd, data);
246 		break;
247 	}
248 	splx(s);
249 	return (err);
250 }
251 
252 /*
253  * Encapsulate a packet of type family for the local net.
254  */
255 hide void
256 mcstart(struct ifnet *ifp)
257 {
258 	struct mc_softc	*sc = ifp->if_softc;
259 	struct mbuf	*m;
260 
261 	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
262 		return;
263 
264 	while (1) {
265 		if (ifp->if_flags & IFF_OACTIVE)
266 			return;
267 
268 		IF_DEQUEUE(&ifp->if_snd, m);
269 		if (m == 0)
270 			return;
271 
272 		/*
273 		 * If bpf is listening on this interface, let it
274 		 * see the packet before we commit it to the wire.
275 		 */
276 		bpf_mtap(ifp, m, BPF_D_OUT);
277 
278 		/*
279 		 * Copy the mbuf chain into the transmit buffer.
280 		 */
281 		ifp->if_flags |= IFF_OACTIVE;
282 		maceput(sc, m);
283 
284 		ifp->if_opackets++;		/* # of pkts */
285 	}
286 }
287 
288 /*
289  * reset and restart the MACE.  Called in case of fatal
290  * hardware/software errors.
291  */
292 hide void
293 mcreset(struct mc_softc *sc)
294 {
295 	mcstop(sc);
296 	mcinit(sc);
297 }
298 
299 hide int
300 mcinit(struct mc_softc *sc)
301 {
302 	int s;
303 	u_int8_t maccc, ladrf[8];
304 
305 	if (sc->sc_if.if_flags & IFF_RUNNING)
306 		/* already running */
307 		return (0);
308 
309 	s = splnet();
310 
311 	NIC_PUT(sc, MACE_BIUCC, sc->sc_biucc);
312 	NIC_PUT(sc, MACE_FIFOCC, sc->sc_fifocc);
313 	NIC_PUT(sc, MACE_IMR, ~0); /* disable all interrupts */
314 	NIC_PUT(sc, MACE_PLSCC, sc->sc_plscc);
315 
316 	NIC_PUT(sc, MACE_UTR, RTRD); /* disable reserved test registers */
317 
318 	/* set MAC address */
319 	NIC_PUT(sc, MACE_IAC, ADDRCHG);
320 	while (NIC_GET(sc, MACE_IAC) & ADDRCHG)
321 		;
322 	NIC_PUT(sc, MACE_IAC, PHYADDR);
323 	bus_space_write_multi_1(sc->sc_regt, sc->sc_regh, MACE_REG(MACE_PADR),
324 	    sc->sc_enaddr, ETHER_ADDR_LEN);
325 
326 	/* set logical address filter */
327 	mace_calcladrf(&sc->sc_ethercom, ladrf);
328 
329 	NIC_PUT(sc, MACE_IAC, ADDRCHG);
330 	while (NIC_GET(sc, MACE_IAC) & ADDRCHG)
331 		;
332 	NIC_PUT(sc, MACE_IAC, LOGADDR);
333 	bus_space_write_multi_1(sc->sc_regt, sc->sc_regh, MACE_REG(MACE_LADRF),
334 	    ladrf, 8);
335 
336 	NIC_PUT(sc, MACE_XMTFC, APADXMT);
337 	/*
338 	 * No need to autostrip padding on receive... Ethernet frames
339 	 * don't have a length field, unlike 802.3 frames, so the MACE
340 	 * can't figure out the length of the packet anyways.
341 	 */
342 	NIC_PUT(sc, MACE_RCVFC, 0);
343 
344 	maccc = ENXMT | ENRCV;
345 	if (sc->sc_if.if_flags & IFF_PROMISC)
346 		maccc |= PROM;
347 
348 	NIC_PUT(sc, MACE_MACCC, maccc);
349 
350 	if (sc->sc_bus_init)
351 		(*sc->sc_bus_init)(sc);
352 
353 	/*
354 	 * Enable all interrupts except receive, since we use the DMA
355 	 * completion interrupt for that.
356 	 */
357 	NIC_PUT(sc, MACE_IMR, RCVINTM);
358 
359 	/* flag interface as "running" */
360 	sc->sc_if.if_flags |= IFF_RUNNING;
361 	sc->sc_if.if_flags &= ~IFF_OACTIVE;
362 
363 	splx(s);
364 	return (0);
365 }
366 
367 /*
368  * close down an interface and free its buffers
369  * Called on final close of device, or if mcinit() fails
370  * part way through.
371  */
372 hide int
373 mcstop(struct mc_softc *sc)
374 {
375 	int	s = splnet();
376 
377 	NIC_PUT(sc, MACE_BIUCC, SWRST);
378 	DELAY(100);
379 
380 	sc->sc_if.if_timer = 0;
381 	sc->sc_if.if_flags &= ~IFF_RUNNING;
382 
383 	splx(s);
384 	return (0);
385 }
386 
387 /*
388  * Called if any Tx packets remain unsent after 5 seconds,
389  * In all cases we just reset the chip, and any retransmission
390  * will be handled by higher level protocol timeouts.
391  */
392 hide void
393 mcwatchdog(struct ifnet *ifp)
394 {
395 	struct mc_softc *sc = ifp->if_softc;
396 
397 	printf("mcwatchdog: resetting chip\n");
398 	mcreset(sc);
399 }
400 
401 /*
402  * stuff packet into MACE (at splnet)
403  */
404 integrate u_int
405 maceput(struct mc_softc *sc, struct mbuf *m)
406 {
407 	struct mbuf *n;
408 	u_int len, totlen = 0;
409 	u_char *buff;
410 
411 	buff = sc->sc_txbuf;
412 
413 	for (; m; m = n) {
414 		u_char *data = mtod(m, u_char *);
415 		len = m->m_len;
416 		totlen += len;
417 		memcpy(buff, data, len);
418 		buff += len;
419 		n = m_free(m);
420 	}
421 
422 	if (totlen > PAGE_SIZE)
423 		panic("%s: maceput: packet overflow", device_xname(sc->sc_dev));
424 
425 #if 0
426 	if (totlen < ETHERMIN + sizeof(struct ether_header)) {
427 		int pad = ETHERMIN + sizeof(struct ether_header) - totlen;
428 		memset(sc->sc_txbuf + totlen, 0, pad);
429 		totlen = ETHERMIN + sizeof(struct ether_header);
430 	}
431 #endif
432 
433 	(*sc->sc_putpacket)(sc, totlen);
434 
435 	sc->sc_if.if_timer = 5;	/* 5 seconds to watch for failing to transmit */
436 	return (totlen);
437 }
438 
439 int
440 mcintr(void *arg)
441 {
442 	struct mc_softc *sc = arg;
443 	u_int8_t ir;
444 
445 	ir = NIC_GET(sc, MACE_IR) & ~NIC_GET(sc, MACE_IMR);
446 	if (ir == 0)
447 		return 0;
448 
449 	if (ir & JAB) {
450 #ifdef MCDEBUG
451 		printf("%s: jabber error\n", device_xname(sc->sc_dev));
452 #endif
453 		sc->sc_if.if_oerrors++;
454 	}
455 
456 	if (ir & BABL) {
457 #ifdef MCDEBUG
458 		printf("%s: babble\n", device_xname(sc->sc_dev));
459 #endif
460 		sc->sc_if.if_oerrors++;
461 	}
462 
463 	if (ir & CERR) {
464 		printf("%s: collision error\n", device_xname(sc->sc_dev));
465 		sc->sc_if.if_collisions++;
466 	}
467 
468 	/*
469 	 * Pretend we have carrier; if we don't this will be cleared
470 	 * shortly.
471 	 */
472 	sc->sc_havecarrier = 1;
473 
474 	if (ir & XMTINT)
475 		mc_tint(sc);
476 
477 	if (ir & RCVINT)
478 		mc_rint(sc);
479 
480 	return 1;
481 }
482 
483 integrate void
484 mc_tint(struct mc_softc *sc)
485 {
486 	u_int8_t xmtfs;
487 
488 	(void)NIC_GET(sc, MACE_XMTRC);
489 	xmtfs = NIC_GET(sc, MACE_XMTFS);
490 
491 	if ((xmtfs & XMTSV) == 0)
492 		return;
493 
494 	if (xmtfs & UFLO) {
495 		printf("%s: underflow\n", device_xname(sc->sc_dev));
496 		mcreset(sc);
497 		return;
498 	}
499 
500 	if (xmtfs & LCOL) {
501 		printf("%s: late collision\n", device_xname(sc->sc_dev));
502 		sc->sc_if.if_oerrors++;
503 		sc->sc_if.if_collisions++;
504 	}
505 
506 	if (xmtfs & MORE)
507 		/* Real number is unknown. */
508 		sc->sc_if.if_collisions += 2;
509 	else if (xmtfs & ONE)
510 		sc->sc_if.if_collisions++;
511 	else if (xmtfs & RTRY) {
512 		sc->sc_if.if_collisions += 16;
513 		sc->sc_if.if_oerrors++;
514 	}
515 
516 	if (xmtfs & LCAR) {
517 		sc->sc_havecarrier = 0;
518 		printf("%s: lost carrier\n", device_xname(sc->sc_dev));
519 		sc->sc_if.if_oerrors++;
520 	}
521 
522 	sc->sc_if.if_flags &= ~IFF_OACTIVE;
523 	sc->sc_if.if_timer = 0;
524 	if_schedule_deferred_start(&sc->sc_if);
525 }
526 
527 void
528 mc_rint(struct mc_softc *sc)
529 {
530 #define	rxf	sc->sc_rxframe
531 	u_int len;
532 
533 	len = (rxf.rx_rcvcnt | ((rxf.rx_rcvsts & 0xf) << 8)) - 4;
534 
535 #ifdef MCDEBUG
536 	if (rxf.rx_rcvsts & 0xf0)
537 		printf("%s: rcvcnt %02x rcvsts %02x rntpc 0x%02x rcvcc 0x%02x\n",
538 		    device_xname(sc->sc_dev), rxf.rx_rcvcnt, rxf.rx_rcvsts,
539 		    rxf.rx_rntpc, rxf.rx_rcvcc);
540 #endif
541 
542 	if (rxf.rx_rcvsts & OFLO) {
543 		printf("%s: receive FIFO overflow\n", device_xname(sc->sc_dev));
544 		sc->sc_if.if_ierrors++;
545 		return;
546 	}
547 
548 	if (rxf.rx_rcvsts & CLSN)
549 		sc->sc_if.if_collisions++;
550 
551 	if (rxf.rx_rcvsts & FRAM) {
552 #ifdef MCDEBUG
553 		printf("%s: framing error\n", device_xname(sc->sc_dev));
554 #endif
555 		sc->sc_if.if_ierrors++;
556 		return;
557 	}
558 
559 	if (rxf.rx_rcvsts & FCS) {
560 #ifdef MCDEBUG
561 		printf("%s: frame control checksum error\n", device_xname(sc->sc_dev));
562 #endif
563 		sc->sc_if.if_ierrors++;
564 		return;
565 	}
566 
567 	mace_read(sc, rxf.rx_frame, len);
568 #undef	rxf
569 }
570 
571 integrate void
572 mace_read(struct mc_softc *sc, uint8_t *pkt, int len)
573 {
574 	struct ifnet *ifp = &sc->sc_if;
575 	struct mbuf *m;
576 
577 	if (len <= sizeof(struct ether_header) ||
578 	    len > ETHERMTU + sizeof(struct ether_header)) {
579 #ifdef MCDEBUG
580 		printf("%s: invalid packet size %d; dropping\n",
581 		    device_xname(sc->sc_dev), len);
582 #endif
583 		ifp->if_ierrors++;
584 		return;
585 	}
586 
587 	m = mace_get(sc, pkt, len);
588 	if (m == NULL) {
589 		ifp->if_ierrors++;
590 		return;
591 	}
592 
593 	/* Pass the packet up. */
594 	if_percpuq_enqueue(ifp->if_percpuq, m);
595 }
596 
597 /*
598  * Pull data off an interface.
599  * Len is length of data, with local net header stripped.
600  * We copy the data into mbufs.  When full cluster sized units are present
601  * we copy into clusters.
602  */
603 integrate struct mbuf *
604 mace_get(struct mc_softc *sc, uint8_t *pkt, int totlen)
605 {
606 	register struct mbuf *m;
607 	struct mbuf *top, **mp;
608 	int len;
609 
610 	MGETHDR(m, M_DONTWAIT, MT_DATA);
611 	if (m == 0)
612 		return (0);
613 	m_set_rcvif(m, &sc->sc_if);
614 	m->m_pkthdr.len = totlen;
615 	len = MHLEN;
616 	top = 0;
617 	mp = &top;
618 
619 	while (totlen > 0) {
620 		if (top) {
621 			MGET(m, M_DONTWAIT, MT_DATA);
622 			if (m == 0) {
623 				m_freem(top);
624 				return 0;
625 			}
626 			len = MLEN;
627 		}
628 		if (totlen >= MINCLSIZE) {
629 			MCLGET(m, M_DONTWAIT);
630 			if ((m->m_flags & M_EXT) == 0) {
631 				m_free(m);
632 				m_freem(top);
633 				return 0;
634 			}
635 			len = MCLBYTES;
636 		}
637 		m->m_len = len = min(totlen, len);
638 		memcpy(mtod(m, void *), pkt, len);
639 		pkt += len;
640 		totlen -= len;
641 		*mp = m;
642 		mp = &m->m_next;
643 	}
644 
645 	return (top);
646 }
647 
648 /*
649  * Go through the list of multicast addresses and calculate the logical
650  * address filter.
651  */
652 void
653 mace_calcladrf(struct ethercom *ac, u_int8_t *af)
654 {
655 	struct ifnet *ifp = &ac->ec_if;
656 	struct ether_multi *enm;
657 	register u_char *cp, c;
658 	register u_int32_t crc;
659 	register int i, len;
660 	struct ether_multistep step;
661 
662 	/*
663 	 * Set up multicast address filter by passing all multicast addresses
664 	 * through a crc generator, and then using the high order 6 bits as an
665 	 * index into the 64 bit logical address filter.  The high order bit
666 	 * selects the word, while the rest of the bits select the bit within
667 	 * the word.
668 	 */
669 
670 	*((u_int32_t *)af) = *((u_int32_t *)af + 1) = 0;
671 
672 	ETHER_FIRST_MULTI(step, ac, enm);
673 	while (enm != NULL) {
674 		if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) {
675 			/*
676 			 * We must listen to a range of multicast addresses.
677 			 * For now, just accept all multicasts, rather than
678 			 * trying to set only those filter bits needed to match
679 			 * the range.  (At this time, the only use of address
680 			 * ranges is for IP multicast routing, for which the
681 			 * range is big enough to require all bits set.)
682 			 */
683 			goto allmulti;
684 		}
685 
686 		cp = enm->enm_addrlo;
687 		crc = 0xffffffff;
688 		for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
689 			c = *cp++;
690 			for (i = 8; --i >= 0;) {
691 				if ((crc & 0x01) ^ (c & 0x01)) {
692 					crc >>= 1;
693 					crc ^= 0xedb88320;
694 				} else
695 					crc >>= 1;
696 				c >>= 1;
697 			}
698 		}
699 		/* Just want the 6 most significant bits. */
700 		crc >>= 26;
701 
702 		/* Set the corresponding bit in the filter. */
703 		af[crc >> 3] |= 1 << (crc & 7);
704 
705 		ETHER_NEXT_MULTI(step, enm);
706 	}
707 	ifp->if_flags &= ~IFF_ALLMULTI;
708 	return;
709 
710 allmulti:
711 	ifp->if_flags |= IFF_ALLMULTI;
712 	*((u_int32_t *)af) = *((u_int32_t *)af + 1) = 0xffffffff;
713 }
714 
715 int
716 mc_mediachange(struct ifnet *ifp)
717 {
718 	return EINVAL;
719 }
720 
721 void
722 mc_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
723 {
724 	struct mc_softc *sc = ifp->if_softc;
725 
726 	if ((ifp->if_flags & IFF_UP) == 0)
727 		return;
728 
729 	if (sc->sc_havecarrier)
730 		ifmr->ifm_status |= IFM_ACTIVE;
731 }
732