net: dsa: mt7530: add support for changing DSA master
Subsystems (5)
PATCH 1/1 net: dsa: mt7530: add support for changing DSA master
From: Richard van Schagen <[email protected]>
Add support for changing the master of a port on the MT7530 DSA subdriver.
[ [email protected]: Wrote subject and changelog ]
--- drivers/net/dsa/mt7530.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/net/dsa/mt7530.c +33 -0
@@ -1072,6 +1072,38 @@ mt7530_port_disable(struct dsa_switch *ds, int port)mutex_unlock (&priv->reg_mutex); } +static int +mt7530_port_change_master (struct dsa_switch *ds,int port, +struct net_device *master, +struct netlink_ext_ack *extack) +{ +struct mt7530_priv *priv = ds->priv; +struct dsa_port *dp =dsa_to_port (ds, port); +struct dsa_port *cpu_dp = master->dsa_ptr; +int old_cpu = dp->cpu_dp->index; +int new_cpu = cpu_dp->index; + +mutex_lock (&priv->reg_mutex); + +/* Move old to new cpu on User port */ + priv->ports[port].pm &= ~PCR_MATRIX (BIT (old_cpu)); + priv->ports[port].pm |=PCR_MATRIX (BIT (new_cpu)); + +mt7530_rmw (priv,MT7530_PCR_P (port),PCR_MATRIX_MASK , + priv->ports[port].pm); + +/* Move user port from old cpu to new cpu */ + priv->ports[old_cpu].pm &= ~PCR_MATRIX (BIT (port)); + priv->ports[new_cpu].pm |=PCR_MATRIX (BIT (port)); + +mt7530_write (priv,MT7530_PCR_P (old_cpu), priv->ports[old_cpu].pm); +mt7530_write (priv,MT7530_PCR_P (new_cpu), priv->ports[new_cpu].pm); + +mutex_unlock (&priv->reg_mutex); + +return 0 ; +} +static int mt7530_port_change_mtu (struct dsa_switch *ds,int port,int new_mtu) {
@@ -3157,6 +3189,7 @@ static const struct dsa_switch_ops mt7530_switch_ops = { .set_ageing_time = mt7530_set_ageing_time, .port_enable = mt7530_port_enable, .port_disable = mt7530_port_disable, + .port_change_master = mt7530_port_change_master, .port_change_mtu = mt7530_port_change_mtu, .port_max_mtu = mt7530_port_max_mtu, .port_stp_state_set = mt7530_stp_state_set,
Signature · 1 line
2.37.2
Vladimir Oltean
maintainerQuoted 18 lines · On Fri, Feb 10, 2023 at 08:29:43PM +0300, [email protected] wrote:
From: Richard van Schagen <[email protected]>
Add support for changing the master of a port on the MT7530 DSA subdriver.
[ [email protected]: Wrote subject and changelog ]
Tested-by Arınç ÜNAL <[email protected]>Signed-off-by Richard van Schagen <[email protected]>Signed-off-by Arınç ÜNAL <[email protected]>--- drivers/net/dsa/mt7530.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/net/dsa/mt7530.c +0
-0
drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1078
Quoted 7 lines
drivers/net/dsa/mt7530.c +4
-0@@ -1072,6 +1072,38 @@ mt7530_port_disable(struct dsa_switch *ds, int port)mutex_unlock (&priv->reg_mutex); } +static int +mt7530_port_change_master (struct dsa_switch *ds,int port, +struct net_device *master, +struct netlink_ext_ack *extack)
alignment
drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1084
Quoted 6 lines
drivers/net/dsa/mt7530.c +6
-0+{ +struct mt7530_priv *priv = ds->priv; +struct dsa_port *dp =dsa_to_port (ds, port); +struct dsa_port *cpu_dp = master->dsa_ptr; +int old_cpu = dp->cpu_dp->index; +int new_cpu = cpu_dp->index;
I believe you need to reject LAG DSA masters.
Quoted 6 lines
drivers/net/dsa/mt7530.c +6
-0+ +mutex_lock (&priv->reg_mutex); + +/* Move old to new cpu on User port */ + priv->ports[port].pm &= ~PCR_MATRIX (BIT (old_cpu)); + priv->ports[port].pm |=PCR_MATRIX (BIT (new_cpu));
drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1100
Quoted 10 lines
drivers/net/dsa/mt7530.c +10
-0+ +mt7530_rmw (priv,MT7530_PCR_P (port),PCR_MATRIX_MASK , + priv->ports[port].pm); + +/* Move user port from old cpu to new cpu */ + priv->ports[old_cpu].pm &= ~PCR_MATRIX (BIT (port)); + priv->ports[new_cpu].pm |=PCR_MATRIX (BIT (port)); + +mt7530_write (priv,MT7530_PCR_P (old_cpu), priv->ports[old_cpu].pm); +mt7530_write (priv,MT7530_PCR_P (new_cpu), priv->ports[new_cpu].pm);
- who writes to the "pm" field of CPU ports?
- how does this line up with your other patch which said (AFAIU) that the port matrix of CPU ports should be 0 and that should be fine?
- read/modify/write (rmw) using PCR_MATRIX_MASK rather than mt7530_write(). That overwrites the other PCR fields.
Quoted 20 lines
drivers/net/dsa/mt7530.c +7
-0+ +mutex_unlock (&priv->reg_mutex); + +return 0 ; +} +static int mt7530_port_change_mtu (struct dsa_switch *ds,int port,int new_mtu) {@@ -3157,6 +3189,7 @@ static const struct dsa_switch_ops mt7530_switch_ops = { .set_ageing_time = mt7530_set_ageing_time, .port_enable = mt7530_port_enable, .port_disable = mt7530_port_disable, + .port_change_master = mt7530_port_change_master, .port_change_mtu = mt7530_port_change_mtu, .port_max_mtu = mt7530_port_max_mtu, .port_stp_state_set = mt7530_stp_state_set,Signature · 1 line
2.37.2
Quoted 26 lines · Vladimir Oltean
Quoted 21 lines · On Fri, Feb 10, 2023 at 08:29:43PM +0300, [email protected] wrote:
From: Richard van Schagen <[email protected]>
Add support for changing the master of a port on the MT7530 DSA subdriver.
[ [email protected]: Wrote subject and changelog ]
Tested-by Arınç ÜNAL <[email protected]>Signed-off-by Richard van Schagen <[email protected]>Signed-off-by Arınç ÜNAL <[email protected]>---
drivers/net/dsa/mt7530.c| 33 +++++++++++++++++++++++++++++++++1 file changed, 33 insertions(+)drivers/net/dsa/mt7530.c +0
-0@@ -1072,6 +1072,38 @@ mt7530_port_disable(struct dsa_switch *ds, int port)mutex_unlock (&priv->reg_mutex); }
Quoted 7 lines
drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1078
Quoted 4 lines
drivers/net/dsa/mt7530.c +4
-0+static int +mt7530_port_change_master (struct dsa_switch *ds,int port, +struct net_device *master, +struct netlink_ext_ack *extack)alignment
Will fix
Quoted 9 lines
drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1084
Quoted 6 lines
drivers/net/dsa/mt7530.c +6
-0+{ +struct mt7530_priv *priv = ds->priv; +struct dsa_port *dp =dsa_to_port (ds, port); +struct dsa_port *cpu_dp = master->dsa_ptr; +int old_cpu = dp->cpu_dp->index; +int new_cpu = cpu_dp->index;I believe you need to reject LAG DSA masters.
Not sure what you mean: how is this different from the change_master in the Felix driver when using 8021q tags? But. Can add a check if you prefer. It might be a good idea anyway to be future proof. The MT7531 has support for LAG in hw.
Quoted 10 lines
Quoted 10 lines
drivers/net/dsa/mt7530.c +10
-0+ +mutex_lock (&priv->reg_mutex); + +/* Move old to new cpu on User port */ + priv->ports[port].pm &= ~PCR_MATRIX (BIT (old_cpu)); + priv->ports[port].pm |=PCR_MATRIX (BIT (new_cpu)); + +mt7530_rmw (priv,MT7530_PCR_P (port),PCR_MATRIX_MASK , + priv->ports[port].pm); +
Quoted 8 lines
drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1100
Quoted 6 lines
drivers/net/dsa/mt7530.c +6
-0+/* Move user port from old cpu to new cpu */ + priv->ports[old_cpu].pm &= ~PCR_MATRIX (BIT (port)); + priv->ports[new_cpu].pm |=PCR_MATRIX (BIT (port)); + +mt7530_write (priv,MT7530_PCR_P (old_cpu), priv->ports[old_cpu].pm); +mt7530_write (priv,MT7530_PCR_P (new_cpu), priv->ports[new_cpu].pm);- who writes to the "pm" field of CPU ports?
Nobody actually writes to cpu.pm. I “fixed” that, and dropped that later. This is left over.
Quoted 2 lines
- how does this line up with your other patch which said (AFAIU) that the port matrix of CPU ports should be 0 and that should be fine?
Since cpu.pm was never user, and all user ports were added without using this field when enabling
the cpu, I changed that to add user ports belonging to that CPU. Arinc reported that it didn’t work.
Since the cpu.pm (empty) is writing during dsa_enable_port and that worked (for a long time already) the cpu.pm can be dropped.
Quoted 3 lines
- read/modify/write (rmw) using
PCR_MATRIX_MASKrather thanmt7530_write(). That overwrites the other PCR fields.
Good catch. Will fix.
Quoted 19 lines
Quoted 19 lines
drivers/net/dsa/mt7530.c +6
-0+ +mutex_unlock (&priv->reg_mutex); + +return 0 ; +} +static int
mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu){drivers/net/dsa/mt7530.c +1
-0@@ -3157,6 +3189,7 @@ static const struct dsa_switch_ops mt7530_switch_ops = { .set_ageing_time = mt7530_set_ageing_time, .port_enable = mt7530_port_enable, .port_disable = mt7530_port_disable, + .port_change_master = mt7530_port_change_master, .port_change_mtu = mt7530_port_change_mtu, .port_max_mtu = mt7530_port_max_mtu, .port_stp_state_set = mt7530_stp_state_set,Signature · 1 line
2.37.2
Vladimir Oltean
maintainerQuoted 4 lines · Richard van Schagen
Quoted 1 line
I believe you need to reject LAG DSA masters.
Not sure what you mean: how is this different from the
change_masterin the Felix driver when using 8021q tags? But. Can add a check if you prefer. It might be a good idea anyway to be future proof. The MT7531 has support for LAG in hw.
I mean, like Documentation/networking/dsa/configuration.rst says, that the user can attempt to put the DSA masters in a LAG and create a larger DSA master which is that bonding device.
The difference from the Felix driver is that Felix supports LAG DSA masters and this driver doesn't.
I don't believe there is any other restriction in the code which would prevent a driver which implements port_change_master() from accepting that as a valid configuration, so it's going to be the mt7530 driver who acts as the final frontier in this case.
An "if (netif_is_lag_master(master)) return -EOPNOTSUPP" will do. But it would always be good to check if it's really needed :)