1 From ad2606f6fafae3a7d41c4f2af5554c8f6adecbc7 Mon Sep 17 00:00:00 2001
2 From: Frank Wunderlich <frank-w@public-files.de>
3 Date: Fri, 10 Jun 2022 19:05:39 +0200
4 Subject: [PATCH 13/13] net: dsa: mt7530: get cpu-port via dp->cpu_dp instead
7 Replace last occurences of hardcoded cpu-port by cpu_dp member of
10 Now the constant can be dropped.
12 Suggested-by: Vladimir Oltean <olteanv@gmail.com>
13 Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
14 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
15 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
16 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
18 drivers/net/dsa/mt7530.c | 27 ++++++++++++++++++++-------
19 drivers/net/dsa/mt7530.h | 1 -
20 2 files changed, 20 insertions(+), 8 deletions(-)
22 --- a/drivers/net/dsa/mt7530.c
23 +++ b/drivers/net/dsa/mt7530.c
24 @@ -1038,6 +1038,7 @@ static int
25 mt7530_port_enable(struct dsa_switch *ds, int port,
26 struct phy_device *phy)
28 + struct dsa_port *dp = dsa_to_port(ds, port);
29 struct mt7530_priv *priv = ds->priv;
31 mutex_lock(&priv->reg_mutex);
32 @@ -1046,7 +1047,11 @@ mt7530_port_enable(struct dsa_switch *ds
33 * restore the port matrix if the port is the member of a certain
36 - priv->ports[port].pm |= PCR_MATRIX(BIT(MT7530_CPU_PORT));
37 + if (dsa_port_is_user(dp)) {
38 + struct dsa_port *cpu_dp = dp->cpu_dp;
40 + priv->ports[port].pm |= PCR_MATRIX(BIT(cpu_dp->index));
42 priv->ports[port].enable = true;
43 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
44 priv->ports[port].pm);
45 @@ -1194,7 +1199,8 @@ mt7530_port_bridge_join(struct dsa_switc
46 struct net_device *bridge)
48 struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
49 - u32 port_bitmap = BIT(MT7530_CPU_PORT);
50 + struct dsa_port *cpu_dp = dp->cpu_dp;
51 + u32 port_bitmap = BIT(cpu_dp->index);
52 struct mt7530_priv *priv = ds->priv;
54 mutex_lock(&priv->reg_mutex);
55 @@ -1271,9 +1277,12 @@ mt7530_port_set_vlan_unaware(struct dsa_
56 * the CPU port get out of VLAN filtering mode.
58 if (all_user_ports_removed) {
59 - mt7530_write(priv, MT7530_PCR_P(MT7530_CPU_PORT),
60 + struct dsa_port *dp = dsa_to_port(ds, port);
61 + struct dsa_port *cpu_dp = dp->cpu_dp;
63 + mt7530_write(priv, MT7530_PCR_P(cpu_dp->index),
64 PCR_MATRIX(dsa_user_ports(priv->ds)));
65 - mt7530_write(priv, MT7530_PVC_P(MT7530_CPU_PORT), PORT_SPEC_TAG
66 + mt7530_write(priv, MT7530_PVC_P(cpu_dp->index), PORT_SPEC_TAG
67 | PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
70 @@ -1311,6 +1320,7 @@ mt7530_port_bridge_leave(struct dsa_swit
71 struct net_device *bridge)
73 struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
74 + struct dsa_port *cpu_dp = dp->cpu_dp;
75 struct mt7530_priv *priv = ds->priv;
77 mutex_lock(&priv->reg_mutex);
78 @@ -1339,8 +1349,8 @@ mt7530_port_bridge_leave(struct dsa_swit
80 if (priv->ports[port].enable)
81 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK,
82 - PCR_MATRIX(BIT(MT7530_CPU_PORT)));
83 - priv->ports[port].pm = PCR_MATRIX(BIT(MT7530_CPU_PORT));
84 + PCR_MATRIX(BIT(cpu_dp->index)));
85 + priv->ports[port].pm = PCR_MATRIX(BIT(cpu_dp->index));
87 /* When a port is removed from the bridge, the port would be set up
88 * back to the default as is at initial boot which is a VLAN-unaware
89 @@ -1503,6 +1513,9 @@ static int
90 mt7530_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
91 struct netlink_ext_ack *extack)
93 + struct dsa_port *dp = dsa_to_port(ds, port);
94 + struct dsa_port *cpu_dp = dp->cpu_dp;
97 /* The port is being kept as VLAN-unaware port when bridge is
98 * set up with vlan_filtering not being set, Otherwise, the
99 @@ -1510,7 +1523,7 @@ mt7530_port_vlan_filtering(struct dsa_sw
100 * for becoming a VLAN-aware port.
102 mt7530_port_set_vlan_aware(ds, port);
103 - mt7530_port_set_vlan_aware(ds, MT7530_CPU_PORT);
104 + mt7530_port_set_vlan_aware(ds, cpu_dp->index);
106 mt7530_port_set_vlan_unaware(ds, port);
108 --- a/drivers/net/dsa/mt7530.h
109 +++ b/drivers/net/dsa/mt7530.h
112 #define MT7530_NUM_PORTS 7
113 #define MT7530_NUM_PHYS 5
114 -#define MT7530_CPU_PORT 6
115 #define MT7530_NUM_FDB_RECORDS 2048
116 #define MT7530_ALL_MEMBERS 0xff