]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
net: phy: Use an internal, searchable storage for the linkmodes
authorMaxime Chevallier <maxime.chevallier@bootlin.com>
Fri, 7 Mar 2025 17:35:59 +0000 (18:35 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 18 Mar 2025 08:03:11 +0000 (09:03 +0100)
commitd8c838a57ce25c746c9882ffa427d8bb3f22b526
tree8b359d4d6ca3bc854824e213ad004447bdb49bdc
parent79f88a584e35133359c394506b351a60230cf37b
net: phy: Use an internal, searchable storage for the linkmodes

The canonical definition for all the link modes is in linux/ethtool.h,
which is complemented by the link_mode_params array stored in
net/ethtool/common.h . That array contains all the metadata about each
of these modes, including the Speed and Duplex information.

Phylib and phylink needs that information as well for internal
management of the link, which was done by duplicating that information
in locally-stored arrays and lookup functions. This makes it easy for
developpers adding new modes to forget modifying phylib and phylink
accordingly.

However, the link_mode_params array in net/ethtool/common.c is fairly
inefficient to search through, as it isn't sorted in any manner. Phylib
and phylink perform a lot of lookup operations, mostly to filter modes
by speed and/or duplex.

We therefore introduce the link_caps private array in phy_caps.c, that
indexes linkmodes in a more efficient manner. Each element associated a
tuple <speed, duplex> to a bitfield of all the linkmodes runs at these
speed/duplex.

We end-up with an array that's fairly short, easily addressable and that
it optimised for the typical use-cases of phylib/phylink.

That array is initialized at the same time as phylib. As the
link_mode_params array is part of the net stack, which phylink depends
on, it should always be accessible from phylib.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20250307173611.129125-3-maxime.chevallier@bootlin.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/phy/Makefile
drivers/net/phy/phy-caps.h [new file with mode: 0644]
drivers/net/phy/phy_caps.c [new file with mode: 0644]
drivers/net/phy/phy_device.c