net: stmmac: Add dedicated XPCS cleanup method
authorSerge Semin <fancer.lancer@gmail.com>
Mon, 13 May 2024 07:25:13 +0000 (09:25 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 14 May 2024 00:19:59 +0000 (17:19 -0700)
Currently the XPCS handler destruction is performed in the
stmmac_mdio_unregister() method. It doesn't look good because the handler
isn't originally created in the corresponding protagonist
stmmac_mdio_unregister(), but in the stmmac_xpcs_setup() function. In
order to have more coherent MDIO and XPCS setup/cleanup procedures,
let's move the DW XPCS destruction to the dedicated stmmac_pcs_clean()
method.

This method will also be used to cleanup PCS hardware using the
pcs_exit() callback that will be introduced to stmmac in a subsequent
patch.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
Co-developed-by: Romain Gantois <romain.gantois@bootlin.com>
Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>
Link: https://lore.kernel.org/r/20240513-rzn1-gmac1-v7-2-6acf58b5440d@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac.h
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c

index dddcaa9220cc386a3eca5cfc5e09aa7e84bbeb7b..badfe686a5702c48e3a0ab72f21145101c11364a 100644 (file)
@@ -361,6 +361,7 @@ 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);
+void stmmac_pcs_clean(struct net_device *ndev);
 void stmmac_set_ethtool_ops(struct net_device *netdev);
 
 int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags);
index 3d828904db0d38ad73c5274ce7c32d51a6940267..0ac99c132733d4e9eb4eee34790b308c0633ef0c 100644 (file)
@@ -7789,8 +7789,9 @@ int stmmac_dvr_probe(struct device *device,
 
 error_netdev_register:
        phylink_destroy(priv->phylink);
-error_xpcs_setup:
 error_phy_setup:
+       stmmac_pcs_clean(ndev);
+error_xpcs_setup:
        if (priv->hw->pcs != STMMAC_PCS_TBI &&
            priv->hw->pcs != STMMAC_PCS_RTBI)
                stmmac_mdio_unregister(ndev);
@@ -7832,6 +7833,9 @@ void stmmac_dvr_remove(struct device *dev)
        if (priv->plat->stmmac_rst)
                reset_control_assert(priv->plat->stmmac_rst);
        reset_control_assert(priv->plat->stmmac_ahb_rst);
+
+       stmmac_pcs_clean(ndev);
+
        if (priv->hw->pcs != STMMAC_PCS_TBI &&
            priv->hw->pcs != STMMAC_PCS_RTBI)
                stmmac_mdio_unregister(ndev);
index 0542cfd1817e62a50adb9a739625ac9c04d40b33..73ba9901a4439e3e97d526adf7ecfb11edbda42f 100644 (file)
@@ -523,6 +523,17 @@ int stmmac_xpcs_setup(struct mii_bus *bus)
        return 0;
 }
 
+void stmmac_pcs_clean(struct net_device *ndev)
+{
+       struct stmmac_priv *priv = netdev_priv(ndev);
+
+       if (!priv->hw->xpcs)
+               return;
+
+       xpcs_destroy(priv->hw->xpcs);
+       priv->hw->xpcs = NULL;
+}
+
 /**
  * stmmac_mdio_register
  * @ndev: net device structure
@@ -679,9 +690,6 @@ int stmmac_mdio_unregister(struct net_device *ndev)
        if (!priv->mii)
                return 0;
 
-       if (priv->hw->xpcs)
-               xpcs_destroy(priv->hw->xpcs);
-
        mdiobus_unregister(priv->mii);
        priv->mii->priv = NULL;
        mdiobus_free(priv->mii);