* [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support
2026-07-24 8:52 [PATCH net-next] " Zxyan Zhu
@ 2026-07-27 9:38 ` Zxyan Zhu
2026-07-27 19:46 ` Andrew Lunn
0 siblings, 1 reply; 6+ messages in thread
From: Zxyan Zhu @ 2026-07-27 9:38 UTC (permalink / raw)
To: andrew+netdev
Cc: davem, edumazet, kuba, pabeni, mcoquelin.stm32, alexandre.torgue,
linux, hkallweit1, rmk+kernel, maxime.chevallier, netdev,
linux-stm32, linux-arm-kernel, linux-kernel, bjorn, Zxyan Zhu
Some Ethernet MAC drivers (such as stmmac) need to perform PCS-level
loopback for selftest purposes when no external PHY is present. Add a
new phylink_pcs_loopback() method that allows MAC drivers to request
PCS loopback mode through the phylink framework.
Implement the pcs_loopback callback in the stmmac integrated PCS
using the GMAC_AN_CTRL_ELE register bit. Add a helper function
stmmac_selftest_get_pcs() in stmmac selftests to unify PCS lookup
across glue driver PCS and integrated PCS. Update the selftest
enable/disable paths to use the new helper.
Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>
---
.../net/ethernet/stmicro/stmmac/stmmac_pcs.c | 17 +++++++
.../stmicro/stmmac/stmmac_selftests.c | 51 ++++++++++++++++---
drivers/net/phy/phylink.c | 19 +++++++
include/linux/phylink.h | 16 ++++++
4 files changed, 95 insertions(+), 8 deletions(-)
Changes in v2:
- Implement pcs_loopback callback in stmmac integrated PCS using
GMAC_AN_CTRL_ELE register bit.
- Add stmmac_selftest_get_pcs() helper to unify PCS lookup across glue
driver PCS and integrated PCS.
- Add NULL check in phylink_pcs_loopback() wrapper.
Note on loopback direction:
The pcs_loopback callback uses a simple enable/disable boolean, matching
the existing phy_loopback() API. Direction is not needed at this level:
selftest loopback is always host-side (TX looped back to RX). The
future ethtool user-space loopback API can handle direction selection
at a higher layer.
Note on phylink_set_loopback() vs phylink_pcs_loopback():
This patch follows the same pattern as phy_loopback() - a direct
callback on the PCS object. Keeping the API minimal avoids introducing
a new phylink-level loopback abstraction with location enumeration
before Björn's ethtool loopback series lands upstream. Once that
series is merged, phylink_pcs_loopback() can serve as a building block
for a higher-level phylink_set_loopback() if needed.
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c
index df37af5ab837..90a21a2f7e87 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c
@@ -168,6 +168,22 @@ static void dwmac_integrated_pcs_an_restart(struct phylink_pcs *pcs)
}
}
+static int dwmac_integrated_pcs_loopback(struct phylink_pcs *pcs, bool enable)
+{
+ struct stmmac_pcs *spcs = phylink_pcs_to_stmmac_pcs(pcs);
+ void __iomem *an_control = spcs->base + GMAC_AN_CTRL(0);
+ u32 ctrl;
+
+ ctrl = readl(an_control);
+ if (enable)
+ ctrl |= GMAC_AN_CTRL_ELE;
+ else
+ ctrl &= ~GMAC_AN_CTRL_ELE;
+ writel(ctrl, an_control);
+
+ return 0;
+}
+
static const struct phylink_pcs_ops dwmac_integrated_pcs_ops = {
.pcs_inband_caps = dwmac_integrated_pcs_inband_caps,
.pcs_enable = dwmac_integrated_pcs_enable,
@@ -175,6 +191,7 @@ static const struct phylink_pcs_ops dwmac_integrated_pcs_ops = {
.pcs_get_state = dwmac_integrated_pcs_get_state,
.pcs_config = dwmac_integrated_pcs_config,
.pcs_an_restart = dwmac_integrated_pcs_an_restart,
+ .pcs_loopback = dwmac_integrated_pcs_loopback,
};
void stmmac_integrated_pcs_irq(struct stmmac_priv *priv, u32 status,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 29e824bd90ca..77a457b2fa5c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -19,6 +19,7 @@
#include <net/udp.h>
#include <net/tc_act/tc_gact.h>
#include "stmmac.h"
+#include "stmmac_pcs.h"
struct stmmachdr {
__be32 version;
@@ -374,23 +375,51 @@ static int stmmac_test_mac_loopback(struct stmmac_priv *priv)
return __stmmac_test_loopback(priv, &attr);
}
+static struct phylink_pcs *stmmac_selftest_get_pcs(struct stmmac_priv *priv)
+{
+ /* Try glue driver's PCS first, then the integrated PCS. */
+ if (priv->hw->phylink_pcs)
+ return priv->hw->phylink_pcs;
+
+ if (priv->integrated_pcs)
+ return &priv->integrated_pcs->pcs;
+
+ return NULL;
+}
+
static int stmmac_test_phy_loopback(struct stmmac_priv *priv)
{
struct stmmac_packet_attrs attr = { };
+ struct phylink_pcs *pcs;
int ret;
- if (!priv->dev->phydev)
- return -EOPNOTSUPP;
+ if (priv->dev->phydev) {
+ ret = phy_loopback(priv->dev->phydev, true, 0);
+ if (ret)
+ return ret;
- ret = phy_loopback(priv->dev->phydev, true, 0);
- if (ret)
+ attr.dst = priv->dev->dev_addr;
+ ret = __stmmac_test_loopback(priv, &attr);
+
+ phy_loopback(priv->dev->phydev, false, 0);
return ret;
+ }
- attr.dst = priv->dev->dev_addr;
- ret = __stmmac_test_loopback(priv, &attr);
+ /* Use PCS loopback for interfaces without an external PHY. */
+ pcs = stmmac_selftest_get_pcs(priv);
+ if (pcs) {
+ ret = phylink_pcs_loopback(pcs, true);
+ if (ret)
+ return ret;
- phy_loopback(priv->dev->phydev, false, 0);
- return ret;
+ attr.dst = priv->dev->dev_addr;
+ ret = __stmmac_test_loopback(priv, &attr);
+
+ phylink_pcs_loopback(pcs, false);
+ return ret;
+ }
+
+ return -EOPNOTSUPP;
}
static int stmmac_test_mmc(struct stmmac_priv *priv)
@@ -1986,6 +2015,9 @@ void stmmac_selftest_run(struct net_device *dev,
ret = -EOPNOTSUPP;
if (dev->phydev)
ret = phy_loopback(dev->phydev, true, 0);
+ else
+ ret = phylink_pcs_loopback(stmmac_selftest_get_pcs(priv),
+ true);
if (!ret)
break;
fallthrough;
@@ -2019,6 +2051,9 @@ void stmmac_selftest_run(struct net_device *dev,
ret = -EOPNOTSUPP;
if (dev->phydev)
ret = phy_loopback(dev->phydev, false, 0);
+ else
+ ret = phylink_pcs_loopback(stmmac_selftest_get_pcs(priv),
+ false);
if (!ret)
break;
fallthrough;
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 59dfe35afa54..69242caffaef 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -997,6 +997,25 @@ int phylink_pcs_pre_init(struct phylink *pl, struct phylink_pcs *pcs)
}
EXPORT_SYMBOL_GPL(phylink_pcs_pre_init);
+/**
+ * phylink_pcs_loopback() - Enable or disable loopback at the PCS
+ * @pcs: a pointer to a &struct phylink_pcs.
+ * @enable: true to enable loopback, false to disable
+ *
+ * Enable or disable loopback mode at the PCS level. This is used by MAC
+ * drivers for selftest purposes when no external PHY is present.
+ *
+ * Returns 0 on success, negative error code on failure.
+ */
+int phylink_pcs_loopback(struct phylink_pcs *pcs, bool enable)
+{
+ if (pcs && pcs->ops->pcs_loopback)
+ return pcs->ops->pcs_loopback(pcs, enable);
+
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(phylink_pcs_loopback);
+
static void phylink_mac_config(struct phylink *pl,
const struct phylink_link_state *state)
{
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 2bc0db3d52ac..66c7016d4acd 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -518,6 +518,7 @@ struct phylink_pcs {
* the MAC.
* @pcs_pre_init: configure PCS components necessary for MAC hardware
* initialization e.g. RX clock for stmmac.
+ * @pcs_loopback: enable/disable loopback mode at the PCS.
*/
struct phylink_pcs_ops {
int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
@@ -542,6 +543,7 @@ struct phylink_pcs_ops {
void (*pcs_disable_eee)(struct phylink_pcs *pcs);
void (*pcs_enable_eee)(struct phylink_pcs *pcs);
int (*pcs_pre_init)(struct phylink_pcs *pcs);
+ int (*pcs_loopback)(struct phylink_pcs *pcs, bool enable);
};
#if 0 /* For kernel-doc purposes only. */
@@ -717,8 +719,22 @@ void pcs_enable_eee(struct phylink_pcs *pcs);
*/
int pcs_pre_init(struct phylink_pcs *pcs);
+/**
+ * pcs_loopback() - Enable or disable loopback at the PCS
+ * @pcs: a pointer to a &struct phylink_pcs.
+ * @enable: true to enable loopback, false to disable
+ *
+ * Enable or disable loopback mode at the PCS level. This is used by MAC
+ * drivers for selftest purposes when no external PHY is present.
+ *
+ * Returns 0 on success, or a negative error code on failure.
+ */
+int pcs_loopback(struct phylink_pcs *pcs, bool enable);
+
#endif
+int phylink_pcs_loopback(struct phylink_pcs *pcs, bool enable);
+
struct phylink *phylink_create(struct phylink_config *,
const struct fwnode_handle *,
phy_interface_t,
base-commit: 1df10cef2d1e7f9f2fb7eddb67fc70d3abf101f9
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support
@ 2026-07-27 12:07 Zxyan Zhu
2026-07-28 8:41 ` Maxime Chevallier
0 siblings, 1 reply; 6+ messages in thread
From: Zxyan Zhu @ 2026-07-27 12:07 UTC (permalink / raw)
To: andrew+netdev, rmk+kernel, alexandre.torgue
Cc: davem, edumazet, kuba, pabeni, hkallweit1, mcoquelin.stm32,
maxime.chevallier, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, Zxyan Zhu
Some Ethernet MAC drivers (such as stmmac) need to perform PCS-level
loopback for selftest purposes when no external PHY is present. Add a
new phylink_pcs_loopback() method that allows MAC drivers to request
PCS loopback mode through the phylink framework.
Implement the pcs_loopback callback in the stmmac integrated PCS
using the GMAC_AN_CTRL_ELE register bit. Add a helper function
stmmac_selftest_get_pcs() in stmmac selftests to unify PCS lookup
across glue driver PCS and integrated PCS. Update the selftest
enable/disable paths to use the new helper.
Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>
---
.../net/ethernet/stmicro/stmmac/stmmac_pcs.c | 17 +++++++
.../stmicro/stmmac/stmmac_selftests.c | 51 ++++++++++++++++---
drivers/net/phy/phylink.c | 19 +++++++
include/linux/phylink.h | 16 ++++++
4 files changed, 95 insertions(+), 8 deletions(-)
v2:
- Implement pcs_loopback callback in stmmac integrated PCS using
GMAC_AN_CTRL_ELE register bit.
- Add stmmac_selftest_get_pcs() helper to unify PCS lookup across glue
driver PCS and integrated PCS.
- Add NULL check in phylink_pcs_loopback() wrapper.
v1: https://lore.kernel.org/netdev/20260724085224.3321663-1-zxyan0222@gmail.com/
Note on loopback direction:
The pcs_loopback callback uses a simple enable/disable boolean, matching
the existing phy_loopback() API. Direction is not needed at this level:
selftest loopback is always host-side (TX looped back to RX). The
future ethtool user-space loopback API can handle direction selection
at a higher layer.
Note on phylink_set_loopback() vs phylink_pcs_loopback():
This patch follows the same pattern as phy_loopback() - a direct
callback on the PCS object. Keeping the API minimal avoids introducing
a new phylink-level loopback abstraction with location enumeration
before Björn's ethtool loopback series lands upstream. Once that
series is merged, phylink_pcs_loopback() can serve as a building block
for a higher-level phylink_set_loopback() if needed.
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c
index df37af5ab837..90a21a2f7e87 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c
@@ -168,6 +168,22 @@ static void dwmac_integrated_pcs_an_restart(struct phylink_pcs *pcs)
}
}
+static int dwmac_integrated_pcs_loopback(struct phylink_pcs *pcs, bool enable)
+{
+ struct stmmac_pcs *spcs = phylink_pcs_to_stmmac_pcs(pcs);
+ void __iomem *an_control = spcs->base + GMAC_AN_CTRL(0);
+ u32 ctrl;
+
+ ctrl = readl(an_control);
+ if (enable)
+ ctrl |= GMAC_AN_CTRL_ELE;
+ else
+ ctrl &= ~GMAC_AN_CTRL_ELE;
+ writel(ctrl, an_control);
+
+ return 0;
+}
+
static const struct phylink_pcs_ops dwmac_integrated_pcs_ops = {
.pcs_inband_caps = dwmac_integrated_pcs_inband_caps,
.pcs_enable = dwmac_integrated_pcs_enable,
@@ -175,6 +191,7 @@ static const struct phylink_pcs_ops dwmac_integrated_pcs_ops = {
.pcs_get_state = dwmac_integrated_pcs_get_state,
.pcs_config = dwmac_integrated_pcs_config,
.pcs_an_restart = dwmac_integrated_pcs_an_restart,
+ .pcs_loopback = dwmac_integrated_pcs_loopback,
};
void stmmac_integrated_pcs_irq(struct stmmac_priv *priv, u32 status,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index 29e824bd90ca..77a457b2fa5c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -19,6 +19,7 @@
#include <net/udp.h>
#include <net/tc_act/tc_gact.h>
#include "stmmac.h"
+#include "stmmac_pcs.h"
struct stmmachdr {
__be32 version;
@@ -374,23 +375,51 @@ static int stmmac_test_mac_loopback(struct stmmac_priv *priv)
return __stmmac_test_loopback(priv, &attr);
}
+static struct phylink_pcs *stmmac_selftest_get_pcs(struct stmmac_priv *priv)
+{
+ /* Try glue driver's PCS first, then the integrated PCS. */
+ if (priv->hw->phylink_pcs)
+ return priv->hw->phylink_pcs;
+
+ if (priv->integrated_pcs)
+ return &priv->integrated_pcs->pcs;
+
+ return NULL;
+}
+
static int stmmac_test_phy_loopback(struct stmmac_priv *priv)
{
struct stmmac_packet_attrs attr = { };
+ struct phylink_pcs *pcs;
int ret;
- if (!priv->dev->phydev)
- return -EOPNOTSUPP;
+ if (priv->dev->phydev) {
+ ret = phy_loopback(priv->dev->phydev, true, 0);
+ if (ret)
+ return ret;
- ret = phy_loopback(priv->dev->phydev, true, 0);
- if (ret)
+ attr.dst = priv->dev->dev_addr;
+ ret = __stmmac_test_loopback(priv, &attr);
+
+ phy_loopback(priv->dev->phydev, false, 0);
return ret;
+ }
- attr.dst = priv->dev->dev_addr;
- ret = __stmmac_test_loopback(priv, &attr);
+ /* Use PCS loopback for interfaces without an external PHY. */
+ pcs = stmmac_selftest_get_pcs(priv);
+ if (pcs) {
+ ret = phylink_pcs_loopback(pcs, true);
+ if (ret)
+ return ret;
- phy_loopback(priv->dev->phydev, false, 0);
- return ret;
+ attr.dst = priv->dev->dev_addr;
+ ret = __stmmac_test_loopback(priv, &attr);
+
+ phylink_pcs_loopback(pcs, false);
+ return ret;
+ }
+
+ return -EOPNOTSUPP;
}
static int stmmac_test_mmc(struct stmmac_priv *priv)
@@ -1986,6 +2015,9 @@ void stmmac_selftest_run(struct net_device *dev,
ret = -EOPNOTSUPP;
if (dev->phydev)
ret = phy_loopback(dev->phydev, true, 0);
+ else
+ ret = phylink_pcs_loopback(stmmac_selftest_get_pcs(priv),
+ true);
if (!ret)
break;
fallthrough;
@@ -2019,6 +2051,9 @@ void stmmac_selftest_run(struct net_device *dev,
ret = -EOPNOTSUPP;
if (dev->phydev)
ret = phy_loopback(dev->phydev, false, 0);
+ else
+ ret = phylink_pcs_loopback(stmmac_selftest_get_pcs(priv),
+ false);
if (!ret)
break;
fallthrough;
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 59dfe35afa54..69242caffaef 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -997,6 +997,25 @@ int phylink_pcs_pre_init(struct phylink *pl, struct phylink_pcs *pcs)
}
EXPORT_SYMBOL_GPL(phylink_pcs_pre_init);
+/**
+ * phylink_pcs_loopback() - Enable or disable loopback at the PCS
+ * @pcs: a pointer to a &struct phylink_pcs.
+ * @enable: true to enable loopback, false to disable
+ *
+ * Enable or disable loopback mode at the PCS level. This is used by MAC
+ * drivers for selftest purposes when no external PHY is present.
+ *
+ * Returns 0 on success, negative error code on failure.
+ */
+int phylink_pcs_loopback(struct phylink_pcs *pcs, bool enable)
+{
+ if (pcs && pcs->ops->pcs_loopback)
+ return pcs->ops->pcs_loopback(pcs, enable);
+
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(phylink_pcs_loopback);
+
static void phylink_mac_config(struct phylink *pl,
const struct phylink_link_state *state)
{
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 2bc0db3d52ac..66c7016d4acd 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -518,6 +518,7 @@ struct phylink_pcs {
* the MAC.
* @pcs_pre_init: configure PCS components necessary for MAC hardware
* initialization e.g. RX clock for stmmac.
+ * @pcs_loopback: enable/disable loopback mode at the PCS.
*/
struct phylink_pcs_ops {
int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
@@ -542,6 +543,7 @@ struct phylink_pcs_ops {
void (*pcs_disable_eee)(struct phylink_pcs *pcs);
void (*pcs_enable_eee)(struct phylink_pcs *pcs);
int (*pcs_pre_init)(struct phylink_pcs *pcs);
+ int (*pcs_loopback)(struct phylink_pcs *pcs, bool enable);
};
#if 0 /* For kernel-doc purposes only. */
@@ -717,8 +719,22 @@ void pcs_enable_eee(struct phylink_pcs *pcs);
*/
int pcs_pre_init(struct phylink_pcs *pcs);
+/**
+ * pcs_loopback() - Enable or disable loopback at the PCS
+ * @pcs: a pointer to a &struct phylink_pcs.
+ * @enable: true to enable loopback, false to disable
+ *
+ * Enable or disable loopback mode at the PCS level. This is used by MAC
+ * drivers for selftest purposes when no external PHY is present.
+ *
+ * Returns 0 on success, or a negative error code on failure.
+ */
+int pcs_loopback(struct phylink_pcs *pcs, bool enable);
+
#endif
+int phylink_pcs_loopback(struct phylink_pcs *pcs, bool enable);
+
struct phylink *phylink_create(struct phylink_config *,
const struct fwnode_handle *,
phy_interface_t,
base-commit: 1df10cef2d1e7f9f2fb7eddb67fc70d3abf101f9
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support
2026-07-27 9:38 ` [PATCH net-next v2] " Zxyan Zhu
@ 2026-07-27 19:46 ` Andrew Lunn
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2026-07-27 19:46 UTC (permalink / raw)
To: Zxyan Zhu
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
alexandre.torgue, linux, hkallweit1, rmk+kernel,
maxime.chevallier, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, bjorn
> static int stmmac_test_phy_loopback(struct stmmac_priv *priv)
> {
> struct stmmac_packet_attrs attr = { };
> + struct phylink_pcs *pcs;
> int ret;
>
> - if (!priv->dev->phydev)
> - return -EOPNOTSUPP;
> + if (priv->dev->phydev) {
> + ret = phy_loopback(priv->dev->phydev, true, 0);
> + if (ret)
> + return ret;
>
> - ret = phy_loopback(priv->dev->phydev, true, 0);
> - if (ret)
> + attr.dst = priv->dev->dev_addr;
> + ret = __stmmac_test_loopback(priv, &attr);
> +
> + phy_loopback(priv->dev->phydev, false, 0);
> return ret;
> + }
>
> - attr.dst = priv->dev->dev_addr;
> - ret = __stmmac_test_loopback(priv, &attr);
> + /* Use PCS loopback for interfaces without an external PHY. */
It should not be an either/or. You can have a PCS and an external PHY.
You might actually want to test both.
So i think you want stmmac_test_phy_loopback() and
stmmac_test_pcs_loopback() with the shared code in a helper.
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support
2026-07-27 12:07 [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support Zxyan Zhu
@ 2026-07-28 8:41 ` Maxime Chevallier
2026-07-28 13:02 ` Oleksij Rempel
2026-07-28 13:22 ` Zxyan Zhu
0 siblings, 2 replies; 6+ messages in thread
From: Maxime Chevallier @ 2026-07-28 8:41 UTC (permalink / raw)
To: Zxyan Zhu, andrew+netdev, rmk+kernel, alexandre.torgue
Cc: davem, edumazet, kuba, pabeni, hkallweit1, mcoquelin.stm32,
netdev, linux-stm32, linux-arm-kernel, linux-kernel,
Oleksij Rempel
Hi,
On 7/27/26 14:07, Zxyan Zhu wrote:
> Some Ethernet MAC drivers (such as stmmac) need to perform PCS-level
> loopback for selftest purposes when no external PHY is present. Add a
> new phylink_pcs_loopback() method that allows MAC drivers to request
> PCS loopback mode through the phylink framework.
>
> Implement the pcs_loopback callback in the stmmac integrated PCS
> using the GMAC_AN_CTRL_ELE register bit. Add a helper function
> stmmac_selftest_get_pcs() in stmmac selftests to unify PCS lookup
> across glue driver PCS and integrated PCS. Update the selftest
> enable/disable paths to use the new helper.
>
> Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>
I'm actually seriously wondering if we shouldn't just stick to MAC loopback only
for stmmac selftests. I even have a patch ready to send for that, as I've
been struggling with selftests in the past days because some PHYs will
either stop their RXC while in loopback, or bring the carrier down which
makes the dev_xmit drop the packets we're sending to ourselves.
Using an external loopnback (in PCS, in PHY, somewhere else...) doesn't
bring anything to the table given what we are testing today, which is
internal stmmac behaviour. The MAC loopback (on dwmac1000 and dwmac4 at
least) happends at the GMII level, so everything we are currently testing
happens before that.
If the goal is to validate what comes after (RGMII, PCS behaviour and so on),
I think we should instead add some other, more generic selftests that aren't
stmmac specific, that we could run on any netdev, such as the ones Oleksij
has added in:
3e1e58d64c3d net: add generic selftest support
Maxime
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support
2026-07-28 8:41 ` Maxime Chevallier
@ 2026-07-28 13:02 ` Oleksij Rempel
2026-07-28 13:22 ` Zxyan Zhu
1 sibling, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2026-07-28 13:02 UTC (permalink / raw)
To: Maxime Chevallier
Cc: Zxyan Zhu, andrew+netdev, rmk+kernel, alexandre.torgue, davem,
edumazet, kuba, pabeni, hkallweit1, mcoquelin.stm32, netdev,
linux-stm32, linux-arm-kernel, linux-kernel
On Tue, Jul 28, 2026 at 10:41:12AM +0200, Maxime Chevallier wrote:
> Hi,
>
> On 7/27/26 14:07, Zxyan Zhu wrote:
> > Some Ethernet MAC drivers (such as stmmac) need to perform PCS-level
> > loopback for selftest purposes when no external PHY is present. Add a
> > new phylink_pcs_loopback() method that allows MAC drivers to request
> > PCS loopback mode through the phylink framework.
> >
> > Implement the pcs_loopback callback in the stmmac integrated PCS
> > using the GMAC_AN_CTRL_ELE register bit. Add a helper function
> > stmmac_selftest_get_pcs() in stmmac selftests to unify PCS lookup
> > across glue driver PCS and integrated PCS. Update the selftest
> > enable/disable paths to use the new helper.
> >
> > Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>
>
> I'm actually seriously wondering if we shouldn't just stick to MAC loopback only
> for stmmac selftests. I even have a patch ready to send for that, as I've
> been struggling with selftests in the past days because some PHYs will
> either stop their RXC while in loopback, or bring the carrier down which
> makes the dev_xmit drop the packets we're sending to ourselves.
>
> Using an external loopnback (in PCS, in PHY, somewhere else...) doesn't
> bring anything to the table given what we are testing today, which is
> internal stmmac behaviour. The MAC loopback (on dwmac1000 and dwmac4 at
> least) happends at the GMII level, so everything we are currently testing
> happens before that.
>
> If the goal is to validate what comes after (RGMII, PCS behaviour and so on),
> I think we should instead add some other, more generic selftests that aren't
> stmmac specific, that we could run on any netdev, such as the ones Oleksij
> has added in:
>
> 3e1e58d64c3d net: add generic selftest support
Ack, it is better to push the effort towards generic selftests.
Best Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support
2026-07-28 8:41 ` Maxime Chevallier
2026-07-28 13:02 ` Oleksij Rempel
@ 2026-07-28 13:22 ` Zxyan Zhu
1 sibling, 0 replies; 6+ messages in thread
From: Zxyan Zhu @ 2026-07-28 13:22 UTC (permalink / raw)
To: maxime.chevallier
Cc: andrew+netdev, rmk+kernel, alexandre.torgue, davem, edumazet,
kuba, pabeni, hkallweit1, mcoquelin.stm32, netdev, linux-stm32,
linux-arm-kernel, linux-kernel
On Tue, Jul 28, 2026 at 10:41:12AM +0200, Maxime Chevallier wrote:
> I'm actually seriously wondering if we shouldn't just stick to MAC
> loopback only for stmmac selftests. [...]
> Using an external loopback (in PCS, in PHY, somewhere else...) doesn't
> bring anything to the table given what we are testing today, which is
> internal stmmac behaviour. The MAC loopback happens at the GMII level,
> so everything we are currently testing happens before that.
You're right. MAC loopback at the GMII level already covers everything
stmmac selftests actually test (DMA, filtering, VLAN, checksum offload,
etc.). PCS acts only as external transceivers beyond the MAC boundary
and do not bring additional test coverage.
Given that, I will drop this PCS loopback patch series.
Thanks for the explanation!
Zxyan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-28 13:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-27 12:07 [PATCH net-next v2] net: phylink: add phylink_pcs_loopback() method for PCS loopback support Zxyan Zhu
2026-07-28 8:41 ` Maxime Chevallier
2026-07-28 13:02 ` Oleksij Rempel
2026-07-28 13:22 ` Zxyan Zhu
-- strict thread matches above, loose matches on Subject: below --
2026-07-24 8:52 [PATCH net-next] " Zxyan Zhu
2026-07-27 9:38 ` [PATCH net-next v2] " Zxyan Zhu
2026-07-27 19:46 ` Andrew Lunn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox