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