From nobody Tue Dec 16 19:44:55 2025 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, i= nt port, u8 state) qca8k_port_configure_learning(ds, port, learning); } =20 +static int qca8k_update_port_member(struct qca8k_priv *priv, int port, + const struct net_device *bridge_dev, + bool join) +{ + struct dsa_port *dp =3D dsa_to_port(priv->ds, port), *other_dp; + u32 port_mask =3D BIT(dp->cpu_dp->index); + int i, ret; + + for (i =3D 0; i < QCA8K_NUM_PORTS; i++) { + if (i =3D=3D port) + continue; + if (dsa_is_cpu_port(priv->ds, i)) + continue; + + other_dp =3D 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 |=3D BIT(i); + ret =3D regmap_set_bits(priv->regmap, + QCA8K_PORT_LOOKUP_CTRL(i), + BIT(port)); + } else { + ret =3D 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 =3D 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 =3D ds->priv; - int port_mask, cpu_port; - int i, ret; - - cpu_port =3D dsa_to_port(ds, port)->cpu_dp->index; - port_mask =3D BIT(cpu_port); =20 - for (i =3D 0; i < QCA8K_NUM_PORTS; i++) { - if (i =3D=3D 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 =3D regmap_set_bits(priv->regmap, - QCA8K_PORT_LOOKUP_CTRL(i), - BIT(port)); - if (ret) - return ret; - port_mask |=3D BIT(i); - } - - /* Add all other ports to this ports portvlan mask */ - ret =3D 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); } =20 void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) { struct qca8k_priv *priv =3D ds->priv; - int cpu_port, i; - - cpu_port =3D dsa_to_port(ds, port)->cpu_dp->index; + int err; =20 - for (i =3D 0; i < QCA8K_NUM_PORTS; i++) { - if (i =3D=3D 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 =3D 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); } =20 void qca8k_port_fast_age(struct dsa_switch *ds, int port) --=20 2.45.2