From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Romain Gantois <romain.gantois@bootlin.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
thomas.petazzoni@bootlin.com, "Andrew Lunn" <andrew@lunn.ch>,
"Jakub Kicinski" <kuba@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Russell King" <linux@armlinux.org.uk>,
linux-arm-kernel@lists.infradead.org,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Herve Codina" <herve.codina@bootlin.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Marek Behún" <kabel@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Nicolò Veronese" <nicveronese@gmail.com>,
"Simon Horman" <horms@kernel.org>,
mwojtas@chromium.org, "Antoine Tenart" <atenart@kernel.org>,
devicetree@vger.kernel.org, "Conor Dooley" <conor+dt@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Daniel Golle" <daniel@makrotopia.org>,
"Dimitri Fedrau" <dimitri.fedrau@liebherr.com>
Subject: Re: [PATCH net-next v6 06/14] net: phy: Introduce generic SFP handling for PHY drivers
Date: Wed, 28 May 2025 10:14:33 +0200 [thread overview]
Message-ID: <20250528101433.138b2f31@device-24.home> (raw)
In-Reply-To: <13770694.uLZWGnKmhe@fw-rgant>
Hi Romain
On Wed, 28 May 2025 09:35:35 +0200
Romain Gantois <romain.gantois@bootlin.com> wrote:
> On Friday, 23 May 2025 14:54:57 CEST Maxime Chevallier wrote:
> > Hi Romain,
> >
> > On Mon, 12 May 2025 10:38:52 +0200
> >
> > Romain Gantois <romain.gantois@bootlin.com> wrote:
> > > Hi Maxime,
> > >
> > > On Wednesday, 7 May 2025 15:53:22 CEST Maxime Chevallier wrote:
> > > > There are currently 4 PHY drivers that can drive downstream SFPs:
> > > > marvell.c, marvell10g.c, at803x.c and marvell-88x2222.c. Most of the
> > > > logic is boilerplate, either calling into generic phylib helpers (for
> > > > SFP PHY attach, bus attach, etc.) or performing the same tasks with a
> > > >
> > > > bit of validation :
> > > > - Getting the module's expected interface mode
> > > > - Making sure the PHY supports it
> > > > - Optionnaly perform some configuration to make sure the PHY outputs
> > > >
> > > > the right mode
> > > >
> > > > This can be made more generic by leveraging the phy_port, and its
> > > > configure_mii() callback which allows setting a port's interfaces when
> > > > the port is a serdes.
> > > >
> > > > Introduce a generic PHY SFP support. If a driver doesn't probe the SFP
> > > > bus itself, but an SFP phandle is found in devicetree/firmware, then the
> > > > generic PHY SFP support will be used, relying on port ops.
> > > >
> > > > PHY driver need to :
> > > > - Register a .attach_port() callback
> > > > - When a serdes port is registered to the PHY, drivers must set
> > > >
> > > > port->interfaces to the set of PHY_INTERFACE_MODE the port can output
> > > >
> > > > - If the port has limitations regarding speed, duplex and aneg, the
> > > >
> > > > port can also fine-tune the final linkmodes that can be supported
> > > >
> > > > - The port may register a set of ops, including .configure_mii(), that
> > > >
> > > > will be called at module_insert time to adjust the interface based on
> > > > the module detected.
> > > >
> > > > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> > > > ---
> > > >
> > > > drivers/net/phy/phy_device.c | 107 +++++++++++++++++++++++++++++++++++
> > > > include/linux/phy.h | 2 +
> > > > 2 files changed, 109 insertions(+)
> > > >
> > > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > > > index aaf0eccbefba..aca3a47cbb66 100644
> > > > --- a/drivers/net/phy/phy_device.c
> > > > +++ b/drivers/net/phy/phy_device.c
> > > > @@ -1450,6 +1450,87 @@ void phy_sfp_detach(void *upstream, struct
> > > > sfp_bus
> > > > *bus) }
> > > >
> > > > EXPORT_SYMBOL(phy_sfp_detach);
> > > >
> > > > +static int phy_sfp_module_insert(void *upstream, const struct
> > > > sfp_eeprom_id *id) +{
> > > > + struct phy_device *phydev = upstream;
> > > > + struct phy_port *port = phy_get_sfp_port(phydev);
> > > > +
> > >
> > > RCT
> >
> > Can't be done here, it won't build if in the other order...
> >
>
> You could always separate the declaration from the assignment, I've seen that
> done quite a lot to keep things in RCT.
>
> > > > + __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
> > > > + DECLARE_PHY_INTERFACE_MASK(interfaces);
> > > > + phy_interface_t iface;
> > > > +
> > > > + linkmode_zero(sfp_support);
> > > > +
> > > > + if (!port)
> > > > + return -EINVAL;
> > > > +
> > > > + sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
> > > > +
> > > > + if (phydev->n_ports == 1)
> > > > + phydev->port = sfp_parse_port(phydev->sfp_bus, id,
> > >
> > > sfp_support);
> > >
> > > As mentionned below, this check looks a bit strange to me. Why are we only
> > > parsing the SFP port if the PHY device only has one registered port?
> >
> > Because phydev->port is global to the PHY. If we have another port,
> > then phydev->port must be handled differently so that SFP insertion /
> > removal doesn't overwrite what the other port is.
> >
>
> Okay, I see, thanks for explaining.
>
> > Handling of phydev->port is still fragile in this state of the series,
> > I'll try to improve on that for V7 and document it better.
> >
> > > > +
> > > > + linkmode_and(sfp_support, port->supported, sfp_support);
> > > > +
> > > > + if (linkmode_empty(sfp_support)) {
> > > > + dev_err(&phydev->mdio.dev, "incompatible SFP module
> > >
> > > inserted\n");
> > >
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > + iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
> > > > +
> > > > + /* Check that this interface is supported */
> > > > + if (!test_bit(iface, port->interfaces)) {
> > > > + dev_err(&phydev->mdio.dev, "incompatible SFP module
> > >
> > > inserted\n");
> > >
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > + if (port->ops && port->ops->configure_mii)
> > > > + return port->ops->configure_mii(port, true, iface);
> > >
> > > The name "configure_mii()" seems a bit narrow-scoped to me, as this
> > > callback might have to configure something else than a MII link. For
> > > example, if a DAC SFP module is inserted, the downstream side of the
> > > transciever will have to be configured to 1000Base-X or something
> > > similar.
> >
> > In that regard, you can consider 1000BaseX as a MII mode (we do have
> > PHY_INTERFACE_MODE_1000BASEX).
> >
>
> Ugh, the "1000BaseX" terminology never ceases to confuse me, but yes you're
> right.
>
> > > I'd suggest something like "post_sfp_insert()", please let me know what
> > > you
> > > think.
> >
> > That's not intended to be SFP-specific though. post_sfp_insert() sounds
> > lke the narrow-scoped name to me :) Here we are dealing with a PHy that
> > has a media-side port that isn't a MDI port, but an MII interface like
> > a MAC would usually export. There may be an SFP here, or something else
> > entirely :)
> >
>
> Is that callback really not meant to be SFP-specific? It's only called from
> phy_sfp_module_insert() though.
Well for now yeah as this is the only user now, but ports are meant to
be about more than drving SFPs.
This series as of today is quite long but doesn't cover the other
classes of use-cases which are non-phy-driven ports.
Taking the example of the Turris Omnia, we have something like that :
+------------------+
| MUX +--------+ |
| +-| port 1 | --- SGMII - PHY
| | +--------+ |
MAC -------+ |
| | +--------+ |
| +-| port 2 | ---- SGMII/1000BaseX - SFP
| +--------+ |
+------------------+
Here we have 1 mac that drives 2 ports through a MUX. So the ports here
would be driven by the mux driver (which I have a framewrok for ready to
send once this series lands). The goal would be to use the same
phy_port representation for these 2 ports, the .configure_mii()
callback will be used to switch between ports (so, perform the muxing),
then the rest of the stack takes over through the usual means (phylink,
phylib and all that). So here, the .configure_mii() ops doesn't
necessarily drives an SFP :)
Maxime
next prev parent reply other threads:[~2025-05-28 8:14 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 13:53 [PATCH net-next v6 00/14] Introduce an ethernet port representation Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 01/14] dt-bindings: net: Introduce the ethernet-connector description Maxime Chevallier
2025-05-13 13:08 ` Kory Maincent
2025-05-07 13:53 ` [PATCH net-next v6 02/14] net: ethtool: Introduce ETHTOOL_LINK_MEDIUM_* values Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 03/14] net: phy: Introduce PHY ports representation Maxime Chevallier
2025-05-12 7:53 ` Romain Gantois
2025-06-27 16:54 ` Maxime Chevallier
2025-05-13 13:53 ` Kory Maincent
2025-06-27 17:02 ` Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 04/14] net: phy: dp83822: Add support for phy_port representation Maxime Chevallier
2025-05-13 14:00 ` Kory Maincent
2025-05-07 13:53 ` [PATCH net-next v6 05/14] net: phy: Create a phy_port for PHY-driven SFPs Maxime Chevallier
2025-05-13 12:25 ` Romain Gantois
2025-06-27 17:06 ` Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 06/14] net: phy: Introduce generic SFP handling for PHY drivers Maxime Chevallier
2025-05-12 8:38 ` Romain Gantois
2025-05-23 12:54 ` Maxime Chevallier
2025-05-28 7:35 ` Romain Gantois
2025-05-28 8:14 ` Maxime Chevallier [this message]
2025-05-28 8:16 ` Romain Gantois
2025-05-29 13:23 ` Russell King (Oracle)
2025-05-30 7:28 ` Romain Gantois
2025-05-30 7:46 ` Russell King (Oracle)
2025-05-30 9:08 ` Romain Gantois
2025-05-07 13:53 ` [PATCH net-next v6 07/14] net: phy: marvell-88x2222: Support SFP through phy_port interface Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 08/14] net: phy: marvell: " Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 09/14] net: phy: marvell10g: Support SFP through phy_port Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 10/14] net: phy: at803x: Support SFP through phy_port interface Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 11/14] net: phy: qca807x: " Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 12/14] net: phy: Only rely on phy_port for PHY-driven SFP Maxime Chevallier
2025-05-12 8:52 ` Romain Gantois
2025-05-07 13:53 ` [PATCH net-next v6 13/14] net: phy: dp83822: Add SFP support through the phy_port interface Maxime Chevallier
2025-05-07 13:53 ` [PATCH net-next v6 14/14] Documentation: networking: Document the phy_port infrastructure Maxime Chevallier
2025-05-12 9:22 ` Romain Gantois
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=20250528101433.138b2f31@device-24.home \
--to=maxime.chevallier@bootlin.com \
--cc=andrew@lunn.ch \
--cc=atenart@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=conor+dt@kernel.org \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=dimitri.fedrau@liebherr.com \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mwojtas@chromium.org \
--cc=netdev@vger.kernel.org \
--cc=nicveronese@gmail.com \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
--cc=romain.gantois@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.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).