From patchwork Sun Mar 12 22:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1755978 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=wEQrbqWy; 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=gHUllt3+; 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 4PZZyb2z7Gz246h 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=l8H5/DnTaLjFhJLRN2q4PKt7sgSWToIQzssD7M6KhDI=; b=wEQrbqWyRWK8Os 9mL0ef6rIeEDu47YEyPD3FPhcThsh9U4AYdpHRzCgzX7LUXkNfTZz52PgggV75NDOucTRt5th9eX7 QshJVzraTqHfRiV+xIoWMk85cN17AHEpBvqdzbgKWbQ9NApHA7Xsc00Kefr3dRKQ6LajpESq7I3St 0v4lkKMCgHbe2aBQLQVq/YNTCEUz1Wk5VKQX6gQJ6qX8kJmShIH+EQ6PydOdbt0vczr5ek+O/QJnT dxXEFLssvw/OJC3dfhhWEo/vqeajfB0LUPM313lSm6wOvHFlMXPfnKP+2Itgc8O7cd387UqXtFMVO yF63aMfgYe75jSyRJTgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbUeE-003kTR-65; Sun, 12 Mar 2023 22:58:38 +0000 Received: from srv5.3e8.eu ([2a03:4000:28:8d0::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbUdi-003kPV-Pm for openwrt-devel@lists.openwrt.org; Sun, 12 Mar 2023 22:58:09 +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 6B569120CDD; Sun, 12 Mar 2023 23:57:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1678661868; 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=pw5/4bVAwvQK++/HM/JNLYTequpAAqkooauh5BFl4Y0=; b=gHUllt3+eAgM7hvEwQ975TA90LIacqdKAt5T2fcITPUQ34z8elMKi8Mcizo5NmvdDEbIKd 67aMf1juG3f9vVp654ZLywyLy/+GxEBRLjlIJzfTZfoi/5kkZ6/M9nLK6yxaJymqyadwBx NbM4tOC60LNBjFO7EySulhpxSYKJShDU2bpGFPVCBpD1R61BXsvhyriYQ2tY8OYcu/Uct8 ZUUJwzCu0AcNYR4q/t1sqIAuLev/0CHjiFAQEjX/6XzsOAxWDZkHvKlNOCaQ1+ddZtpctK Hl/NrtbkCOYUavxFvL36/GN5YGf9g8co3lpo03kWQs6CvonM1fo+Tde2cLZQKw== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Sander Vanheule , Jan Hoffmann Subject: [PATCH 1/4] realtek: properly update port masks when port leaves bridge Date: Sun, 12 Mar 2023 23:57:27 +0100 Message-Id: <20230312225730.1409294-2-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_155807_025150_0D54E1D7 X-CRM114-Status: GOOD ( 15.81 ) 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: Correctly update the isolation mask of the port being configured. The port_bitmap variable should contain all other bridge members and needs to be actually removed from the isolation mask instead of a [...] 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 Correctly update the isolation mask of the port being configured. The port_bitmap variable should contain all other bridge members and needs to be actually removed from the isolation mask instead of added to it. Also actually remove the port being configured from the pm field of the other ports, so that any other ports that are currently disabled will be configured correctly when they are enabled. Signed-off-by: Jan Hoffmann --- I originally wanted to put a proper Fixes tag here, but I'm not sure which commit to choose. This bug seems to have existed since this target was introduced, and survived through multiple refactorings. It looks like the incorrect update to the pm field was even fixed in 2b88563ee5aa ("realtek: update the tree to the latest refactored version"), but then 27029277f98d ("realtek: add switch driver support for the RTL93XX based switches") reintroduced the issue. .../realtek/files-5.10/drivers/net/dsa/rtl83xx/dsa.c | 10 +++++----- .../realtek/files-5.15/drivers/net/dsa/rtl83xx/dsa.c | 10 +++++----- 2 files changed, 10 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 63461ff57348..220f1d5d281d 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 @@ -1227,7 +1227,7 @@ static void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *bridge) { struct rtl838x_switch_priv *priv = ds->priv; - u64 port_bitmap = BIT_ULL(priv->cpu_port), v; + u64 port_bitmap = 0, v; int i; pr_debug("%s %x: %d", __func__, (u32)priv, port); @@ -1245,16 +1245,16 @@ static void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, if (priv->ports[i].enable) priv->r->traffic_disable(i, port); - priv->ports[i].pm |= BIT_ULL(port); - port_bitmap &= ~BIT_ULL(i); + priv->ports[i].pm &= ~BIT_ULL(port); + port_bitmap |= BIT_ULL(i); } } store_mcgroups(priv, port); - /* Add all other ports to this port matrix. */ + /* Remove all other ports from this port matrix. */ if (priv->ports[port].enable) { v = priv->r->traffic_get(port); - v |= port_bitmap; + v &= ~port_bitmap; priv->r->traffic_set(port, v); } priv->ports[port].pm &= ~port_bitmap; 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 83a0441ce27c..7eebb2107f84 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 @@ -1212,7 +1212,7 @@ static void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *bridge) { struct rtl838x_switch_priv *priv = ds->priv; - u64 port_bitmap = BIT_ULL(priv->cpu_port), v; + u64 port_bitmap = 0, v; pr_debug("%s %x: %d", __func__, (u32)priv, port); mutex_lock(&priv->reg_mutex); @@ -1229,16 +1229,16 @@ static void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, if (priv->ports[i].enable) priv->r->traffic_disable(i, port); - priv->ports[i].pm |= BIT_ULL(port); - port_bitmap &= ~BIT_ULL(i); + priv->ports[i].pm &= ~BIT_ULL(port); + port_bitmap |= BIT_ULL(i); } } store_mcgroups(priv, port); - /* Add all other ports to this port matrix. */ + /* Remove all other ports from this port matrix. */ if (priv->ports[port].enable) { v = priv->r->traffic_get(port); - v |= port_bitmap; + v &= ~port_bitmap; priv->r->traffic_set(port, v); } priv->ports[port].pm &= ~port_bitmap; From patchwork Sun Mar 12 22:57:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1755980 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=pohB5rQY; 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=iNwyMepQ; 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 4PZZyy59bdz1yWt for ; Mon, 13 Mar 2023 10:01:14 +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=Yyy7tUa7x56nRwQboMPoJihGrWBVeIQlgrGTV91k98Y=; b=pohB5rQYCMbgoG 3G+q2dsRupkF1ISP5JOCs3jaLCAPCJf7Ug2XZrk11rDo+uJu7uLuOI85pUUaSJgHkKJEjutpdUPKr nK14nw9ZCwpWOauhTHOimALk9M7FnTk8QIYkcLoO81UPfWSCv8KzqAl5aClKx2gqkTVl8a/pcAa/O gQ0PWPWn/7OVFFfCdiarwvRJBT+odfrdrcPWeVoQM9ZUjt8LsHIGoM0siCj2OppUiLssXLUmDMI8R I9CDI6JVsKMt34OkhdtAh4i53O5TP5utx/aiG0BamiKpH9C7OMjobNOg+OaCykUp6XJVF8OlIwsCj QYedgbWj4S35eCKLRY4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbUdz-003kSG-2z; Sun, 12 Mar 2023 22:58:23 +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-003kPS-Tu for openwrt-devel@lists.openwrt.org; Sun, 12 Mar 2023 22:58:08 +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 84443120CEE; 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=OBF45W7W+An+cwnZeuaZ7qeeSQ5fltDG/X32kXwi0UU=; b=iNwyMepQyGKHyUX2MMRGj3Y7KlPYlbABR55UORT6PWIBC9rAMm6Js1j2jsn4auUm8tduKZ F60SYMjg1KUQ+qNY2JQekWuUSckqUxllxYkisqFb9OWxAyUNi9/K3L6lxayb056Z9swgrp emG+rMykfxillnXvmhXHrnHQTSGiWprNoMJfbhgsIBxGICLgIwOYlhm/pJ/YMLJ7zD2/4T u1AFA+3o9zdMiMaYGylurdU55VJBc9eDy24hiSzU6FZhYtMJz8znSqVqL1G9eMptCMnqJE fFmPky+gNSQSsNAap4bj5kUcnLR5kLzOr1FMzTtSpsgIdq9sxZb4CUpEpX7WFQ== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Sander Vanheule , Jan Hoffmann Subject: [PATCH 2/4] realtek: initialize port masks to match the default state Date: Sun, 12 Mar 2023 23:57:28 +0100 Message-Id: <20230312225730.1409294-3-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_726457_7C7E2AD1 X-CRM114-Status: GOOD ( 14.01 ) 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: All ports are disabled by default, so configure the port isolation masks and the pm field accordingly in the setup function. When port_enable is called for a port, the isolation masks will be set up s [...] 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 All ports are disabled by default, so configure the port isolation masks and the pm field accordingly in the setup function. When port_enable is called for a port, the isolation masks will be set up so that traffic can flow between the port and the CPU. While at it, change the code to also use the traffic_set method in rtl83xx_setup. Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/dsa/rtl83xx/dsa.c | 22 ++++++++++--------- .../files-5.15/drivers/net/dsa/rtl83xx/dsa.c | 22 ++++++++++--------- 2 files changed, 24 insertions(+), 20 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 220f1d5d281d..5936f5e7d2c3 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 @@ -176,7 +176,6 @@ static int rtl83xx_setup(struct dsa_switch *ds) { int i; struct rtl838x_switch_priv *priv = ds->priv; - u64 port_bitmap = BIT_ULL(priv->cpu_port); pr_debug("%s called\n", __func__); @@ -187,18 +186,19 @@ static int rtl83xx_setup(struct dsa_switch *ds) priv->ports[i].enable = false; priv->ports[priv->cpu_port].enable = true; - /* Isolate ports from each other: traffic only CPU <-> port */ + /* Configure ports so they are disabled by default, but once enabled + * they will work in isolated mode (only traffic between port and CPU). + */ /* Setting bit j in register RTL838X_PORT_ISO_CTRL(i) allows * traffic from source port i to destination port j */ for (i = 0; i < priv->cpu_port; i++) { if (priv->ports[i].phy) { - priv->r->set_port_reg_be(BIT_ULL(priv->cpu_port) | BIT_ULL(i), - priv->r->port_iso_ctrl(i)); - port_bitmap |= BIT_ULL(i); + priv->ports[i].pm = BIT_ULL(priv->cpu_port); + priv->r->traffic_set(i, BIT_ULL(i)); } } - priv->r->set_port_reg_be(port_bitmap, priv->r->port_iso_ctrl(priv->cpu_port)); + priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port)); if (priv->family_id == RTL8380_FAMILY_ID) rtl838x_print_matrix(); @@ -240,7 +240,6 @@ static int rtl93xx_setup(struct dsa_switch *ds) { int i; struct rtl838x_switch_priv *priv = ds->priv; - u32 port_bitmap = BIT(priv->cpu_port); pr_info("%s called\n", __func__); @@ -258,13 +257,16 @@ static int rtl93xx_setup(struct dsa_switch *ds) priv->ports[i].enable = false; priv->ports[priv->cpu_port].enable = true; + /* Configure ports so they are disabled by default, but once enabled + * they will work in isolated mode (only traffic between port and CPU). + */ for (i = 0; i < priv->cpu_port; i++) { if (priv->ports[i].phy) { - priv->r->traffic_set(i, BIT_ULL(priv->cpu_port) | BIT_ULL(i)); - port_bitmap |= BIT_ULL(i); + priv->ports[i].pm = BIT_ULL(priv->cpu_port); + priv->r->traffic_set(i, BIT_ULL(i)); } } - priv->r->traffic_set(priv->cpu_port, port_bitmap); + priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port)); rtl930x_print_matrix(); 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 7eebb2107f84..05f00ef20765 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 @@ -167,7 +167,6 @@ static void rtl83xx_port_set_salrn(struct rtl838x_switch_priv *priv, static int rtl83xx_setup(struct dsa_switch *ds) { struct rtl838x_switch_priv *priv = ds->priv; - u64 port_bitmap = BIT_ULL(priv->cpu_port); pr_debug("%s called\n", __func__); @@ -178,18 +177,19 @@ static int rtl83xx_setup(struct dsa_switch *ds) priv->ports[i].enable = false; priv->ports[priv->cpu_port].enable = true; - /* Isolate ports from each other: traffic only CPU <-> port */ + /* Configure ports so they are disabled by default, but once enabled + * they will work in isolated mode (only traffic between port and CPU). + */ /* Setting bit j in register RTL838X_PORT_ISO_CTRL(i) allows * traffic from source port i to destination port j */ for (int i = 0; i < priv->cpu_port; i++) { if (priv->ports[i].phy) { - priv->r->set_port_reg_be(BIT_ULL(priv->cpu_port) | BIT_ULL(i), - priv->r->port_iso_ctrl(i)); - port_bitmap |= BIT_ULL(i); + priv->ports[i].pm = BIT_ULL(priv->cpu_port); + priv->r->traffic_set(i, BIT_ULL(i)); } } - priv->r->set_port_reg_be(port_bitmap, priv->r->port_iso_ctrl(priv->cpu_port)); + priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port)); if (priv->family_id == RTL8380_FAMILY_ID) rtl838x_print_matrix(); @@ -229,7 +229,6 @@ static int rtl83xx_setup(struct dsa_switch *ds) static int rtl93xx_setup(struct dsa_switch *ds) { struct rtl838x_switch_priv *priv = ds->priv; - u32 port_bitmap = BIT(priv->cpu_port); pr_info("%s called\n", __func__); @@ -247,13 +246,16 @@ static int rtl93xx_setup(struct dsa_switch *ds) priv->ports[i].enable = false; priv->ports[priv->cpu_port].enable = true; + /* Configure ports so they are disabled by default, but once enabled + * they will work in isolated mode (only traffic between port and CPU). + */ for (int i = 0; i < priv->cpu_port; i++) { if (priv->ports[i].phy) { - priv->r->traffic_set(i, BIT_ULL(priv->cpu_port) | BIT_ULL(i)); - port_bitmap |= BIT_ULL(i); + priv->ports[i].pm = BIT_ULL(priv->cpu_port); + priv->r->traffic_set(i, BIT_ULL(i)); } } - priv->r->traffic_set(priv->cpu_port, port_bitmap); + priv->r->traffic_set(priv->cpu_port, BIT_ULL(priv->cpu_port)); rtl930x_print_matrix(); 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, From patchwork Sun Mar 12 22:57:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1755976 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=qb/m5w9/; 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=fHWKTqwk; 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 4PZZyc69brz247B for ; Mon, 13 Mar 2023 10:00:56 +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=sIvKZ+EYta4NlopowYBXb+wTxVENmksQ8iQF/i9LJ7E=; b=qb/m5w9/Px0RWF r2UeWHd/+cpMZGhHvt2f1iOn1QZ7jcCPMLrbFJnGmdHF0Mknn8lRpTddT05tKblwaTE+GWp6Phfn/ b+e5zJ04fDP7GHQVAOpMUs+MS8vMEmN+PxwSjbCq/NscUnQMtNw+Zj5mEzoyLZRlI1G+40dvQ21GG WquJv+53sxiLoQnMupa9kqALG4UuVBpnBiht2T3JWYqhxPKknYMZ7DfKTUFNeYMi0nZCLBzAX1/LN X6Df42C0SUWQWYd8bSjf22VXcfklbKLc+21rAAPBt9anwxnVBPDx95XU6BtO7A7FHXa52On87VWOW yoN5cavRx+XWQ9ZHMDnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbUeQ-003kVV-HN; Sun, 12 Mar 2023 22:58:50 +0000 Received: from srv5.3e8.eu ([2a03:4000:28:8d0::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbUdj-003kPT-96 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 C63B3120D14; 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=nYhsJOc0Osy3iLrQjfy9ufl/9gSVCPyZ9j7Om8Grc8Y=; b=fHWKTqwkiPh2IUtSYCfQodmVvdNdihxoPJKUD9GlLK9fe9luAV4qUnMqE+E6DjTRHDlZMn FvIRCMhZg9QHXL2w+TKMnBy8lZlFETB53SOB5e186/mdVCKXc0Vx8UP5LO/y3c+YN051ab nojnAgn4mUX2/lO12XUiZwJkT7noLZdlcUDYH5uj4vUVmGCcQuBt/CDwRg1baisps4HSDj T8DdHWbXW1+O/fF1ASBl6JpDht0Q62F9A156o+bUDbi/WUNEK2bvuu5IXyl8GtEUN8amPI 8hCmJNK22wbF4D1DA5ggXHpF9eHBjc2c+c7BJtPUuDUpdxFkdD00QacYU8bAJw== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Sander Vanheule , Jan Hoffmann Subject: [PATCH 4/4] realtek: handle changed flags in VLAN configuration Date: Sun, 12 Mar 2023 23:57:30 +0100 Message-Id: <20230312225730.1409294-5-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_155807_663893_B94BD4BE X-CRM114-Status: GOOD ( 14.12 ) 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 port_vlan_add method may be called while a port is already a member of that VLAN, so it needs to be able to handle changed flags. Fix it to properly handle when the PVID or UNTAGGED flag was previ [...] 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 port_vlan_add method may be called while a port is already a member of that VLAN, so it needs to be able to handle changed flags. Fix it to properly handle when the PVID or UNTAGGED flag was previously set, but now no longer is. To reduce duplication, move PVID configuration to a separate function. Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/dsa/rtl83xx/dsa.c | 41 ++++++++++--------- .../files-5.15/drivers/net/dsa/rtl83xx/dsa.c | 37 +++++++++-------- 2 files changed, 43 insertions(+), 35 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 6fee8f646167..efeca23d2253 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 @@ -1454,6 +1454,20 @@ static int rtl83xx_vlan_prepare(struct dsa_switch *ds, int port, return 0; } +static void rtl83xx_vlan_set_pvid(struct rtl838x_switch_priv *priv, + int port, int pvid) +{ + /* Set both inner and outer PVID of the port */ + priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_INNER, pvid); + priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_OUTER, pvid); + priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_INNER, + PBVLAN_MODE_UNTAG_AND_PRITAG); + priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_OUTER, + PBVLAN_MODE_UNTAG_AND_PRITAG); + + priv->ports[port].pvid = pvid; +} + static void rtl83xx_vlan_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { @@ -1472,19 +1486,11 @@ static void rtl83xx_vlan_add(struct dsa_switch *ds, int port, mutex_lock(&priv->reg_mutex); - if (vlan->flags & BRIDGE_VLAN_INFO_PVID) { - for (v = vlan->vid_begin; v <= vlan->vid_end; v++) { - if (!v) - continue; - /* Set both inner and outer PVID of the port */ - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_INNER, v); - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_OUTER, v); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_INNER, - PBVLAN_MODE_UNTAG_AND_PRITAG); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_OUTER, - PBVLAN_MODE_UNTAG_AND_PRITAG); - - priv->ports[port].pvid = vlan->vid_end; + for (v = vlan->vid_begin; v <= vlan->vid_end; v++) { + if (vlan->flags & BRIDGE_VLAN_INFO_PVID) { + rtl83xx_vlan_set_pvid(priv, port, v); + } else if (priv->ports[port].pvid == v) { + rtl83xx_vlan_set_pvid(priv, port, 0); } } @@ -1507,6 +1513,8 @@ static void rtl83xx_vlan_add(struct dsa_switch *ds, int port, info.tagged_ports |= BIT_ULL(port); if (vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED) info.untagged_ports |= BIT_ULL(port); + else + info.untagged_ports &= ~BIT_ULL(port); priv->r->vlan_set_untagged(v, info.untagged_ports); pr_debug("Untagged ports, VLAN %d: %llx\n", v, info.untagged_ports); @@ -1541,12 +1549,7 @@ static int rtl83xx_vlan_del(struct dsa_switch *ds, int port, for (v = vlan->vid_begin; v <= vlan->vid_end; v++) { /* Reset to default if removing the current PVID */ if (v == pvid) { - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_INNER, 0); - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_OUTER, 0); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_INNER, - PBVLAN_MODE_UNTAG_AND_PRITAG); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_OUTER, - PBVLAN_MODE_UNTAG_AND_PRITAG); + rtl83xx_vlan_set_pvid(priv, port, 0); } /* Get port memberships of this vlan */ priv->r->vlan_tables_read(v, &info); 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 46296d191797..d24a488d66cf 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 @@ -1438,6 +1438,20 @@ static int rtl83xx_vlan_prepare(struct dsa_switch *ds, int port, return 0; } +static void rtl83xx_vlan_set_pvid(struct rtl838x_switch_priv *priv, + int port, int pvid) +{ + /* Set both inner and outer PVID of the port */ + priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_INNER, pvid); + priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_OUTER, pvid); + priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_INNER, + PBVLAN_MODE_UNTAG_AND_PRITAG); + priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_OUTER, + PBVLAN_MODE_UNTAG_AND_PRITAG); + + priv->ports[port].pvid = pvid; +} + static int rtl83xx_vlan_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan, struct netlink_ext_ack *extack) @@ -1460,16 +1474,10 @@ static int rtl83xx_vlan_add(struct dsa_switch *ds, int port, mutex_lock(&priv->reg_mutex); - if (vlan->flags & BRIDGE_VLAN_INFO_PVID && vlan->vid) { - /* Set both inner and outer PVID of the port */ - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_INNER, vlan->vid); - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_OUTER, vlan->vid); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_INNER, - PBVLAN_MODE_UNTAG_AND_PRITAG); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_OUTER, - PBVLAN_MODE_UNTAG_AND_PRITAG); - - priv->ports[port].pvid = vlan->vid; + if (vlan->flags & BRIDGE_VLAN_INFO_PVID) { + rtl83xx_vlan_set_pvid(priv, port, vlan->vid); + } else if (priv->ports[port].pvid == vlan->vid) { + rtl83xx_vlan_set_pvid(priv, port, 0); } /* Get port memberships of this vlan */ @@ -1490,6 +1498,8 @@ static int rtl83xx_vlan_add(struct dsa_switch *ds, int port, info.tagged_ports |= BIT_ULL(port); if (vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED) info.untagged_ports |= BIT_ULL(port); + else + info.untagged_ports &= ~BIT_ULL(port); priv->r->vlan_set_untagged(vlan->vid, info.untagged_ports); pr_debug("Untagged ports, VLAN %d: %llx\n", vlan->vid, info.untagged_ports); @@ -1522,12 +1532,7 @@ static int rtl83xx_vlan_del(struct dsa_switch *ds, int port, /* Reset to default if removing the current PVID */ if (vlan->vid == pvid) { - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_INNER, 0); - priv->r->vlan_port_pvid_set(port, PBVLAN_TYPE_OUTER, 0); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_INNER, - PBVLAN_MODE_UNTAG_AND_PRITAG); - priv->r->vlan_port_pvidmode_set(port, PBVLAN_TYPE_OUTER, - PBVLAN_MODE_UNTAG_AND_PRITAG); + rtl83xx_vlan_set_pvid(priv, port, 0); } /* Get port memberships of this vlan */ priv->r->vlan_tables_read(vlan->vid, &info);