Author: glebius
Date: Mon Oct 21 18:11:19 2019
New Revision: 353843
URL: https://svnweb.freebsd.org/changeset/base/353843

Log:
  Convert to if_foreach_llmaddr() KPI.

Modified:
  head/sys/dev/dwc/if_dwc.c

Modified: head/sys/dev/dwc/if_dwc.c
==============================================================================
--- head/sys/dev/dwc/if_dwc.c   Mon Oct 21 18:11:15 2019        (r353842)
+++ head/sys/dev/dwc/if_dwc.c   Mon Oct 21 18:11:19 2019        (r353843)
@@ -581,13 +581,37 @@ bitreverse(uint8_t x)
        return (nibbletab[x & 0xf] << 4) | nibbletab[x >> 4];
 }
 
+struct dwc_hash_maddr_ctx {
+       struct dwc_softc *sc;
+       uint32_t hash[8];
+};
+
+static u_int
+dwc_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
+{
+       struct dwc_hash_maddr_ctx *ctx = arg;
+       uint32_t crc, hashbit, hashreg;
+       uint8_t val;
+
+       crc = ether_crc32_le(LLADDR(sdl), ETHER_ADDR_LEN);
+       /* Take lower 8 bits and reverse it */
+       val = bitreverse(~crc & 0xff);
+       if (ctx->sc->mactype == DWC_GMAC_ALT_DESC)
+               val >>= 2; /* Only need lower 6 bits */
+       hashreg = (val >> 5);
+       hashbit = (val & 31);
+       ctx->hash[hashreg] |= (1 << hashbit);
+
+       return (1);
+}
+
 static void
 dwc_setup_rxfilter(struct dwc_softc *sc)
 {
-       struct ifmultiaddr *ifma;
+       struct dwc_hash_maddr_ctx ctx;
        struct ifnet *ifp;
-       uint8_t *eaddr, val;
-       uint32_t crc, ffval, hashbit, hashreg, hi, lo, hash[8];
+       uint8_t *eaddr;
+       uint32_t ffval, hi, lo;
        int nhash, i;
 
        DWC_ASSERT_LOCKED(sc);
@@ -601,27 +625,13 @@ dwc_setup_rxfilter(struct dwc_softc *sc)
        if ((ifp->if_flags & IFF_ALLMULTI) != 0) {
                ffval = (FRAME_FILTER_PM);
                for (i = 0; i < nhash; i++)
-                       hash[i] = ~0;
+                       ctx.hash[i] = ~0;
        } else {
                ffval = (FRAME_FILTER_HMC);
                for (i = 0; i < nhash; i++)
-                       hash[i] = 0;
-               if_maddr_rlock(ifp);
-               CK_STAILQ_FOREACH(ifma, &sc->ifp->if_multiaddrs, ifma_link) {
-                       if (ifma->ifma_addr->sa_family != AF_LINK)
-                               continue;
-                       crc = ether_crc32_le(LLADDR((struct sockaddr_dl *)
-                               ifma->ifma_addr), ETHER_ADDR_LEN);
-
-                       /* Take lower 8 bits and reverse it */
-                       val = bitreverse(~crc & 0xff);
-                       if (sc->mactype == DWC_GMAC_ALT_DESC)
-                               val >>= nhash; /* Only need lower 6 bits */
-                       hashreg = (val >> 5);
-                       hashbit = (val & 31);
-                       hash[hashreg] |= (1 << hashbit);
-               }
-               if_maddr_runlock(ifp);
+                       ctx.hash[i] = 0;
+               ctx.sc = sc;
+               if_foreach_llmaddr(ifp, dwc_hash_maddr, &ctx);
        }
 
        /*
@@ -641,11 +651,11 @@ dwc_setup_rxfilter(struct dwc_softc *sc)
        WRITE4(sc, MAC_ADDRESS_HIGH(0), hi);
        WRITE4(sc, MAC_FRAME_FILTER, ffval);
        if (sc->mactype == DWC_GMAC_ALT_DESC) {
-               WRITE4(sc, GMAC_MAC_HTLOW, hash[0]);
-               WRITE4(sc, GMAC_MAC_HTHIGH, hash[1]);
+               WRITE4(sc, GMAC_MAC_HTLOW, ctx.hash[0]);
+               WRITE4(sc, GMAC_MAC_HTHIGH, ctx.hash[1]);
        } else {
                for (i = 0; i < nhash; i++)
-                       WRITE4(sc, HASH_TABLE_REG(i), hash[i]);
+                       WRITE4(sc, HASH_TABLE_REG(i), ctx.hash[i]);
        }
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to