gpio-nct5104d: fix compilation with kernel 6.6
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 705-01-v5.17-net-dsa-mt7530-iterate-using-dsa_switch_for_each_use.patch
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
6
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.
11
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.
15
16 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
17 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
18 ---
19 drivers/net/dsa/mt7530.c | 52 +++++++++++++++++++++++-----------------
20 1 file changed, 30 insertions(+), 22 deletions(-)
21
22 --- a/drivers/net/dsa/mt7530.c
23 +++ b/drivers/net/dsa/mt7530.c
24 @@ -1198,27 +1198,31 @@ static int
25 mt7530_port_bridge_join(struct dsa_switch *ds, int port,
26 struct net_device *bridge)
27 {
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);
31 - int i;
32 + struct mt7530_priv *priv = ds->priv;
33
34 mutex_lock(&priv->reg_mutex);
35
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;
39 +
40 + if (dp == other_dp)
41 + continue;
42 +
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.
46 */
47 - if (dsa_is_user_port(ds, i) && i != port) {
48 - if (dsa_to_port(ds, i)->bridge_dev != bridge)
49 - continue;
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)
55 + continue;
56
57 - port_bitmap |= BIT(i);
58 - }
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));
63 +
64 + port_bitmap |= BIT(other_port);
65 }
66
67 /* Add the all other ports to this port matrix. */
68 @@ -1323,24 +1327,28 @@ static void
69 mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
70 struct net_device *bridge)
71 {
72 + struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
73 struct mt7530_priv *priv = ds->priv;
74 - int i;
75
76 mutex_lock(&priv->reg_mutex);
77
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;
81 +
82 + if (dp == other_dp)
83 + continue;
84 +
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.
88 */
89 - if (dsa_is_user_port(ds, i) && i != port) {
90 - if (dsa_to_port(ds, i)->bridge_dev != bridge)
91 - continue;
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));
96 - }
97 + if (other_dp->bridge_dev != bridge)
98 + continue;
99 +
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));
104 }
105
106 /* Set the cpu port to be the only one in the port matrix of