[PATCH net-next 11/13] net: phy: store phy_modes in a static array

Maxime Chevallier
2026-01-27T13:42:47Z

The phy_modes() helper provided by include/linux/phy.h returns the name of
a phy_interface_t value.

As it may be used by callers that don't depend on PHYLIB, it's a static
inline function.

We want to report using netlink the phy_interface_t types that may be
accessible on a phy_port, especially for SFP cages. We need access to
that array of phy_interface_t names, let's therefore store it into a
dedicated array in net/ethtool/common.c. This is part of CONFIG_NET, so
it's accessible even without dependency on PHYLIB.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
include/linux/phy.h | 84 +++-----------------------------------------
net/ethtool/common.c | 44 +++++++++++++++++++++++
2 files changed, 49 insertions(+), 79 deletions(-)

diff --git a/include/linux/phy.h b/include/linux/phy.h
index dc788ae4da64..cf607c1a5127 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -199,6 +199,8 @@ static inline void phy_interface_set_rgmii(unsigned long *intf)
__set_bit(PHY_INTERFACE_MODE_RGMII_TXID, intf);
}

+extern const char phy_interface_names[][ETH_GSTRING_LEN];
+
/**
* phy_modes - map phy_interface_t enum to device tree binding of phy-mode
* @interface: enum phy_interface_t value
@@ -209,86 +211,10 @@ static inline void phy_interface_set_rgmii(unsigned long *intf)
*/
static inline const char *phy_modes(phy_interface_t interface)
{
- switch (interface) {
- case PHY_INTERFACE_MODE_NA:
- return "";
- case PHY_INTERFACE_MODE_INTERNAL:
- return "internal";
- case PHY_INTERFACE_MODE_MII:
- return "mii";
- case PHY_INTERFACE_MODE_GMII:
- return "gmii";
- case PHY_INTERFACE_MODE_SGMII:
- return "sgmii";
- case PHY_INTERFACE_MODE_TBI:
- return "tbi";
- case PHY_INTERFACE_MODE_REVMII:
- return "rev-mii";
- case PHY_INTERFACE_MODE_RMII:
- return "rmii";
- case PHY_INTERFACE_MODE_REVRMII:
- return "rev-rmii";
- case PHY_INTERFACE_MODE_RGMII:
- return "rgmii";
- case PHY_INTERFACE_MODE_RGMII_ID:
- return "rgmii-id";
- case PHY_INTERFACE_MODE_RGMII_RXID:
- return "rgmii-rxid";
- case PHY_INTERFACE_MODE_RGMII_TXID:
- return "rgmii-txid";
- case PHY_INTERFACE_MODE_RTBI:
- return "rtbi";
- case PHY_INTERFACE_MODE_SMII:
- return "smii";
- case PHY_INTERFACE_MODE_XGMII:
- return "xgmii";
- case PHY_INTERFACE_MODE_XLGMII:
- return "xlgmii";
- case PHY_INTERFACE_MODE_MOCA:
- return "moca";
- case PHY_INTERFACE_MODE_PSGMII:
- return "psgmii";
- case PHY_INTERFACE_MODE_QSGMII:
- return "qsgmii";
- case PHY_INTERFACE_MODE_TRGMII:
- return "trgmii";
- case PHY_INTERFACE_MODE_1000BASEX:
- return "1000base-x";
- case PHY_INTERFACE_MODE_1000BASEKX:
- return "1000base-kx";
- case PHY_INTERFACE_MODE_2500BASEX:
- return "2500base-x";
- case PHY_INTERFACE_MODE_5GBASER:
- return "5gbase-r";
- case PHY_INTERFACE_MODE_RXAUI:
- return "rxaui";
- case PHY_INTERFACE_MODE_XAUI:
- return "xaui";
- case PHY_INTERFACE_MODE_10GBASER:
- return "10gbase-r";
- case PHY_INTERFACE_MODE_25GBASER:
- return "25gbase-r";
- case PHY_INTERFACE_MODE_USXGMII:
- return "usxgmii";
- case PHY_INTERFACE_MODE_10GKR:
- return "10gbase-kr";
- case PHY_INTERFACE_MODE_100BASEX:
- return "100base-x";
- case PHY_INTERFACE_MODE_QUSGMII:
- return "qusgmii";
- case PHY_INTERFACE_MODE_10G_QXGMII:
- return "10g-qxgmii";
- case PHY_INTERFACE_MODE_50GBASER:
- return "50gbase-r";
- case PHY_INTERFACE_MODE_LAUI:
- return "laui";
- case PHY_INTERFACE_MODE_100GBASEP:
- return "100gbase-p";
- case PHY_INTERFACE_MODE_MIILITE:
- return "mii-lite";
- default:
+ if (interface > PHY_INTERFACE_MODE_MAX)
return "unknown";
- }
+
+ return phy_interface_names[interface];
}

/**
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 4036561b078b..d795d9a8b0cd 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -483,6 +483,50 @@ static const char ethtool_link_medium_names[][ETH_GSTRING_LEN] = {
};
static_assert(ARRAY_SIZE(ethtool_link_medium_names) == __ETHTOOL_LINK_MEDIUM_LAST);

+const char phy_interface_names[][ETH_GSTRING_LEN] = {
+ [PHY_INTERFACE_MODE_NA] = "",
+ [PHY_INTERFACE_MODE_INTERNAL] = "internal",
+ [PHY_INTERFACE_MODE_MII] = "mii",
+ [PHY_INTERFACE_MODE_GMII] = "gmii",
+ [PHY_INTERFACE_MODE_SGMII] = "sgmii",
+ [PHY_INTERFACE_MODE_TBI] = "tbi",
+ [PHY_INTERFACE_MODE_REVMII] = "rev-mii",
+ [PHY_INTERFACE_MODE_RMII] = "rmii",
+ [PHY_INTERFACE_MODE_REVRMII] = "rev-rmii",
+ [PHY_INTERFACE_MODE_RGMII] = "rgmii",
+ [PHY_INTERFACE_MODE_RGMII_ID] = "rgmii-id",
+ [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
+ [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
+ [PHY_INTERFACE_MODE_RTBI] = "rtbi",
+ [PHY_INTERFACE_MODE_SMII] = "smii",
+ [PHY_INTERFACE_MODE_XGMII] = "xgmii",
+ [PHY_INTERFACE_MODE_XLGMII] = "xlgmii",
+ [PHY_INTERFACE_MODE_MOCA] = "moca",
+ [PHY_INTERFACE_MODE_PSGMII] = "psgmii",
+ [PHY_INTERFACE_MODE_QSGMII] = "qsgmii",
+ [PHY_INTERFACE_MODE_TRGMII] = "trgmii",
+ [PHY_INTERFACE_MODE_1000BASEX] = "1000base-x",
+ [PHY_INTERFACE_MODE_1000BASEKX] = "1000base-kx",
+ [PHY_INTERFACE_MODE_2500BASEX] = "2500base-x",
+ [PHY_INTERFACE_MODE_5GBASER] = "5gbase-r",
+ [PHY_INTERFACE_MODE_RXAUI] = "rxaui",
+ [PHY_INTERFACE_MODE_XAUI] = "xaui",
+ [PHY_INTERFACE_MODE_10GBASER] = "10gbase-r",
+ [PHY_INTERFACE_MODE_25GBASER] = "25gbase-r",
+ [PHY_INTERFACE_MODE_USXGMII] = "usxgmii",
+ [PHY_INTERFACE_MODE_10GKR] = "10gbase-kr",
+ [PHY_INTERFACE_MODE_100BASEX] = "100base-x",
+ [PHY_INTERFACE_MODE_QUSGMII] = "qusgmii",
+ [PHY_INTERFACE_MODE_10G_QXGMII] = "10g-qxgmii",
+ [PHY_INTERFACE_MODE_50GBASER] = "50gbase-r",
+ [PHY_INTERFACE_MODE_LAUI] = "laui",
+ [PHY_INTERFACE_MODE_100GBASEP] = "100gbase-p",
+ [PHY_INTERFACE_MODE_MIILITE] = "mii-lite",
+
+};
+static_assert(ARRAY_SIZE(phy_interface_names) == PHY_INTERFACE_MODE_MAX);
+EXPORT_SYMBOL_GPL(phy_interface_names);
+
const char netif_msg_class_names[][ETH_GSTRING_LEN] = {
[NETIF_MSG_DRV_BIT] = "drv",
[NETIF_MSG_PROBE_BIT] = "probe",
--
2.49.0