netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Claudiu Manoil <claudiu.manoil@nxp.com>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Vladimir Oltean <vladimir.oltean@nxp.com>
Subject: [PATCH net-next 2/4] enetc: Clean up serdes configuration
Date: Mon,  5 Oct 2020 17:28:16 +0300	[thread overview]
Message-ID: <20201005142818.15110-3-claudiu.manoil@nxp.com> (raw)
In-Reply-To: <20201005142818.15110-1-claudiu.manoil@nxp.com>

Decouple internal mdio bus creation from serdes
configuration, as a prerequisite to offloading
serdes configuration to a different module.
Group together mdio bus creation routines, cleanup.

Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com>
---
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 101 +++++++++---------
 1 file changed, 48 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 64596731c1c9..6c533bf9e615 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -775,25 +775,7 @@ static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
 	return 0;
 }
 
-static int enetc_mdiobus_create(struct enetc_pf *pf)
-{
-	struct device *dev = &pf->si->pdev->dev;
-	struct device_node *mdio_np;
-	int err;
-
-	mdio_np = of_get_child_by_name(dev->of_node, "mdio");
-	if (mdio_np) {
-		err = enetc_mdio_probe(pf, mdio_np);
-
-		of_node_put(mdio_np);
-		if (err)
-			return err;
-	}
-
-	return 0;
-}
-
-static void enetc_mdiobus_destroy(struct enetc_pf *pf)
+static void enetc_mdio_remove(struct enetc_pf *pf)
 {
 	if (pf->mdio)
 		mdiobus_unregister(pf->mdio);
@@ -844,7 +826,7 @@ static void enetc_of_put_phy(struct enetc_pf *pf)
 		of_node_put(pf->phy_node);
 }
 
-static int enetc_imdio_init(struct enetc_pf *pf, bool is_c45)
+static int enetc_imdio_create(struct enetc_pf *pf)
 {
 	struct device *dev = &pf->si->pdev->dev;
 	struct enetc_mdio_priv *mdio_priv;
@@ -872,7 +854,7 @@ static int enetc_imdio_init(struct enetc_pf *pf, bool is_c45)
 		goto free_mdio_bus;
 	}
 
-	pcs = get_phy_device(bus, 0, is_c45);
+	pcs = get_phy_device(bus, 0, pf->if_mode == PHY_INTERFACE_MODE_USXGMII);
 	if (IS_ERR(pcs)) {
 		err = PTR_ERR(pcs);
 		dev_err(dev, "cannot get internal PCS PHY (%d)\n", err);
@@ -901,6 +883,45 @@ static void enetc_imdio_remove(struct enetc_pf *pf)
 	}
 }
 
+static bool enetc_port_has_pcs(struct enetc_pf *pf)
+{
+	return (pf->if_mode == PHY_INTERFACE_MODE_SGMII ||
+		pf->if_mode == PHY_INTERFACE_MODE_2500BASEX ||
+		pf->if_mode == PHY_INTERFACE_MODE_USXGMII);
+}
+
+static int enetc_mdiobus_create(struct enetc_pf *pf)
+{
+	struct device *dev = &pf->si->pdev->dev;
+	struct device_node *mdio_np;
+	int err;
+
+	mdio_np = of_get_child_by_name(dev->of_node, "mdio");
+	if (mdio_np) {
+		err = enetc_mdio_probe(pf, mdio_np);
+
+		of_node_put(mdio_np);
+		if (err)
+			return err;
+	}
+
+	if (enetc_port_has_pcs(pf)) {
+		err = enetc_imdio_create(pf);
+		if (err) {
+			enetc_mdio_remove(pf);
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+static void enetc_mdiobus_destroy(struct enetc_pf *pf)
+{
+	enetc_mdio_remove(pf);
+	enetc_imdio_remove(pf);
+}
+
 static void enetc_configure_sgmii(struct phy_device *pcs)
 {
 	/* SGMII spec requires tx_config_Reg[15:0] to be exactly 0x4001
@@ -940,22 +961,9 @@ static void enetc_configure_usxgmii(struct phy_device *pcs)
 		      BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART);
 }
 
-static int enetc_configure_serdes(struct enetc_ndev_priv *priv)
+static void enetc_configure_serdes(struct enetc_pf *pf)
 {
-	bool is_c45 = priv->if_mode == PHY_INTERFACE_MODE_USXGMII;
-	struct enetc_pf *pf = enetc_si_priv(priv->si);
-	int err;
-
-	if (priv->if_mode != PHY_INTERFACE_MODE_SGMII &&
-	    priv->if_mode != PHY_INTERFACE_MODE_2500BASEX &&
-	    priv->if_mode != PHY_INTERFACE_MODE_USXGMII)
-		return 0;
-
-	err = enetc_imdio_init(pf, is_c45);
-	if (err)
-		return err;
-
-	switch (priv->if_mode) {
+	switch (pf->if_mode) {
 	case PHY_INTERFACE_MODE_SGMII:
 		enetc_configure_sgmii(pf->pcs);
 		break;
@@ -966,18 +974,9 @@ static int enetc_configure_serdes(struct enetc_ndev_priv *priv)
 		enetc_configure_usxgmii(pf->pcs);
 		break;
 	default:
-		dev_err(&pf->si->pdev->dev, "Unsupported link mode %s\n",
-			phy_modes(priv->if_mode));
+		dev_dbg(&pf->si->pdev->dev, "Unsupported link mode %s\n",
+			phy_modes(pf->if_mode));
 	}
-
-	return 0;
-}
-
-static void enetc_teardown_serdes(struct enetc_ndev_priv *priv)
-{
-	struct enetc_pf *pf = enetc_si_priv(priv->si);
-
-	enetc_imdio_remove(pf);
 }
 
 static int enetc_pf_probe(struct pci_dev *pdev,
@@ -1052,9 +1051,8 @@ static int enetc_pf_probe(struct pci_dev *pdev,
 		if (err)
 			goto err_mdiobus_create;
 
-		err = enetc_configure_serdes(priv);
-		if (err)
-			goto err_configure_serdes;
+		if (enetc_port_has_pcs(pf))
+			enetc_configure_serdes(pf);
 
 		enetc_mac_config(&pf->si->hw, pf->if_mode);
 	}
@@ -1068,8 +1066,6 @@ static int enetc_pf_probe(struct pci_dev *pdev,
 	return 0;
 
 err_reg_netdev:
-	enetc_teardown_serdes(priv);
-err_configure_serdes:
 	enetc_mdiobus_destroy(pf);
 err_mdiobus_create:
 	enetc_of_put_phy(pf);
@@ -1094,7 +1090,6 @@ static void enetc_pf_remove(struct pci_dev *pdev)
 	struct enetc_ndev_priv *priv;
 
 	priv = netdev_priv(si->ndev);
-	enetc_teardown_serdes(priv);
 	enetc_mdiobus_destroy(pf);
 	enetc_of_put_phy(pf);
 
-- 
2.17.1


  parent reply	other threads:[~2020-10-05 14:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05 14:28 [PATCH net-next 0/4] enetc: Migrate to PHYLINK and PCS_LYNX Claudiu Manoil
2020-10-05 14:28 ` [PATCH net-next 1/4] enetc: Clean up MAC and link configuration Claudiu Manoil
2020-10-05 14:28 ` Claudiu Manoil [this message]
2020-10-05 14:28 ` [PATCH net-next 3/4] arm64: dts: fsl-ls1028a-rdb: Specify in-band mode for ENETC port 0 Claudiu Manoil
2020-10-05 14:28 ` [PATCH net-next 4/4] enetc: Migrate to PHYLINK and PCS_LYNX Claudiu Manoil
2020-10-06  6:09   ` Ioana Ciornei
2020-10-07 10:06     ` Claudiu Manoil

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=20201005142818.15110-3-claudiu.manoil@nxp.com \
    --to=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=vladimir.oltean@nxp.com \
    /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;
as well as URLs for NNTP newsgroup(s).