| @@ -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 *); |
101 | static int hme_mii_readreg(struct device *, int, int); | | 101 | static int hme_mii_readreg(struct device *, int, int); |
102 | static void hme_mii_writereg(struct device *, int, int, int); | | 102 | static void hme_mii_writereg(struct device *, int, int, int); |
103 | static void hme_mii_statchg(struct device *); | | 103 | static void hme_mii_statchg(struct device *); |
104 | | | 104 | |
105 | int hme_mediachange(struct ifnet *); | | 105 | int hme_mediachange(struct ifnet *); |
106 | | | 106 | |
107 | struct mbuf *hme_get(struct hme_softc *, int, uint32_t); | | 107 | struct mbuf *hme_get(struct hme_softc *, int, uint32_t); |
108 | int hme_put(struct hme_softc *, int, struct mbuf *); | | 108 | int hme_put(struct hme_softc *, int, struct mbuf *); |
109 | void hme_read(struct hme_softc *, int, uint32_t); | | 109 | void hme_read(struct hme_softc *, int, uint32_t); |
110 | int hme_eint(struct hme_softc *, u_int); | | 110 | int hme_eint(struct hme_softc *, u_int); |
111 | int hme_rint(struct hme_softc *); | | 111 | int hme_rint(struct hme_softc *); |
112 | int hme_tint(struct hme_softc *); | | 112 | int hme_tint(struct hme_softc *); |
113 | | | 113 | |
114 | static int ether_cmp(u_char *, u_char *); | | | |
115 | | | | |
116 | /* Default buffer copy routines */ | | 114 | /* Default buffer copy routines */ |
117 | void hme_copytobuf_contig(struct hme_softc *, void *, int, int); | | 115 | void hme_copytobuf_contig(struct hme_softc *, void *, int, int); |
118 | void hme_copyfrombuf_contig(struct hme_softc *, void *, int, int); | | 116 | void hme_copyfrombuf_contig(struct hme_softc *, void *, int, int); |
119 | void hme_zerobuf_contig(struct hme_softc *, int, int); | | 117 | void hme_zerobuf_contig(struct hme_softc *, int, int); |
120 | | | 118 | |
121 | | | 119 | |
122 | void | | 120 | void |
123 | hme_config(sc) | | 121 | hme_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 | */ | | | |
648 | static inline int | | | |
649 | ether_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 | */ |
665 | int | | 647 | int |
666 | hme_put(sc, ri, m) | | 648 | hme_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 | |