diff mbox series

[net-next,1/2] net: altera: tse: add a dedicated helper for reset

Message ID 20220823140517.3091239-2-maxime.chevallier@bootlin.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: altera: tse: phylink conversion | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 85 this patch: 85
netdev/cc_maintainers warning 1 maintainers not CCed: joyce.ooi@intel.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 85 this patch: 85
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 53 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Maxime Chevallier Aug. 23, 2022, 2:05 p.m. UTC
Performing a soft reset on the PCS block for altera TSE re-initializes
the decoding logic, and should be done when reconfiguring the link.

Move the reset logic to a dedicated helper, to ease transition to
phylink.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/ethernet/altera/altera_tse_main.c | 35 +++++++++++--------
 1 file changed, 20 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 8c5828582c21..ad59b0befc18 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -107,6 +107,25 @@  static int sgmii_pcs_scratch_test(struct altera_tse_private *priv, u16 value)
 	return (sgmii_pcs_read(priv, SGMII_PCS_SCRATCH) == value);
 }
 
+static int sgmii_pcs_reset(struct altera_tse_private *priv)
+{
+	u16 bmcr;
+	int i = 0;
+
+	/* Reset PCS block */
+	bmcr = sgmii_pcs_read(priv, MII_BMCR);
+	bmcr |= BMCR_RESET;
+	sgmii_pcs_write(priv, MII_BMCR, bmcr);
+
+	for (i = 0; i < SGMII_PCS_SW_RESET_TIMEOUT; i++) {
+		if (!(sgmii_pcs_read(priv, MII_BMCR) & BMCR_RESET))
+			return 0;
+		udelay(1);
+	}
+
+	return -ETIMEDOUT;
+}
+
 /* MDIO specific functions
  */
 static int altera_tse_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
@@ -1092,7 +1111,6 @@  static void tse_set_rx_mode(struct net_device *dev)
 static int init_sgmii_pcs(struct net_device *dev)
 {
 	struct altera_tse_private *priv = netdev_priv(dev);
-	int n;
 	unsigned int tmp_reg = 0;
 
 	if (priv->phy_iface != PHY_INTERFACE_MODE_SGMII)
@@ -1131,20 +1149,7 @@  static int init_sgmii_pcs(struct net_device *dev)
 	tmp_reg |= (BMCR_SPEED1000 | BMCR_FULLDPLX | BMCR_ANENABLE);
 	sgmii_pcs_write(priv, MII_BMCR, tmp_reg);
 
-	/* Reset PCS block */
-	tmp_reg |= BMCR_RESET;
-	sgmii_pcs_write(priv, MII_BMCR, tmp_reg);
-	for (n = 0; n < SGMII_PCS_SW_RESET_TIMEOUT; n++) {
-		if (!(sgmii_pcs_read(priv, MII_BMCR) & BMCR_RESET)) {
-			netdev_info(dev, "SGMII PCS block initialised OK\n");
-			return 0;
-		}
-		udelay(1);
-	}
-
-	/* We failed to reset the block, return a timeout */
-	netdev_err(dev, "SGMII PCS block reset failed.\n");
-	return -ETIMEDOUT;
+	return sgmii_pcs_reset(priv);
 }
 
 /* Open and initialize the interface