net: phy: Introduce ethernet link topology representation
authorMaxime Chevallier <maxime.chevallier@bootlin.com>
Thu, 4 Apr 2024 09:29:51 +0000 (11:29 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 6 Apr 2024 17:25:14 +0000 (18:25 +0100)
commit6916e461e7933d3d003441291c543938f2ccb371
treec5b2ed5f02cf0cefb191c90a1acd9b0514df5e0c
parentd133ef1ee2a256ba5a589493cd28dccfede6af11
net: phy: Introduce ethernet link topology representation

Link topologies containing multiple network PHYs attached to the same
net_device can be found when using a PHY as a media converter for use
with an SFP connector, on which an SFP transceiver containing a PHY can
be used.

With the current model, the transceiver's PHY can't be used for
operations such as cable testing, timestamping, macsec offload, etc.

The reason being that most of the logic for these configuration, coming
from either ethtool netlink or ioctls tend to use netdev->phydev, which
in multi-phy systems will reference the PHY closest to the MAC.

Introduce a numbering scheme allowing to enumerate PHY devices that
belong to any netdev, which can in turn allow userspace to take more
precise decisions with regard to each PHY's configuration.

The numbering is maintained per-netdev, in a phy_device_list.
The numbering works similarly to a netdevice's ifindex, with
identifiers that are only recycled once INT_MAX has been reached.

This prevents races that could occur between PHY listing and SFP
transceiver removal/insertion.

The identifiers are assigned at phy_attach time, as the numbering
depends on the netdevice the phy is attached to. The PHY index can be
re-used for PHYs that are persistent.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
MAINTAINERS
drivers/net/phy/Makefile
drivers/net/phy/phy_device.c
drivers/net/phy/phy_link_topology.c [new file with mode: 0644]
include/linux/netdevice.h
include/linux/phy.h
include/linux/phy_link_topology.h [new file with mode: 0644]
include/linux/phy_link_topology_core.h [new file with mode: 0644]
include/uapi/linux/ethtool.h
net/core/dev.c