Re: [PATCH net-next v3 5/7] net: dsa: Add helpers to convert netdev to ds or port index

Vladimir Oltean
2024-04-02T20:51:25Z

On Tue, Apr 02, 2024 at 02:31:34PM +0100, Russell King (Oracle) wrote:
> Yes, I would tend to agree having done this for my experimental phylink
> changes. struct dsa_port seems to make the most sense:
>
> static inline struct dsa_port *
> dsa_phylink_to_port(struct phylink_config *config)
> {
> return container_of(config, struct dsa_port, pl_config);
> }
>
> which then means e.g.:
>
> static void mv88e6xxx_mac_config(struct phylink_config *config,
> unsigned int mode,
> const struct phylink_link_state *state)
> {
> struct dsa_port *dp = dsa_phylink_to_port(config);
> struct mv88e6xxx_chip *chip = dp->ds->priv;
> int port = dp->index;
> int err = 0;
>
> mv88e6xxx_reg_lock(chip);
>
> if (mode != MLO_AN_PHY || !mv88e6xxx_phy_is_internal(chip, port)) {
> err = mv88e6xxx_port_config_interface(chip, port,
> state->interface);
> if (err && err != -EOPNOTSUPP)
> goto err_unlock;
> }
>
> err_unlock:
> mv88e6xxx_reg_unlock(chip);
>
> if (err && err != -EOPNOTSUPP)
> dev_err(dp->ds->dev, "p%d: failed to configure MAC/PCS\n",
> port);
> }

Looks ok, looking forward to seeing more of it. Maybe a slight
preference to keeping "struct dsa_switch *ds" as a local variable of its
own, even if this means declaring and initializing "chip" on separate
lines.