netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH net-next 0/7] net: phy: introduce phy numbering
@ 2023-09-07  9:23 Maxime Chevallier
  2023-09-07  9:23 ` [RFC PATCH net-next 1/7] net: phy: introduce phy numbering and phy namespaces Maxime Chevallier
                   ` (9 more replies)
  0 siblings, 10 replies; 35+ messages in thread
From: Maxime Chevallier @ 2023-09-07  9:23 UTC (permalink / raw)
  To: davem
  Cc: Maxime Chevallier, netdev, linux-kernel, Andrew Lunn,
	Jakub Kicinski, Eric Dumazet, Paolo Abeni, Florian Fainelli,
	Heiner Kallweit, Russell King, Vladimir Oltean, Oleksij Rempel,
	Nicolò Veronese, thomas.petazzoni, Christophe Leroy

Hello everyone,

This is the first RFC series introducing ethernet PHY numbering, in an
effort to better represent the link components and allow userspace to
configure these.

As of today, PHY devices are hidden behind the struct net_device from
userspace, but there exists commands such as PLCA configuration,
cable-testing, soon timestamping, that actually target the phy_device.

These commands rely on the ndev->phydev pointer to find the phy_device.

However, there exists use-cases where we have multiple PHY devices
between the MAC and the front-facing port. The most common case right
now is when a PHY acts as a media-converter, and is wired to an SFP
port :

[MAC] - [PHY] - [SFP][PHY]


Modules plugged in that port may contain a PHY too, and this is
where discrepencies start to happen.

In this case, ndev->phydev will point to the innermost PHY. Users
willing to use the SFP phy for cable-testing for example would get
unexpected results, as the middle PHY will be reached.

This is worsen by the fact that in a scenario like this :

[MAC] - [SFP][PHY]

the ndev->phydev pointer do point to the SFP PHY.

This is only the tip of the iceberg, such scenarios can happen with
other designs that include a mii mux, which isn't supported yet but
would require PHY enumeration to work.

This series therefore tries to add the ability to enumerate the PHYs
sitting behind a MAC, and assign them a unique number.

I've used the term of "phy namespace" to emphasize the fact that the PHY
numbering really is specific to an interface, each interface maintaining
its numbering scheme, starting from 0, and wrapping after all u32 values
have been exhausted.

The PHY namespace is for now contained within struct net_device, meaning
that PHYs that aren't related at all to any net_device wouldn't be
numbered as of right now. The only case I identified is when a PHY sits
between 2 DSA switches, but I don't know how relevant this is.

The phy_ns is its own struct, for now owned by net_device, but it could
be shared with struct dsa_port for example to make a MAC and the DSA CPU
port share the same phy ns.

This is early work, and it has its shortcomings :

 - I didn't include netlink notifications on PHY insersion/removal, but
   I think this could definitely be useful

 - the netlink API would need polishing, I struggle a bit with finding
   the correct netlink design pattern to return variale-length list of u32.

 - I would like to port netlink commands such as cable-test and plca to
   this new model, by adding an optional PHYINDEX field in the request.
   The idea would be that if the PHYINDEX is passed in the netlink
   request, we lookup the corresponding phy_device, and if not, we
   fallback to ndev->phydev.

 - Naming is hard, feel free to suggest any correction

Let me know what you think of this approach,

Best regards,

Maxime

Maxime Chevallier (7):
  net: phy: introduce phy numbering and phy namespaces
  net: sfp: pass the phy_device when disconnecting an sfp module's PHY
  net: phy: add helpers to handle sfp phy connect/disconnect
  net: ethtool: add a netlink command to list PHYs
  netlink: specs: add phy_list command
  net: ethtool: add a netlink command to get PHY information
  netlink: specs: add command to show individual phy information

 Documentation/netlink/specs/ethtool.yaml |  65 ++++++++++++
 drivers/net/phy/Makefile                 |   2 +-
 drivers/net/phy/at803x.c                 |   2 +
 drivers/net/phy/marvell-88x2222.c        |   2 +
 drivers/net/phy/marvell.c                |   2 +
 drivers/net/phy/marvell10g.c             |   2 +
 drivers/net/phy/phy_device.c             |  53 ++++++++++
 drivers/net/phy/phy_ns.c                 |  65 ++++++++++++
 drivers/net/phy/phylink.c                |   3 +-
 drivers/net/phy/sfp-bus.c                |   4 +-
 include/linux/netdevice.h                |   2 +
 include/linux/phy.h                      |   6 ++
 include/linux/phy_ns.h                   |  30 ++++++
 include/linux/sfp.h                      |   2 +-
 include/uapi/linux/ethtool.h             |   7 ++
 include/uapi/linux/ethtool_netlink.h     |  27 +++++
 net/core/dev.c                           |   3 +
 net/ethtool/Makefile                     |   2 +-
 net/ethtool/netlink.c                    |  20 ++++
 net/ethtool/netlink.h                    |   4 +
 net/ethtool/phy.c                        | 124 +++++++++++++++++++++++
 net/ethtool/phy_list.c                   |  99 ++++++++++++++++++
 22 files changed, 520 insertions(+), 6 deletions(-)
 create mode 100644 drivers/net/phy/phy_ns.c
 create mode 100644 include/linux/phy_ns.h
 create mode 100644 net/ethtool/phy.c
 create mode 100644 net/ethtool/phy_list.c

-- 
2.41.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2023-10-03 18:26 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-07  9:23 [RFC PATCH net-next 0/7] net: phy: introduce phy numbering Maxime Chevallier
2023-09-07  9:23 ` [RFC PATCH net-next 1/7] net: phy: introduce phy numbering and phy namespaces Maxime Chevallier
2023-09-07  9:32   ` Russell King (Oracle)
2023-09-07 10:14   ` Russell King (Oracle)
2023-09-07 12:19     ` Maxime Chevallier
2023-09-08 15:36       ` Jakub Kicinski
2023-09-11 13:05         ` Maxime Chevallier
2023-09-12 15:41   ` Andrew Lunn
2023-09-12 16:10     ` Maxime Chevallier
2023-09-12 17:08       ` Florian Fainelli
2023-09-12 16:15   ` Andrew Lunn
2023-09-12 17:01     ` Maxime Chevallier
2023-09-07  9:24 ` [RFC PATCH net-next 2/7] net: sfp: pass the phy_device when disconnecting an sfp module's PHY Maxime Chevallier
2023-09-07  9:24 ` [RFC PATCH net-next 3/7] net: phy: add helpers to handle sfp phy connect/disconnect Maxime Chevallier
2023-09-07  9:24 ` [RFC PATCH net-next 4/7] net: ethtool: add a netlink command to list PHYs Maxime Chevallier
2023-09-07 10:00   ` Russell King (Oracle)
2023-09-07 12:16     ` Maxime Chevallier
2023-09-12 16:01       ` Andrew Lunn
2023-09-12 16:29   ` Andrew Lunn
2023-09-07  9:24 ` [RFC PATCH net-next 5/7] netlink: specs: add phy_list command Maxime Chevallier
2023-09-07  9:24 ` [RFC PATCH net-next 6/7] net: ethtool: add a netlink command to get PHY information Maxime Chevallier
2023-09-07 10:04   ` Russell King (Oracle)
2023-09-07 12:20     ` Maxime Chevallier
2023-09-08 15:42   ` Jakub Kicinski
2023-09-08 15:46   ` Jakub Kicinski
2023-09-14  9:36     ` Maxime Chevallier
2023-10-03 13:55       ` Jakub Kicinski
2023-10-03 18:26         ` Andrew Lunn
2023-09-07  9:24 ` [RFC PATCH net-next 7/7] netlink: specs: add command to show individual phy information Maxime Chevallier
2023-09-08 15:41 ` [RFC PATCH net-next 0/7] net: phy: introduce phy numbering Jakub Kicinski
2023-09-11 13:09   ` Maxime Chevallier
2023-09-12 15:36 ` Andrew Lunn
2023-09-12 15:51   ` Maxime Chevallier
2023-09-14 10:06 ` Christophe Leroy
2023-09-14 12:47   ` Andrew Lunn

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).