From patchwork Thu Jun 20 17:25:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 13705951 X-Patchwork-Delegate: kuba@kernel.org Received: from orthanc.universe-factory.net (orthanc.universe-factory.net [104.238.176.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 814C31B3F20; Thu, 20 Jun 2024 17:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.238.176.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718904390; cv=none; b=DTRJN5YZD2lXBoCVMF7FGVNVFRgRef38l4KJRetQ91966nvoS4r6ZfeFaX/XRBUIdl9lH0POIk0ELEeQlHgdCGzvQM1n+egpr3jhDLAyJA/U2C6JIfqQy8XkrBQUdNnb+jY+pyA9ynqQ4c21Vm83q2I5GxIcWisQqLh5UWwT0iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718904390; c=relaxed/simple; bh=BIG3IdgzLqLpVof7URKdPMLEz+6z8QlvjSJwuwcRHnM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gi7PIvkeuHNSZdbOzNNsOcVgqZIRLQeeUrkBPUUelZLsvSm83YQwxb8eGtG5Rb0UXYM06+mMPCL6KSO9V0ZtKbTUiLRi+v7DS6q6z6s394CugiIHnm10WFlBFB1xFndK+6RUyAEoan/v8f6OG/g/t5yMAOB6Dicj2QlOnX5zKFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=universe-factory.net; spf=pass smtp.mailfrom=universe-factory.net; arc=none smtp.client-ip=104.238.176.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=universe-factory.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=universe-factory.net Received: from avalon.fritz.box (unknown [IPv6:2001:19f0:6c01:100::2]) (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 orthanc.universe-factory.net (Postfix) with ESMTPSA id 4095C1FC64; Thu, 20 Jun 2024 19:26:21 +0200 (CEST) From: Matthias Schiffer To: Andrew Lunn , Florian Fainelli , Vladimir Oltean Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Schiffer Subject: [PATCH net-next 1/3] net: dsa: qca8k: do not write port mask twice in bridge join/leave Date: Thu, 20 Jun 2024 19:25:48 +0200 Message-ID: <9e5682c68a4930dae2e277b9cecc8b8ec97ba2af.1718899575.git.mschiffer@universe-factory.net> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org qca8k_port_bridge_join() set QCA8K_PORT_LOOKUP_CTRL() for i == port twice, once in the loop handling all other port's masks, and finally at the end with the accumulated port_mask. The first time it would incorrectly set the port's own bit in the mask, only to correct the mistake a moment later. qca8k_port_bridge_leave() had the same issue, but here the regmap_clear_bits() was a no-op rather than setting an unintended value. Remove the duplicate assignment by skipping the whole loop iteration for i == port. The unintended bit setting doesn't seem to have any negative effects (even when not reverted right away), so the change is submitted as a simple cleanup rather than a fix. Signed-off-by: Matthias Schiffer Reviewed-by: Wojciech Drewek --- drivers/net/dsa/qca/qca8k-common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c index 7f80035c5441..b33df84070d3 100644 --- a/drivers/net/dsa/qca/qca8k-common.c +++ b/drivers/net/dsa/qca/qca8k-common.c @@ -653,6 +653,8 @@ int qca8k_port_bridge_join(struct dsa_switch *ds, int port, port_mask = BIT(cpu_port); for (i = 0; i < QCA8K_NUM_PORTS; i++) { + if (i == port) + continue; if (dsa_is_cpu_port(ds, i)) continue; if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) @@ -665,8 +667,7 @@ int qca8k_port_bridge_join(struct dsa_switch *ds, int port, BIT(port)); if (ret) return ret; - if (i != port) - port_mask |= BIT(i); + port_mask |= BIT(i); } /* Add all other ports to this ports portvlan mask */ @@ -685,6 +686,8 @@ void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, cpu_port = dsa_to_port(ds, port)->cpu_dp->index; for (i = 0; i < QCA8K_NUM_PORTS; i++) { + if (i == port) + continue; if (dsa_is_cpu_port(ds, i)) continue; if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) From patchwork Thu Jun 20 17:25:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 13705953 X-Patchwork-Delegate: kuba@kernel.org Received: from orthanc.universe-factory.net (orthanc.universe-factory.net [104.238.176.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B0D61B3F31; Thu, 20 Jun 2024 17:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.238.176.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718904390; cv=none; b=Q6+6U1bjn8fkAK0oAnvc30JmeLPCtNoHmDR/hKMFYU+dzHQXFKsduN36o/1lhW/FaWj+P9B463w0v+ap/PtOfCUG3pBkNJ/luBJ0qpibQEm1Mtuva38uqvgLxs4HWAbkDhsMepwZYRpmxJNm2T25CQ9x4vW2iC5T0nljAwdGTMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718904390; c=relaxed/simple; bh=6WaQiHAzpozAOWsjO8vThELufTOv961S4o5WXeWByHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F/YvxqqSP4pV4K1vEoCoq5OBzfR4l0ZenSjR6ClTdLADplq/6LDS4ABHQ/KiW0vBVZA0nBq7KUV0RGy1vwm6+2Q9aKsgt7EBD5udVlUjS2nXXDdRexQmQjagNVpClt86ypBvLc7Rz8wtWvxf5U99KJ/yIKEvLrJcmN85UfXlZxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=universe-factory.net; spf=pass smtp.mailfrom=universe-factory.net; arc=none smtp.client-ip=104.238.176.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=universe-factory.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=universe-factory.net Received: from avalon.fritz.box (unknown [IPv6:2001:19f0:6c01:100::2]) (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 orthanc.universe-factory.net (Postfix) with ESMTPSA id 78D371FE13; Thu, 20 Jun 2024 19:26:21 +0200 (CEST) From: Matthias Schiffer To: Andrew Lunn , Florian Fainelli , Vladimir Oltean Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Schiffer Subject: [PATCH net-next 2/3] net: dsa: qca8k: factor out bridge join/leave logic Date: Thu, 20 Jun 2024 19:25:49 +0200 Message-ID: <7fbdc27fab4df365db91defca8037b87bdf49438.1718899575.git.mschiffer@universe-factory.net> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Most of the logic in qca8k_port_bridge_join() and qca8k_port_bridge_leave() is the same. Refactor to reduce duplication and prepare for reusing the code for implementing bridge port isolation. dsa_port_offloads_bridge_dev() is used instead of dsa_port_offloads_bridge(), passing the bridge in as a struct netdevice *, as we won't have a struct dsa_bridge in qca8k_port_bridge_flags(). The error handling is changed slightly in the bridge leave case, returning early and emitting an error message when a regmap access fails. This shouldn't matter in practice, as there isn't much we can do if communication with the switch breaks down in the middle of reconfiguration. Signed-off-by: Matthias Schiffer Reviewed-by: Wojciech Drewek --- drivers/net/dsa/qca/qca8k-common.c | 101 ++++++++++++++--------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c index b33df84070d3..09108fa99dbe 100644 --- a/drivers/net/dsa/qca/qca8k-common.c +++ b/drivers/net/dsa/qca/qca8k-common.c @@ -614,6 +614,49 @@ void qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) qca8k_port_configure_learning(ds, port, learning); } +static int qca8k_update_port_member(struct qca8k_priv *priv, int port, + const struct net_device *bridge_dev, + bool join) +{ + struct dsa_port *dp = dsa_to_port(priv->ds, port), *other_dp; + u32 port_mask = BIT(dp->cpu_dp->index); + int i, ret; + + for (i = 0; i < QCA8K_NUM_PORTS; i++) { + if (i == port) + continue; + if (dsa_is_cpu_port(priv->ds, i)) + continue; + + other_dp = dsa_to_port(priv->ds, i); + if (!dsa_port_offloads_bridge_dev(other_dp, bridge_dev)) + continue; + + /* Add/remove this port to/from the portvlan mask of the other + * ports in the bridge + */ + if (join) { + port_mask |= BIT(i); + ret = regmap_set_bits(priv->regmap, + QCA8K_PORT_LOOKUP_CTRL(i), + BIT(port)); + } else { + ret = regmap_clear_bits(priv->regmap, + QCA8K_PORT_LOOKUP_CTRL(i), + BIT(port)); + } + + if (ret) + return ret; + } + + /* Add/remove all other ports to/from this port's portvlan mask */ + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), + QCA8K_PORT_LOOKUP_MEMBER, port_mask); + + return ret; +} + int qca8k_port_pre_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack) @@ -646,65 +689,21 @@ int qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack) { struct qca8k_priv *priv = ds->priv; - int port_mask, cpu_port; - int i, ret; - - cpu_port = dsa_to_port(ds, port)->cpu_dp->index; - port_mask = BIT(cpu_port); - for (i = 0; i < QCA8K_NUM_PORTS; i++) { - if (i == port) - continue; - if (dsa_is_cpu_port(ds, i)) - continue; - if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) - continue; - /* Add this port to the portvlan mask of the other ports - * in the bridge - */ - ret = regmap_set_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(i), - BIT(port)); - if (ret) - return ret; - port_mask |= BIT(i); - } - - /* Add all other ports to this ports portvlan mask */ - ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_MEMBER, port_mask); - - return ret; + return qca8k_update_port_member(priv, port, bridge.dev, true); } void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) { struct qca8k_priv *priv = ds->priv; - int cpu_port, i; - - cpu_port = dsa_to_port(ds, port)->cpu_dp->index; + int err; - for (i = 0; i < QCA8K_NUM_PORTS; i++) { - if (i == port) - continue; - if (dsa_is_cpu_port(ds, i)) - continue; - if (!dsa_port_offloads_bridge(dsa_to_port(ds, i), &bridge)) - continue; - /* Remove this port to the portvlan mask of the other ports - * in the bridge - */ - regmap_clear_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(i), - BIT(port)); - } - - /* Set the cpu port to be the only one in the portvlan mask of - * this port - */ - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port), - QCA8K_PORT_LOOKUP_MEMBER, BIT(cpu_port)); + err = qca8k_update_port_member(priv, port, bridge.dev, false); + if (err) + dev_err(priv->dev, + "Failed to update switch config for bridge leave: %d\n", + err); } void qca8k_port_fast_age(struct dsa_switch *ds, int port) From patchwork Thu Jun 20 17:25:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 13705952 X-Patchwork-Delegate: kuba@kernel.org Received: from orthanc.universe-factory.net (orthanc.universe-factory.net [104.238.176.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48C111B3F30; Thu, 20 Jun 2024 17:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.238.176.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718904390; cv=none; b=nLugQOzmG+y8Mj5PDB1xtCfzj6ra6NWpy14sXPz+vLnLsRTbR5B/YT+L3ueiVYgvSSDEoTCvy3baBRzJjozC4YI3clg+mayWz+n54lRoYHJlwlPsxGXAeVBFqSfCeepUS1wg6Nr4+JjP58LgSpsk3ns6KxYQjbWQ2NVBCDLHIgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718904390; c=relaxed/simple; bh=+BEZU4JYC67QYSKnlrzNLmCywz5jZnZGSOdFUns4VWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dh+M+7wFnu2xjmLLU0ZMRKwZkPbBy6E2qjTY38lt7Lu999MQh0xNWG+LGWFuIdMsy/SJ67ehqCztU18qpJ2SIkVzV3zi3KXW85vw8siHO1QPFCLwOUikRO04uUIMGS8wfe4Lzg7k4QRIcx3f9zbtNq0JohdSfX2JfKAIg6Kqq1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=universe-factory.net; spf=pass smtp.mailfrom=universe-factory.net; arc=none smtp.client-ip=104.238.176.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=universe-factory.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=universe-factory.net Received: from avalon.fritz.box (unknown [IPv6:2001:19f0:6c01:100::2]) (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 orthanc.universe-factory.net (Postfix) with ESMTPSA id B22921FEC4; Thu, 20 Jun 2024 19:26:21 +0200 (CEST) From: Matthias Schiffer To: Andrew Lunn , Florian Fainelli , Vladimir Oltean Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Schiffer Subject: [PATCH net-next 3/3] net: dsa: qca8k: add support for bridge port isolation Date: Thu, 20 Jun 2024 19:25:50 +0200 Message-ID: <78b4bbb3644e1fabae9cc53501d0842ccd1a1c5d.1718899575.git.mschiffer@universe-factory.net> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Remove a pair of ports from the port matrix when both ports have the isolated flag set. Signed-off-by: Matthias Schiffer Reviewed-by: Wojciech Drewek Reviewed-by: Vladimir Oltean --- drivers/net/dsa/qca/qca8k-common.c | 22 ++++++++++++++++++++-- drivers/net/dsa/qca/qca8k.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c index 09108fa99dbe..560c74c4ac3d 100644 --- a/drivers/net/dsa/qca/qca8k-common.c +++ b/drivers/net/dsa/qca/qca8k-common.c @@ -618,6 +618,7 @@ static int qca8k_update_port_member(struct qca8k_priv *priv, int port, const struct net_device *bridge_dev, bool join) { + bool isolated = !!(priv->port_isolated_map & BIT(port)), other_isolated; struct dsa_port *dp = dsa_to_port(priv->ds, port), *other_dp; u32 port_mask = BIT(dp->cpu_dp->index); int i, ret; @@ -632,10 +633,12 @@ static int qca8k_update_port_member(struct qca8k_priv *priv, int port, if (!dsa_port_offloads_bridge_dev(other_dp, bridge_dev)) continue; + other_isolated = !!(priv->port_isolated_map & BIT(i)); + /* Add/remove this port to/from the portvlan mask of the other * ports in the bridge */ - if (join) { + if (join && !(isolated && other_isolated)) { port_mask |= BIT(i); ret = regmap_set_bits(priv->regmap, QCA8K_PORT_LOOKUP_CTRL(i), @@ -661,7 +664,7 @@ int qca8k_port_pre_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack) { - if (flags.mask & ~BR_LEARNING) + if (flags.mask & ~(BR_LEARNING | BR_ISOLATED)) return -EINVAL; return 0; @@ -671,6 +674,7 @@ int qca8k_port_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack) { + struct qca8k_priv *priv = ds->priv; int ret; if (flags.mask & BR_LEARNING) { @@ -680,6 +684,20 @@ int qca8k_port_bridge_flags(struct dsa_switch *ds, int port, return ret; } + if (flags.mask & BR_ISOLATED) { + struct dsa_port *dp = dsa_to_port(ds, port); + struct net_device *bridge_dev = dsa_port_bridge_dev_get(dp); + + if (flags.val & BR_ISOLATED) + priv->port_isolated_map |= BIT(port); + else + priv->port_isolated_map &= ~BIT(port); + + ret = qca8k_update_port_member(priv, port, bridge_dev, true); + if (ret) + return ret; + } + return 0; } diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h index 2184d8d2d5a9..3664a2e2f1f6 100644 --- a/drivers/net/dsa/qca/qca8k.h +++ b/drivers/net/dsa/qca/qca8k.h @@ -451,6 +451,7 @@ struct qca8k_priv { * Bit 1: port enabled. Bit 0: port disabled. */ u8 port_enabled_map; + u8 port_isolated_map; struct qca8k_ports_config ports_config; struct regmap *regmap; struct mii_bus *bus;