[PATCH net-next v5 3/7] net: stmmac: Make stmmac_xpcs_setup() generic to all PCS devices

From: Romain Gantois
Date: Tue Apr 30 2024 - 03:30:33 EST


From: Serge Semin <fancer.lancer@xxxxxxxxx>

A pcs_init() callback will be introduced to stmmac in a future patch. This
new function will be called during the hardware initialization phase.
Instead of separately initializing XPCS and PCS components, let's group all
PCS-related hardware initialization logic in the current
stmmac_xpcs_setup() function.

Rename stmmac_xpcs_setup() to stmmac_pcs_setup() and move the conditional
call to stmmac_xpcs_setup() inside the function itself.

Signed-off-by: Serge Semin <fancer.lancer@xxxxxxxxx>
Co-developed-by: Romain Gantois <romain.gantois@xxxxxxxxxxx>
Signed-off-by: Romain Gantois <romain.gantois@xxxxxxxxxxx>
---
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 10 ++++----
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 28 ++++++++++++++---------
3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 7e0d727ed795b..f275f2fd91c3e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -360,7 +360,7 @@ enum stmmac_state {
int stmmac_mdio_unregister(struct net_device *ndev);
int stmmac_mdio_register(struct net_device *ndev);
int stmmac_mdio_reset(struct mii_bus *mii);
-int stmmac_xpcs_setup(struct mii_bus *mii);
+int stmmac_pcs_setup(struct net_device *ndev);
void stmmac_pcs_clean(struct stmmac_priv *priv);
void stmmac_set_ethtool_ops(struct net_device *netdev);

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 2a55c5d07f6b8..72f4deda76407 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -7754,11 +7754,9 @@ int stmmac_dvr_probe(struct device *device,
if (priv->plat->speed_mode_2500)
priv->plat->speed_mode_2500(ndev, priv->plat->bsp_priv);

- if (priv->plat->mdio_bus_data && priv->plat->mdio_bus_data->has_xpcs) {
- ret = stmmac_xpcs_setup(priv->mii);
- if (ret)
- goto error_xpcs_setup;
- }
+ ret = stmmac_pcs_setup(ndev);
+ if (ret)
+ goto error_pcs_setup;

ret = stmmac_phy_setup(priv);
if (ret) {
@@ -7791,7 +7789,7 @@ int stmmac_dvr_probe(struct device *device,
phylink_destroy(priv->phylink);
error_phy_setup:
stmmac_pcs_clean(priv);
-error_xpcs_setup:
+error_pcs_setup:
if (priv->hw->pcs != STMMAC_PCS_TBI &&
priv->hw->pcs != STMMAC_PCS_RTBI)
stmmac_mdio_unregister(ndev);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 508bd39cbe2b3..af8ad9768da10 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -495,31 +495,37 @@ int stmmac_mdio_reset(struct mii_bus *bus)
return 0;
}

-int stmmac_xpcs_setup(struct mii_bus *bus)
+int stmmac_pcs_setup(struct net_device *ndev)
{
- struct net_device *ndev = bus->priv;
struct stmmac_priv *priv;
struct dw_xpcs *xpcs;
+ int ret = -ENODEV;
int mode, addr;

priv = netdev_priv(ndev);
mode = priv->plat->phy_interface;

- /* Try to probe the XPCS by scanning all addresses. */
- for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
- xpcs = xpcs_create_mdiodev(bus, addr, mode);
- if (IS_ERR(xpcs))
- continue;
+ if (priv->plat->mdio_bus_data && priv->plat->mdio_bus_data->has_xpcs) {
+ /* Try to probe the XPCS by scanning all addresses */
+ for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
+ xpcs = xpcs_create_mdiodev(priv->mii, addr, mode);
+ if (IS_ERR(xpcs))
+ continue;

- priv->hw->xpcs = xpcs;
- break;
+ ret = 0;
+ break;
+ }
+ } else {
+ return 0;
}

- if (!priv->hw->xpcs) {
+ if (ret) {
dev_warn(priv->device, "No xPCS found\n");
- return -ENODEV;
+ return ret;
}

+ priv->hw->xpcs = xpcs;
+
return 0;
}


--
2.44.0