From owner-svn-src-head@freebsd.org Mon Oct 21 18:10:59 2019 Return-Path: Delivered-To: svn-src-head@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 B93CB15DE65; Mon, 21 Oct 2019 18:10:59 +0000 (UTC) (envelope-from glebius@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) server-signature RSA-PSS (4096 bits) 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 46xl7R2htmz4cGd; Mon, 21 Oct 2019 18:10:59 +0000 (UTC) (envelope-from glebius@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 35AF827BA5; Mon, 21 Oct 2019 18:10:59 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9LIAxKl067299; Mon, 21 Oct 2019 18:10:59 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9LIAxf9067298; Mon, 21 Oct 2019 18:10:59 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201910211810.x9LIAxf9067298@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Mon, 21 Oct 2019 18:10:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353838 - head/sys/dev/cadence X-SVN-Group: head X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: head/sys/dev/cadence X-SVN-Commit-Revision: 353838 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Oct 2019 18:10:59 -0000 Author: glebius Date: Mon Oct 21 18:10:58 2019 New Revision: 353838 URL: https://svnweb.freebsd.org/changeset/base/353838 Log: Convert to if_foreach_llmaddr() KPI. Modified: head/sys/dev/cadence/if_cgem.c Modified: head/sys/dev/cadence/if_cgem.c ============================================================================== --- head/sys/dev/cadence/if_cgem.c Mon Oct 21 18:10:52 2019 (r353837) +++ head/sys/dev/cadence/if_cgem.c Mon Oct 21 18:10:58 2019 (r353838) @@ -299,6 +299,21 @@ cgem_mac_hash(u_char eaddr[]) return hash; } +static u_int +cgem_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) +{ + uint32_t *hashes = arg; + int index; + + index = cgem_mac_hash(LLADDR(sdl)); + if (index > 31) + hashes[0] |= (1 << (index - 32)); + else + hashes[1] |= (1 << index); + + return (1); +} + /* After any change in rx flags or multi-cast addresses, set up * hash registers and net config register bits. */ @@ -306,15 +321,9 @@ static void cgem_rx_filter(struct cgem_softc *sc) { if_t ifp = sc->ifp; - u_char *mta; - - int index, i, mcnt; - uint32_t hash_hi, hash_lo; + uint32_t hashes[2] = { 0, 0 }; uint32_t net_cfg; - hash_hi = 0; - hash_lo = 0; - net_cfg = RD4(sc, CGEM_NET_CFG); net_cfg &= ~(CGEM_NET_CFG_MULTI_HASH_EN | @@ -327,36 +336,17 @@ cgem_rx_filter(struct cgem_softc *sc) if ((if_getflags(ifp) & IFF_BROADCAST) == 0) net_cfg |= CGEM_NET_CFG_NO_BCAST; if ((if_getflags(ifp) & IFF_ALLMULTI) != 0) { - hash_hi = 0xffffffff; - hash_lo = 0xffffffff; - } else { - mcnt = if_multiaddr_count(ifp, -1); - mta = malloc(ETHER_ADDR_LEN * mcnt, M_DEVBUF, - M_NOWAIT); - if (mta == NULL) { - device_printf(sc->dev, - "failed to allocate temp mcast list\n"); - return; - } - if_multiaddr_array(ifp, mta, &mcnt, mcnt); - for (i = 0; i < mcnt; i++) { - index = cgem_mac_hash( - LLADDR((struct sockaddr_dl *) - (mta + (i * ETHER_ADDR_LEN)))); - if (index > 31) - hash_hi |= (1 << (index - 32)); - else - hash_lo |= (1 << index); - } - free(mta, M_DEVBUF); - } + hashes[0] = 0xffffffff; + hashes[1] = 0xffffffff; + } else + if_foreach_llmaddr(ifp, cgem_hash_maddr, hashes); - if (hash_hi != 0 || hash_lo != 0) + if (hashes[0] != 0 || hashes[1] != 0) net_cfg |= CGEM_NET_CFG_MULTI_HASH_EN; } - WR4(sc, CGEM_HASH_TOP, hash_hi); - WR4(sc, CGEM_HASH_BOT, hash_lo); + WR4(sc, CGEM_HASH_TOP, hashes[0]); + WR4(sc, CGEM_HASH_BOT, hashes[1]); WR4(sc, CGEM_NET_CFG, net_cfg); }