Fri May 1 01:54:09 2009 UTC ()
Pull up following revision(s) (requested by tsutsui in ticket #595):
	sys/dev/ic/hme.c: revision 1.70
Replace incorrect local ether_cmp() function with memcmp(9)
on checking multicast addresses, which is not so critical.
Noticed by FUKAUMI Naoki.


(snj)
diff -r1.66.10.1 -r1.66.10.2 src/sys/dev/ic/hme.c

cvs diff -r1.66.10.1 -r1.66.10.2 src/sys/dev/ic/hme.c (expand / switch to unified diff)

--- src/sys/dev/ic/hme.c 2009/05/01 01:52:56 1.66.10.1
+++ src/sys/dev/ic/hme.c 2009/05/01 01:54:09 1.66.10.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: hme.c,v 1.66.10.1 2009/05/01 01:52:56 snj Exp $ */ 1/* $NetBSD: hme.c,v 1.66.10.2 2009/05/01 01:54:09 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg. 8 * by Paul Kranenburg.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * HME Ethernet module driver. 33 * HME Ethernet module driver.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.66.10.1 2009/05/01 01:52:56 snj Exp $"); 37__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.66.10.2 2009/05/01 01:54:09 snj Exp $");
38 38
39/* #define HMEDEBUG */ 39/* #define HMEDEBUG */
40 40
41#include "opt_inet.h" 41#include "opt_inet.h"
42#include "bpfilter.h" 42#include "bpfilter.h"
43#include "rnd.h" 43#include "rnd.h"
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47#include <sys/kernel.h> 47#include <sys/kernel.h>
48#include <sys/mbuf.h> 48#include <sys/mbuf.h>
49#include <sys/syslog.h> 49#include <sys/syslog.h>
50#include <sys/socket.h> 50#include <sys/socket.h>
@@ -101,28 +101,26 @@ void hme_setladrf(struct hme_softc *); @@ -101,28 +101,26 @@ void hme_setladrf(struct hme_softc *);
101static int hme_mii_readreg(struct device *, int, int); 101static int hme_mii_readreg(struct device *, int, int);
102static void hme_mii_writereg(struct device *, int, int, int); 102static void hme_mii_writereg(struct device *, int, int, int);
103static void hme_mii_statchg(struct device *); 103static void hme_mii_statchg(struct device *);
104 104
105int hme_mediachange(struct ifnet *); 105int hme_mediachange(struct ifnet *);
106 106
107struct mbuf *hme_get(struct hme_softc *, int, uint32_t); 107struct mbuf *hme_get(struct hme_softc *, int, uint32_t);
108int hme_put(struct hme_softc *, int, struct mbuf *); 108int hme_put(struct hme_softc *, int, struct mbuf *);
109void hme_read(struct hme_softc *, int, uint32_t); 109void hme_read(struct hme_softc *, int, uint32_t);
110int hme_eint(struct hme_softc *, u_int); 110int hme_eint(struct hme_softc *, u_int);
111int hme_rint(struct hme_softc *); 111int hme_rint(struct hme_softc *);
112int hme_tint(struct hme_softc *); 112int hme_tint(struct hme_softc *);
113 113
114static int ether_cmp(u_char *, u_char *); 
115 
116/* Default buffer copy routines */ 114/* Default buffer copy routines */
117void hme_copytobuf_contig(struct hme_softc *, void *, int, int); 115void hme_copytobuf_contig(struct hme_softc *, void *, int, int);
118void hme_copyfrombuf_contig(struct hme_softc *, void *, int, int); 116void hme_copyfrombuf_contig(struct hme_softc *, void *, int, int);
119void hme_zerobuf_contig(struct hme_softc *, int, int); 117void hme_zerobuf_contig(struct hme_softc *, int, int);
120 118
121 119
122void 120void
123hme_config(sc) 121hme_config(sc)
124 struct hme_softc *sc; 122 struct hme_softc *sc;
125{ 123{
126 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 124 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
127 struct mii_data *mii = &sc->sc_mii; 125 struct mii_data *mii = &sc->sc_mii;
128 struct mii_softc *child; 126 struct mii_softc *child;
@@ -632,42 +630,26 @@ hme_init(sc) @@ -632,42 +630,26 @@ hme_init(sc)
632 630
633 /* Start the one second timer. */ 631 /* Start the one second timer. */
634 callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc); 632 callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc);
635 633
636 ifp->if_flags |= IFF_RUNNING; 634 ifp->if_flags |= IFF_RUNNING;
637 ifp->if_flags &= ~IFF_OACTIVE; 635 ifp->if_flags &= ~IFF_OACTIVE;
638 sc->sc_if_flags = ifp->if_flags; 636 sc->sc_if_flags = ifp->if_flags;
639 ifp->if_timer = 0; 637 ifp->if_timer = 0;
640 hme_start(ifp); 638 hme_start(ifp);
641 return 0; 639 return 0;
642} 640}
643 641
644/* 642/*
645 * Compare two Ether/802 addresses for equality, inlined and unrolled for 
646 * speed. 
647 */ 
648static inline int 
649ether_cmp(a, b) 
650 u_char *a, *b; 
651{ 
652 
653 if (a[5] != b[5] || a[4] != b[4] || a[3] != b[3] || 
654 a[2] != b[2] || a[1] != b[1] || a[0] != b[0]) 
655 return (0); 
656 return (1); 
657} 
658 
659 
660/* 
661 * Routine to copy from mbuf chain to transmit buffer in 643 * Routine to copy from mbuf chain to transmit buffer in
662 * network buffer memory. 644 * network buffer memory.
663 * Returns the amount of data copied. 645 * Returns the amount of data copied.
664 */ 646 */
665int 647int
666hme_put(sc, ri, m) 648hme_put(sc, ri, m)
667 struct hme_softc *sc; 649 struct hme_softc *sc;
668 int ri; /* Ring index */ 650 int ri; /* Ring index */
669 struct mbuf *m; 651 struct mbuf *m;
670{ 652{
671 struct mbuf *n; 653 struct mbuf *n;
672 int len, tlen = 0; 654 int len, tlen = 0;
673 char *bp; 655 char *bp;
@@ -1543,27 +1525,27 @@ hme_setladrf(sc) @@ -1543,27 +1525,27 @@ hme_setladrf(sc)
1543 v &= ~HME_MAC_RXCFG_PMISC; 1525 v &= ~HME_MAC_RXCFG_PMISC;
1544 v |= HME_MAC_RXCFG_HENABLE; 1526 v |= HME_MAC_RXCFG_HENABLE;
1545 1527
1546 /* 1528 /*
1547 * Set up multicast address filter by passing all multicast addresses 1529 * Set up multicast address filter by passing all multicast addresses
1548 * through a crc generator, and then using the high order 6 bits as an 1530 * through a crc generator, and then using the high order 6 bits as an
1549 * index into the 64 bit logical address filter. The high order bit 1531 * index into the 64 bit logical address filter. The high order bit
1550 * selects the word, while the rest of the bits select the bit within 1532 * selects the word, while the rest of the bits select the bit within
1551 * the word. 1533 * the word.
1552 */ 1534 */
1553 1535
1554 ETHER_FIRST_MULTI(step, ec, enm); 1536 ETHER_FIRST_MULTI(step, ec, enm);
1555 while (enm != NULL) { 1537 while (enm != NULL) {
1556 if (ether_cmp(enm->enm_addrlo, enm->enm_addrhi)) { 1538 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
1557 /* 1539 /*
1558 * We must listen to a range of multicast addresses. 1540 * We must listen to a range of multicast addresses.
1559 * For now, just accept all multicasts, rather than 1541 * For now, just accept all multicasts, rather than
1560 * trying to set only those filter bits needed to match 1542 * trying to set only those filter bits needed to match
1561 * the range. (At this time, the only use of address 1543 * the range. (At this time, the only use of address
1562 * ranges is for IP multicast routing, for which the 1544 * ranges is for IP multicast routing, for which the
1563 * range is big enough to require all bits set.) 1545 * range is big enough to require all bits set.)
1564 */ 1546 */
1565 hash[3] = hash[2] = hash[1] = hash[0] = 0xffff; 1547 hash[3] = hash[2] = hash[1] = hash[0] = 0xffff;
1566 ifp->if_flags |= IFF_ALLMULTI; 1548 ifp->if_flags |= IFF_ALLMULTI;
1567 goto chipit; 1549 goto chipit;
1568 } 1550 }
1569 1551