Re: [PATCH v2 net-next 07/10] net: dsa: Pass MST state changes to driver

From: Vladimir Oltean
Date: Thu Mar 03 2022 - 17:21:06 EST


On Tue, Mar 01, 2022 at 11:03:18AM +0100, Tobias Waldekranz wrote:
> Add the usual trampoline functionality from the generic DSA layer down
> to the drivers for MST state changes.
>
> Signed-off-by: Tobias Waldekranz <tobias@xxxxxxxxxxxxxx>
> ---
> include/net/dsa.h | 2 ++
> net/dsa/dsa_priv.h | 2 ++
> net/dsa/port.c | 30 ++++++++++++++++++++++++++++++
> net/dsa/slave.c | 6 ++++++
> 4 files changed, 40 insertions(+)
>
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index cc8acb01bd9b..096e6e3a8e1e 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -943,6 +943,8 @@ struct dsa_switch_ops {
> struct dsa_bridge bridge);
> void (*port_stp_state_set)(struct dsa_switch *ds, int port,
> u8 state);
> + int (*port_mst_state_set)(struct dsa_switch *ds, int port,
> + const struct switchdev_mst_state *state);
> void (*port_fast_age)(struct dsa_switch *ds, int port);
> int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port,
> struct switchdev_brport_flags flags,
> diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
> index 87ec0697e92e..a620e079ebc5 100644
> --- a/net/dsa/dsa_priv.h
> +++ b/net/dsa/dsa_priv.h
> @@ -198,6 +198,8 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
> void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
> const struct dsa_device_ops *tag_ops);
> int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age);
> +int dsa_port_set_mst_state(struct dsa_port *dp,
> + const struct switchdev_mst_state *state);
> int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy);
> int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
> void dsa_port_disable_rt(struct dsa_port *dp);
> diff --git a/net/dsa/port.c b/net/dsa/port.c
> index 5f45cb7d70ba..26cfbc8ab499 100644
> --- a/net/dsa/port.c
> +++ b/net/dsa/port.c
> @@ -108,6 +108,36 @@ int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age)
> return 0;
> }
>
> +int dsa_port_set_mst_state(struct dsa_port *dp,
> + const struct switchdev_mst_state *state)
> +{
> + struct dsa_switch *ds = dp->ds;
> + int err, port = dp->index;
> +
> + if (!ds->ops->port_mst_state_set)
> + return -EOPNOTSUPP;
> +
> + err = ds->ops->port_mst_state_set(ds, port, state);
> + if (err)
> + return err;
> +
> + if (!dsa_port_can_configure_learning(dp) || dp->learning) {
> + switch (state->state) {
> + case BR_STATE_DISABLED:
> + case BR_STATE_BLOCKING:
> + case BR_STATE_LISTENING:
> + /* Ideally we would only fast age entries
> + * belonging to VLANs controlled by this
> + * MST.
> + */
> + dsa_port_fast_age(dp);

Does mv88e6xxx support this? If it does, you might just as well
introduce another variant of ds->ops->port_fast_age() for an msti.

And since it is new code, you could require that drivers _do_ support
configuring learning before they could support MSTP. After all, we don't
want to keep legacy mechanisms in place forever.

> + break;
> + }
> + }
> +
> + return 0;
> +}
> +
> static void dsa_port_set_state_now(struct dsa_port *dp, u8 state,
> bool do_fast_age)
> {
> diff --git a/net/dsa/slave.c b/net/dsa/slave.c
> index c6ffcd782b5a..32b006a5b778 100644
> --- a/net/dsa/slave.c
> +++ b/net/dsa/slave.c
> @@ -288,6 +288,12 @@ static int dsa_slave_port_attr_set(struct net_device *dev, const void *ctx,
>
> ret = dsa_port_set_state(dp, attr->u.stp_state, true);
> break;
> + case SWITCHDEV_ATTR_ID_PORT_MST_STATE:
> + if (!dsa_port_offloads_bridge_port(dp, attr->orig_dev))
> + return -EOPNOTSUPP;
> +
> + ret = dsa_port_set_mst_state(dp, &attr->u.mst_state);
> + break;
> case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
> if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
> return -EOPNOTSUPP;
> --
> 2.25.1
>