Date: Mon, 21 Oct 2019 18:11:08 +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: r353840 - in head/sys/dev/cxgb: . common Message-ID: <201910211811.x9LIB8j5067433@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Mon Oct 21 18:11:08 2019 New Revision: 353840 URL: https://svnweb.freebsd.org/changeset/base/353840 Log: Convert to if_foreach_llmaddr() KPI. Modified: head/sys/dev/cxgb/common/cxgb_xgmac.c head/sys/dev/cxgb/cxgb_adapter.h Modified: head/sys/dev/cxgb/common/cxgb_xgmac.c ============================================================================== --- head/sys/dev/cxgb/common/cxgb_xgmac.c Mon Oct 21 18:11:02 2019 (r353839) +++ head/sys/dev/cxgb/common/cxgb_xgmac.c Mon Oct 21 18:11:08 2019 (r353840) @@ -408,9 +408,32 @@ static int hash_hw_addr(const u8 *addr) * Configures the MAC Rx mode (promiscuity, etc) and exact and hash * address filters. */ +struct t3_mcaddr_ctx { + struct cmac *mac; + u32 hash_lo, hash_hi; +}; + +static u_int +t3_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) +{ + struct t3_mcaddr_ctx *ctx = arg; + int hash; + + if (ctx->mac->nucast + cnt < EXACT_ADDR_FILTERS) + set_addr_filter(ctx->mac, ctx->mac->nucast + cnt, LLADDR(sdl)); + else { + hash = hash_hw_addr(LLADDR(sdl)); + if (hash < 32) + ctx->hash_lo |= (1 << hash); + else + ctx->hash_hi |= (1 << (hash - 32)); + } + return (1); +} + int t3_mac_set_rx_mode(struct cmac *mac, struct t3_rx_mode *rm) { - u32 hash_lo, hash_hi; + struct t3_mcaddr_ctx ctx; adapter_t *adap = mac->adapter; unsigned int oft = mac->offset; @@ -422,27 +445,15 @@ int t3_mac_set_rx_mode(struct cmac *mac, struct t3_rx_ mac->promisc_map ? F_COPYALLFRAMES : 0); if (allmulti_rx_mode(rm) || mac->multiport) - hash_lo = hash_hi = 0xffffffff; + ctx.hash_lo = ctx.hash_hi = 0xffffffff; else { - u8 *addr; - int exact_addr_idx = mac->nucast; - - hash_lo = hash_hi = 0; - while ((addr = t3_get_next_mcaddr(rm))) - if (exact_addr_idx < EXACT_ADDR_FILTERS) - set_addr_filter(mac, exact_addr_idx++, addr); - else { - int hash = hash_hw_addr(addr); - - if (hash < 32) - hash_lo |= (1 << hash); - else - hash_hi |= (1 << (hash - 32)); - } + ctx.mac = mac; + ctx.hash_lo = ctx.hash_hi = 0; + if_foreach_llmaddr(rm->port->ifp, t3_hash_maddr, &ctx); } - t3_write_reg(adap, A_XGM_RX_HASH_LOW + oft, hash_lo); - t3_write_reg(adap, A_XGM_RX_HASH_HIGH + oft, hash_hi); + t3_write_reg(adap, A_XGM_RX_HASH_LOW + oft, ctx.hash_lo); + t3_write_reg(adap, A_XGM_RX_HASH_HIGH + oft, ctx.hash_hi); return 0; } Modified: head/sys/dev/cxgb/cxgb_adapter.h ============================================================================== --- head/sys/dev/cxgb/cxgb_adapter.h Mon Oct 21 18:11:02 2019 (r353839) +++ head/sys/dev/cxgb/cxgb_adapter.h Mon Oct 21 18:11:08 2019 (r353840) @@ -463,30 +463,6 @@ t3_os_pci_write_config_2(adapter_t *adapter, int reg, pci_write_config(adapter->dev, reg, val, 2); } -static __inline uint8_t * -t3_get_next_mcaddr(struct t3_rx_mode *rm) -{ - uint8_t *macaddr = NULL; - struct ifnet *ifp = rm->port->ifp; - struct ifmultiaddr *ifma; - int i = 0; - - if_maddr_rlock(ifp); - CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { - if (ifma->ifma_addr->sa_family != AF_LINK) - continue; - if (i == rm->idx) { - macaddr = LLADDR((struct sockaddr_dl *)ifma->ifma_addr); - break; - } - i++; - } - if_maddr_runlock(ifp); - - rm->idx++; - return (macaddr); -} - static __inline void t3_init_rx_mode(struct t3_rx_mode *rm, struct port_info *port) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910211811.x9LIB8j5067433>