From owner-svn-src-stable@freebsd.org Sun Sep 6 18:27:37 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2D0143D9BA4; Sun, 6 Sep 2020 18:27:37 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bl0JT0QtRz4KFB; Sun, 6 Sep 2020 18:27:37 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E5FAA12A31; Sun, 6 Sep 2020 18:27:36 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 086IRaTw092512; Sun, 6 Sep 2020 18:27:36 GMT (envelope-from gonzo@FreeBSD.org) Received: (from gonzo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 086IRawb092511; Sun, 6 Sep 2020 18:27:36 GMT (envelope-from gonzo@FreeBSD.org) Message-Id: <202009061827.086IRawb092511@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gonzo set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko Date: Sun, 6 Sep 2020 18:27:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r365386 - stable/12/sys/dev/dwc X-SVN-Group: stable-12 X-SVN-Commit-Author: gonzo X-SVN-Commit-Paths: stable/12/sys/dev/dwc X-SVN-Commit-Revision: 365386 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Sep 2020 18:27:37 -0000 Author: gonzo Date: Sun Sep 6 18:27:36 2020 New Revision: 365386 URL: https://svnweb.freebsd.org/changeset/base/365386 Log: MFC r353843 by glebius: Convert to if_foreach_llmaddr() KPI. Modified: stable/12/sys/dev/dwc/if_dwc.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/dwc/if_dwc.c ============================================================================== --- stable/12/sys/dev/dwc/if_dwc.c Sun Sep 6 18:25:50 2020 (r365385) +++ stable/12/sys/dev/dwc/if_dwc.c Sun Sep 6 18:27:36 2020 (r365386) @@ -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]); } }