mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Petrous via B4 Relay <devnull+jan.petrous.oss.nxp.com@kernel.org>
To: "Vincent Guittot" <vincent.guittot@linaro.org>,
	"Ghennadi Procopciuc" <ghennadi.procopciuc@oss.nxp.com>,
	"Ciprian Marian Costea" <ciprianmarian.costea@oss.nxp.com>,
	"NXP S32 Linux Team" <s32@nxp.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Bogdan Hamciuc" <bogdan.hamciuc@nxp.com>,
	"Ionut Vicovan" <ionut.vicovan@nxp.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
	"Chester Lin" <chester62515@gmail.com>,
	"Matthias Brugger" <mbrugger@suse.com>,
	"Frank Li" <Frank.Li@nxp.com>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Richard Cochran" <richardcochran@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-phy@lists.infradead.org,  netdev@vger.kernel.org,
	devicetree@vger.kernel.org,  linux-kernel@vger.kernel.org,
	imx@lists.linux.dev,  linux-pci@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	 "Jan Petrous (OSS)" <jan.petrous@oss.nxp.com>
Subject: [PATCH RFC v4 05/15] net: pcs: xpcs: let a glue driver declare the PCS and PMA IDs
Date: Wed, 25 Nov 2026 10:33:47 +0100	[thread overview]
Message-ID: <20261125-s32g_serdes-v4-5-3bfe0589be8d@oss.nxp.com> (raw)
In-Reply-To: <20261125-s32g_serdes-v4-0-3bfe0589be8d@oss.nxp.com>

From: "Jan Petrous (OSS)" <jan.petrous@oss.nxp.com>

pcs-xpcs selects its description entry by the PCS ID read from the
device. An XPCS integrated with a vendor PMA reports the generic
DesignWare PCS ID, so the entry cannot tell such an integration from a
plain XPCS. Glue drivers have answered this so far by returning a
synthetic PCS ID from their MDIO bus emulation.

The core already takes declared IDs through struct dw_xpcs_info, which
pcs-xpcs-plat passes for PMA generations it cannot read from the
device, but only from the platform data of an MDIO device the creator
registered itself.

Let a glue driver declare them instead:

 - xpcs_create_pcs_mdiodev_info() creates the PCS like
   xpcs_create_pcs_mdiodev() and takes a struct dw_xpcs_info;

 - with both IDs declared, no ID register is read. A glue whose
   register window is not clocked when it creates the PCS needs that;

 - a description entry may name a PMA ID. It then matches only that
   PMA, and takes precedence over an entry for the same PCS ID that
   matches any PMA.

No entry names a PMA yet and no existing caller declares both IDs, so
there is no functional change.

Signed-off-by: Jan Petrous (OSS) <jan.petrous@oss.nxp.com>
---
 drivers/net/pcs/pcs-xpcs.c   | 95 ++++++++++++++++++++++++++++++++++----------
 include/linux/pcs/pcs-xpcs.h |  2 +
 2 files changed, 75 insertions(+), 22 deletions(-)

diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
index 442c64a731b7..3b5857dc44f3 100644
--- a/drivers/net/pcs/pcs-xpcs.c
+++ b/drivers/net/pcs/pcs-xpcs.c
@@ -170,6 +170,8 @@ struct dw_xpcs_compat {
 struct dw_xpcs_desc {
 	u32 id;
 	u32 mask;
+	/* Match only this PMA ID; 0 matches any PMA */
+	u32 pma;
 	const struct dw_xpcs_compat *compat;
 	unsigned int quirks;
 };
@@ -1366,6 +1368,11 @@ static int xpcs_read_ids(struct dw_xpcs *xpcs)
 	int ret;
 	u32 id;
 
+	/* Both IDs declared by the creator, nothing to read */
+	if (xpcs->info.pcs != DW_XPCS_ID_NATIVE &&
+	    xpcs->info.pma != DW_XPCS_PMA_ID_NATIVE)
+		return 0;
+
 	/* First, search C73 PCS using PCS MMD 3. Return ENODEV if communication
 	 * failed indicating that device couldn't be reached.
 	 */
@@ -1530,22 +1537,36 @@ static const struct phylink_pcs_ops xpcs_phylink_ops = {
 
 static int xpcs_identify(struct dw_xpcs *xpcs)
 {
+	const struct dw_xpcs_desc *match = NULL;
 	int i, ret;
 
 	ret = xpcs_read_ids(xpcs);
 	if (ret < 0)
 		return ret;
 
+	/* An entry for the PMA ID takes precedence over one for any PMA */
 	for (i = 0; i < ARRAY_SIZE(xpcs_desc_list); i++) {
 		const struct dw_xpcs_desc *entry = &xpcs_desc_list[i];
 
-		if ((xpcs->info.pcs & entry->mask) == entry->id) {
-			xpcs->desc = entry;
-			return 0;
+		if ((xpcs->info.pcs & entry->mask) != entry->id)
+			continue;
+
+		if (entry->pma) {
+			if (entry->pma == xpcs->info.pma) {
+				match = entry;
+				break;
+			}
+		} else if (!match) {
+			match = entry;
 		}
 	}
 
-	return -ENODEV;
+	if (!match)
+		return -ENODEV;
+
+	xpcs->desc = match;
+
+	return 0;
 }
 
 static struct dw_xpcs *xpcs_create_data(struct mdio_device *mdiodev)
@@ -1602,11 +1623,10 @@ static void xpcs_clear_clks(struct dw_xpcs *xpcs)
 	clk_bulk_put(DW_XPCS_NUM_CLKS, xpcs->clks);
 }
 
-static int xpcs_init_id(struct dw_xpcs *xpcs)
+static int xpcs_init_id(struct dw_xpcs *xpcs, const struct dw_xpcs_info *info)
 {
-	const struct dw_xpcs_info *info;
-
-	info = dev_get_platdata(&xpcs->mdiodev->dev);
+	if (!info)
+		info = dev_get_platdata(&xpcs->mdiodev->dev);
 	if (!info) {
 		xpcs->info.pcs = DW_XPCS_ID_NATIVE;
 		xpcs->info.pma = DW_XPCS_PMA_ID_NATIVE;
@@ -1617,7 +1637,8 @@ static int xpcs_init_id(struct dw_xpcs *xpcs)
 	return xpcs_identify(xpcs);
 }
 
-static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev)
+static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
+				   const struct dw_xpcs_info *info)
 {
 	struct dw_xpcs *xpcs;
 	int ret;
@@ -1630,7 +1651,7 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev)
 	if (ret)
 		goto out_free_data;
 
-	ret = xpcs_init_id(xpcs);
+	ret = xpcs_init_id(xpcs, info);
 	if (ret)
 		goto out_clear_clks;
 
@@ -1653,16 +1674,8 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev)
 	return ERR_PTR(ret);
 }
 
-/**
- * xpcs_create_mdiodev() - create a DW xPCS instance with the MDIO @addr
- * @bus: pointer to the MDIO-bus descriptor for the device to be looked at
- * @addr: device MDIO-bus ID
- *
- * Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if
- * the PCS device couldn't be found on the bus and other negative errno related
- * to the data allocation and MDIO-bus communications.
- */
-struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr)
+static struct dw_xpcs *xpcs_create_mdiodev_info(struct mii_bus *bus, int addr,
+						const struct dw_xpcs_info *info)
 {
 	struct mdio_device *mdiodev;
 	struct dw_xpcs *xpcs;
@@ -1671,7 +1684,7 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr)
 	if (IS_ERR(mdiodev))
 		return ERR_CAST(mdiodev);
 
-	xpcs = xpcs_create(mdiodev);
+	xpcs = xpcs_create(mdiodev, info);
 
 	/* xpcs_create() has taken a refcount on the mdiodev if it was
 	 * successful. If xpcs_create() fails, this will free the mdio
@@ -1683,6 +1696,20 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr)
 
 	return xpcs;
 }
+
+/**
+ * xpcs_create_mdiodev() - create a DW xPCS instance with the MDIO @addr
+ * @bus: pointer to the MDIO-bus descriptor for the device to be looked at
+ * @addr: device MDIO-bus ID
+ *
+ * Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if
+ * the PCS device couldn't be found on the bus and other negative errno related
+ * to the data allocation and MDIO-bus communications.
+ */
+struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr)
+{
+	return xpcs_create_mdiodev_info(bus, addr, NULL);
+}
 EXPORT_SYMBOL_GPL(xpcs_create_mdiodev);
 
 struct phylink_pcs *xpcs_create_pcs_mdiodev(struct mii_bus *bus, int addr)
@@ -1697,6 +1724,30 @@ struct phylink_pcs *xpcs_create_pcs_mdiodev(struct mii_bus *bus, int addr)
 }
 EXPORT_SYMBOL_GPL(xpcs_create_pcs_mdiodev);
 
+/**
+ * xpcs_create_pcs_mdiodev_info() - create a DW xPCS PCS with declared IDs
+ * @bus: MDIO bus of the PCS
+ * @addr: MDIO address of the PCS
+ * @info: PCS and PMA IDs; an ID left native is read from the device
+ *
+ * For a glue driver that knows the integration of its XPCS. With both IDs
+ * declared, no ID register is read. @info is copied.
+ *
+ * Return: the phylink PCS, or an ERR_PTR() as for xpcs_create_mdiodev().
+ */
+struct phylink_pcs *xpcs_create_pcs_mdiodev_info(struct mii_bus *bus, int addr,
+						 const struct dw_xpcs_info *info)
+{
+	struct dw_xpcs *xpcs;
+
+	xpcs = xpcs_create_mdiodev_info(bus, addr, info);
+	if (IS_ERR(xpcs))
+		return ERR_CAST(xpcs);
+
+	return &xpcs->pcs;
+}
+EXPORT_SYMBOL_GPL(xpcs_create_pcs_mdiodev_info);
+
 /**
  * xpcs_create_fwnode() - Create a DW xPCS instance from @fwnode
  * @fwnode: fwnode handle poining to the DW XPCS device
@@ -1719,7 +1770,7 @@ struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode)
 	if (!mdiodev)
 		return ERR_PTR(-EPROBE_DEFER);
 
-	xpcs = xpcs_create(mdiodev);
+	xpcs = xpcs_create(mdiodev, NULL);
 
 	/* xpcs_create() has taken a refcount on the mdiodev if it was
 	 * successful. If xpcs_create() fails, this will free the mdio
diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h
index 36073f7b6bb4..f46434958383 100644
--- a/include/linux/pcs/pcs-xpcs.h
+++ b/include/linux/pcs/pcs-xpcs.h
@@ -58,6 +58,8 @@ struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode);
 void xpcs_destroy(struct dw_xpcs *xpcs);
 
 struct phylink_pcs *xpcs_create_pcs_mdiodev(struct mii_bus *bus, int addr);
+struct phylink_pcs *xpcs_create_pcs_mdiodev_info(struct mii_bus *bus, int addr,
+						 const struct dw_xpcs_info *info);
 void xpcs_destroy_pcs(struct phylink_pcs *pcs);
 
 #endif /* __LINUX_PCS_XPCS_H */

-- 
2.55.0



  parent reply	other threads:[~2026-11-25  9:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  9:33 [PATCH RFC v4 00/15] Add support for the NXP S32G SerDes subsystem Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 01/15] dt-bindings: phy: Add " Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 02/15] dt-bindings: net: nxp,s32-dwmac: Document pcs-handle Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 03/15] dt-bindings: PCI: nxp,s32g-pcie: One PHY per lane Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 04/15] net: pcs: xpcs: allow a PCS to opt out of soft reset and EEE Jan Petrous via B4 Relay
2026-11-25  9:33 ` Jan Petrous via B4 Relay [this message]
2026-11-25  9:33 ` [PATCH RFC v4 06/15] net: pcs: xpcs: add NXP S32G SerDes XPCS support Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 07/15] net: pcs: xpcs: wait for SGMII AN to complete in-band Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 08/15] net: pcs: Add NXP S32G XPCS glue Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 09/15] phy: freescale: s32g: Add SerDes subsystem PHY Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 10/15] net: stmmac: s32: Add SGMII support Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 11/15] MAINTAINERS: Add NXP S32G SerDes entry Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 12/15] arm64: dts: s32g: Add SCMI reset controller Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 13/15] arm64: dts: s32g: Add SerDes controller nodes Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 14/15] arm64: dts: s32g: Add PCIe " Jan Petrous via B4 Relay
2026-11-25  9:33 ` [PATCH RFC v4 15/15] arm64: dts: s32g: Add S32G3-RDB3 SerDes routing variants Jan Petrous via B4 Relay

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=20261125-s32g_serdes-v4-5-3bfe0589be8d@oss.nxp.com \
    --to=devnull+jan.petrous.oss.nxp.com@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=bhelgaas@google.com \
    --cc=bogdan.hamciuc@nxp.com \
    --cc=chester62515@gmail.com \
    --cc=ciprianmarian.costea@oss.nxp.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=festevam@gmail.com \
    --cc=ghennadi.procopciuc@oss.nxp.com \
    --cc=hkallweit1@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=ionut.vicovan@nxp.com \
    --cc=jan.petrous@oss.nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux@armlinux.org.uk \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mbrugger@suse.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=neil.armstrong@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=s32@nxp.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vkoul@kernel.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

all inboxes | Powered by JetHome®