From patchwork Tue Oct 25 22:20:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1694652 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=CcMK3dTT; 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=murrerNe; 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 4Mxmfb5m2Gz23lL for ; Wed, 26 Oct 2022 09:23:03 +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=1X6rSyqh48jZAEvro4gE9ShYMivXIO4BYOwCzzaDId4=; b=CcMK3dTTEChv4C M8s6oRMwdbhW9JzGpSoYubqnCiOr06aL/vHKKNRIt2SZcTNpHIEpTsvucOFxWsEZUWIasxwXpxNVg sI6CFpeXX22xaGLpmjocRsscGMFJ9IfPhZIx59C03UBV4C1tk4Gl1jUnHkDx5OuxCSGRZDfLyw4Ej KAfYy833Kj3zkNNLaxE+V+CeLPpPQaMw7j3UXZu5EmRFEnyhFx6jOF7+RhoDJOt1IYfMhK9u5EX4w s2+pO/RNbFVTQ/DqJ/HS5LvnUPKQnl8z8ftpIYnfdMOG5yVu71JmpK2JhgG7kJWpF8lm8xWqSsBfE 9BFkb6M8V5fs82k9ciTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onSIA-007NFM-7Z; Tue, 25 Oct 2022 22:21:02 +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 1onSHt-007NC1-E8 for openwrt-devel@lists.openwrt.org; Tue, 25 Oct 2022 22:20:48 +0000 Received: from localhost.localdomain (p200300c6cf0a9ba0e4a0b66677a12f02.dip0.t-ipconnect.de [IPv6:2003:c6:cf0a:9ba0:e4a0:b666:77a1:2f02]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv5.3e8.eu (Postfix) with ESMTPSA id 0D155E0722; Wed, 26 Oct 2022 00:20:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1666736431; 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=Z6NIVSo/J5PQFEybt6KxyplbtrBesfwtcDv/PZ8gIUw=; b=murrerNeS7kJQgms2TmZ+wzstBm4vTFPKWgcssM08nnpw/jEzxJbMai+V6x1SuvK0BnBG2 dn1AvFv3YocleBq1hXtXDJH+14pXGLRqEcC/AcKBwdyk0Uo0SFPMB+dYC+aZXxzXL3SbzP vlACL0qnXQn+3JuUnG4ls9tDLWuqs1vKIQn0G4tABf/ltkjaczO6GeVzCaGum+lBSqD81L uHHDS6H5Aw2EKfLffE4MzU3xTdbT8ytqUg+FEYMWZG1D8EC3K2mJJYd5g3Iwxc8Zof2dEe W2tZaEPqx/ohL/k+WjNjI3o7oNy5IUEV9KgL0RJxYNHfcw4yBZ0KJiMEVjuqRQ== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Sander Vanheule , Jan Hoffmann Subject: [PATCH v2 1/2] realtek: set up L2 table entries properly Date: Wed, 26 Oct 2022 00:20:04 +0200 Message-Id: <20221025222005.4074737-2-jan@3e8.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025222005.4074737-1-jan@3e8.eu> References: <20221025222005.4074737-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_152046_206779_EA08B614 X-CRM114-Status: GOOD ( 12.38 ) 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: Initialize the data structure using memset to avoid the possibility of writing garbage values to the hardware. Always set a valid entry type, which should fix writing unicast entries on RTL930x. For unicast entries, set the is_static flag to prevent the switch from aging them out. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an 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 Initialize the data structure using memset to avoid the possibility of writing garbage values to the hardware. Always set a valid entry type, which should fix writing unicast entries on RTL930x. For unicast entries, set the is_static flag to prevent the switch from aging them out. Also set the rvid field for unicast entries. This is not strictly necessary, as the switch fills it in automatically from a non-zero vid. However, this makes the code consistent with multicast entry setup. While at it, reorder the statements and fix some style issues (double space, comma instead of semicolon at end of statement). Also remove the unneeded priv parameter and debug print for the multicast entry setup function. Fixes: cde31976e37 ("realtek: Add support for Layer 2 Multicast") Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/dsa/rtl83xx/dsa.c | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) 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 3ff1a96ed680..474d540945d1 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 @@ -1559,23 +1559,32 @@ static void dump_l2_entry(struct rtl838x_l2_entry *e) static void rtl83xx_setup_l2_uc_entry(struct rtl838x_l2_entry *e, int port, int vid, u64 mac) { - e->is_ip_mc = e->is_ipv6_mc = false; + memset(e, 0, sizeof(*e)); + + e->type = L2_UNICAST; e->valid = true; + e->age = 3; - e->port = port, - e->vid = vid; + e->is_static = true; + + e->port = port; + + e->rvid = e->vid = vid; + e->is_ip_mc = e->is_ipv6_mc = false; u64_to_ether_addr(mac, e->mac); } -static void rtl83xx_setup_l2_mc_entry(struct rtl838x_switch_priv *priv, - struct rtl838x_l2_entry *e, int vid, u64 mac, int mc_group) +static void rtl83xx_setup_l2_mc_entry(struct rtl838x_l2_entry *e, int vid, u64 mac, int mc_group) { - e->is_ip_mc = e->is_ipv6_mc = false; + memset(e, 0, sizeof(*e)); + + e->type = L2_MULTICAST; e->valid = true; + e->mc_portmask_index = mc_group; - e->type = L2_MULTICAST; + e->rvid = e->vid = vid; - pr_debug("%s: vid: %d, rvid: %d\n", __func__, e->vid, e->rvid); + e->is_ip_mc = e->is_ipv6_mc = false; u64_to_ether_addr(mac, e->mac); } @@ -1815,7 +1824,7 @@ static void rtl83xx_port_mdb_add(struct dsa_switch *ds, int port, err = -ENOTSUPP; goto out; } - rtl83xx_setup_l2_mc_entry(priv, &e, vid, mac, mc_group); + rtl83xx_setup_l2_mc_entry(&e, vid, mac, mc_group); priv->r->write_l2_entry_using_hash(idx >> 2, idx & 0x3, &e); } goto out; @@ -1836,7 +1845,7 @@ static void rtl83xx_port_mdb_add(struct dsa_switch *ds, int port, err = -ENOTSUPP; goto out; } - rtl83xx_setup_l2_mc_entry(priv, &e, vid, mac, mc_group); + rtl83xx_setup_l2_mc_entry(&e, vid, mac, mc_group); priv->r->write_cam(idx, &e); } goto out; From patchwork Tue Oct 25 22:20:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1694651 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=G4+Y9r83; 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=jsAlvyHK; 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 4MxmfZ73XBz23lJ for ; Wed, 26 Oct 2022 09:23:02 +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=A+izHq2wasCBPDFp/i4j7a/FbEN5MQQn4JlkKJMG7tQ=; b=G4+Y9r83aZCUxd XbyOXUh5LyyV/lF76Ai1WC+KRMxXwJD8cJEZwyS4wc+wqPtS5lpxYJBaDUxKjBz3ycl/c7GwUqfny 59o/lPmjwKY/5OdZbUOiRcCoURXHILxeLNRldTIQq/r5jW9MYYfZ5Es28drwGaIPCwMKv2irfbtT7 VV7gOXDLzhl9BrcspIegfounR5RbqzXCM9Rgjh+l4ymsNlrtGHkSCmsGou7zOAX74r9bj7odv9Mc9 yWNdxhr5QWS7dkpQBTjpomVhWh4VKIAAEvR31vO7W110XXverLOmqevUVoB6Ydx/V8g9Oyt+kpKtE 0f0KDoY1lNKn3Sz3IGmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onSIM-007NGu-N4; Tue, 25 Oct 2022 22:21:14 +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 1onSHt-007NC3-Cs for openwrt-devel@lists.openwrt.org; Tue, 25 Oct 2022 22:20:49 +0000 Received: from localhost.localdomain (p200300c6cf0a9ba0e4a0b66677a12f02.dip0.t-ipconnect.de [IPv6:2003:c6:cf0a:9ba0:e4a0:b666:77a1:2f02]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv5.3e8.eu (Postfix) with ESMTPSA id 083CBE072E; Wed, 26 Oct 2022 00:20:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1666736432; 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=ma0ky+zUiXmhe0WNMpMxky29KAV3OyBTAeu8LGaU8bM=; b=jsAlvyHK+ZSNitPEibrcWfjbWmpCEvvOBzIh9Yisq5N6psH8gJdefZ6Qh2M/j+fHKAZFAG hm3VPzk+lcRtQWWS3YpkIqIfIeHAP7v9yehqnhEjeChXYh2Hn2IeKjVDmAGlF1CjpHO6t0 x1hvezoVBOfihbFl1ML1sXINPYtM1BOnAGIwe2iNcixYosblPbEr2HbRLfwgar6pTwDxXX 3WrZnRcu600Wuisg2e82zAvKTgIzwgnpuNAjZDfFN0CBWkmMfmHvpYi1owv3EKWI3Oyyhj jSSodpF0VZqUO2RZxO+puo9iO7N3u6A9yIa2z8MwNe4h+2IBRzCdKKZAJZer4w== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Sander Vanheule , Jan Hoffmann Subject: [PATCH v2 2/2] realtek: use assisted learning on CPU port Date: Wed, 26 Oct 2022 00:20:05 +0200 Message-Id: <20221025222005.4074737-3-jan@3e8.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025222005.4074737-1-jan@3e8.eu> References: <20221025222005.4074737-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_152046_209198_82640445 X-CRM114-Status: GOOD ( 15.16 ) 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: L2 learning on the CPU port is currently not consistently configured and relies on the default configuration of the device. On RTL83xx, it is disabled for packets transmitted with a TX header, as hard [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an 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 L2 learning on the CPU port is currently not consistently configured and relies on the default configuration of the device. On RTL83xx, it is disabled for packets transmitted with a TX header, as hardware learning corrupts the forwarding table otherwise. As a result, unneeded flooding of traffic for the CPU port can already happen on some devices now. It is also likely that similar issues exist on RTL93xx, which doesn't have a field to disable learning in the TX header. To address this, disable hardware learning for the CPU port globally on all devices. Instead, enable assisted learning to let DSA write FDB entries to the switch. For now, this does not sync local/bridge entries to the switch. However, support for that was added in Linux 5.14, so the next switch to a newer kernel version is going to fix this. Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/dsa/rtl83xx/dsa.c | 16 ++++++++++++++++ .../files-5.10/drivers/net/dsa/rtl83xx/rtl838x.h | 6 ++++++ 2 files changed, 22 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 474d540945d1..319f171eaacc 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 @@ -162,6 +162,16 @@ static void rtl83xx_setup_bpdu_traps(struct rtl838x_switch_priv *priv) priv->r->set_receive_management_action(i, BPDU, COPY2CPU); } +static void rtl83xx_port_set_salrn(struct rtl838x_switch_priv *priv, + int port, bool enable) +{ + int shift = SALRN_PORT_SHIFT(port); + int val = enable ? SALRN_MODE_HARDWARE : SALRN_MODE_DISABLED; + + sw_w32_mask(SALRN_MODE_MASK << shift, val << shift, + priv->r->l2_port_new_salrn(port)); +} + static int rtl83xx_setup(struct dsa_switch *ds) { int i; @@ -205,6 +215,9 @@ static int rtl83xx_setup(struct dsa_switch *ds) priv->r->l2_learning_setup(); + rtl83xx_port_set_salrn(priv, priv->cpu_port, false); + ds->assisted_learning_on_cpu_port = true; + /* * Make sure all frames sent to the switch's MAC are trapped to the CPU-port * 0: FWD, 1: DROP, 2: TRAP2CPU @@ -263,6 +276,9 @@ static int rtl93xx_setup(struct dsa_switch *ds) priv->r->l2_learning_setup(); + rtl83xx_port_set_salrn(priv, priv->cpu_port, false); + ds->assisted_learning_on_cpu_port = true; + rtl83xx_enable_phy_polling(priv); priv->r->pie_init(priv); 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 e2b82a4975f0..10913dacef42 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 @@ -245,6 +245,12 @@ #define RTL839X_L2_PORT_NEW_SALRN(p) (0x38F0 + (((p >> 4) << 2))) #define RTL930X_L2_PORT_SALRN(p) (0x8FEC + (((p >> 4) << 2))) #define RTL931X_L2_PORT_NEW_SALRN(p) (0xC820 + (((p >> 4) << 2))) + +#define SALRN_PORT_SHIFT(p) ((p % 16) * 2) +#define SALRN_MODE_MASK 0x3 +#define SALRN_MODE_HARDWARE 0 +#define SALRN_MODE_DISABLED 2 + #define RTL838X_L2_PORT_NEW_SA_FWD(p) (0x3294 + (((p >> 4) << 2))) #define RTL839X_L2_PORT_NEW_SA_FWD(p) (0x3900 + (((p >> 4) << 2))) #define RTL930X_L2_PORT_NEW_SA_FWD(p) (0x8FF4 + (((p / 10) << 2)))