From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796389115; b=zgi2Tfuex3BBRTSR7fliCIebJy0ZWTVm/9q0a3pe8Om5O1nRG1zJ0+eQAlhmVKXDwyDL ZzAPRM0lOTJkfhsWXYK1LIOS6Wud1AegorqAMz0s6Loms11jE5KMkkCSJpYZepGRd17fD xnF1udX/Sv2m/9lJz0X1zHeM2ni/rHVwvAsmgn8J1IUkUO1PpqywagernteCvhf4zwolL pd3Z80Z8tq3x8qf2Q5fygkM+Hy844okcFBQwwfxnEYMpBRuC71pdU+u8g0hxEGnOdKHLA 8mSlaRFSrk93SMXvpyuJYDdOd8b79iibfqACOALQYBIV/s3VeWDQJAveKgsn/JKJmJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389115; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=xJq90tNCWOytl0B89EWYU4vLs08MKX3LnePYIW9HYLI=; b=ZQk32dpbKJp9iAWYMWjL1xh2WCZRqclu2W/qE5e7WdYbFa4t+wl0bZVM9mDneJ/LxylO w90AJI+exXioG1qufypgAWk+dr9TaaIBVYF2ptIJ9BBlcgTJG2pA1Bttsz3L4Ksp9uD/s 05/TpIxQ8rH4vP0O8DRQ5+OFm5SB8y0TW42OjQUyxfGKFNVu86Wj0jbC11HcXyxzhS/dq JHD9MTlJEOUU8qFr1Ajkx7Ib4CndDp5L1U9N1Bcnfg1hr7vL4qNqzMuculBUOSsrlaFB4 XfmZ+ktAkHPx+XL+Kr/cCkOMBVtiXfF9z5AjAh3VICHJeH5pVXiPV84pScWwhzORH+A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=1qjcwY8j; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB983606A322; Fri, 4 Dec 2026 12:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=1qjcwY8j Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EB911F00935; Fri, 4 Dec 2026 12:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389114; bh=xJq90tNCWOytl0B89EWYU4vLs08MKX3LnePYIW9HYLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1qjcwY8jashkm5AbgjNr6wEpBPBPjbLVJXnMwkPQdw66KoZbV2hKwifCdDL/io943 jdHfblgXR9PrgOi93YOolqB2K2CTf/mTj0496SUC8pkNdFhchL5r5puvgUjo6/Ki+S mNnr9EQkHieiTUKUl4sBo6yWQtsaai5cJxhJO3xI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Florian Fainelli , Willem de Bruijn , Sasha Levin Subject: [PATCH 6.1 0871/1059] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365 Date: Fri, 4 Dec 2026 19:06:42 +0900 Message-ID: <20261204100706.579699034@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Fainelli [ Upstream commit 000d468855945953c491810f97fb0bd4166b0b07 ] BCM5325 and BCM5365 use an 11-bit bitmap for the mirror capture port, whereas newer switches use a four-bit port ID. Programming the port number directly can select no destination or the wrong destination, and can select multiple destinations. For example, port 2 requires BIT(2), but writing 2 selects port 1 instead. Use the bitmap encoding on BCM5325 and BCM5365, including translating logical CPU port 5 to hardware bit 8. Apply the corresponding field mask when checking for a conflicting destination, replacing the destination, and clearing it after the last mirror source is removed. Keep the port ID encoding for newer switches. The ingress and egress mirror source masks use the same layout on these switches, with the CPU port at bit 8 and bits 5-7 reserved, so apply the same translation when setting and clearing a source port bit. Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring") Signed-off-by: Florian Fainelli Signed-off-by: Willem de Bruijn Signed-off-by: Sasha Levin --- drivers/net/dsa/b53/b53_common.c | 35 +++++++++++++++++++++++++++----- drivers/net/dsa/b53/b53_regs.h | 1 + 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index d8a9c02c279e8..af2cd7e50a3b1 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -2223,6 +2223,31 @@ enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port, } EXPORT_SYMBOL(b53_get_tag_protocol); +static u16 b53_mirror_capture_port_mask(struct b53_device *dev) +{ + if (is5325(dev) || is5365(dev)) + return CAP_PORT_MASK_25; + + return CAP_PORT_MASK; +} + +static u16 b53_mirror_port_mask(struct b53_device *dev, int port) +{ + /* These switches use a bitmap with the CPU port at bit 8. */ + if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) + port = B53_CPU_PORT; + + return BIT(port); +} + +static u16 b53_mirror_capture_port(struct b53_device *dev, int port) +{ + if (is5325(dev) || is5365(dev)) + return b53_mirror_port_mask(dev, port); + + return port; +} + int b53_mirror_add(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror, bool ingress, struct netlink_ext_ack *extack) @@ -2236,12 +2261,12 @@ int b53_mirror_add(struct dsa_switch *ds, int port, loc = B53_EG_MIR_CTL; b53_read16(dev, B53_MGMT_PAGE, loc, ®); - reg |= BIT(port); + reg |= b53_mirror_port_mask(dev, port); b53_write16(dev, B53_MGMT_PAGE, loc, reg); b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); - reg &= ~CAP_PORT_MASK; - reg |= mirror->to_local_port; + reg &= ~b53_mirror_capture_port_mask(dev); + reg |= b53_mirror_capture_port(dev, mirror->to_local_port); reg |= MIRROR_EN; b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); @@ -2263,7 +2288,7 @@ void b53_mirror_del(struct dsa_switch *ds, int port, /* Update the desired ingress/egress register */ b53_read16(dev, B53_MGMT_PAGE, loc, ®); - reg &= ~BIT(port); + reg &= ~b53_mirror_port_mask(dev, port); if (!(reg & MIRROR_MASK)) loc_disable = true; b53_write16(dev, B53_MGMT_PAGE, loc, reg); @@ -2282,7 +2307,7 @@ void b53_mirror_del(struct dsa_switch *ds, int port, /* Both no longer have ports, let's disable mirroring */ if (loc_disable && other_loc_disable) { reg &= ~MIRROR_EN; - reg &= ~mirror->to_local_port; + reg &= ~b53_mirror_capture_port_mask(dev); } b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); } diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h index 0b4343fcfcfd8..7b025662c75d1 100644 --- a/drivers/net/dsa/b53/b53_regs.h +++ b/drivers/net/dsa/b53/b53_regs.h @@ -220,6 +220,7 @@ /* Mirror capture control register (16 bit) */ #define B53_MIR_CAP_CTL 0x10 #define CAP_PORT_MASK 0xf +#define CAP_PORT_MASK_25 0x7ff #define BLK_NOT_MIR BIT(14) #define MIRROR_EN BIT(15) -- 2.53.0