Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
	"David S. Miller" <davem@davemloft.net>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	Kurt Kanzenbach <kurt@linutronix.de>,
	Woojung Huh <woojung.huh@microchip.com>,
	UNGLinuxDriver@microchip.com, Sean Wang <sean.wang@mediatek.com>,
	Landen Chao <Landen.Chao@mediatek.com>,
	DENG Qingfang <dqfext@gmail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	George McCollister <george.mccollister@gmail.com>
Subject: [RFC PATCH v2 net-next 8/8] net: dsa: tag_8021q: finish conversion to dsa_switch_for_each_port
Date: Tue, 10 Aug 2021 19:14:48 +0300	[thread overview]
Message-ID: <20210810161448.1879192-9-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20210810161448.1879192-1-vladimir.oltean@nxp.com>

The tag_8021q cross-chip notifiers have been converted to iterate using
dp, but the setup and teardown functions have not yet. This patch makes
that change.

Note that we jump directly to the "for_each_available_port" variant
because it didn't make too much sense to set up tag_8021q for unused
ports even before, but skipping them was too much of a hassle.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/tag_8021q.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c
index 8e4fbbfc6d86..9e7c6b46d62a 100644
--- a/net/dsa/tag_8021q.c
+++ b/net/dsa/tag_8021q.c
@@ -428,13 +428,13 @@ void dsa_tag_8021q_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
 EXPORT_SYMBOL_GPL(dsa_tag_8021q_bridge_tx_fwd_unoffload);
 
 /* Set up a port's tag_8021q RX and TX VLAN for standalone mode operation */
-static int dsa_tag_8021q_port_setup(struct dsa_switch *ds, int port)
+static int dsa_port_tag_8021q_setup(struct dsa_port *dp)
 {
-	struct dsa_8021q_context *ctx = ds->tag_8021q_ctx;
-	struct dsa_port *dp = dsa_to_port(ds, port);
-	u16 rx_vid = dsa_8021q_rx_vid(ds, port);
-	u16 tx_vid = dsa_8021q_tx_vid(ds, port);
+	struct dsa_8021q_context *ctx = dp->ds->tag_8021q_ctx;
+	struct dsa_switch *ds = dp->ds;
 	struct net_device *master;
+	int port = dp->index;
+	u16 rx_vid, tx_vid;
 	int err;
 
 	/* The CPU port is implicitly configured by
@@ -443,6 +443,8 @@ static int dsa_tag_8021q_port_setup(struct dsa_switch *ds, int port)
 	if (!dsa_port_is_user(dp))
 		return 0;
 
+	rx_vid = dsa_8021q_rx_vid(ds, port);
+	tx_vid = dsa_8021q_tx_vid(ds, port);
 	master = dp->cpu_dp->master;
 
 	/* Add this user port's RX VID to the membership list of all others
@@ -473,13 +475,13 @@ static int dsa_tag_8021q_port_setup(struct dsa_switch *ds, int port)
 	return err;
 }
 
-static void dsa_tag_8021q_port_teardown(struct dsa_switch *ds, int port)
+static void dsa_port_tag_8021q_teardown(struct dsa_port *dp)
 {
-	struct dsa_8021q_context *ctx = ds->tag_8021q_ctx;
-	struct dsa_port *dp = dsa_to_port(ds, port);
-	u16 rx_vid = dsa_8021q_rx_vid(ds, port);
-	u16 tx_vid = dsa_8021q_tx_vid(ds, port);
+	struct dsa_8021q_context *ctx = dp->ds->tag_8021q_ctx;
+	struct dsa_switch *ds = dp->ds;
 	struct net_device *master;
+	int port = dp->index;
+	u16 rx_vid, tx_vid;
 
 	/* The CPU port is implicitly configured by
 	 * configuring the front-panel ports
@@ -487,6 +489,8 @@ static void dsa_tag_8021q_port_teardown(struct dsa_switch *ds, int port)
 	if (!dsa_port_is_user(dp))
 		return;
 
+	rx_vid = dsa_8021q_rx_vid(ds, port);
+	tx_vid = dsa_8021q_tx_vid(ds, port);
 	master = dp->cpu_dp->master;
 
 	dsa_port_tag_8021q_vlan_del(dp, rx_vid);
@@ -498,16 +502,17 @@ static void dsa_tag_8021q_port_teardown(struct dsa_switch *ds, int port)
 
 static int dsa_tag_8021q_setup(struct dsa_switch *ds)
 {
-	int err, port;
+	struct dsa_port *dp;
+	int err;
 
 	ASSERT_RTNL();
 
-	for (port = 0; port < ds->num_ports; port++) {
-		err = dsa_tag_8021q_port_setup(ds, port);
+	dsa_switch_for_each_available_port(dp, ds) {
+		err = dsa_port_tag_8021q_setup(dp);
 		if (err < 0) {
 			dev_err(ds->dev,
 				"Failed to setup VLAN tagging for port %d: %pe\n",
-				port, ERR_PTR(err));
+				dp->index, ERR_PTR(err));
 			return err;
 		}
 	}
@@ -517,12 +522,12 @@ static int dsa_tag_8021q_setup(struct dsa_switch *ds)
 
 static void dsa_tag_8021q_teardown(struct dsa_switch *ds)
 {
-	int port;
+	struct dsa_port *dp;
 
 	ASSERT_RTNL();
 
-	for (port = 0; port < ds->num_ports; port++)
-		dsa_tag_8021q_port_teardown(ds, port);
+	dsa_switch_for_each_available_port(dp, ds)
+		dsa_port_tag_8021q_teardown(dp);
 }
 
 int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto)
-- 
2.25.1


      parent reply	other threads:[~2021-08-10 16:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 16:14 [RFC PATCH v2 net-next 0/8] Remove the "dsa_to_port in a loop" antipattern Vladimir Oltean
2021-08-10 16:14 ` [RFC PATCH v2 net-next 1/8] net: dsa: introduce a dsa_port_is_unused helper Vladimir Oltean
2021-08-10 16:14 ` [RFC PATCH v2 net-next 2/8] net: dsa: remove the "dsa_to_port in a loop" antipattern from the core Vladimir Oltean
2021-08-10 16:14 ` [RFC PATCH v2 net-next 3/8] net: dsa: remove the "dsa_to_port in a loop" antipattern from drivers Vladimir Oltean
2021-08-10 16:14 ` [RFC PATCH v2 net-next 4/8] net: dsa: b53: express b53_for_each_port in terms of dsa_switch_for_each_port Vladimir Oltean
2021-08-11  8:40   ` Florian Fainelli
2021-08-10 16:14 ` [RFC PATCH v2 net-next 5/8] net: dsa: finish conversion to dsa_switch_for_each_port Vladimir Oltean
2021-08-10 16:14 ` [RFC PATCH v2 net-next 6/8] net: dsa: remove gratuitous use of dsa_is_{user,dsa,cpu}_port Vladimir Oltean
2021-08-10 16:14 ` [RFC PATCH v2 net-next 7/8] net: dsa: convert cross-chip notifiers to iterate using dp Vladimir Oltean
2021-08-10 16:14 ` Vladimir Oltean [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210810161448.1879192-9-vladimir.oltean@nxp.com \
    --to=vladimir.oltean@nxp.com \
    --cc=Landen.Chao@mediatek.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=dqfext@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=george.mccollister@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kurt@linutronix.de \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=sean.wang@mediatek.com \
    --cc=vivien.didelot@gmail.com \
    --cc=woojung.huh@microchip.com \
    --subject='Re: [RFC PATCH v2 net-next 8/8] net: dsa: tag_8021q: finish conversion to dsa_switch_for_each_port' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).