From patchwork Sun Mar 12 22:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1755977 X-Patchwork-Delegate: sander@svanheule.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=W57U31ZQ; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=cYTrXh8p; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PZZyb2pzFz1yXD for ; Mon, 13 Mar 2023 10:00:54 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i5FpvovrY2HlqTyB9m1ElOPvtqlzqmqJAAmQlDE45P4=; b=W57U31ZQhYRNrS EPJlE3zJcv25bpOHdXld7b0OL6xCP5QUAtWTbyHpXjZ7FPdlpUEG7e555TGeLU1JmtdVmYaL8gtWz HRVkAheyK47/8gXYSCjCbfVgQC3HkbMyk8er2DpXFhS6X4CmMnMlKvU0YYr9VAcubKp5zK5O+5iLK LuhSaFEx+IkS/kKTQ3QkfGgDf1ojCEqL3i3DcBTbg+PQxZhUs99qiKIO/jpbEY57v+b5FLBbdR4fG GOoshzDgJNJ6t1EjHQnJ6vmcGR74Iu2EGDJrtT+jIvPIgbwZvlYBg8l19qmsmb5rEu4IAUjGPoRgy hZAD5t4R3+pIWptuW+Ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbUed-003kYV-Gt; Sun, 12 Mar 2023 22:59:03 +0000 Received: from srv5.3e8.eu ([94.16.113.219]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbUdg-003kPR-TA for openwrt-devel@lists.openwrt.org; Sun, 12 Mar 2023 22:58:10 +0000 Received: from localhost.localdomain (p200300c6cf0202a073867d2e443a1890.dip0.t-ipconnect.de [IPv6:2003:c6:cf02:2a0:7386:7d2e:443a:1890]) (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) (No client certificate requested) by srv5.3e8.eu (Postfix) with ESMTPSA id A5B53120CF8; Sun, 12 Mar 2023 23:57:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1678661869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u4SATnfRv603803B2HIt4oW0sWDUnqaWMFuZCibv7xQ=; b=cYTrXh8p8HPGjSKf+Cqbb9ZHq/sakF8hfEGGM6Qyk1UNODJiMXvBzeJ3QtMg1fnk/BcpVA ZcDDtPtiqVG4KHkxYmt9Gcst9J2yXCNW/esziJRsUnhAoYIViGnd5LCEgTO/uSesiYVhym ntqEX2hrVsXys8LiQ/wnCJoDZuyQSDZ5dWvGBdjtnvsKuAOb8OOdc8Y773xbWuGEfRlj0v M373XCE+17xB3bX3DbYU/bPRz8fBUYakXQ6hxS1oJawMTTAQHI9gzRD7rTqqvNoFKgIGMg Ac2wFd9LLf2zbPmDcQL+76IDLaXk7zRrWRMuIevRfWagNjToFIzmmJxkO6ielg== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Sander Vanheule , Jan Hoffmann Subject: [PATCH 3/4] realtek: fix standalone ports in presence of static fdb entries Date: Sun, 12 Mar 2023 23:57:29 +0100 Message-Id: <20230312225730.1409294-4-jan@3e8.eu> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230312225730.1409294-1-jan@3e8.eu> References: <20230312225730.1409294-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230312_155805_726464_8E30E56D X-CRM114-Status: GOOD ( 17.69 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The registers L2_PORT_STATIC_MV_ACT seem to specify the action to take when the source address of a packet exists as a static fdb entry on another port. By default the configured action is to drop suc [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The registers L2_PORT_STATIC_MV_ACT seem to specify the action to take when the source address of a packet exists as a static fdb entry on another port. By default the configured action is to drop such packets. For standalone ports, this behaviour is undesired, as all traffic should be forwarded to the CPU. So change the action to forward on standalone ports. A situation where this issue can occur is when a non-offloaded bond interface is part of a bridge. In that case, the CPU port will have fdb entries for devices connected to the bond interface, which are managed by the assisted learning feature. For now, this is only implemented for RTL838x/RTL839x, as the available set of registers differs for the other devices. Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/dsa/rtl83xx/dsa.c | 16 ++++++++++++++++ .../files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c | 10 ++++++++++ .../files-5.10/drivers/net/dsa/rtl83xx/rtl838x.h | 14 ++++++++++++++ .../files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c | 11 +++++++++++ .../files-5.15/drivers/net/dsa/rtl83xx/dsa.c | 16 ++++++++++++++++ .../files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c | 10 ++++++++++ .../files-5.15/drivers/net/dsa/rtl83xx/rtl838x.h | 14 ++++++++++++++ .../files-5.15/drivers/net/dsa/rtl83xx/rtl839x.c | 11 +++++++++++ 8 files changed, 102 insertions(+) diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/dsa.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/dsa.c index 5936f5e7d2c3..6fee8f646167 100644 --- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/dsa.c +++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/dsa.c @@ -200,6 +200,15 @@ static int rtl83xx_setup(struct dsa_switch *ds) } priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port)); + /* For standalone ports, forward packets even if a static fdb + * entry for the source address exists on another port. + */ + if (priv->r->set_static_move_action) { + for (i = 0; i <= priv->cpu_port; i++) { + priv->r->set_static_move_action(i, true); + } + } + if (priv->family_id == RTL8380_FAMILY_ID) rtl838x_print_matrix(); else @@ -1220,6 +1229,10 @@ static int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port, priv->r->traffic_set(port, v); } priv->ports[port].pm |= port_bitmap; + + if (priv->r->set_static_move_action) + priv->r->set_static_move_action(port, false); + mutex_unlock(&priv->reg_mutex); return 0; @@ -1261,6 +1274,9 @@ static void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, } priv->ports[port].pm &= ~port_bitmap; + if (priv->r->set_static_move_action) + priv->r->set_static_move_action(port, true); + mutex_unlock(&priv->reg_mutex); } diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c index 9ce50989790e..74ad03127687 100644 --- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c +++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c @@ -559,6 +559,15 @@ static void rtl838x_enable_bcast_flood(int port, bool enable) } +static void rtl838x_set_static_move_action(int port, bool forward) +{ + int shift = MV_ACT_PORT_SHIFT(port); + u32 val = forward ? MV_ACT_FORWARD : MV_ACT_DROP; + + sw_w32_mask(MV_ACT_MASK << shift, val << shift, + RTL838X_L2_PORT_STATIC_MV_ACT(port)); +} + static void rtl838x_stp_get(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]) { int i; @@ -1750,6 +1759,7 @@ const struct rtl838x_reg rtl838x_reg = { .enable_flood = rtl838x_enable_flood, .enable_mcast_flood = rtl838x_enable_mcast_flood, .enable_bcast_flood = rtl838x_enable_bcast_flood, + .set_static_move_action = rtl838x_set_static_move_action, .stp_get = rtl838x_stp_get, .stp_set = rtl838x_stp_set, .mac_port_ctrl = rtl838x_mac_port_ctrl, diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.h b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.h index 19049e4c957a..3f1f1d49f8e7 100644 --- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.h +++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.h @@ -251,6 +251,19 @@ #define RTL930X_L2_PORT_NEW_SA_FWD(p) (0x8FF4 + (((p / 10) << 2))) #define RTL931X_L2_PORT_NEW_SA_FWD(p) (0xC830 + (((p / 10) << 2))) +#define RTL838X_L2_PORT_MV_ACT(p) (0x335c + (((p >> 4) << 2))) +#define RTL839X_L2_PORT_MV_ACT(p) (0x3b80 + (((p >> 4) << 2))) + +#define RTL838X_L2_PORT_STATIC_MV_ACT(p) (0x327c + (((p >> 4) << 2))) +#define RTL839X_L2_PORT_STATIC_MV_ACT(p) (0x38dc + (((p >> 4) << 2))) + +#define MV_ACT_PORT_SHIFT(p) ((p % 16) * 2) +#define MV_ACT_MASK 0x3 +#define MV_ACT_FORWARD 0 +#define MV_ACT_DROP 1 +#define MV_ACT_TRAP2CPU 2 +#define MV_ACT_COPY2CPU 3 + #define RTL930X_ST_CTRL (0x8798) #define RTL930X_L2_PORT_SABLK_CTRL (0x905c) @@ -982,6 +995,7 @@ struct rtl838x_reg { void (*enable_flood)(int port, bool enable); void (*enable_mcast_flood)(int port, bool enable); void (*enable_bcast_flood)(int port, bool enable); + void (*set_static_move_action)(int port, bool forward); void (*stp_get)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]); void (*stp_set)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]); int (*mac_force_mode_ctrl)(int port); diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c index 986a4b5f45c7..c34bff78d73b 100644 --- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c +++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c @@ -602,6 +602,16 @@ static void rtl839x_enable_bcast_flood(int port, bool enable) { } + +static void rtl839x_set_static_move_action(int port, bool forward) +{ + int shift = MV_ACT_PORT_SHIFT(port); + u32 val = forward ? MV_ACT_FORWARD : MV_ACT_DROP; + + sw_w32_mask(MV_ACT_MASK << shift, val << shift, + RTL839X_L2_PORT_STATIC_MV_ACT(port)); +} + irqreturn_t rtl839x_switch_irq(int irq, void *dev_id) { struct dsa_switch *ds = dev_id; @@ -1893,6 +1903,7 @@ const struct rtl838x_reg rtl839x_reg = { .enable_flood = rtl839x_enable_flood, .enable_mcast_flood = rtl839x_enable_mcast_flood, .enable_bcast_flood = rtl839x_enable_bcast_flood, + .set_static_move_action = rtl839x_set_static_move_action, .stp_get = rtl839x_stp_get, .stp_set = rtl839x_stp_set, .mac_force_mode_ctrl = rtl839x_mac_force_mode_ctrl, diff --git a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/dsa.c b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/dsa.c index 05f00ef20765..46296d191797 100644 --- a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/dsa.c +++ b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/dsa.c @@ -191,6 +191,15 @@ static int rtl83xx_setup(struct dsa_switch *ds) } priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port)); + /* For standalone ports, forward packets even if a static fdb + * entry for the source address exists on another port. + */ + if (priv->r->set_static_move_action) { + for (int i = 0; i <= priv->cpu_port; i++) { + priv->r->set_static_move_action(i, true); + } + } + if (priv->family_id == RTL8380_FAMILY_ID) rtl838x_print_matrix(); else @@ -1205,6 +1214,10 @@ static int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port, priv->r->traffic_set(port, v); } priv->ports[port].pm |= port_bitmap; + + if (priv->r->set_static_move_action) + priv->r->set_static_move_action(port, false); + mutex_unlock(&priv->reg_mutex); return 0; @@ -1245,6 +1258,9 @@ static void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, } priv->ports[port].pm &= ~port_bitmap; + if (priv->r->set_static_move_action) + priv->r->set_static_move_action(port, true); + mutex_unlock(&priv->reg_mutex); } diff --git a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c index 504b29822a1f..606066aeea9b 100644 --- a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c +++ b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c @@ -543,6 +543,15 @@ static void rtl838x_enable_bcast_flood(int port, bool enable) } +static void rtl838x_set_static_move_action(int port, bool forward) +{ + int shift = MV_ACT_PORT_SHIFT(port); + u32 val = forward ? MV_ACT_FORWARD : MV_ACT_DROP; + + sw_w32_mask(MV_ACT_MASK << shift, val << shift, + RTL838X_L2_PORT_STATIC_MV_ACT(port)); +} + static void rtl838x_stp_get(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]) { u32 cmd = 1 << 15 | /* Execute cmd */ @@ -1717,6 +1726,7 @@ const struct rtl838x_reg rtl838x_reg = { .enable_flood = rtl838x_enable_flood, .enable_mcast_flood = rtl838x_enable_mcast_flood, .enable_bcast_flood = rtl838x_enable_bcast_flood, + .set_static_move_action = rtl838x_set_static_move_action, .stp_get = rtl838x_stp_get, .stp_set = rtl838x_stp_set, .mac_port_ctrl = rtl838x_mac_port_ctrl, diff --git a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.h b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.h index a4bfc285a60c..bfab576e06ec 100644 --- a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.h +++ b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.h @@ -249,6 +249,19 @@ #define RTL930X_L2_PORT_NEW_SA_FWD(p) (0x8FF4 + (((p / 10) << 2))) #define RTL931X_L2_PORT_NEW_SA_FWD(p) (0xC830 + (((p / 10) << 2))) +#define RTL838X_L2_PORT_MV_ACT(p) (0x335c + (((p >> 4) << 2))) +#define RTL839X_L2_PORT_MV_ACT(p) (0x3b80 + (((p >> 4) << 2))) + +#define RTL838X_L2_PORT_STATIC_MV_ACT(p) (0x327c + (((p >> 4) << 2))) +#define RTL839X_L2_PORT_STATIC_MV_ACT(p) (0x38dc + (((p >> 4) << 2))) + +#define MV_ACT_PORT_SHIFT(p) ((p % 16) * 2) +#define MV_ACT_MASK 0x3 +#define MV_ACT_FORWARD 0 +#define MV_ACT_DROP 1 +#define MV_ACT_TRAP2CPU 2 +#define MV_ACT_COPY2CPU 3 + #define RTL930X_ST_CTRL (0x8798) #define RTL930X_L2_PORT_SABLK_CTRL (0x905c) @@ -978,6 +991,7 @@ struct rtl838x_reg { void (*enable_flood)(int port, bool enable); void (*enable_mcast_flood)(int port, bool enable); void (*enable_bcast_flood)(int port, bool enable); + void (*set_static_move_action)(int port, bool forward); void (*stp_get)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]); void (*stp_set)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]); int (*mac_force_mode_ctrl)(int port); diff --git a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl839x.c b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl839x.c index 06fdbd893619..fe5572a4476e 100644 --- a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl839x.c +++ b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl839x.c @@ -590,6 +590,16 @@ static void rtl839x_enable_bcast_flood(int port, bool enable) { } + +static void rtl839x_set_static_move_action(int port, bool forward) +{ + int shift = MV_ACT_PORT_SHIFT(port); + u32 val = forward ? MV_ACT_FORWARD : MV_ACT_DROP; + + sw_w32_mask(MV_ACT_MASK << shift, val << shift, + RTL839X_L2_PORT_STATIC_MV_ACT(port)); +} + irqreturn_t rtl839x_switch_irq(int irq, void *dev_id) { struct dsa_switch *ds = dev_id; @@ -1855,6 +1865,7 @@ const struct rtl838x_reg rtl839x_reg = { .enable_flood = rtl839x_enable_flood, .enable_mcast_flood = rtl839x_enable_mcast_flood, .enable_bcast_flood = rtl839x_enable_bcast_flood, + .set_static_move_action = rtl839x_set_static_move_action, .stp_get = rtl839x_stp_get, .stp_set = rtl839x_stp_set, .mac_force_mode_ctrl = rtl839x_mac_force_mode_ctrl,