Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1101480lqs; Fri, 14 Jun 2024 15:28:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZ2rzPx7aX1hkwHqCjeoV+A6QXoKfaWc5pcbHetid3eBVjd/vO3bU6CsRIUPenvBtUFrQdeKsCFNxPRZTipx1YgpRLNnh/sb2WNjSlHg== X-Google-Smtp-Source: AGHT+IGmSXN7WkysEi2bbKOi78ifPo8hEDaTrEgRNXnawnXV2wFrs1F/FL82/jC6aUWF8xRY82/j X-Received: by 2002:a05:6870:858c:b0:254:c7f6:3294 with SMTP id 586e51a60fabf-25842ba533bmr4491471fac.47.1718404133858; Fri, 14 Jun 2024 15:28:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718404133; cv=pass; d=google.com; s=arc-20160816; b=AOylavgPDLks56DdcpLg+77yblR7tVMRxHY9Up4MdYxmvQTTuFqW3bhhWST52qLxiM LtHNGAhiV4l85deZ52okn4C3DxORKoKPmL4vNn3i2I1xx6Vl2ouT79Tkgl4r0XibHisO iPQKH8/9KipY2O3RIwJoJ1e+5tvhxJb4XxUbZMgCXZDVGtFyJXLBOFV9n/6hqrCqA/fA /ylSAcShYc9A1a6OyD6olN0q9Gy5ydtqYOwdv5bGdx3f9CwXLVaM99UolnPEU0k51dvB SMQ+gphh9cDWL+DvFFlXLg0wzN8bsZ2/FGqQVb6ljLEGvPD7uQs5+Y3mw691r0d83FJh f+sA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=ZYZis2XMVwVPPVMMMc8/iJ2Rd0WJw/FwEKDW3OP/a1A=; fh=gUMpjBs7ss4AUQHr0dRCXAZTR6QahUKM3AoWruz0a7w=; b=EN4HI3dLmxeeXoaAtDSrc7rwkgdj64WogCxjzqMYGJbi/I5oSnzMyddUfnFxXnuiSi d6Oi/lNcofkkaPxW4KV0uJprJ+8+JHoSIfcAMSY5qASxx4rc6pe4Ol/F52nigyRfQz7a DygDwwLir9QGje5lNcw2kA26wUpBVb9KbrIW7gGmS5FoCc4sxz7xF560UFPQgad6h/9F h6UYmaawZ0Fj9qt4FZNcWCuTzqo3QTqvOrBIHHM5o0+P9ggt0IIhDyP63U9GyzQ32abb WKLrlChc0hkjPl/kbV2UoQ+Pp0vPpl4fFunDMUkY5f4OfpjaGPpBjifoyuJeuzhi56IK 03fg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=universe-factory.net); spf=pass (google.com: domain of linux-kernel+bounces-215527-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215527-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fee310cecasi4371560a12.368.2024.06.14.15.28.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 15:28:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215527-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=universe-factory.net); spf=pass (google.com: domain of linux-kernel+bounces-215527-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215527-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 50C0B284939 for ; Fri, 14 Jun 2024 22:28:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C40A8187349; Fri, 14 Jun 2024 22:28:33 +0000 (UTC) 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 951AE146A8E; Fri, 14 Jun 2024 22:28:31 +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=1718404113; cv=none; b=c6sHw5r1UmpWX42kKLiDnR02hNsfOxNI2Rz9WLffRoRqTtcZoUUV89TDokg3+DpKyEthDzH3k6vlnI7fLQE45RebK3ySO7MTnh9Yug6zVRaYHXeBnSfOe2VLzxQmbRooUjetMhlnsxEgVaofpFSrWggIu12ez2hzsmL6u9pbDpM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718404113; c=relaxed/simple; bh=uUA2+FX6VTSsOybb4e6VmoDgXuVZI/yyoqS9UFhVENQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XZ5Xupw3RrizhqtTtIgP3Mg7hS6H5ZXxZc9mtE1wdRnKTskPsdO9BM9/9+EObj1Y1yloaRA7jPK/QBzvG4QeUBdzTUo77qC6E4MJONOrn1xWSvqYtC017OcM+DdUDN06Ku4NI2xrroPKP0PZLcLmz6mXKUk7DhU6Jls/18JY0KQ= 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 AF1C71F401; Sat, 15 Jun 2024 00:22:27 +0200 (CEST) From: Matthias Schiffer To: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= , Daniel Golle , DENG Qingfang , Sean Wang Cc: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Matthias Schiffer Subject: [PATCH net-next 1/2] net: dsa: mt7530: factor out bridge join/leave logic Date: Sat, 15 Jun 2024 00:21:53 +0200 Message-ID: <378bc964b49f9e9954336e99009932ac22bfe172.1718400508.git.mschiffer@universe-factory.net> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit As preparation for implementing bridge port isolation, move the logic to add and remove bits in the port matrix into a new helper mt7530_update_port_member(), which is called from mt7530_port_bridge_join() and mt7530_port_bridge_leave(). No functional change intended. Signed-off-by: Matthias Schiffer --- drivers/net/dsa/mt7530.c | 103 +++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 57 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 598434d8d6e4..ecacaefdd694 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -1302,6 +1302,50 @@ mt7530_stp_state_set(struct dsa_switch *ds, int port, u8 state) FID_PST(FID_BRIDGED, stp_state)); } +static void mt7530_update_port_member(struct mt7530_priv *priv, int port, + const struct net_device *bridge_dev, bool join) + __must_hold(&priv->reg_mutex) +{ + struct dsa_port *dp = dsa_to_port(priv->ds, port), *other_dp; + struct mt7530_port *p = &priv->ports[port], *other_p; + struct dsa_port *cpu_dp = dp->cpu_dp; + u32 port_bitmap = BIT(cpu_dp->index); + int other_port; + + dsa_switch_for_each_user_port(other_dp, priv->ds) { + other_port = other_dp->index; + other_p = &priv->ports[other_port]; + + if (dp == other_dp) + continue; + + /* Add/remove this port to/from the port matrix of the other + * ports in the same bridge. If the port is disabled, port + * matrix is kept and not being setup until the port becomes + * enabled. + */ + if (!dsa_port_offloads_bridge_dev(other_dp, bridge_dev)) + continue; + + if (join) { + other_p->pm |= PCR_MATRIX(BIT(port)); + port_bitmap |= BIT(other_port); + } else { + other_p->pm &= ~PCR_MATRIX(BIT(port)); + } + + if (other_p->enable) + mt7530_rmw(priv, MT7530_PCR_P(other_port), + PCR_MATRIX_MASK, other_p->pm); + } + + /* Add/remove the all other ports to this port matrix. */ + p->pm = PCR_MATRIX(port_bitmap); + if (priv->ports[port].enable) + mt7530_rmw(priv, MT7530_PCR_P(port), + PCR_MATRIX_MASK, p->pm); +} + static int mt7530_port_pre_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, @@ -1345,39 +1389,11 @@ mt7530_port_bridge_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge, bool *tx_fwd_offload, struct netlink_ext_ack *extack) { - struct dsa_port *dp = dsa_to_port(ds, port), *other_dp; - struct dsa_port *cpu_dp = dp->cpu_dp; - u32 port_bitmap = BIT(cpu_dp->index); struct mt7530_priv *priv = ds->priv; mutex_lock(&priv->reg_mutex); - dsa_switch_for_each_user_port(other_dp, ds) { - int other_port = other_dp->index; - - if (dp == other_dp) - continue; - - /* Add this port to the port matrix of the other ports in the - * same bridge. If the port is disabled, port matrix is kept - * and not being setup until the port becomes enabled. - */ - if (!dsa_port_offloads_bridge(other_dp, &bridge)) - continue; - - if (priv->ports[other_port].enable) - mt7530_set(priv, MT7530_PCR_P(other_port), - PCR_MATRIX(BIT(port))); - priv->ports[other_port].pm |= PCR_MATRIX(BIT(port)); - - port_bitmap |= BIT(other_port); - } - - /* Add the all other ports to this port matrix. */ - if (priv->ports[port].enable) - mt7530_rmw(priv, MT7530_PCR_P(port), - PCR_MATRIX_MASK, PCR_MATRIX(port_bitmap)); - priv->ports[port].pm |= PCR_MATRIX(port_bitmap); + mt7530_update_port_member(priv, port, bridge.dev, true); /* Set to fallback mode for independent VLAN learning */ mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK, @@ -1478,38 +1494,11 @@ static void mt7530_port_bridge_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge) { - struct dsa_port *dp = dsa_to_port(ds, port), *other_dp; - struct dsa_port *cpu_dp = dp->cpu_dp; struct mt7530_priv *priv = ds->priv; mutex_lock(&priv->reg_mutex); - dsa_switch_for_each_user_port(other_dp, ds) { - int other_port = other_dp->index; - - if (dp == other_dp) - continue; - - /* Remove this port from the port matrix of the other ports - * in the same bridge. If the port is disabled, port matrix - * is kept and not being setup until the port becomes enabled. - */ - if (!dsa_port_offloads_bridge(other_dp, &bridge)) - continue; - - if (priv->ports[other_port].enable) - mt7530_clear(priv, MT7530_PCR_P(other_port), - PCR_MATRIX(BIT(port))); - priv->ports[other_port].pm &= ~PCR_MATRIX(BIT(port)); - } - - /* Set the cpu port to be the only one in the port matrix of - * this port. - */ - if (priv->ports[port].enable) - mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK, - PCR_MATRIX(BIT(cpu_dp->index))); - priv->ports[port].pm = PCR_MATRIX(BIT(cpu_dp->index)); + mt7530_update_port_member(priv, port, bridge.dev, false); /* When a port is removed from the bridge, the port would be set up * back to the default as is at initial boot which is a VLAN-unaware -- 2.45.2