From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: davem@davemloft.net, 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>,
Heiner Kallweit <hkallweit1@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
thomas.petazzoni@bootlin.com,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Herve Codina" <herve.codina@bootlin.com>,
"Florian Fainelli" <f.fainelli@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,
"Romain Gantois" <romain.gantois@bootlin.com>,
"Daniel Golle" <daniel@makrotopia.org>,
"Dimitri Fedrau" <dimitri.fedrau@liebherr.com>,
"Frank Wunderlich" <frank.wunderlich@linux.dev>
Subject: Re: [PATCH net-next v11 02/10] net: phy: phy_link_topology: Track ports in phy_link_topology
Date: Sat, 30 May 2026 08:58:25 +0200 [thread overview]
Message-ID: <4a919501-b3f2-489a-ac9d-a7f8709abf6e@bootlin.com> (raw)
In-Reply-To: <20260521121040.1199622-3-maxime.chevallier@bootlin.com>
On 5/21/26 14:10, Maxime Chevallier wrote:
> phy_port is aimed at representing the various physical interfaces of a
> net_device. They can be controlled by various components in the link,
> such as the Ethernet PHY, the Ethernet MAC, and SFP module, etc.
>
> Let's therefore make so we keep track of all the ports connected to a
> netdev in phy_link_topology. The only ports added for now are phy-driven
> ports.
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> ---
> drivers/net/phy/phy_link_topology.c | 53 +++++++++++++++++++++++++++++
> include/linux/phy_link_topology.h | 18 ++++++++++
> include/linux/phy_port.h | 2 ++
> net/core/dev.c | 1 +
> 4 files changed, 74 insertions(+)
>
> diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c
> index fdfafd951905..207128303ca2 100644
> --- a/drivers/net/phy/phy_link_topology.c
> +++ b/drivers/net/phy/phy_link_topology.c
> @@ -7,6 +7,7 @@
> */
>
> #include <linux/phy_link_topology.h>
> +#include <linux/phy_port.h>
> #include <linux/phy.h>
> #include <linux/rtnetlink.h>
> #include <linux/xarray.h>
> @@ -22,6 +23,9 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev)
> xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1);
> topo->next_phy_index = 1;
>
> + xa_init_flags(&topo->ports, XA_FLAGS_ALLOC1);
> + topo->next_port_index = 1;
> +
> dev->link_topo = topo;
>
> return 0;
> @@ -44,12 +48,45 @@ static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *d
> return dev->link_topo;
> }
>
> +int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port)
> +{
> + struct phy_link_topology *topo;
> + int ret;
> +
> + topo = phy_link_topo_get_or_alloc(dev);
> + if (IS_ERR(topo))
> + return PTR_ERR(topo);
> +
> + /* Attempt to re-use a previously allocated port_id */
> + if (port->id)
> + ret = xa_insert(&topo->ports, port->id, port, GFP_KERNEL);
Sashiko says :
"
If this port is moved to a different netdev (which has a separate
topology), and its old port->id happens to be in use by another port
in the new topology, will xa_insert() return -EBUSY?
Since there is no fallback to xa_alloc_cyclic() on -EBUSY and the
stale ID is never reset to 0 upon removal, does this permanently
prevent the port from attaching to the new topology?
"
So we can't move a port to another netdev, the closest thing we can
conceivably to is unbind/rebind a net_device while the phy_device
stays alive. Even then, we'll be re-adding this ports to a fresh
topology, so no collision risk here.
We don't re-set the port id to 0 upon removal on purpose, as implied
by the comment we try to reuse the id, as a much more common case is
that we attach/detach the phy_device that controls this port during
.ndo_open/close, and we don't want the port id to change at each
link flap
Maxime
next prev parent reply other threads:[~2026-05-30 6:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 12:10 [PATCH net-next v11 00/10] net: phy_port: SFP modules representation and phy_port listing Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 01/10] net: phy: phy_link_topology: Add a helper for opportunistic alloc Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 02/10] net: phy: phy_link_topology: Track ports in phy_link_topology Maxime Chevallier
2026-05-30 6:58 ` Maxime Chevallier [this message]
2026-05-21 12:10 ` [PATCH net-next v11 03/10] net: phylink: Register a phy_port for MAC-driven SFP cages Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 04/10] net: phy: Create SFP phy_port before registering upstream Maxime Chevallier
2026-05-30 7:34 ` Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 05/10] net: phy: Represent PHY-less SFP modules with phy_port Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 06/10] net: phy: phy_port: Store information about a port's upstream Maxime Chevallier
2026-05-25 20:25 ` Jakub Kicinski
2026-05-26 5:54 ` Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 07/10] net: phy: phy_link_topology: Add a helper to retrieve ports Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 08/10] netlink: specs: Add ethernet port listing with ethtool Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 09/10] net: ethtool: Introduce ethtool command to list ports Maxime Chevallier
2026-05-21 12:10 ` [PATCH net-next v11 10/10] Documentation: networking: Update the phy_port infrastructure description Maxime Chevallier
2026-05-28 1:21 ` Andrew Lunn
2026-05-30 6:34 ` Maxime Chevallier
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=4a919501-b3f2-489a-ac9d-a7f8709abf6e@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=andrew@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=dimitri.fedrau@liebherr.com \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=frank.wunderlich@linux.dev \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@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=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
Powered by JetHome