1 From 505560028b6deb9b4385cf6100f05ca6f4aacaf8 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Mon, 6 Dec 2021 18:57:49 +0200
4 Subject: [PATCH 01/13] net: dsa: mt7530: iterate using
5 dsa_switch_for_each_user_port in bridging ops
7 Avoid repeated calls to dsa_to_port() (some hidden behind dsa_is_user_port
8 and some in plain sight) by keeping two struct dsa_port references: one
9 to the port passed as argument, and another to the other ports of the
10 switch that we're iterating over.
12 dsa_to_port(ds, i) gets replaced by other_dp, i gets replaced by
13 other_port which is derived from other_dp->index, dsa_is_user_port is
14 handled by the DSA iterator.
16 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
17 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
19 drivers/net/dsa/mt7530.c | 52 +++++++++++++++++++++++-----------------
20 1 file changed, 30 insertions(+), 22 deletions(-)
22 --- a/drivers/net/dsa/mt7530.c
23 +++ b/drivers/net/dsa/mt7530.c
24 @@ -1243,27 +1243,31 @@ static int
25 mt7530_port_bridge_join(struct dsa_switch *ds, int port,
26 struct net_device *bridge)
28 - struct mt7530_priv *priv = ds->priv;
29 + struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
30 u32 port_bitmap = BIT(MT7530_CPU_PORT);
32 + struct mt7530_priv *priv = ds->priv;
34 mutex_lock(&priv->reg_mutex);
36 - for (i = 0; i < MT7530_NUM_PORTS; i++) {
37 + dsa_switch_for_each_user_port(other_dp, ds) {
38 + int other_port = other_dp->index;
43 /* Add this port to the port matrix of the other ports in the
44 * same bridge. If the port is disabled, port matrix is kept
45 * and not being setup until the port becomes enabled.
47 - if (dsa_is_user_port(ds, i) && i != port) {
48 - if (dsa_to_port(ds, i)->bridge_dev != bridge)
50 - if (priv->ports[i].enable)
51 - mt7530_set(priv, MT7530_PCR_P(i),
52 - PCR_MATRIX(BIT(port)));
53 - priv->ports[i].pm |= PCR_MATRIX(BIT(port));
54 + if (other_dp->bridge_dev != bridge)
57 - port_bitmap |= BIT(i);
59 + if (priv->ports[other_port].enable)
60 + mt7530_set(priv, MT7530_PCR_P(other_port),
61 + PCR_MATRIX(BIT(port)));
62 + priv->ports[other_port].pm |= PCR_MATRIX(BIT(port));
64 + port_bitmap |= BIT(other_port);
67 /* Add the all other ports to this port matrix. */
68 @@ -1368,24 +1372,28 @@ static void
69 mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
70 struct net_device *bridge)
72 + struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
73 struct mt7530_priv *priv = ds->priv;
76 mutex_lock(&priv->reg_mutex);
78 - for (i = 0; i < MT7530_NUM_PORTS; i++) {
79 + dsa_switch_for_each_user_port(other_dp, ds) {
80 + int other_port = other_dp->index;
85 /* Remove this port from the port matrix of the other ports
86 * in the same bridge. If the port is disabled, port matrix
87 * is kept and not being setup until the port becomes enabled.
89 - if (dsa_is_user_port(ds, i) && i != port) {
90 - if (dsa_to_port(ds, i)->bridge_dev != bridge)
92 - if (priv->ports[i].enable)
93 - mt7530_clear(priv, MT7530_PCR_P(i),
94 - PCR_MATRIX(BIT(port)));
95 - priv->ports[i].pm &= ~PCR_MATRIX(BIT(port));
97 + if (other_dp->bridge_dev != bridge)
100 + if (priv->ports[other_port].enable)
101 + mt7530_clear(priv, MT7530_PCR_P(other_port),
102 + PCR_MATRIX(BIT(port)));
103 + priv->ports[other_port].pm &= ~PCR_MATRIX(BIT(port));
106 /* Set the cpu port to be the only one in the port matrix of