Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 2019 18:11:20 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r353843 - head/sys/dev/dwc
Message-ID:  <201910211811.x9LIBKlx068211@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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]);
 	}
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910211811.x9LIBKlx068211>