From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 6/8] net: phy: fix of_get_phy_mode for XLGMII and beyond
Date: Thu, 20 Mar 2025 06:16:39 +0100 [thread overview]
Message-ID: <20250320051641.1721377-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
The phy_modes array needs to be kept in-sync with the
enum phy_interface_t, but this was violated by the most recent sync of
the enum type with Linux.
Th addition of new enumeration constants between existing ones resulted
in phy_modes having NULL-valued gaps, which would panic when passed
to strcmp.
Fix this by replacing the current sparse array, with a function that
always returns a string value. This is what Linux currently does.
Fixes: 63eb097f6639 ("net/phy: sync phy_interface_t types with Linux")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- new patch
---
drivers/of/of_net.c | 36 ++------------------
include/linux/phy.h | 82 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 34 deletions(-)
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 58b4f99da111..d66de875316d 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -10,38 +10,6 @@
#include <linux/phy.h>
#include <linux/nvmem-consumer.h>
-/**
- * It maps 'enum phy_interface_t' found in include/linux/phy.h
- * into the device tree binding of 'phy-mode', so that Ethernet
- * device driver can get phy interface from device tree.
- */
-static const char *phy_modes[] = {
- [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_MOCA] = "moca",
- [PHY_INTERFACE_MODE_QSGMII] = "qsgmii",
- [PHY_INTERFACE_MODE_TRGMII] = "trgmii",
- [PHY_INTERFACE_MODE_1000BASEX] = "1000base-x",
- [PHY_INTERFACE_MODE_2500BASEX] = "2500base-x",
- [PHY_INTERFACE_MODE_RXAUI] = "rxaui",
- [PHY_INTERFACE_MODE_XAUI] = "xaui",
- [PHY_INTERFACE_MODE_10GKR] = "10gbase-kr",
-};
-
/**
* of_get_phy_mode - Get phy mode for given device_node
* @np: Pointer to the given device_node
@@ -60,8 +28,8 @@ int of_get_phy_mode(struct device_node *np)
if (err < 0)
return err;
- for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
- if (!strcmp(pm, phy_modes[i]))
+ for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++)
+ if (!strcasecmp(pm, phy_modes(i)))
return i;
return -ENODEV;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index d8e53d446ef5..5cbd21f91a50 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -115,6 +115,88 @@ typedef enum {
PHY_INTERFACE_MODE_MAX,
} phy_interface_t;
+/**
+ * phy_modes - map phy_interface_t enum to device tree binding of phy-mode
+ * @interface: enum phy_interface_t value
+ *
+ * Description: maps enum &phy_interface_t defined in this file
+ * into the device tree binding of 'phy-mode', so that Ethernet
+ * device driver can get PHY interface from device tree.
+ */
+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";
+ default:
+ return "unknown";
+ }
+}
+
#define PHY_INIT_TIMEOUT 100000
#define PHY_FORCE_TIMEOUT 10
#define PHY_AN_TIMEOUT 10
--
2.39.5
next prev parent reply other threads:[~2025-03-20 5:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 5:16 [PATCH master 0/8] treewide: misc fixes Ahmad Fatoum
2025-03-20 5:16 ` [PATCH master 1/8] firmware: disable MISSING_FIRMWARE_ERROR for COMPILE_TEST builds Ahmad Fatoum
2025-03-20 5:16 ` [PATCH master 2/8] include: asm-generic/pointer.h: fix ASM_PTR definition for i386 Ahmad Fatoum
2025-03-20 5:16 ` [PATCH master 3/8] sandbox: do not enable SANDBOX_LINUX_I386 in allyesconfig Ahmad Fatoum
2025-03-20 5:16 ` [PATCH master 4/8] Documentation: devicetree: fix Sphinx warnings Ahmad Fatoum
2025-03-20 5:16 ` [PATCH master 5/8] ARM: mvebu: kwb_bbu: add missing header Ahmad Fatoum
2025-03-20 5:16 ` Ahmad Fatoum [this message]
2025-03-20 5:16 ` [PATCH master 7/8] vsprintf: fix left indentation when formatting wide string arguments Ahmad Fatoum
2025-03-20 5:16 ` [PATCH master 8/8] test: self: printf: add tests for formatting wide strings Ahmad Fatoum
2025-03-20 11:46 ` [PATCH master 0/8] treewide: misc fixes Sascha Hauer
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=20250320051641.1721377-7-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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