netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Vladimir Oltean <olteanv@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Gregory Clement <gregory.clement@bootlin.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next v3 5/7] net: dsa: Add helpers to convert netdev to ds or port index
Date: Tue, 2 Apr 2024 14:31:34 +0100	[thread overview]
Message-ID: <ZgwItu4gETdLbHWi@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240402105652.mrweu2rnend3n3tf@skbuf>

On Tue, Apr 02, 2024 at 01:56:52PM +0300, Vladimir Oltean wrote:
> On Mon, Apr 01, 2024 at 08:35:50AM -0500, Andrew Lunn wrote:
> > The LED helpers make use of a struct netdev. Add helpers a DSA driver
> > can use to convert a netdev to a struct dsa_switch and the port index.
> > 
> > To do this, dsa_user_to_port() has to be made available out side of
> > net/dev, to convert the inline function in net/dsa/user.h into a
> > normal function, and export it.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> 
> I think the API we have today is sufficient: we have dsa_port_to_netdev(),
> introduced at Vivien's request rather than exporting dsa_user_to_port().
> 
> Also, I believe that having a single API function which returns a single
> struct dsa_port *, from which we force the caller to get the dp->ds and
> dp->index, is better (cheaper) than requiring 2 API functions, one for
> getting the ds and the other for the index.

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);
}

vs the current code:

static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
                                 unsigned int mode,
                                 const struct phylink_link_state *state)
{
        struct mv88e6xxx_chip *chip = ds->priv;
        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(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
}

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

  reply	other threads:[~2024-04-02 13:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 13:35 [PATCH net-next v3 0/7] net: Add generic support for netdev LEDs Andrew Lunn
2024-04-01 13:35 ` [PATCH net-next v3 1/7] dsa: move call to driver port_setup after creation of netdev Andrew Lunn
2024-04-01 15:53   ` Vladimir Oltean
2024-04-01 13:35 ` [PATCH net-next v3 2/7] net: Add helpers for netdev LEDs Andrew Lunn
2024-04-02  9:53   ` Vladimir Oltean
2024-04-03 23:43     ` Andrew Lunn
2024-04-01 13:35 ` [PATCH net-next v3 3/7] net: dsa: mv88e6xxx: Add helpers for 6352 LED blink and brightness Andrew Lunn
2024-04-01 13:35 ` [PATCH net-next v3 4/7] net: dsa: mv88e6xxx: Tie the low level LED functions to device ops Andrew Lunn
2024-04-01 13:35 ` [PATCH net-next v3 5/7] net: dsa: Add helpers to convert netdev to ds or port index Andrew Lunn
2024-04-02 10:56   ` Vladimir Oltean
2024-04-02 13:31     ` Russell King (Oracle) [this message]
2024-04-02 20:51       ` Vladimir Oltean
2024-04-01 13:35 ` [PATCH net-next v3 6/7] dsa: mv88e6xxx: Create port/netdev LEDs Andrew Lunn
2024-04-02 11:03   ` Vladimir Oltean
2024-04-01 13:35 ` [PATCH net-next v3 7/7] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZgwItu4gETdLbHWi@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregory.clement@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).