All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
@ 2018-07-13 14:40 Pankaj Bansal
  2018-07-13 14:40 ` [U-Boot] [PATCH 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
                   ` (7 more replies)
  0 siblings, 8 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-13 14:40 UTC (permalink / raw)
  To: u-boot

This patch set adds support of multiple phys for one dpmac

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where there
are sometimes two phy devices for one dpmac. One phy for TX lanes and one
phy for RX lanes. To handle such cases, add the support for multiple phys
in ethernet driver. The ethernet link is up if all the phy devices
connected to one dpmac report link up.
also the link capabilities are limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G without
autoneg and other operate at 1G with autoneg. Then the ethernet interface
will operate at 1G without autoneg.

Pankaj Bansal (6):
  driver: net: fsl-mc: modify the label name
  driver: net: fsl-mc: remove unused strcture elements
  driver: net: fsl-mc: fix error handing in init_phy
  driver: net: fsl-mc: Modify the dpmac link detection method
  driver: net: fsl-mc: initialize dpmac irrespective of phy
  driver: net: fsl-mc: Add support of multiple phys for dpmac

 board/freescale/ls1088a/eth_ls1088aqds.c   |  18 +--
 board/freescale/ls1088a/eth_ls1088ardb.c   |  21 +--
 board/freescale/ls2080aqds/eth.c           |  26 +--
 board/freescale/ls2080ardb/eth_ls2080rdb.c |  24 +--
 drivers/net/fsl-mc/mc.c                    |   6 +-
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 180 +++++++++++++--------
 drivers/net/ldpaa_eth/ldpaa_eth.h          |   1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c        |  49 ++++--
 include/fsl-mc/ldpaa_wriop.h               |  22 +--
 9 files changed, 209 insertions(+), 138 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 1/6] driver: net: fsl-mc: modify the label name
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
@ 2018-07-13 14:40 ` Pankaj Bansal
  2018-07-25 19:39   ` Joe Hershberger
  2018-07-13 14:40 ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-13 14:40 UTC (permalink / raw)
  To: u-boot

The goto label name is misspelled it should be DPMAC not DPAMC

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 drivers/net/ldpaa_eth/ldpaa_eth.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 79facb4a44..18bc05790a 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -413,7 +413,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		if (err) {
 			printf("%s: Could not initialize\n",
 			       priv->phydev->dev->name);
-			goto err_dpamc_bind;
+			goto err_dpmac_bind;
 		}
 	}
 #else
@@ -441,13 +441,13 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (!priv->phydev->link) {
 		printf("%s: No link.\n", priv->phydev->dev->name);
 		err = -1;
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
 	if (err)
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 
 	/* DPNI initialization */
 	err = ldpaa_dpni_setup(priv);
@@ -540,7 +540,7 @@ err_dpni_bind:
 err_dpbp_setup:
 	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
 err_dpni_setup:
-err_dpamc_bind:
+err_dpmac_bind:
 	dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
 	dpmac_destroy(dflt_mc_io,
 		      dflt_dprc_handle,
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  2018-07-13 14:40 ` [U-Boot] [PATCH 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
@ 2018-07-13 14:40 ` Pankaj Bansal
  2018-07-25 20:03   ` Joe Hershberger
  2018-07-13 14:40 ` [U-Boot] [PATCH 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-13 14:40 UTC (permalink / raw)
  To: u-boot

The phydev structure is present in both ldpaa_eth_priv and
wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used

As the phydev is created based on phy_addr and bus members of
wriop_dpmac_info, it is appropriate to keep phydev in wriop_dpmac_info.

Also phy_regs is not being used, therefore remove it

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 drivers/net/ldpaa_eth/ldpaa_eth.c   | 57 +++++++++++++++------------
 drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
 include/fsl-mc/ldpaa_wriop.h        |  1 -
 4 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 18bc05790a..fbc724fc33 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
 		return -1;
 	}
 
-	priv->phydev = phydev;
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
 	return phy_config(phydev);
 }
@@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct mii_dev *bus;
 	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
+	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_dpmac_setup;
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev) {
-		err = phy_startup(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n",
-			       priv->phydev->dev->name);
+			       phydev->dev->name);
 			goto err_dpmac_bind;
 		}
 	}
 #else
-	priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(priv->phydev, 0, sizeof(struct phy_device));
+	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
+	memset(phydev, 0, sizeof(struct phy_device));
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	priv->phydev->speed = SPEED_1000;
-	priv->phydev->link = 1;
-	priv->phydev->duplex = DUPLEX_FULL;
+	phydev->speed = SPEED_1000;
+	phydev->link = 1;
+	phydev->duplex = DUPLEX_FULL;
 #endif
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	enet_if = wriop_get_enet_if(priv->dpmac_id);
 	if ((bus == NULL) &&
 	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		priv->phydev = (struct phy_device *)
+		phydev = (struct phy_device *)
 				malloc(sizeof(struct phy_device));
-		memset(priv->phydev, 0, sizeof(struct phy_device));
+		memset(phydev, 0, sizeof(struct phy_device));
+		wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-		priv->phydev->speed = SPEED_10000;
-		priv->phydev->link = 1;
-		priv->phydev->duplex = DUPLEX_FULL;
+		phydev->speed = SPEED_10000;
+		phydev->link = 1;
+		phydev->duplex = DUPLEX_FULL;
 	}
 
-	if (!priv->phydev->link) {
-		printf("%s: No link.\n", priv->phydev->dev->name);
+	if (!phydev->link) {
+		printf("%s: No link.\n", phydev->dev->name);
 		err = -1;
 		goto err_dpmac_bind;
 	}
@@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = priv->phydev->speed;
+	dpmac_link_state.rate = phydev->speed;
 
-	if (priv->phydev->autoneg == AUTONEG_DISABLE)
+	if (phydev->autoneg == AUTONEG_DISABLE)
 		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
 	else
 		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
 
-	if (priv->phydev->duplex == DUPLEX_HALF)
+	if (phydev->duplex == DUPLEX_HALF)
 		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
 
-	dpmac_link_state.up = priv->phydev->link;
+	dpmac_link_state.up = phydev->link;
 
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
@@ -530,7 +534,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return priv->phydev->link;
+	return phydev->link;
 
 err_qdid:
 err_get_queue:
@@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 #ifdef CONFIG_PHYLIB
 	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
 #endif
+	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -588,11 +593,13 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev && bus != NULL)
-		phy_shutdown(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev && bus != NULL)
+		phy_shutdown(phydev);
 	else {
-		free(priv->phydev);
-		priv->phydev = NULL;
+		free(phydev);
+		phydev = NULL;
+		wriop_set_phy_dev(priv->dpmac_id, phydev);
 	}
 #endif
 
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h b/drivers/net/ldpaa_eth/ldpaa_eth.h
index ee784a55ee..3f9154b5bb 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.h
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
@@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
 	uint16_t tx_flow_id;
 
 	enum ldpaa_eth_type type;	/* 1G or 10G ethernet */
-	struct phy_device *phydev;
 };
 
 struct dprc_endpoint dpmac_endpoint;
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index 0731a795c8..afbb1ca91e 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
 	dpmac_info[dpmac_id].phy_addr = -1;
+	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -42,6 +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 	dpmac_info[dpmac_id].id = dpmac_id;
 	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
+	dpmac_info[dpmac_id].phydev = NULL;
 }
 
 
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 07e5130264..8971c6c55b 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -41,7 +41,6 @@ struct wriop_dpmac_info {
 	u8 id;
 	u8 board_mux;
 	int phy_addr;
-	void *phy_regs;
 	phy_interface_t enet_if;
 	struct phy_device *phydev;
 	struct mii_dev *bus;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 3/6] driver: net: fsl-mc: fix error handing in init_phy
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  2018-07-13 14:40 ` [U-Boot] [PATCH 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
  2018-07-13 14:40 ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-07-13 14:40 ` Pankaj Bansal
  2018-07-25 20:04   ` Joe Hershberger
  2018-07-13 14:40 ` [U-Boot] [PATCH 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-13 14:40 UTC (permalink / raw)
  To: u-boot

if an error occurs during init_phy, we should free the phydev structure
which has been allocated by phy_connect.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 drivers/net/ldpaa_eth/ldpaa_eth.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index fbc724fc33..8fcb948ee8 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,6 +23,7 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
+	int ret;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
@@ -37,7 +38,15 @@ static int init_phy(struct eth_device *dev)
 
 	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	return phy_config(phydev);
+	ret = phy_config(phydev);
+
+	if (ret) {
+		free(phydev);
+		phydev = NULL;
+		wriop_set_phy_dev(priv->dpmac_id, phydev);
+	}
+
+	return ret;
 }
 #endif
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 4/6] driver: net: fsl-mc: Modify the dpmac link detection method
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
                   ` (2 preceding siblings ...)
  2018-07-13 14:40 ` [U-Boot] [PATCH 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
@ 2018-07-13 14:40 ` Pankaj Bansal
  2018-07-25 20:13   ` Joe Hershberger
  2018-07-13 14:40 ` [U-Boot] [PATCH 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-13 14:40 UTC (permalink / raw)
  To: u-boot

when there is no phy present for a dpmac, a dummy phy device is created.
when we move to multiple phy method, we need to create as many dummy phy
devices.

Change this method so that we don't need to create dummy phy devices.
We always report linkup if no phy is present.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 drivers/net/ldpaa_eth/ldpaa_eth.c | 121 +++++++++++++---------------
 1 file changed, 58 insertions(+), 63 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 8fcb948ee8..d2a6d90f18 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -386,6 +386,60 @@ error:
 	return err;
 }
 
+static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
+				 struct dpmac_link_state *state)
+{
+	struct phy_device *phydev = NULL;
+	phy_interface_t enet_if;
+	int err;
+
+	/* let's start off with maximum capabilities
+	 */
+	enet_if = wriop_get_enet_if(priv->dpmac_id);
+	switch (enet_if) {
+	case PHY_INTERFACE_MODE_XGMII:
+		state->rate = SPEED_10000;
+		break;
+	default:
+		state->rate = SPEED_1000;
+		break;
+	}
+	state->up = 1;
+
+#ifdef CONFIG_PHYLIB
+	state->options |= DPMAC_LINK_OPT_AUTONEG;
+
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
+		if (err) {
+			printf("%s: Could not initialize\n", phydev->dev->name);
+			state->up = 0;
+		}
+		if (phydev->link == 1) {
+			state->rate = state->rate < phydev->speed ?
+				      state->rate : phydev->speed;
+			if (!phydev->duplex)
+				state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
+			if (!phydev->autoneg)
+				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+		} else {
+			state->up = 0;
+		}
+	}
+#endif
+	if (!phydev)
+		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+
+	if (state->up == 0) {
+		state->rate = 0;
+		state->options = 0;
+		return -1;
+	}
+
+	return 0;
+}
+
 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
@@ -394,10 +448,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct dpni_link_state link_state;
 #endif
 	int err = 0;
-	struct mii_dev *bus;
-	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
-	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -417,45 +468,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (err < 0)
 		goto err_dpmac_setup;
 
-#ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
-		err = phy_startup(phydev);
-		if (err) {
-			printf("%s: Could not initialize\n",
-			       phydev->dev->name);
-			goto err_dpmac_bind;
-		}
-	}
-#else
-	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(phydev, 0, sizeof(struct phy_device));
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-	phydev->speed = SPEED_1000;
-	phydev->link = 1;
-	phydev->duplex = DUPLEX_FULL;
-#endif
-
-	bus = wriop_get_mdio(priv->dpmac_id);
-	enet_if = wriop_get_enet_if(priv->dpmac_id);
-	if ((bus == NULL) &&
-	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		phydev = (struct phy_device *)
-				malloc(sizeof(struct phy_device));
-		memset(phydev, 0, sizeof(struct phy_device));
-		wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-		phydev->speed = SPEED_10000;
-		phydev->link = 1;
-		phydev->duplex = DUPLEX_FULL;
-	}
-
-	if (!phydev->link) {
-		printf("%s: No link.\n", phydev->dev->name);
-		err = -1;
+	err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
+	if (err < 0)
 		goto err_dpmac_bind;
-	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
@@ -489,18 +504,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = phydev->speed;
-
-	if (phydev->autoneg == AUTONEG_DISABLE)
-		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
-	else
-		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
-
-	if (phydev->duplex == DUPLEX_HALF)
-		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
-
-	dpmac_link_state.up = phydev->link;
-
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
 	if (err < 0) {
@@ -543,7 +546,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return phydev->link;
+	return dpmac_link_state.up;
 
 err_qdid:
 err_get_queue:
@@ -566,9 +569,6 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
-#ifdef CONFIG_PHYLIB
-	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
-#endif
 	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
@@ -603,13 +603,8 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 
 #ifdef CONFIG_PHYLIB
 	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev && bus != NULL)
+	if (phydev)
 		phy_shutdown(phydev);
-	else {
-		free(phydev);
-		phydev = NULL;
-		wriop_set_phy_dev(priv->dpmac_id, phydev);
-	}
 #endif
 
 	/* Free DPBP handle and reset. */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
                   ` (3 preceding siblings ...)
  2018-07-13 14:40 ` [U-Boot] [PATCH 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
@ 2018-07-13 14:40 ` Pankaj Bansal
  2018-07-25 20:14   ` Joe Hershberger
  2018-07-13 14:40 ` [U-Boot] [PATCH 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-13 14:40 UTC (permalink / raw)
  To: u-boot

The dpmac initalization should not depend on phy.
As the phy is not necessary to be present for dpmac to function.
Therefore, remove dpmac initialization dependency from phy.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 drivers/net/fsl-mc/mc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c
index 982024e31e..e2341a2e3c 100644
--- a/drivers/net/fsl-mc/mc.c
+++ b/drivers/net/fsl-mc/mc.c
@@ -327,8 +327,7 @@ static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
 		/* port not enabled */
-		if ((wriop_is_enabled_dpmac(i) != 1) ||
-		    (wriop_get_phy_address(i) == -1))
+		if (wriop_is_enabled_dpmac(i) != 1)
 			continue;
 
 		sprintf(ethname, "DPMAC%d@%s", i,
@@ -845,8 +844,7 @@ int fsl_mc_ldpaa_init(bd_t *bis)
 	int i;
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
-		if ((wriop_is_enabled_dpmac(i) == 1) &&
-		    (wriop_get_phy_address(i) != -1))
+		if (wriop_is_enabled_dpmac(i) == 1)
 			ldpaa_eth_init(i, wriop_get_enet_if(i));
 	return 0;
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
                   ` (4 preceding siblings ...)
  2018-07-13 14:40 ` [U-Boot] [PATCH 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
@ 2018-07-13 14:40 ` Pankaj Bansal
  2018-07-25 20:52   ` Joe Hershberger
  2018-07-19  3:35 ` [U-Boot] [PATCH 0/6] " Prabhakar Kushwaha
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-13 14:40 UTC (permalink / raw)
  To: u-boot

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where there
are sometimes two phy devices for one dpmac. One phy for TX lanes and
one phy for RX lanes. to handle such cases, add the support for multiple
phys in ethernet driver. The ethernet link is up if all the phy devices
connected to one dpmac report link up. also the link capabilities are
limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G without
autoneg and other operate at 1G with autoneg. Then the ethernet interface
will operate at 1G without autoneg.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 board/freescale/ls1088a/eth_ls1088aqds.c   | 18 ++---
 board/freescale/ls1088a/eth_ls1088ardb.c   | 21 +++---
 board/freescale/ls2080aqds/eth.c           | 26 +++----
 board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 71 ++++++++++++++------
 drivers/net/ldpaa_eth/ldpaa_wriop.c        | 51 ++++++++++----
 include/fsl-mc/ldpaa_wriop.h               | 21 +++---
 7 files changed, 147 insertions(+), 85 deletions(-)

diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c b/board/freescale/ls1088a/eth_ls1088aqds.c
index 40b1a0e631..f16b78cf03 100644
--- a/board/freescale/ls1088a/eth_ls1088aqds.c
+++ b/board/freescale/ls1088a/eth_ls1088aqds.c
@@ -487,16 +487,16 @@ void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
 	case 0x3A:
 		switch (dpmac_id) {
 		case 1:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[1]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
 			break;
 		case 2:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[0]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
 			break;
 		case 3:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[3]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
 			break;
 		case 7:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[2]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
 			break;
 		default:
 			printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
@@ -532,13 +532,13 @@ void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
 		case 4:
 		case 5:
 		case 6:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 9);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
 			break;
 		case 7:
 		case 8:
 		case 9:
 		case 10:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
 			break;
 		}
 
@@ -567,7 +567,7 @@ void ls1088a_handle_phy_interface_xsgmii(int i)
 	case 0x15:
 	case 0x1D:
 	case 0x1E:
-		wriop_set_phy_address(i, i + 26);
+		wriop_set_phy_address(i, 0, i + 26);
 		ls1088a_qds_enable_SFP_TX(SFP_TX);
 		break;
 	default:
@@ -590,13 +590,13 @@ static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
 
 	switch (dpmac_id) {
 	case 4:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY1_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
 		bus = mii_dev_for_muxval(EMI1_RGMII1);
 		wriop_set_mdio(dpmac_id, bus);
 		break;
 	case 5:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY2_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
 		bus = mii_dev_for_muxval(EMI1_RGMII2);
 		wriop_set_mdio(dpmac_id, bus);
diff --git a/board/freescale/ls1088a/eth_ls1088ardb.c b/board/freescale/ls1088a/eth_ls1088ardb.c
index 418f362e9a..a2b52a879b 100644
--- a/board/freescale/ls1088a/eth_ls1088ardb.c
+++ b/board/freescale/ls1088a/eth_ls1088ardb.c
@@ -55,16 +55,17 @@ int board_eth_init(bd_t *bis)
 		 * a MAC has no PHY address, we give a PHY address to XFI
 		 * MAC error.
 		 */
-		wriop_set_phy_address(WRIOP1_DPMAC1, 0x0a);
-		wriop_set_phy_address(WRIOP1_DPMAC2, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC3, QSGMII1_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC4, QSGMII1_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC5, QSGMII1_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC6, QSGMII1_PORT4_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC7, QSGMII2_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC8, QSGMII2_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC9, QSGMII2_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC10, QSGMII2_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, 0x0a);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, QSGMII1_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, QSGMII1_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, QSGMII1_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, QSGMII1_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, QSGMII2_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, QSGMII2_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC9, 0, QSGMII2_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC10, 0,
+				      QSGMII2_PORT4_PHY_ADDR);
 
 		break;
 	default:
diff --git a/board/freescale/ls2080aqds/eth.c b/board/freescale/ls2080aqds/eth.c
index 989d57e09b..f706fd4cb6 100644
--- a/board/freescale/ls2080aqds/eth.c
+++ b/board/freescale/ls2080aqds/eth.c
@@ -623,7 +623,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
@@ -631,7 +631,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			break;
 		case 2:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
 			bus = mii_dev_for_muxval(EMI1_SLOT2);
@@ -641,18 +641,18 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			if (slot == EMI_NONE)
 				return;
 			if (serdes1_prtcl == 0x39) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
@@ -691,7 +691,7 @@ serdes2:
 			break;
 		case 4:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 9]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
 			bus = mii_dev_for_muxval(EMI1_SLOT4);
@@ -701,14 +701,14 @@ serdes2:
 			if (slot == EMI_NONE)
 				return;
 			if (serdes2_prtcl == 0x47) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 10]);
 				if (dpmac_id >= 14 && hwconfig_f("xqsgmii",
 								 env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 11]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 11]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
@@ -717,7 +717,7 @@ serdes2:
 			break;
 		case 6:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 13]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
 			bus = mii_dev_for_muxval(EMI1_SLOT6);
@@ -775,7 +775,7 @@ void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a QSGMII riser card? */
-			wriop_set_phy_address(dpmac_id, dpmac_id - 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id - 1);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
 			wriop_set_mdio(dpmac_id, bus);
@@ -819,7 +819,7 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
 		 * the XAUI card is used for the XFI MAC, which will cause
 		 * error.
 		 */
-		wriop_set_phy_address(i, i + 4);
+		wriop_set_phy_address(i, 0, i + 4);
 		ls2080a_qds_enable_SFP_TX(SFP_TX);
 
 		break;
diff --git a/board/freescale/ls2080ardb/eth_ls2080rdb.c b/board/freescale/ls2080ardb/eth_ls2080rdb.c
index 45f1d60322..62c7a7a315 100644
--- a/board/freescale/ls2080ardb/eth_ls2080rdb.c
+++ b/board/freescale/ls2080ardb/eth_ls2080rdb.c
@@ -50,21 +50,21 @@ int board_eth_init(bd_t *bis)
 
 	switch (srds_s1) {
 	case 0x2A:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
-		wriop_set_phy_address(WRIOP1_DPMAC5, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC6, AQ_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC7, AQ_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC8, AQ_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, AQ_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, AQ_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, AQ_PHY_ADDR4);
 
 		break;
 	case 0x4B:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
 
 		break;
 	default:
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index d2a6d90f18..2bea249fa0 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,27 +23,43 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
-	int ret;
+	struct wriop_dpmac_info *dpmac_info = NULL;
+	int phy_addr, phy_num;
+	int ret = 0;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
 		return 0;
 
-	phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
-			     dev, wriop_get_enet_if(priv->dpmac_id));
-	if (!phydev) {
-		printf("Failed to connect\n");
-		return -1;
+	for (phy_num = 0; phy_num < ARRAY_SIZE(dpmac_info->phydev); phy_num++) {
+		phy_addr = wriop_get_phy_address(priv->dpmac_id, phy_num);
+		if (phy_addr != -1) {
+			phydev = phy_connect(bus, phy_addr, dev,
+					     wriop_get_enet_if(priv->dpmac_id));
+			if (!phydev) {
+				printf("Failed to connect\n");
+				ret = -1;
+				break;
+			}
+			wriop_set_phy_dev(priv->dpmac_id, phy_num, phydev);
+			ret = phy_config(phydev);
+			if (ret)
+				break;
+		}
 	}
 
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-	ret = phy_config(phydev);
-
 	if (ret) {
-		free(phydev);
-		phydev = NULL;
-		wriop_set_phy_dev(priv->dpmac_id, phydev);
+		for (phy_num = 0;
+		     phy_num < ARRAY_SIZE(dpmac_info->phydev);
+		     phy_num++) {
+			phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+			if (phydev) {
+				free(phydev);
+				phydev = NULL;
+				wriop_set_phy_dev(priv->dpmac_id, phy_num,
+						  phydev);
+			}
+		}
 	}
 
 	return ret;
@@ -390,7 +406,9 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 				 struct dpmac_link_state *state)
 {
 	struct phy_device *phydev = NULL;
+	struct wriop_dpmac_info *dpmac_info = NULL;
 	phy_interface_t enet_if;
+	int phy_num, phys_detected;
 	int err;
 
 	/* let's start off with maximum capabilities
@@ -406,15 +424,23 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 	}
 	state->up = 1;
 
+	phys_detected = 0;
 #ifdef CONFIG_PHYLIB
 	state->options |= DPMAC_LINK_OPT_AUTONEG;
 
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
+	/* start the phy devices one by one and update the dpmac state
+	 */
+	for (phy_num = 0; phy_num < ARRAY_SIZE(dpmac_info->phydev); phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (!phydev)
+			continue;
+
+		phys_detected++;
 		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n", phydev->dev->name);
 			state->up = 0;
+			break;
 		}
 		if (phydev->link == 1) {
 			state->rate = state->rate < phydev->speed ?
@@ -424,11 +450,14 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 			if (!phydev->autoneg)
 				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 		} else {
+			/* break out of loop even if one phy is down
+			 */
 			state->up = 0;
+			break;
 		}
 	}
 #endif
-	if (!phydev)
+	if (phys_detected == 0)
 		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 
 	if (state->up == 0) {
@@ -570,6 +599,8 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
 	struct phy_device *phydev = NULL;
+	struct wriop_dpmac_info *dpmac_info = NULL;
+	int phy_num;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -602,9 +633,11 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev)
-		phy_shutdown(phydev);
+	for (phy_num = 0; phy_num < ARRAY_SIZE(dpmac_info->phydev); phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (phydev)
+			phy_shutdown(phydev);
+	}
 #endif
 
 	/* Free DPBP handle and reset. */
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index afbb1ca91e..c065804c49 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -22,11 +22,10 @@ __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
 void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 {
 	phy_interface_t enet_if;
+	int phy_num;
 
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
-	dpmac_info[dpmac_id].phy_addr = -1;
-	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -35,15 +34,35 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 		dpmac_info[dpmac_id].id = dpmac_id;
 		dpmac_info[dpmac_id].enet_if = enet_if;
 	}
+	for (phy_num = 0;
+	     phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phydev);
+	     phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+	}
+	for (phy_num = 0;
+	     phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr);
+	     phy_num++) {
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 {
+	int phy_num;
+
 	dpmac_info[dpmac_id].enabled = 1;
 	dpmac_info[dpmac_id].id = dpmac_id;
-	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
-	dpmac_info[dpmac_id].phydev = NULL;
+	for (phy_num = 0;
+	     phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phydev);
+	     phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+	}
+	for (phy_num = 0;
+	     phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr);
+	     phy_num++) {
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 
@@ -113,44 +132,52 @@ struct mii_dev *wriop_get_mdio(int dpmac_id)
 	return dpmac_info[i].bus;
 }
 
-void wriop_set_phy_address(int dpmac_id, int address)
+void wriop_set_phy_address(int dpmac_id, int phy_num, int address)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
 		return;
+	if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr))
+		return;
 
-	dpmac_info[i].phy_addr = address;
+	dpmac_info[i].phy_addr[phy_num] = address;
 }
 
-int wriop_get_phy_address(int dpmac_id)
+int wriop_get_phy_address(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
 		return -1;
+	if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr))
+		return -1;
 
-	return dpmac_info[i].phy_addr;
+	return dpmac_info[i].phy_addr[phy_num];
 }
 
-void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
+void wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
 		return;
+	if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phydev))
+		return;
 
-	dpmac_info[i].phydev = phydev;
+	dpmac_info[i].phydev[phy_num] = phydev;
 }
 
-struct phy_device *wriop_get_phy_dev(int dpmac_id)
+struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
 		return NULL;
+	if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phydev))
+		return NULL;
 
-	return dpmac_info[i].phydev;
+	return dpmac_info[i].phydev[phy_num];
 }
 
 phy_interface_t wriop_get_enet_if(int dpmac_id)
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 8971c6c55b..a708e527cf 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -6,7 +6,11 @@
 #ifndef __LDPAA_WRIOP_H
 #define __LDPAA_WRIOP_H
 
- #include <phy.h>
+#include <phy.h>
+
+#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
+#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
+#define WRIOP_MAX_PHY_NUM        2
 
 enum wriop_port {
 	WRIOP1_DPMAC1 = 1,
@@ -40,27 +44,24 @@ struct wriop_dpmac_info {
 	u8 enabled;
 	u8 id;
 	u8 board_mux;
-	int phy_addr;
+	int phy_addr[WRIOP_MAX_PHY_NUM];
 	phy_interface_t enet_if;
-	struct phy_device *phydev;
+	struct phy_device *phydev[WRIOP_MAX_PHY_NUM];
 	struct mii_dev *bus;
 };
 
 extern struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
 
-#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
-#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
-
 void wriop_init_dpmac(int, int, int);
 void wriop_disable_dpmac(int);
 void wriop_enable_dpmac(int);
 u8 wriop_is_enabled_dpmac(int dpmac_id);
 void wriop_set_mdio(int, struct mii_dev *);
 struct mii_dev *wriop_get_mdio(int);
-void wriop_set_phy_address(int, int);
-int wriop_get_phy_address(int);
-void wriop_set_phy_dev(int, struct phy_device *);
-struct phy_device *wriop_get_phy_dev(int);
+void wriop_set_phy_address(int, int, int);
+int wriop_get_phy_address(int, int);
+void wriop_set_phy_dev(int, int, struct phy_device *);
+struct phy_device *wriop_get_phy_dev(int, int);
 phy_interface_t wriop_get_enet_if(int);
 
 void wriop_dpmac_disable(int);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
                   ` (5 preceding siblings ...)
  2018-07-13 14:40 ` [U-Boot] [PATCH 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
@ 2018-07-19  3:35 ` Prabhakar Kushwaha
  2018-07-25  3:03   ` Pankaj Bansal
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
  7 siblings, 1 reply; 54+ messages in thread
From: Prabhakar Kushwaha @ 2018-07-19  3:35 UTC (permalink / raw)
  To: u-boot


> -----Original Message-----
> From: Pankaj Bansal
> Sent: Friday, July 13, 2018 8:11 PM
> To: u-boot at lists.denx.de
> Cc: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>; Priyanka Jain
> <priyanka.jain@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; York Sun
> <york.sun@nxp.com>; joe.hershberger at ni.com; Pankaj Bansal
> <pankaj.bansal@nxp.com>
> Subject: [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for
> dpmac
> 
> This patch set adds support of multiple phys for one dpmac
> 
> Till now we have had cases where we had one phy device per dpmac.
> Now, with the upcoming products (LX2160AQDS), we have cases, where
> there are sometimes two phy devices for one dpmac. One phy for TX lanes
> and one phy for RX lanes. To handle such cases, add the support for multiple
> phys in ethernet driver. The ethernet link is up if all the phy devices
> connected to one dpmac report link up.
> also the link capabilities are limited by the weakest phy device.
> 
> i.e. say if there are two phys for one dpmac. one operates at 10G without
> autoneg and other operate at 1G with autoneg. Then the ethernet interface
> will operate at 1G without autoneg.
> 
> Pankaj Bansal (6):
>   driver: net: fsl-mc: modify the label name
>   driver: net: fsl-mc: remove unused strcture elements
>   driver: net: fsl-mc: fix error handing in init_phy
>   driver: net: fsl-mc: Modify the dpmac link detection method
>   driver: net: fsl-mc: initialize dpmac irrespective of phy
>   driver: net: fsl-mc: Add support of multiple phys for dpmac
> 
>  board/freescale/ls1088a/eth_ls1088aqds.c   |  18 +--
>  board/freescale/ls1088a/eth_ls1088ardb.c   |  21 +--
>  board/freescale/ls2080aqds/eth.c           |  26 +--
>  board/freescale/ls2080ardb/eth_ls2080rdb.c |  24 +--
>  drivers/net/fsl-mc/mc.c                    |   6 +-
>  drivers/net/ldpaa_eth/ldpaa_eth.c          | 180 +++++++++++++--------
>  drivers/net/ldpaa_eth/ldpaa_eth.h          |   1 -
>  drivers/net/ldpaa_eth/ldpaa_wriop.c        |  49 ++++--
>  include/fsl-mc/ldpaa_wriop.h               |  22 +--
>  9 files changed, 209 insertions(+), 138 deletions(-)

Patch set looks good. 

Reviewed-by: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-19  3:35 ` [U-Boot] [PATCH 0/6] " Prabhakar Kushwaha
@ 2018-07-25  3:03   ` Pankaj Bansal
  0 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-25  3:03 UTC (permalink / raw)
  To: u-boot

Hi Joe,

Can you please review these changes ?

Regards,
Pankaj Bansal

> -----Original Message-----
> From: Prabhakar Kushwaha
> Sent: Thursday, July 19, 2018 9:06 AM
> To: Pankaj Bansal <pankaj.bansal@nxp.com>; u-boot at lists.denx.de
> Cc: Priyanka Jain <priyanka.jain@nxp.com>; Varun Sethi
> <V.Sethi@nxp.com>; York Sun <york.sun@nxp.com>;
> joe.hershberger at ni.com
> Subject: RE: [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys
> for dpmac
> 
> 
> > -----Original Message-----
> > From: Pankaj Bansal
> > Sent: Friday, July 13, 2018 8:11 PM
> > To: u-boot at lists.denx.de
> > Cc: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>; Priyanka Jain
> > <priyanka.jain@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; York Sun
> > <york.sun@nxp.com>; joe.hershberger at ni.com; Pankaj Bansal
> > <pankaj.bansal@nxp.com>
> > Subject: [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys
> > for dpmac
> >
> > This patch set adds support of multiple phys for one dpmac
> >
> > Till now we have had cases where we had one phy device per dpmac.
> > Now, with the upcoming products (LX2160AQDS), we have cases, where
> > there are sometimes two phy devices for one dpmac. One phy for TX
> > lanes and one phy for RX lanes. To handle such cases, add the support
> > for multiple phys in ethernet driver. The ethernet link is up if all
> > the phy devices connected to one dpmac report link up.
> > also the link capabilities are limited by the weakest phy device.
> >
> > i.e. say if there are two phys for one dpmac. one operates at 10G
> > without autoneg and other operate at 1G with autoneg. Then the
> > ethernet interface will operate at 1G without autoneg.
> >
> > Pankaj Bansal (6):
> >   driver: net: fsl-mc: modify the label name
> >   driver: net: fsl-mc: remove unused strcture elements
> >   driver: net: fsl-mc: fix error handing in init_phy
> >   driver: net: fsl-mc: Modify the dpmac link detection method
> >   driver: net: fsl-mc: initialize dpmac irrespective of phy
> >   driver: net: fsl-mc: Add support of multiple phys for dpmac
> >
> >  board/freescale/ls1088a/eth_ls1088aqds.c   |  18 +--
> >  board/freescale/ls1088a/eth_ls1088ardb.c   |  21 +--
> >  board/freescale/ls2080aqds/eth.c           |  26 +--
> >  board/freescale/ls2080ardb/eth_ls2080rdb.c |  24 +--
> >  drivers/net/fsl-mc/mc.c                    |   6 +-
> >  drivers/net/ldpaa_eth/ldpaa_eth.c          | 180 +++++++++++++--------
> >  drivers/net/ldpaa_eth/ldpaa_eth.h          |   1 -
> >  drivers/net/ldpaa_eth/ldpaa_wriop.c        |  49 ++++--
> >  include/fsl-mc/ldpaa_wriop.h               |  22 +--
> >  9 files changed, 209 insertions(+), 138 deletions(-)
> 
> Patch set looks good.
> 
> Reviewed-by: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>
> 
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 1/6] driver: net: fsl-mc: modify the label name
  2018-07-13 14:40 ` [U-Boot] [PATCH 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
@ 2018-07-25 19:39   ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-25 19:39 UTC (permalink / raw)
  To: u-boot

On Fri, Jul 13, 2018 at 9:40 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> The goto label name is misspelled it should be DPMAC not DPAMC
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-07-13 14:40 ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-07-25 20:03   ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-25 20:03 UTC (permalink / raw)
  To: u-boot

On Fri, Jul 13, 2018 at 9:40 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> The phydev structure is present in both ldpaa_eth_priv and
> wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used
>
> As the phydev is created based on phy_addr and bus members of
> wriop_dpmac_info, it is appropriate to keep phydev in wriop_dpmac_info.
>
> Also phy_regs is not being used, therefore remove it
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

One nit below, but...

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

If we don't need another version of this series, I'll fix it up when
it's applied.

> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c   | 57 +++++++++++++++------------
>  drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
>  drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
>  include/fsl-mc/ldpaa_wriop.h        |  1 -
>  4 files changed, 34 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index 18bc05790a..fbc724fc33 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
>                 return -1;
>         }
>
> -       priv->phydev = phydev;
> +       wriop_set_phy_dev(priv->dpmac_id, phydev);
>
>         return phy_config(phydev);
>  }
> @@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>         struct mii_dev *bus;
>         phy_interface_t enet_if;
>         struct dpni_queue d_queue;
> +       struct phy_device *phydev = NULL;
>
>         if (net_dev->state == ETH_STATE_ACTIVE)
>                 return 0;
> @@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 goto err_dpmac_setup;
>
>  #ifdef CONFIG_PHYLIB
> -       if (priv->phydev) {
> -               err = phy_startup(priv->phydev);
> +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> +       if (phydev) {
> +               err = phy_startup(phydev);
>                 if (err) {
>                         printf("%s: Could not initialize\n",
> -                              priv->phydev->dev->name);
> +                              phydev->dev->name);
>                         goto err_dpmac_bind;
>                 }
>         }
>  #else
> -       priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
> -       memset(priv->phydev, 0, sizeof(struct phy_device));
> +       phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
> +       memset(phydev, 0, sizeof(struct phy_device));
> +       wriop_set_phy_dev(priv->dpmac_id, phydev);
>
> -       priv->phydev->speed = SPEED_1000;
> -       priv->phydev->link = 1;
> -       priv->phydev->duplex = DUPLEX_FULL;
> +       phydev->speed = SPEED_1000;
> +       phydev->link = 1;
> +       phydev->duplex = DUPLEX_FULL;
>  #endif
>
>         bus = wriop_get_mdio(priv->dpmac_id);
>         enet_if = wriop_get_enet_if(priv->dpmac_id);
>         if ((bus == NULL) &&
>             (enet_if == PHY_INTERFACE_MODE_XGMII)) {
> -               priv->phydev = (struct phy_device *)
> +               phydev = (struct phy_device *)
>                                 malloc(sizeof(struct phy_device));
> -               memset(priv->phydev, 0, sizeof(struct phy_device));
> +               memset(phydev, 0, sizeof(struct phy_device));
> +               wriop_set_phy_dev(priv->dpmac_id, phydev);
>
> -               priv->phydev->speed = SPEED_10000;
> -               priv->phydev->link = 1;
> -               priv->phydev->duplex = DUPLEX_FULL;
> +               phydev->speed = SPEED_10000;
> +               phydev->link = 1;
> +               phydev->duplex = DUPLEX_FULL;
>         }
>
> -       if (!priv->phydev->link) {
> -               printf("%s: No link.\n", priv->phydev->dev->name);
> +       if (!phydev->link) {
> +               printf("%s: No link.\n", phydev->dev->name);
>                 err = -1;
>                 goto err_dpmac_bind;
>         }
> @@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 return err;
>         }
>
> -       dpmac_link_state.rate = priv->phydev->speed;
> +       dpmac_link_state.rate = phydev->speed;
>
> -       if (priv->phydev->autoneg == AUTONEG_DISABLE)
> +       if (phydev->autoneg == AUTONEG_DISABLE)
>                 dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
>         else
>                 dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
>
> -       if (priv->phydev->duplex == DUPLEX_HALF)
> +       if (phydev->duplex == DUPLEX_HALF)
>                 dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
>
> -       dpmac_link_state.up = priv->phydev->link;
> +       dpmac_link_state.up = phydev->link;
>
>         err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
>                                   priv->dpmac_handle, &dpmac_link_state);
> @@ -530,7 +534,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 goto err_qdid;
>         }
>
> -       return priv->phydev->link;
> +       return phydev->link;
>
>  err_qdid:
>  err_get_queue:
> @@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>  #ifdef CONFIG_PHYLIB
>         struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
>  #endif
> +       struct phy_device *phydev = NULL;
>
>         if ((net_dev->state == ETH_STATE_PASSIVE) ||
>             (net_dev->state == ETH_STATE_INIT))
> @@ -588,11 +593,13 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>                 printf("dpni_disable() failed\n");
>
>  #ifdef CONFIG_PHYLIB
> -       if (priv->phydev && bus != NULL)
> -               phy_shutdown(priv->phydev);
> +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> +       if (phydev && bus != NULL)

I'm surprised checkpatch.pl doesn't complain about this "!= NULL".
Either way, remove it and just use "phydev && bus"

> +               phy_shutdown(phydev);
>         else {
> -               free(priv->phydev);
> -               priv->phydev = NULL;
> +               free(phydev);
> +               phydev = NULL;
> +               wriop_set_phy_dev(priv->dpmac_id, phydev);
>         }
>  #endif
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h b/drivers/net/ldpaa_eth/ldpaa_eth.h
> index ee784a55ee..3f9154b5bb 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.h
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
> @@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
>         uint16_t tx_flow_id;
>
>         enum ldpaa_eth_type type;       /* 1G or 10G ethernet */
> -       struct phy_device *phydev;
>  };
>
>  struct dprc_endpoint dpmac_endpoint;
> diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> index 0731a795c8..afbb1ca91e 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> @@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
>         dpmac_info[dpmac_id].enabled = 0;
>         dpmac_info[dpmac_id].id = 0;
>         dpmac_info[dpmac_id].phy_addr = -1;
> +       dpmac_info[dpmac_id].phydev = NULL;
>         dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
>
>         enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
> @@ -42,6 +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
>         dpmac_info[dpmac_id].id = dpmac_id;
>         dpmac_info[dpmac_id].phy_addr = -1;
>         dpmac_info[dpmac_id].enet_if = enet_if;
> +       dpmac_info[dpmac_id].phydev = NULL;
>  }
>
>
> diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
> index 07e5130264..8971c6c55b 100644
> --- a/include/fsl-mc/ldpaa_wriop.h
> +++ b/include/fsl-mc/ldpaa_wriop.h
> @@ -41,7 +41,6 @@ struct wriop_dpmac_info {
>         u8 id;
>         u8 board_mux;
>         int phy_addr;
> -       void *phy_regs;
>         phy_interface_t enet_if;
>         struct phy_device *phydev;
>         struct mii_dev *bus;
> --
> 2.17.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 3/6] driver: net: fsl-mc: fix error handing in init_phy
  2018-07-13 14:40 ` [U-Boot] [PATCH 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
@ 2018-07-25 20:04   ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-25 20:04 UTC (permalink / raw)
  To: u-boot

On Fri, Jul 13, 2018 at 9:40 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> if an error occurs during init_phy, we should free the phydev structure
> which has been allocated by phy_connect.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index fbc724fc33..8fcb948ee8 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -23,6 +23,7 @@ static int init_phy(struct eth_device *dev)
>         struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
>         struct phy_device *phydev = NULL;
>         struct mii_dev *bus;
> +       int ret;
>
>         bus = wriop_get_mdio(priv->dpmac_id);
>         if (bus == NULL)
> @@ -37,7 +38,15 @@ static int init_phy(struct eth_device *dev)
>
>         wriop_set_phy_dev(priv->dpmac_id, phydev);
>
> -       return phy_config(phydev);
> +       ret = phy_config(phydev);
> +
> +       if (ret) {
> +               free(phydev);
> +               phydev = NULL;

This seems odd. It's a local variable... why not just pass NULL into
wriop_set_phy_dev()? That seems clearer.

> +               wriop_set_phy_dev(priv->dpmac_id, phydev);
> +       }
> +
> +       return ret;
>  }
>  #endif
>
> --
> 2.17.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 4/6] driver: net: fsl-mc: Modify the dpmac link detection method
  2018-07-13 14:40 ` [U-Boot] [PATCH 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
@ 2018-07-25 20:13   ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-25 20:13 UTC (permalink / raw)
  To: u-boot

On Fri, Jul 13, 2018 at 9:40 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> when there is no phy present for a dpmac, a dummy phy device is created.
> when we move to multiple phy method, we need to create as many dummy phy
> devices.
>
> Change this method so that we don't need to create dummy phy devices.
> We always report linkup if no phy is present.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c | 121 +++++++++++++---------------
>  1 file changed, 58 insertions(+), 63 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index 8fcb948ee8..d2a6d90f18 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -386,6 +386,60 @@ error:
>         return err;
>  }
>
> +static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
> +                                struct dpmac_link_state *state)
> +{
> +       struct phy_device *phydev = NULL;
> +       phy_interface_t enet_if;
> +       int err;
> +
> +       /* let's start off with maximum capabilities
> +        */
> +       enet_if = wriop_get_enet_if(priv->dpmac_id);
> +       switch (enet_if) {
> +       case PHY_INTERFACE_MODE_XGMII:
> +               state->rate = SPEED_10000;
> +               break;
> +       default:
> +               state->rate = SPEED_1000;
> +               break;
> +       }
> +       state->up = 1;
> +
> +#ifdef CONFIG_PHYLIB
> +       state->options |= DPMAC_LINK_OPT_AUTONEG;
> +
> +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> +       if (phydev) {
> +               err = phy_startup(phydev);
> +               if (err) {
> +                       printf("%s: Could not initialize\n", phydev->dev->name);
> +                       state->up = 0;
> +               }
> +               if (phydev->link == 1) {

Just "phydev->link"

> +                       state->rate = state->rate < phydev->speed ?
> +                                     state->rate : phydev->speed;

MIN(state->rate, phydev->speed);

> +                       if (!phydev->duplex)
> +                               state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
> +                       if (!phydev->autoneg)
> +                               state->options &= ~DPMAC_LINK_OPT_AUTONEG;
> +               } else {
> +                       state->up = 0;
> +               }
> +       }
> +#endif
> +       if (!phydev)
> +               state->options &= ~DPMAC_LINK_OPT_AUTONEG;
> +
> +       if (state->up == 0) {
> +               state->rate = 0;
> +               state->options = 0;
> +               return -1;

return -ENODEV;

> +       }
> +
> +       return 0;
> +}
> +
>  static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>  {
>         struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
> @@ -394,10 +448,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>         struct dpni_link_state link_state;
>  #endif
>         int err = 0;
> -       struct mii_dev *bus;
> -       phy_interface_t enet_if;
>         struct dpni_queue d_queue;
> -       struct phy_device *phydev = NULL;
>
>         if (net_dev->state == ETH_STATE_ACTIVE)
>                 return 0;
> @@ -417,45 +468,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>         if (err < 0)
>                 goto err_dpmac_setup;
>
> -#ifdef CONFIG_PHYLIB
> -       phydev = wriop_get_phy_dev(priv->dpmac_id);
> -       if (phydev) {
> -               err = phy_startup(phydev);
> -               if (err) {
> -                       printf("%s: Could not initialize\n",
> -                              phydev->dev->name);
> -                       goto err_dpmac_bind;
> -               }
> -       }
> -#else
> -       phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
> -       memset(phydev, 0, sizeof(struct phy_device));
> -       wriop_set_phy_dev(priv->dpmac_id, phydev);
> -
> -       phydev->speed = SPEED_1000;
> -       phydev->link = 1;
> -       phydev->duplex = DUPLEX_FULL;
> -#endif
> -
> -       bus = wriop_get_mdio(priv->dpmac_id);
> -       enet_if = wriop_get_enet_if(priv->dpmac_id);
> -       if ((bus == NULL) &&
> -           (enet_if == PHY_INTERFACE_MODE_XGMII)) {
> -               phydev = (struct phy_device *)
> -                               malloc(sizeof(struct phy_device));
> -               memset(phydev, 0, sizeof(struct phy_device));
> -               wriop_set_phy_dev(priv->dpmac_id, phydev);
> -
> -               phydev->speed = SPEED_10000;
> -               phydev->link = 1;
> -               phydev->duplex = DUPLEX_FULL;
> -       }
> -
> -       if (!phydev->link) {
> -               printf("%s: No link.\n", phydev->dev->name);
> -               err = -1;
> +       err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
> +       if (err < 0)
>                 goto err_dpmac_bind;
> -       }
>
>         /* DPMAC binding DPNI */
>         err = ldpaa_dpmac_bind(priv);
> @@ -489,18 +504,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 return err;
>         }
>
> -       dpmac_link_state.rate = phydev->speed;
> -
> -       if (phydev->autoneg == AUTONEG_DISABLE)
> -               dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
> -       else
> -               dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
> -
> -       if (phydev->duplex == DUPLEX_HALF)
> -               dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
> -
> -       dpmac_link_state.up = phydev->link;
> -
>         err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
>                                   priv->dpmac_handle, &dpmac_link_state);
>         if (err < 0) {
> @@ -543,7 +546,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 goto err_qdid;
>         }
>
> -       return phydev->link;
> +       return dpmac_link_state.up;
>
>  err_qdid:
>  err_get_queue:
> @@ -566,9 +569,6 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>  {
>         struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
>         int err = 0;
> -#ifdef CONFIG_PHYLIB
> -       struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
> -#endif
>         struct phy_device *phydev = NULL;
>
>         if ((net_dev->state == ETH_STATE_PASSIVE) ||
> @@ -603,13 +603,8 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>
>  #ifdef CONFIG_PHYLIB
>         phydev = wriop_get_phy_dev(priv->dpmac_id);
> -       if (phydev && bus != NULL)
> +       if (phydev)
>                 phy_shutdown(phydev);
> -       else {
> -               free(phydev);
> -               phydev = NULL;
> -               wriop_set_phy_dev(priv->dpmac_id, phydev);
> -       }
>  #endif
>
>         /* Free DPBP handle and reset. */
> --
> 2.17.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy
  2018-07-13 14:40 ` [U-Boot] [PATCH 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
@ 2018-07-25 20:14   ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-25 20:14 UTC (permalink / raw)
  To: u-boot

On Fri, Jul 13, 2018 at 9:40 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> The dpmac initalization should not depend on phy.
> As the phy is not necessary to be present for dpmac to function.
> Therefore, remove dpmac initialization dependency from phy.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-13 14:40 ` [U-Boot] [PATCH 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
@ 2018-07-25 20:52   ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-25 20:52 UTC (permalink / raw)
  To: u-boot

On Fri, Jul 13, 2018 at 9:40 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> Till now we have had cases where we had one phy device per dpmac.
> Now, with the upcoming products (LX2160AQDS), we have cases, where there
> are sometimes two phy devices for one dpmac. One phy for TX lanes and
> one phy for RX lanes. to handle such cases, add the support for multiple
> phys in ethernet driver. The ethernet link is up if all the phy devices
> connected to one dpmac report link up. also the link capabilities are
> limited by the weakest phy device.
>
> i.e. say if there are two phys for one dpmac. one operates at 10G without
> autoneg and other operate at 1G with autoneg. Then the ethernet interface
> will operate at 1G without autoneg.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>  board/freescale/ls1088a/eth_ls1088aqds.c   | 18 ++---
>  board/freescale/ls1088a/eth_ls1088ardb.c   | 21 +++---
>  board/freescale/ls2080aqds/eth.c           | 26 +++----
>  board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
>  drivers/net/ldpaa_eth/ldpaa_eth.c          | 71 ++++++++++++++------
>  drivers/net/ldpaa_eth/ldpaa_wriop.c        | 51 ++++++++++----
>  include/fsl-mc/ldpaa_wriop.h               | 21 +++---
>  7 files changed, 147 insertions(+), 85 deletions(-)
>
> diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c b/board/freescale/ls1088a/eth_ls1088aqds.c
> index 40b1a0e631..f16b78cf03 100644
> --- a/board/freescale/ls1088a/eth_ls1088aqds.c
> +++ b/board/freescale/ls1088a/eth_ls1088aqds.c
> @@ -487,16 +487,16 @@ void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
>         case 0x3A:
>                 switch (dpmac_id) {
>                 case 1:
> -                       wriop_set_phy_address(dpmac_id, riser_phy_addr[1]);
> +                       wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
>                         break;
>                 case 2:
> -                       wriop_set_phy_address(dpmac_id, riser_phy_addr[0]);
> +                       wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
>                         break;
>                 case 3:
> -                       wriop_set_phy_address(dpmac_id, riser_phy_addr[3]);
> +                       wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
>                         break;
>                 case 7:
> -                       wriop_set_phy_address(dpmac_id, riser_phy_addr[2]);
> +                       wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
>                         break;
>                 default:
>                         printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
> @@ -532,13 +532,13 @@ void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
>                 case 4:
>                 case 5:
>                 case 6:
> -                       wriop_set_phy_address(dpmac_id, dpmac_id + 9);
> +                       wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
>                         break;
>                 case 7:
>                 case 8:
>                 case 9:
>                 case 10:
> -                       wriop_set_phy_address(dpmac_id, dpmac_id + 1);
> +                       wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
>                         break;
>                 }
>
> @@ -567,7 +567,7 @@ void ls1088a_handle_phy_interface_xsgmii(int i)
>         case 0x15:
>         case 0x1D:
>         case 0x1E:
> -               wriop_set_phy_address(i, i + 26);
> +               wriop_set_phy_address(i, 0, i + 26);
>                 ls1088a_qds_enable_SFP_TX(SFP_TX);
>                 break;
>         default:
> @@ -590,13 +590,13 @@ static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
>
>         switch (dpmac_id) {
>         case 4:
> -               wriop_set_phy_address(dpmac_id, RGMII_PHY1_ADDR);
> +               wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
>                 dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
>                 bus = mii_dev_for_muxval(EMI1_RGMII1);
>                 wriop_set_mdio(dpmac_id, bus);
>                 break;
>         case 5:
> -               wriop_set_phy_address(dpmac_id, RGMII_PHY2_ADDR);
> +               wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
>                 dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
>                 bus = mii_dev_for_muxval(EMI1_RGMII2);
>                 wriop_set_mdio(dpmac_id, bus);
> diff --git a/board/freescale/ls1088a/eth_ls1088ardb.c b/board/freescale/ls1088a/eth_ls1088ardb.c
> index 418f362e9a..a2b52a879b 100644
> --- a/board/freescale/ls1088a/eth_ls1088ardb.c
> +++ b/board/freescale/ls1088a/eth_ls1088ardb.c
> @@ -55,16 +55,17 @@ int board_eth_init(bd_t *bis)
>                  * a MAC has no PHY address, we give a PHY address to XFI
>                  * MAC error.
>                  */
> -               wriop_set_phy_address(WRIOP1_DPMAC1, 0x0a);
> -               wriop_set_phy_address(WRIOP1_DPMAC2, AQ_PHY_ADDR1);
> -               wriop_set_phy_address(WRIOP1_DPMAC3, QSGMII1_PORT1_PHY_ADDR);
> -               wriop_set_phy_address(WRIOP1_DPMAC4, QSGMII1_PORT2_PHY_ADDR);
> -               wriop_set_phy_address(WRIOP1_DPMAC5, QSGMII1_PORT3_PHY_ADDR);
> -               wriop_set_phy_address(WRIOP1_DPMAC6, QSGMII1_PORT4_PHY_ADDR);
> -               wriop_set_phy_address(WRIOP1_DPMAC7, QSGMII2_PORT1_PHY_ADDR);
> -               wriop_set_phy_address(WRIOP1_DPMAC8, QSGMII2_PORT2_PHY_ADDR);
> -               wriop_set_phy_address(WRIOP1_DPMAC9, QSGMII2_PORT3_PHY_ADDR);
> -               wriop_set_phy_address(WRIOP1_DPMAC10, QSGMII2_PORT4_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC1, 0, 0x0a);
> +               wriop_set_phy_address(WRIOP1_DPMAC2, 0, AQ_PHY_ADDR1);
> +               wriop_set_phy_address(WRIOP1_DPMAC3, 0, QSGMII1_PORT1_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC4, 0, QSGMII1_PORT2_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC5, 0, QSGMII1_PORT3_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC6, 0, QSGMII1_PORT4_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC7, 0, QSGMII2_PORT1_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC8, 0, QSGMII2_PORT2_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC9, 0, QSGMII2_PORT3_PHY_ADDR);
> +               wriop_set_phy_address(WRIOP1_DPMAC10, 0,
> +                                     QSGMII2_PORT4_PHY_ADDR);
>
>                 break;
>         default:
> diff --git a/board/freescale/ls2080aqds/eth.c b/board/freescale/ls2080aqds/eth.c
> index 989d57e09b..f706fd4cb6 100644
> --- a/board/freescale/ls2080aqds/eth.c
> +++ b/board/freescale/ls2080aqds/eth.c
> @@ -623,7 +623,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
>                 switch (++slot) {
>                 case 1:
>                         /* Slot housing a SGMII riser card? */
> -                       wriop_set_phy_address(dpmac_id,
> +                       wriop_set_phy_address(dpmac_id, 0,
>                                               riser_phy_addr[dpmac_id - 1]);
>                         dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
>                         bus = mii_dev_for_muxval(EMI1_SLOT1);
> @@ -631,7 +631,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
>                         break;
>                 case 2:
>                         /* Slot housing a SGMII riser card? */
> -                       wriop_set_phy_address(dpmac_id,
> +                       wriop_set_phy_address(dpmac_id, 0,
>                                               riser_phy_addr[dpmac_id - 1]);
>                         dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
>                         bus = mii_dev_for_muxval(EMI1_SLOT2);
> @@ -641,18 +641,18 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
>                         if (slot == EMI_NONE)
>                                 return;
>                         if (serdes1_prtcl == 0x39) {
> -                               wriop_set_phy_address(dpmac_id,
> +                               wriop_set_phy_address(dpmac_id, 0,
>                                         riser_phy_addr[dpmac_id - 2]);
>                                 if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
>                                                                 env_hwconfig))
> -                                       wriop_set_phy_address(dpmac_id,
> +                                       wriop_set_phy_address(dpmac_id, 0,
>                                                 riser_phy_addr[dpmac_id - 3]);
>                         } else {
> -                               wriop_set_phy_address(dpmac_id,
> +                               wriop_set_phy_address(dpmac_id, 0,
>                                         riser_phy_addr[dpmac_id - 2]);
>                                 if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
>                                                                 env_hwconfig))
> -                                       wriop_set_phy_address(dpmac_id,
> +                                       wriop_set_phy_address(dpmac_id, 0,
>                                                 riser_phy_addr[dpmac_id - 3]);
>                         }
>                         dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
> @@ -691,7 +691,7 @@ serdes2:
>                         break;
>                 case 4:
>                         /* Slot housing a SGMII riser card? */
> -                       wriop_set_phy_address(dpmac_id,
> +                       wriop_set_phy_address(dpmac_id, 0,
>                                               riser_phy_addr[dpmac_id - 9]);
>                         dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
>                         bus = mii_dev_for_muxval(EMI1_SLOT4);
> @@ -701,14 +701,14 @@ serdes2:
>                         if (slot == EMI_NONE)
>                                 return;
>                         if (serdes2_prtcl == 0x47) {
> -                               wriop_set_phy_address(dpmac_id,
> +                               wriop_set_phy_address(dpmac_id, 0,
>                                               riser_phy_addr[dpmac_id - 10]);
>                                 if (dpmac_id >= 14 && hwconfig_f("xqsgmii",
>                                                                  env_hwconfig))
> -                                       wriop_set_phy_address(dpmac_id,
> +                                       wriop_set_phy_address(dpmac_id, 0,
>                                                 riser_phy_addr[dpmac_id - 11]);
>                         } else {
> -                               wriop_set_phy_address(dpmac_id,
> +                               wriop_set_phy_address(dpmac_id, 0,
>                                         riser_phy_addr[dpmac_id - 11]);
>                         }
>                         dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
> @@ -717,7 +717,7 @@ serdes2:
>                         break;
>                 case 6:
>                         /* Slot housing a SGMII riser card? */
> -                       wriop_set_phy_address(dpmac_id,
> +                       wriop_set_phy_address(dpmac_id, 0,
>                                               riser_phy_addr[dpmac_id - 13]);
>                         dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
>                         bus = mii_dev_for_muxval(EMI1_SLOT6);
> @@ -775,7 +775,7 @@ void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
>                 switch (++slot) {
>                 case 1:
>                         /* Slot housing a QSGMII riser card? */
> -                       wriop_set_phy_address(dpmac_id, dpmac_id - 1);
> +                       wriop_set_phy_address(dpmac_id, 0, dpmac_id - 1);
>                         dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
>                         bus = mii_dev_for_muxval(EMI1_SLOT1);
>                         wriop_set_mdio(dpmac_id, bus);
> @@ -819,7 +819,7 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
>                  * the XAUI card is used for the XFI MAC, which will cause
>                  * error.
>                  */
> -               wriop_set_phy_address(i, i + 4);
> +               wriop_set_phy_address(i, 0, i + 4);
>                 ls2080a_qds_enable_SFP_TX(SFP_TX);
>
>                 break;
> diff --git a/board/freescale/ls2080ardb/eth_ls2080rdb.c b/board/freescale/ls2080ardb/eth_ls2080rdb.c
> index 45f1d60322..62c7a7a315 100644
> --- a/board/freescale/ls2080ardb/eth_ls2080rdb.c
> +++ b/board/freescale/ls2080ardb/eth_ls2080rdb.c
> @@ -50,21 +50,21 @@ int board_eth_init(bd_t *bis)
>
>         switch (srds_s1) {
>         case 0x2A:
> -               wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
> -               wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
> -               wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
> -               wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
> -               wriop_set_phy_address(WRIOP1_DPMAC5, AQ_PHY_ADDR1);
> -               wriop_set_phy_address(WRIOP1_DPMAC6, AQ_PHY_ADDR2);
> -               wriop_set_phy_address(WRIOP1_DPMAC7, AQ_PHY_ADDR3);
> -               wriop_set_phy_address(WRIOP1_DPMAC8, AQ_PHY_ADDR4);
> +               wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
> +               wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
> +               wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
> +               wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
> +               wriop_set_phy_address(WRIOP1_DPMAC5, 0, AQ_PHY_ADDR1);
> +               wriop_set_phy_address(WRIOP1_DPMAC6, 0, AQ_PHY_ADDR2);
> +               wriop_set_phy_address(WRIOP1_DPMAC7, 0, AQ_PHY_ADDR3);
> +               wriop_set_phy_address(WRIOP1_DPMAC8, 0, AQ_PHY_ADDR4);
>
>                 break;
>         case 0x4B:
> -               wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
> -               wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
> -               wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
> -               wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
> +               wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
> +               wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
> +               wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
> +               wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
>
>                 break;
>         default:
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index d2a6d90f18..2bea249fa0 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -23,27 +23,43 @@ static int init_phy(struct eth_device *dev)
>         struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
>         struct phy_device *phydev = NULL;
>         struct mii_dev *bus;
> -       int ret;
> +       struct wriop_dpmac_info *dpmac_info = NULL;
> +       int phy_addr, phy_num;
> +       int ret = 0;
>
>         bus = wriop_get_mdio(priv->dpmac_id);
>         if (bus == NULL)
>                 return 0;
>
> -       phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
> -                            dev, wriop_get_enet_if(priv->dpmac_id));
> -       if (!phydev) {
> -               printf("Failed to connect\n");
> -               return -1;
> +       for (phy_num = 0; phy_num < ARRAY_SIZE(dpmac_info->phydev); phy_num++) {

Why not use WRIOP_MAX_PHY_NUM here directly?

> +               phy_addr = wriop_get_phy_address(priv->dpmac_id, phy_num);
> +               if (phy_addr != -1) {

If you instead say:

if (phy_addr == -1)
        continue;

Then you don't have to have the whole next chunk indented in a deeper block.

> +                       phydev = phy_connect(bus, phy_addr, dev,
> +                                            wriop_get_enet_if(priv->dpmac_id));
> +                       if (!phydev) {
> +                               printf("Failed to connect\n");
> +                               ret = -1;

ret = -ENODEV; since this would be NULL if phy_find_by_mask() can't
find the phy.

> +                               break;
> +                       }
> +                       wriop_set_phy_dev(priv->dpmac_id, phy_num, phydev);
> +                       ret = phy_config(phydev);
> +                       if (ret)
> +                               break;
> +               }
>         }
>
> -       wriop_set_phy_dev(priv->dpmac_id, phydev);
> -
> -       ret = phy_config(phydev);
> -
>         if (ret) {
> -               free(phydev);
> -               phydev = NULL;
> -               wriop_set_phy_dev(priv->dpmac_id, phydev);
> +               for (phy_num = 0;
> +                    phy_num < ARRAY_SIZE(dpmac_info->phydev);

Throughout it would be better to use WRIOP_MAX_PHY_NUM.

> +                    phy_num++) {
> +                       phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
> +                       if (phydev) {
> +                               free(phydev);
> +                               phydev = NULL;
> +                               wriop_set_phy_dev(priv->dpmac_id, phy_num,
> +                                                 phydev);
> +                       }
> +               }
>         }
>
>         return ret;
> @@ -390,7 +406,9 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
>                                  struct dpmac_link_state *state)
>  {
>         struct phy_device *phydev = NULL;
> +       struct wriop_dpmac_info *dpmac_info = NULL;
>         phy_interface_t enet_if;
> +       int phy_num, phys_detected;
>         int err;
>
>         /* let's start off with maximum capabilities
> @@ -406,15 +424,23 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
>         }
>         state->up = 1;
>
> +       phys_detected = 0;
>  #ifdef CONFIG_PHYLIB
>         state->options |= DPMAC_LINK_OPT_AUTONEG;
>
> -       phydev = wriop_get_phy_dev(priv->dpmac_id);
> -       if (phydev) {
> +       /* start the phy devices one by one and update the dpmac state
> +        */

Please use single-line comment format.

> +       for (phy_num = 0; phy_num < ARRAY_SIZE(dpmac_info->phydev); phy_num++) {
> +               phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
> +               if (!phydev)
> +                       continue;
> +
> +               phys_detected++;
>                 err = phy_startup(phydev);
>                 if (err) {
>                         printf("%s: Could not initialize\n", phydev->dev->name);
>                         state->up = 0;
> +                       break;
>                 }
>                 if (phydev->link == 1) {
>                         state->rate = state->rate < phydev->speed ?
> @@ -424,11 +450,14 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
>                         if (!phydev->autoneg)
>                                 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
>                 } else {
> +                       /* break out of loop even if one phy is down
> +                        */

Please use single-line comment format.

>                         state->up = 0;
> +                       break;
>                 }
>         }
>  #endif
> -       if (!phydev)
> +       if (phys_detected == 0)
>                 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
>
>         if (state->up == 0) {
> @@ -570,6 +599,8 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>         struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
>         int err = 0;
>         struct phy_device *phydev = NULL;
> +       struct wriop_dpmac_info *dpmac_info = NULL;
> +       int phy_num;
>
>         if ((net_dev->state == ETH_STATE_PASSIVE) ||
>             (net_dev->state == ETH_STATE_INIT))
> @@ -602,9 +633,11 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>                 printf("dpni_disable() failed\n");
>
>  #ifdef CONFIG_PHYLIB
> -       phydev = wriop_get_phy_dev(priv->dpmac_id);
> -       if (phydev)
> -               phy_shutdown(phydev);
> +       for (phy_num = 0; phy_num < ARRAY_SIZE(dpmac_info->phydev); phy_num++) {

Use WRIOP_MAX_PHY_NUM

> +               phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
> +               if (phydev)
> +                       phy_shutdown(phydev);
> +       }
>  #endif
>
>         /* Free DPBP handle and reset. */
> diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> index afbb1ca91e..c065804c49 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> @@ -22,11 +22,10 @@ __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
>  void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
>  {
>         phy_interface_t enet_if;
> +       int phy_num;
>
>         dpmac_info[dpmac_id].enabled = 0;
>         dpmac_info[dpmac_id].id = 0;
> -       dpmac_info[dpmac_id].phy_addr = -1;
> -       dpmac_info[dpmac_id].phydev = NULL;
>         dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
>
>         enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
> @@ -35,15 +34,35 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
>                 dpmac_info[dpmac_id].id = dpmac_id;
>                 dpmac_info[dpmac_id].enet_if = enet_if;
>         }

This should jut call wriop_init_dpmac_enet_if(). You can just set
dpmac_info[dpmac_id].enabled = 0 after calling
wriop_init_dpmac_enet_if().

> +       for (phy_num = 0;
> +            phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phydev);
> +            phy_num++) {
> +               dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> +       }
> +       for (phy_num = 0;
> +            phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr);
> +            phy_num++) {
> +               dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
> +       }
>  }
>
>  void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
>  {
> +       int phy_num;
> +
>         dpmac_info[dpmac_id].enabled = 1;
>         dpmac_info[dpmac_id].id = dpmac_id;
> -       dpmac_info[dpmac_id].phy_addr = -1;
>         dpmac_info[dpmac_id].enet_if = enet_if;
> -       dpmac_info[dpmac_id].phydev = NULL;
> +       for (phy_num = 0;
> +            phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phydev);

Use WRIOP_MAX_PHY_NUM

> +            phy_num++) {
> +               dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> +       }
> +       for (phy_num = 0;
> +            phy_num < ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr);
> +            phy_num++) {
> +               dpmac_info[dpmac_id].phy_addr[phy_num] = -1;

Move this to the other loop.

> +       }
>  }
>
>
> @@ -113,44 +132,52 @@ struct mii_dev *wriop_get_mdio(int dpmac_id)
>         return dpmac_info[i].bus;
>  }
>
> -void wriop_set_phy_address(int dpmac_id, int address)
> +void wriop_set_phy_address(int dpmac_id, int phy_num, int address)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
>                 return;
> +       if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr))

Use WRIOP_MAX_PHY_NUM

> +               return;
>
> -       dpmac_info[i].phy_addr = address;
> +       dpmac_info[i].phy_addr[phy_num] = address;
>  }
>
> -int wriop_get_phy_address(int dpmac_id)
> +int wriop_get_phy_address(int dpmac_id, int phy_num)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
>                 return -1;

This should probably return -ENODEV;

> +       if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phy_addr))

Use WRIOP_MAX_PHY_NUM

> +               return -1;

Use return -EINVAL;

>
> -       return dpmac_info[i].phy_addr;
> +       return dpmac_info[i].phy_addr[phy_num];
>  }
>
> -void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
> +void wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)

Please make this return an int and use the same errors as above.

>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
>                 return;
> +       if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phydev))
> +               return;
>
> -       dpmac_info[i].phydev = phydev;
> +       dpmac_info[i].phydev[phy_num] = phydev;
>  }
>
> -struct phy_device *wriop_get_phy_dev(int dpmac_id)
> +struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
>                 return NULL;
> +       if (phy_num < 0 || phy_num >= ARRAY_SIZE(dpmac_info[dpmac_id].phydev))
> +               return NULL;
>
> -       return dpmac_info[i].phydev;
> +       return dpmac_info[i].phydev[phy_num];
>  }
>
>  phy_interface_t wriop_get_enet_if(int dpmac_id)
> diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
> index 8971c6c55b..a708e527cf 100644
> --- a/include/fsl-mc/ldpaa_wriop.h
> +++ b/include/fsl-mc/ldpaa_wriop.h
> @@ -6,7 +6,11 @@
>  #ifndef __LDPAA_WRIOP_H
>  #define __LDPAA_WRIOP_H
>
> - #include <phy.h>
> +#include <phy.h>
> +
> +#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
> +#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
> +#define WRIOP_MAX_PHY_NUM        2
>
>  enum wriop_port {
>         WRIOP1_DPMAC1 = 1,
> @@ -40,27 +44,24 @@ struct wriop_dpmac_info {
>         u8 enabled;
>         u8 id;
>         u8 board_mux;
> -       int phy_addr;
> +       int phy_addr[WRIOP_MAX_PHY_NUM];
>         phy_interface_t enet_if;
> -       struct phy_device *phydev;
> +       struct phy_device *phydev[WRIOP_MAX_PHY_NUM];
>         struct mii_dev *bus;
>  };
>
>  extern struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
>
> -#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
> -#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
> -
>  void wriop_init_dpmac(int, int, int);
>  void wriop_disable_dpmac(int);
>  void wriop_enable_dpmac(int);
>  u8 wriop_is_enabled_dpmac(int dpmac_id);
>  void wriop_set_mdio(int, struct mii_dev *);
>  struct mii_dev *wriop_get_mdio(int);
> -void wriop_set_phy_address(int, int);
> -int wriop_get_phy_address(int);
> -void wriop_set_phy_dev(int, struct phy_device *);
> -struct phy_device *wriop_get_phy_dev(int);
> +void wriop_set_phy_address(int, int, int);
> +int wriop_get_phy_address(int, int);
> +void wriop_set_phy_dev(int, int, struct phy_device *);
> +struct phy_device *wriop_get_phy_dev(int, int);

Please include the variable names in the headers too. No need to be
obfuscated. Function comments would be even better.

>  phy_interface_t wriop_get_enet_if(int);
>
>  void wriop_dpmac_disable(int);
> --
> 2.17.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
@ 2018-07-30  8:05     ` Pankaj Bansal
  2018-07-30 21:43     ` Joe Hershberger
  2018-10-09 21:32     ` Joe Hershberger
  2 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30  8:05 UTC (permalink / raw)
  To: u-boot

Hi Joe,

I have incorporated all your review comments except one:

"This should jut call wriop_init_dpmac_enet_if(). You can just set
dpmac_info[dpmac_id].enabled = 0 after calling
wriop_init_dpmac_enet_if()."

Actually in  wriop_init_dpmac, we assign -1 to phy_addr array and NULL to phydev array irrespective of enet_if.
If we call wriop_init_dpmac_enet_if from wriop_init_dpmac then this would be done only for dpmacs for which enet_if is not PHY_INTERFACE_MODE_NONE.

Regards,
Pankaj Bansal

> -----Original Message-----
> From: Pankaj Bansal
> Sent: Monday, July 30, 2018 6:45 PM
> To: u-boot at lists.denx.de; joe.hershberger at ni.com
> Cc: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>; Priyanka Jain
> <priyanka.jain@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; York Sun
> <york.sun@nxp.com>; Pankaj Bansal <pankaj.bansal@nxp.com>
> Subject: [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys
> for dpmac
> 
> Till now we have had cases where we had one phy device per dpmac.
> Now, with the upcoming products (LX2160AQDS), we have cases, where
> there are sometimes two phy devices for one dpmac. One phy for TX lanes
> and one phy for RX lanes. to handle such cases, add the support for multiple
> phys in ethernet driver. The ethernet link is up if all the phy devices
> connected to one dpmac report link up. also the link capabilities are limited
> by the weakest phy device.
> 
> i.e. say if there are two phys for one dpmac. one operates at 10G without
> autoneg and other operate at 1G with autoneg. Then the ethernet interface
> will operate at 1G without autoneg.
> 
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
> 
> Notes:
>     V2:
>     - use single-line comment format.
>     - use WRIOP_MAX_PHY_NUM.
>     - use -ENODEV or -EINVAL instead of -1 wherever appropriate
>     - include the variable names in the headers too.
>     - Change the return type of some functions from void to int so that
>       a meaningful error message can be returned
> 
>  board/freescale/ls1088a/eth_ls1088aqds.c   | 18 +++---
>  board/freescale/ls1088a/eth_ls1088ardb.c   | 21 ++++---
>  board/freescale/ls2080aqds/eth.c           | 26 ++++----
>  board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
>  drivers/net/ldpaa_eth/ldpaa_eth.c          | 66 ++++++++++++++------
>  drivers/net/ldpaa_eth/ldpaa_wriop.c        | 61 +++++++++++-------
>  include/fsl-mc/ldpaa_wriop.h               | 45 ++++++-------
>  7 files changed, 152 insertions(+), 109 deletions(-)
> 
> diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c
> b/board/freescale/ls1088a/eth_ls1088aqds.c
> index 40b1a0e631..f16b78cf03 100644
> --- a/board/freescale/ls1088a/eth_ls1088aqds.c
> +++ b/board/freescale/ls1088a/eth_ls1088aqds.c
> @@ -487,16 +487,16 @@ void ls1088a_handle_phy_interface_sgmii(int
> dpmac_id)
>  	case 0x3A:
>  		switch (dpmac_id) {
>  		case 1:
> -			wriop_set_phy_address(dpmac_id,
> riser_phy_addr[1]);
> +			wriop_set_phy_address(dpmac_id, 0,
> riser_phy_addr[1]);
>  			break;
>  		case 2:
> -			wriop_set_phy_address(dpmac_id,
> riser_phy_addr[0]);
> +			wriop_set_phy_address(dpmac_id, 0,
> riser_phy_addr[0]);
>  			break;
>  		case 3:
> -			wriop_set_phy_address(dpmac_id,
> riser_phy_addr[3]);
> +			wriop_set_phy_address(dpmac_id, 0,
> riser_phy_addr[3]);
>  			break;
>  		case 7:
> -			wriop_set_phy_address(dpmac_id,
> riser_phy_addr[2]);
> +			wriop_set_phy_address(dpmac_id, 0,
> riser_phy_addr[2]);
>  			break;
>  		default:
>  			printf("WRIOP: Wrong DPMAC%d set to SGMII",
> dpmac_id); @@ -532,13 +532,13 @@ void
> ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
>  		case 4:
>  		case 5:
>  		case 6:
> -			wriop_set_phy_address(dpmac_id, dpmac_id + 9);
> +			wriop_set_phy_address(dpmac_id, 0, dpmac_id +
> 9);
>  			break;
>  		case 7:
>  		case 8:
>  		case 9:
>  		case 10:
> -			wriop_set_phy_address(dpmac_id, dpmac_id + 1);
> +			wriop_set_phy_address(dpmac_id, 0, dpmac_id +
> 1);
>  			break;
>  		}
> 
> @@ -567,7 +567,7 @@ void ls1088a_handle_phy_interface_xsgmii(int i)
>  	case 0x15:
>  	case 0x1D:
>  	case 0x1E:
> -		wriop_set_phy_address(i, i + 26);
> +		wriop_set_phy_address(i, 0, i + 26);
>  		ls1088a_qds_enable_SFP_TX(SFP_TX);
>  		break;
>  	default:
> @@ -590,13 +590,13 @@ static void
> ls1088a_handle_phy_interface_rgmii(int dpmac_id)
> 
>  	switch (dpmac_id) {
>  	case 4:
> -		wriop_set_phy_address(dpmac_id, RGMII_PHY1_ADDR);
> +		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
>  		dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
>  		bus = mii_dev_for_muxval(EMI1_RGMII1);
>  		wriop_set_mdio(dpmac_id, bus);
>  		break;
>  	case 5:
> -		wriop_set_phy_address(dpmac_id, RGMII_PHY2_ADDR);
> +		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
>  		dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
>  		bus = mii_dev_for_muxval(EMI1_RGMII2);
>  		wriop_set_mdio(dpmac_id, bus);
> diff --git a/board/freescale/ls1088a/eth_ls1088ardb.c
> b/board/freescale/ls1088a/eth_ls1088ardb.c
> index 418f362e9a..a2b52a879b 100644
> --- a/board/freescale/ls1088a/eth_ls1088ardb.c
> +++ b/board/freescale/ls1088a/eth_ls1088ardb.c
> @@ -55,16 +55,17 @@ int board_eth_init(bd_t *bis)
>  		 * a MAC has no PHY address, we give a PHY address to XFI
>  		 * MAC error.
>  		 */
> -		wriop_set_phy_address(WRIOP1_DPMAC1, 0x0a);
> -		wriop_set_phy_address(WRIOP1_DPMAC2,
> AQ_PHY_ADDR1);
> -		wriop_set_phy_address(WRIOP1_DPMAC3,
> QSGMII1_PORT1_PHY_ADDR);
> -		wriop_set_phy_address(WRIOP1_DPMAC4,
> QSGMII1_PORT2_PHY_ADDR);
> -		wriop_set_phy_address(WRIOP1_DPMAC5,
> QSGMII1_PORT3_PHY_ADDR);
> -		wriop_set_phy_address(WRIOP1_DPMAC6,
> QSGMII1_PORT4_PHY_ADDR);
> -		wriop_set_phy_address(WRIOP1_DPMAC7,
> QSGMII2_PORT1_PHY_ADDR);
> -		wriop_set_phy_address(WRIOP1_DPMAC8,
> QSGMII2_PORT2_PHY_ADDR);
> -		wriop_set_phy_address(WRIOP1_DPMAC9,
> QSGMII2_PORT3_PHY_ADDR);
> -		wriop_set_phy_address(WRIOP1_DPMAC10,
> QSGMII2_PORT4_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC1, 0, 0x0a);
> +		wriop_set_phy_address(WRIOP1_DPMAC2, 0,
> AQ_PHY_ADDR1);
> +		wriop_set_phy_address(WRIOP1_DPMAC3, 0,
> QSGMII1_PORT1_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC4, 0,
> QSGMII1_PORT2_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC5, 0,
> QSGMII1_PORT3_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC6, 0,
> QSGMII1_PORT4_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC7, 0,
> QSGMII2_PORT1_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC8, 0,
> QSGMII2_PORT2_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC9, 0,
> QSGMII2_PORT3_PHY_ADDR);
> +		wriop_set_phy_address(WRIOP1_DPMAC10, 0,
> +				      QSGMII2_PORT4_PHY_ADDR);
> 
>  		break;
>  	default:
> diff --git a/board/freescale/ls2080aqds/eth.c
> b/board/freescale/ls2080aqds/eth.c
> index 989d57e09b..f706fd4cb6 100644
> --- a/board/freescale/ls2080aqds/eth.c
> +++ b/board/freescale/ls2080aqds/eth.c
> @@ -623,7 +623,7 @@ void ls2080a_handle_phy_interface_sgmii(int
> dpmac_id)
>  		switch (++slot) {
>  		case 1:
>  			/* Slot housing a SGMII riser card? */
> -			wriop_set_phy_address(dpmac_id,
> +			wriop_set_phy_address(dpmac_id, 0,
>  					      riser_phy_addr[dpmac_id - 1]);
>  			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
>  			bus = mii_dev_for_muxval(EMI1_SLOT1); @@ -
> 631,7 +631,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
>  			break;
>  		case 2:
>  			/* Slot housing a SGMII riser card? */
> -			wriop_set_phy_address(dpmac_id,
> +			wriop_set_phy_address(dpmac_id, 0,
>  					      riser_phy_addr[dpmac_id - 1]);
>  			dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
>  			bus = mii_dev_for_muxval(EMI1_SLOT2); @@ -
> 641,18 +641,18 @@ void ls2080a_handle_phy_interface_sgmii(int
> dpmac_id)
>  			if (slot == EMI_NONE)
>  				return;
>  			if (serdes1_prtcl == 0x39) {
> -				wriop_set_phy_address(dpmac_id,
> +				wriop_set_phy_address(dpmac_id, 0,
>  					riser_phy_addr[dpmac_id - 2]);
>  				if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
> 
> 	env_hwconfig))
> -					wriop_set_phy_address(dpmac_id,
> +					wriop_set_phy_address(dpmac_id,
> 0,
>  						riser_phy_addr[dpmac_id -
> 3]);
>  			} else {
> -				wriop_set_phy_address(dpmac_id,
> +				wriop_set_phy_address(dpmac_id, 0,
>  					riser_phy_addr[dpmac_id - 2]);
>  				if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
> 
> 	env_hwconfig))
> -					wriop_set_phy_address(dpmac_id,
> +					wriop_set_phy_address(dpmac_id,
> 0,
>  						riser_phy_addr[dpmac_id -
> 3]);
>  			}
>  			dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
> @@ -691,7 +691,7 @@ serdes2:
>  			break;
>  		case 4:
>  			/* Slot housing a SGMII riser card? */
> -			wriop_set_phy_address(dpmac_id,
> +			wriop_set_phy_address(dpmac_id, 0,
>  					      riser_phy_addr[dpmac_id - 9]);
>  			dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
>  			bus = mii_dev_for_muxval(EMI1_SLOT4); @@ -
> 701,14 +701,14 @@ serdes2:
>  			if (slot == EMI_NONE)
>  				return;
>  			if (serdes2_prtcl == 0x47) {
> -				wriop_set_phy_address(dpmac_id,
> +				wriop_set_phy_address(dpmac_id, 0,
>  					      riser_phy_addr[dpmac_id - 10]);
>  				if (dpmac_id >= 14 &&
> hwconfig_f("xqsgmii",
> 
> env_hwconfig))
> -					wriop_set_phy_address(dpmac_id,
> +					wriop_set_phy_address(dpmac_id,
> 0,
>  						riser_phy_addr[dpmac_id -
> 11]);
>  			} else {
> -				wriop_set_phy_address(dpmac_id,
> +				wriop_set_phy_address(dpmac_id, 0,
>  					riser_phy_addr[dpmac_id - 11]);
>  			}
>  			dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
> @@ -717,7 +717,7 @@ serdes2:
>  			break;
>  		case 6:
>  			/* Slot housing a SGMII riser card? */
> -			wriop_set_phy_address(dpmac_id,
> +			wriop_set_phy_address(dpmac_id, 0,
>  					      riser_phy_addr[dpmac_id - 13]);
>  			dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
>  			bus = mii_dev_for_muxval(EMI1_SLOT6); @@ -
> 775,7 +775,7 @@ void ls2080a_handle_phy_interface_qsgmii(int
> dpmac_id)
>  		switch (++slot) {
>  		case 1:
>  			/* Slot housing a QSGMII riser card? */
> -			wriop_set_phy_address(dpmac_id, dpmac_id - 1);
> +			wriop_set_phy_address(dpmac_id, 0, dpmac_id -
> 1);
>  			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
>  			bus = mii_dev_for_muxval(EMI1_SLOT1);
>  			wriop_set_mdio(dpmac_id, bus);
> @@ -819,7 +819,7 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
>  		 * the XAUI card is used for the XFI MAC, which will cause
>  		 * error.
>  		 */
> -		wriop_set_phy_address(i, i + 4);
> +		wriop_set_phy_address(i, 0, i + 4);
>  		ls2080a_qds_enable_SFP_TX(SFP_TX);
> 
>  		break;
> diff --git a/board/freescale/ls2080ardb/eth_ls2080rdb.c
> b/board/freescale/ls2080ardb/eth_ls2080rdb.c
> index 45f1d60322..62c7a7a315 100644
> --- a/board/freescale/ls2080ardb/eth_ls2080rdb.c
> +++ b/board/freescale/ls2080ardb/eth_ls2080rdb.c
> @@ -50,21 +50,21 @@ int board_eth_init(bd_t *bis)
> 
>  	switch (srds_s1) {
>  	case 0x2A:
> -		wriop_set_phy_address(WRIOP1_DPMAC1,
> CORTINA_PHY_ADDR1);
> -		wriop_set_phy_address(WRIOP1_DPMAC2,
> CORTINA_PHY_ADDR2);
> -		wriop_set_phy_address(WRIOP1_DPMAC3,
> CORTINA_PHY_ADDR3);
> -		wriop_set_phy_address(WRIOP1_DPMAC4,
> CORTINA_PHY_ADDR4);
> -		wriop_set_phy_address(WRIOP1_DPMAC5,
> AQ_PHY_ADDR1);
> -		wriop_set_phy_address(WRIOP1_DPMAC6,
> AQ_PHY_ADDR2);
> -		wriop_set_phy_address(WRIOP1_DPMAC7,
> AQ_PHY_ADDR3);
> -		wriop_set_phy_address(WRIOP1_DPMAC8,
> AQ_PHY_ADDR4);
> +		wriop_set_phy_address(WRIOP1_DPMAC1, 0,
> CORTINA_PHY_ADDR1);
> +		wriop_set_phy_address(WRIOP1_DPMAC2, 0,
> CORTINA_PHY_ADDR2);
> +		wriop_set_phy_address(WRIOP1_DPMAC3, 0,
> CORTINA_PHY_ADDR3);
> +		wriop_set_phy_address(WRIOP1_DPMAC4, 0,
> CORTINA_PHY_ADDR4);
> +		wriop_set_phy_address(WRIOP1_DPMAC5, 0,
> AQ_PHY_ADDR1);
> +		wriop_set_phy_address(WRIOP1_DPMAC6, 0,
> AQ_PHY_ADDR2);
> +		wriop_set_phy_address(WRIOP1_DPMAC7, 0,
> AQ_PHY_ADDR3);
> +		wriop_set_phy_address(WRIOP1_DPMAC8, 0,
> AQ_PHY_ADDR4);
> 
>  		break;
>  	case 0x4B:
> -		wriop_set_phy_address(WRIOP1_DPMAC1,
> CORTINA_PHY_ADDR1);
> -		wriop_set_phy_address(WRIOP1_DPMAC2,
> CORTINA_PHY_ADDR2);
> -		wriop_set_phy_address(WRIOP1_DPMAC3,
> CORTINA_PHY_ADDR3);
> -		wriop_set_phy_address(WRIOP1_DPMAC4,
> CORTINA_PHY_ADDR4);
> +		wriop_set_phy_address(WRIOP1_DPMAC1, 0,
> CORTINA_PHY_ADDR1);
> +		wriop_set_phy_address(WRIOP1_DPMAC2, 0,
> CORTINA_PHY_ADDR2);
> +		wriop_set_phy_address(WRIOP1_DPMAC3, 0,
> CORTINA_PHY_ADDR3);
> +		wriop_set_phy_address(WRIOP1_DPMAC4, 0,
> CORTINA_PHY_ADDR4);
> 
>  		break;
>  	default:
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c
> b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index d2bec31dd7..4fc5a0626b 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -23,26 +23,40 @@ static int init_phy(struct eth_device *dev)
>  	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
>  	struct phy_device *phydev = NULL;
>  	struct mii_dev *bus;
> -	int ret;
> +	int phy_addr, phy_num;
> +	int ret = 0;
> 
>  	bus = wriop_get_mdio(priv->dpmac_id);
>  	if (bus == NULL)
>  		return 0;
> 
> -	phydev = phy_connect(bus, wriop_get_phy_address(priv-
> >dpmac_id),
> -			     dev, wriop_get_enet_if(priv->dpmac_id));
> -	if (!phydev) {
> -		printf("Failed to connect\n");
> -		return -1;
> -	}
> -
> -	wriop_set_phy_dev(priv->dpmac_id, phydev);
> +	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> +		phy_addr = wriop_get_phy_address(priv->dpmac_id,
> phy_num);
> +		if (phy_addr < 0)
> +			continue;
> 
> -	ret = phy_config(phydev);
> +		phydev = phy_connect(bus, phy_addr, dev,
> +				     wriop_get_enet_if(priv->dpmac_id));
> +		if (!phydev) {
> +			printf("Failed to connect\n");
> +			ret = -ENODEV;
> +			break;
> +		}
> +		wriop_set_phy_dev(priv->dpmac_id, phy_num, phydev);
> +		ret = phy_config(phydev);
> +		if (ret)
> +			break;
> +	}
> 
>  	if (ret) {
> -		free(phydev);
> -		wriop_set_phy_dev(priv->dpmac_id, NULL);
> +		for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> +			phydev = wriop_get_phy_dev(priv->dpmac_id,
> phy_num);
> +			if (!phydev)
> +				continue;
> +
> +			free(phydev);
> +			wriop_set_phy_dev(priv->dpmac_id, phy_num,
> NULL);
> +		}
>  	}
> 
>  	return ret;
> @@ -390,10 +404,10 @@ static int ldpaa_get_dpmac_state(struct
> ldpaa_eth_priv *priv,  {
>  	struct phy_device *phydev = NULL;
>  	phy_interface_t enet_if;
> +	int phy_num, phys_detected;
>  	int err;
> 
> -	/* let's start off with maximum capabilities
> -	 */
> +	/* let's start off with maximum capabilities */
>  	enet_if = wriop_get_enet_if(priv->dpmac_id);
>  	switch (enet_if) {
>  	case PHY_INTERFACE_MODE_XGMII:
> @@ -405,15 +419,22 @@ static int ldpaa_get_dpmac_state(struct
> ldpaa_eth_priv *priv,
>  	}
>  	state->up = 1;
> 
> +	phys_detected = 0;
>  #ifdef CONFIG_PHYLIB
>  	state->options |= DPMAC_LINK_OPT_AUTONEG;
> 
> -	phydev = wriop_get_phy_dev(priv->dpmac_id);
> -	if (phydev) {
> +	/* start the phy devices one by one and update the dpmac state */
> +	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> +		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
> +		if (!phydev)
> +			continue;
> +
> +		phys_detected++;
>  		err = phy_startup(phydev);
>  		if (err) {
>  			printf("%s: Could not initialize\n", phydev->dev-
> >name);
>  			state->up = 0;
> +			break;
>  		}
>  		if (phydev->link) {
>  			state->rate = min(state->rate, (uint32_t)phydev-
> >speed); @@ -422,11 +443,13 @@ static int
> ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
>  			if (!phydev->autoneg)
>  				state->options &=
> ~DPMAC_LINK_OPT_AUTONEG;
>  		} else {
> +			/* break out of loop even if one phy is down */
>  			state->up = 0;
> +			break;
>  		}
>  	}
>  #endif
> -	if (!phydev)
> +	if (!phys_detected)
>  		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
> 
>  	if (!state->up) {
> @@ -568,6 +591,7 @@ static void ldpaa_eth_stop(struct eth_device
> *net_dev)
>  	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev-
> >priv;
>  	int err = 0;
>  	struct phy_device *phydev = NULL;
> +	int phy_num;
> 
>  	if ((net_dev->state == ETH_STATE_PASSIVE) ||
>  	    (net_dev->state == ETH_STATE_INIT)) @@ -600,9 +624,11 @@
> static void ldpaa_eth_stop(struct eth_device *net_dev)
>  		printf("dpni_disable() failed\n");
> 
>  #ifdef CONFIG_PHYLIB
> -	phydev = wriop_get_phy_dev(priv->dpmac_id);
> -	if (phydev)
> -		phy_shutdown(phydev);
> +	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> +		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
> +		if (phydev)
> +			phy_shutdown(phydev);
> +	}
>  #endif
> 
>  	/* Free DPBP handle and reset. */
> diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> index afbb1ca91e..be3101d26a 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> @@ -22,11 +22,10 @@ __weak phy_interface_t wriop_dpmac_enet_if(int
> dpmac_id, int lane_prtc)  void wriop_init_dpmac(int sd, int dpmac_id, int
> lane_prtcl)  {
>  	phy_interface_t enet_if;
> +	int phy_num;
> 
>  	dpmac_info[dpmac_id].enabled = 0;
>  	dpmac_info[dpmac_id].id = 0;
> -	dpmac_info[dpmac_id].phy_addr = -1;
> -	dpmac_info[dpmac_id].phydev = NULL;
>  	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
> 
>  	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); @@ -35,15
> +34,23 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
>  		dpmac_info[dpmac_id].id = dpmac_id;
>  		dpmac_info[dpmac_id].enet_if = enet_if;
>  	}
> +	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> +		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> +		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
> +	}
>  }
> 
>  void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)  {
> +	int phy_num;
> +
>  	dpmac_info[dpmac_id].enabled = 1;
>  	dpmac_info[dpmac_id].id = dpmac_id;
> -	dpmac_info[dpmac_id].phy_addr = -1;
>  	dpmac_info[dpmac_id].enet_if = enet_if;
> -	dpmac_info[dpmac_id].phydev = NULL;
> +	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> +		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> +		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
> +	}
>  }
> 
> 
> @@ -60,45 +67,45 @@ static int wriop_dpmac_to_index(int dpmac_id)
>  	return -1;
>  }
> 
> -void wriop_disable_dpmac(int dpmac_id)
> +int wriop_disable_dpmac(int dpmac_id)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
> -		return;
> +		return -ENODEV;
> 
>  	dpmac_info[i].enabled = 0;
>  	wriop_dpmac_disable(dpmac_id);
>  }
> 
> -void wriop_enable_dpmac(int dpmac_id)
> +int wriop_enable_dpmac(int dpmac_id)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
> -		return;
> +		return -ENODEV;
> 
>  	dpmac_info[i].enabled = 1;
>  	wriop_dpmac_enable(dpmac_id);
>  }
> 
> -u8 wriop_is_enabled_dpmac(int dpmac_id)
> +int wriop_is_enabled_dpmac(int dpmac_id)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
> -		return -1;
> +		return -ENODEV;
> 
>  	return dpmac_info[i].enabled;
>  }
> 
> 
> -void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
> +int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
> -		return;
> +		return -ENODEV;
> 
>  	dpmac_info[i].bus = bus;
>  }
> @@ -113,44 +120,52 @@ struct mii_dev *wriop_get_mdio(int dpmac_id)
>  	return dpmac_info[i].bus;
>  }
> 
> -void wriop_set_phy_address(int dpmac_id, int address)
> +int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
> -		return;
> +		return -ENODEV;
> +	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +		return -EINVAL;
> 
> -	dpmac_info[i].phy_addr = address;
> +	dpmac_info[i].phy_addr[phy_num] = address;
>  }
> 
> -int wriop_get_phy_address(int dpmac_id)
> +int wriop_get_phy_address(int dpmac_id, int phy_num)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
> -		return -1;
> +		return -ENODEV;
> +	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +		return -EINVAL;
> 
> -	return dpmac_info[i].phy_addr;
> +	return dpmac_info[i].phy_addr[phy_num];
>  }
> 
> -void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
> +int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device
> +*phydev)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
> -		return;
> +		return -ENODEV;
> +	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +		return -EINVAL;
> 
> -	dpmac_info[i].phydev = phydev;
> +	dpmac_info[i].phydev[phy_num] = phydev;
>  }
> 
> -struct phy_device *wriop_get_phy_dev(int dpmac_id)
> +struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
>  {
>  	int i = wriop_dpmac_to_index(dpmac_id);
> 
>  	if (i == -1)
>  		return NULL;
> +	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +		return NULL;
> 
> -	return dpmac_info[i].phydev;
> +	return dpmac_info[i].phydev[phy_num];
>  }
> 
>  phy_interface_t wriop_get_enet_if(int dpmac_id) diff --git a/include/fsl-
> mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h index
> 8971c6c55b..b55c39cbb2 100644
> --- a/include/fsl-mc/ldpaa_wriop.h
> +++ b/include/fsl-mc/ldpaa_wriop.h
> @@ -6,7 +6,11 @@
>  #ifndef __LDPAA_WRIOP_H
>  #define __LDPAA_WRIOP_H
> 
> - #include <phy.h>
> +#include <phy.h>
> +
> +#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
> +#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
> +#define WRIOP_MAX_PHY_NUM        2
> 
>  enum wriop_port {
>  	WRIOP1_DPMAC1 = 1,
> @@ -40,33 +44,30 @@ struct wriop_dpmac_info {
>  	u8 enabled;
>  	u8 id;
>  	u8 board_mux;
> -	int phy_addr;
> +	int phy_addr[WRIOP_MAX_PHY_NUM];
>  	phy_interface_t enet_if;
> -	struct phy_device *phydev;
> +	struct phy_device *phydev[WRIOP_MAX_PHY_NUM];
>  	struct mii_dev *bus;
>  };
> 
>  extern struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
> 
> -#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
> -#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
> -
> -void wriop_init_dpmac(int, int, int);
> -void wriop_disable_dpmac(int);
> -void wriop_enable_dpmac(int);
> -u8 wriop_is_enabled_dpmac(int dpmac_id); -void wriop_set_mdio(int,
> struct mii_dev *); -struct mii_dev *wriop_get_mdio(int); -void
> wriop_set_phy_address(int, int); -int wriop_get_phy_address(int); -void
> wriop_set_phy_dev(int, struct phy_device *); -struct phy_device
> *wriop_get_phy_dev(int); -phy_interface_t wriop_get_enet_if(int);
> +void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl); void
> +wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if); int
> +wriop_disable_dpmac(int dpmac_id); int wriop_enable_dpmac(int
> +dpmac_id); int wriop_is_enabled_dpmac(int dpmac_id); int
> +wriop_set_mdio(int dpmac_id, struct mii_dev *bus); struct mii_dev
> +*wriop_get_mdio(int dpmac_id); int wriop_set_phy_address(int
> dpmac_id,
> +int phy_num, int address); int wriop_get_phy_address(int dpmac_id, int
> +phy_num); int wriop_set_phy_dev(int dpmac_id, int phy_num, struct
> +phy_device *phydev); struct phy_device *wriop_get_phy_dev(int
> dpmac_id,
> +int phy_num); phy_interface_t wriop_get_enet_if(int dpmac_id);
> 
> -void wriop_dpmac_disable(int);
> -void wriop_dpmac_enable(int);
> -phy_interface_t wriop_dpmac_enet_if(int, int); -void
> wriop_init_dpmac_qsgmii(int, int);
> +void wriop_dpmac_disable(int dpmac_id); void wriop_dpmac_enable(int
> +dpmac_id); phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int
> +lane_prtcl); void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl);
>  void wriop_init_rgmii(void);
> -void wriop_init_dpmac_enet_if(int , phy_interface_t);
>  #endif	/* __LDPAA_WRIOP_H */
> --
> 2.17.1

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
                   ` (6 preceding siblings ...)
  2018-07-19  3:35 ` [U-Boot] [PATCH 0/6] " Prabhakar Kushwaha
@ 2018-07-30 13:14 ` Pankaj Bansal
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
                     ` (7 more replies)
  7 siblings, 8 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30 13:14 UTC (permalink / raw)
  To: u-boot

This patch set adds support of multiple phys for one dpmac

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where there
are sometimes two phy devices for one dpmac. One phy for TX lanes and one
phy for RX lanes. To handle such cases, add the support for multiple phys
in ethernet driver. The ethernet link is up if all the phy devices
connected to one dpmac report link up.
also the link capabilities are limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G without
autoneg and other operate at 1G with autoneg. Then the ethernet interface
will operate at 1G without autoneg.

Pankaj Bansal (6):
  driver: net: fsl-mc: modify the label name
  driver: net: fsl-mc: remove unused strcture elements
  driver: net: fsl-mc: fix error handing in init_phy
  driver: net: fsl-mc: Modify the dpmac link detection method
  driver: net: fsl-mc: initialize dpmac irrespective of phy
  driver: net: fsl-mc: Add support of multiple phys for dpmac

 board/freescale/ls1088a/eth_ls1088aqds.c   |  18 +--
 board/freescale/ls1088a/eth_ls1088ardb.c   |  21 +--
 board/freescale/ls2080aqds/eth.c           |  26 ++--
 board/freescale/ls2080ardb/eth_ls2080rdb.c |  24 +--
 drivers/net/fsl-mc/mc.c                    |   6 +-
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 171 +++++++++++++--------
 drivers/net/ldpaa_eth/ldpaa_eth.h          |   1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c        |  59 ++++---
 include/fsl-mc/ldpaa_wriop.h               |  46 +++---
 9 files changed, 211 insertions(+), 161 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 1/6] driver: net: fsl-mc: modify the label name
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
@ 2018-07-30 13:15   ` Pankaj Bansal
  2018-07-30 20:20     ` Joe Hershberger
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30 13:15 UTC (permalink / raw)
  To: u-boot

The goto label name is misspelled it should be DPMAC not DPAMC

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---

Notes:
    V2:
    - No change

 drivers/net/ldpaa_eth/ldpaa_eth.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 79facb4a44..18bc05790a 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -413,7 +413,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		if (err) {
 			printf("%s: Could not initialize\n",
 			       priv->phydev->dev->name);
-			goto err_dpamc_bind;
+			goto err_dpmac_bind;
 		}
 	}
 #else
@@ -441,13 +441,13 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (!priv->phydev->link) {
 		printf("%s: No link.\n", priv->phydev->dev->name);
 		err = -1;
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
 	if (err)
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 
 	/* DPNI initialization */
 	err = ldpaa_dpni_setup(priv);
@@ -540,7 +540,7 @@ err_dpni_bind:
 err_dpbp_setup:
 	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
 err_dpni_setup:
-err_dpamc_bind:
+err_dpmac_bind:
 	dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
 	dpmac_destroy(dflt_mc_io,
 		      dflt_dprc_handle,
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
@ 2018-07-30 13:15   ` Pankaj Bansal
  2018-07-30 20:19     ` Joe Hershberger
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
                     ` (5 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30 13:15 UTC (permalink / raw)
  To: u-boot

The phydev structure is present in both ldpaa_eth_priv and
wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used

As the phydev is created based on phy_addr and bus members of
wriop_dpmac_info, it is appropriate to keep phydev in wriop_dpmac_info.

Also phy_regs is not being used, therefore remove it

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---

Notes:
    V2:
    - change (phydev && bus != NULL) to (phydev && bus)
    - after free phydev just pass NULL into wriop_set_phy_dev()

 drivers/net/ldpaa_eth/ldpaa_eth.c   | 56 +++++++++++++++------------
 drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
 include/fsl-mc/ldpaa_wriop.h        |  1 -
 4 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 18bc05790a..4dd0f3913d 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
 		return -1;
 	}
 
-	priv->phydev = phydev;
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
 	return phy_config(phydev);
 }
@@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct mii_dev *bus;
 	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
+	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_dpmac_setup;
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev) {
-		err = phy_startup(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n",
-			       priv->phydev->dev->name);
+			       phydev->dev->name);
 			goto err_dpmac_bind;
 		}
 	}
 #else
-	priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(priv->phydev, 0, sizeof(struct phy_device));
+	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
+	memset(phydev, 0, sizeof(struct phy_device));
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	priv->phydev->speed = SPEED_1000;
-	priv->phydev->link = 1;
-	priv->phydev->duplex = DUPLEX_FULL;
+	phydev->speed = SPEED_1000;
+	phydev->link = 1;
+	phydev->duplex = DUPLEX_FULL;
 #endif
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	enet_if = wriop_get_enet_if(priv->dpmac_id);
 	if ((bus == NULL) &&
 	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		priv->phydev = (struct phy_device *)
+		phydev = (struct phy_device *)
 				malloc(sizeof(struct phy_device));
-		memset(priv->phydev, 0, sizeof(struct phy_device));
+		memset(phydev, 0, sizeof(struct phy_device));
+		wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-		priv->phydev->speed = SPEED_10000;
-		priv->phydev->link = 1;
-		priv->phydev->duplex = DUPLEX_FULL;
+		phydev->speed = SPEED_10000;
+		phydev->link = 1;
+		phydev->duplex = DUPLEX_FULL;
 	}
 
-	if (!priv->phydev->link) {
-		printf("%s: No link.\n", priv->phydev->dev->name);
+	if (!phydev->link) {
+		printf("%s: No link.\n", phydev->dev->name);
 		err = -1;
 		goto err_dpmac_bind;
 	}
@@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = priv->phydev->speed;
+	dpmac_link_state.rate = phydev->speed;
 
-	if (priv->phydev->autoneg == AUTONEG_DISABLE)
+	if (phydev->autoneg == AUTONEG_DISABLE)
 		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
 	else
 		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
 
-	if (priv->phydev->duplex == DUPLEX_HALF)
+	if (phydev->duplex == DUPLEX_HALF)
 		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
 
-	dpmac_link_state.up = priv->phydev->link;
+	dpmac_link_state.up = phydev->link;
 
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
@@ -530,7 +534,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return priv->phydev->link;
+	return phydev->link;
 
 err_qdid:
 err_get_queue:
@@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 #ifdef CONFIG_PHYLIB
 	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
 #endif
+	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -588,11 +593,12 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev && bus != NULL)
-		phy_shutdown(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev && bus)
+		phy_shutdown(phydev);
 	else {
-		free(priv->phydev);
-		priv->phydev = NULL;
+		free(phydev);
+		wriop_set_phy_dev(priv->dpmac_id, NULL);
 	}
 #endif
 
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h b/drivers/net/ldpaa_eth/ldpaa_eth.h
index ee784a55ee..3f9154b5bb 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.h
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
@@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
 	uint16_t tx_flow_id;
 
 	enum ldpaa_eth_type type;	/* 1G or 10G ethernet */
-	struct phy_device *phydev;
 };
 
 struct dprc_endpoint dpmac_endpoint;
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index 0731a795c8..afbb1ca91e 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
 	dpmac_info[dpmac_id].phy_addr = -1;
+	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -42,6 +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 	dpmac_info[dpmac_id].id = dpmac_id;
 	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
+	dpmac_info[dpmac_id].phydev = NULL;
 }
 
 
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 07e5130264..8971c6c55b 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -41,7 +41,6 @@ struct wriop_dpmac_info {
 	u8 id;
 	u8 board_mux;
 	int phy_addr;
-	void *phy_regs;
 	phy_interface_t enet_if;
 	struct phy_device *phydev;
 	struct mii_dev *bus;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 3/6] driver: net: fsl-mc: fix error handing in init_phy
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-07-30 13:15   ` Pankaj Bansal
  2018-07-30 20:26     ` Joe Hershberger
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
                     ` (4 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30 13:15 UTC (permalink / raw)
  To: u-boot

if an error occurs during init_phy, we should free the phydev structure
which has been allocated by phy_connect.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---

Notes:
    V2:
    - after free phydev just pass NULL into wriop_set_phy_dev()

 drivers/net/ldpaa_eth/ldpaa_eth.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 4dd0f3913d..4231fb6119 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,6 +23,7 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
+	int ret;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
@@ -37,7 +38,14 @@ static int init_phy(struct eth_device *dev)
 
 	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	return phy_config(phydev);
+	ret = phy_config(phydev);
+
+	if (ret) {
+		free(phydev);
+		wriop_set_phy_dev(priv->dpmac_id, NULL);
+	}
+
+	return ret;
 }
 #endif
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 4/6] driver: net: fsl-mc: Modify the dpmac link detection method
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
                     ` (2 preceding siblings ...)
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
@ 2018-07-30 13:15   ` Pankaj Bansal
  2018-07-30 20:35     ` Joe Hershberger
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
                     ` (3 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30 13:15 UTC (permalink / raw)
  To: u-boot

when there is no phy present for a dpmac, a dummy phy device is created.
when we move to multiple phy method, we need to create as many dummy phy
devices.

Change this method so that we don't need to create dummy phy devices.
We always report linkup if no phy is present.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---

Notes:
    V2:
    - Change (phydev->link == 1) to (phydev->link)
    - Use min macro instead of ternary operator
    - return -ENOLINK instead of -1 from ldpaa_get_dpmac_state
    - Change (state->up == 0) to (!state->up)

 drivers/net/ldpaa_eth/ldpaa_eth.c | 119 +++++++++++++---------------
 1 file changed, 57 insertions(+), 62 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 4231fb6119..d2bec31dd7 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -385,6 +385,59 @@ error:
 	return err;
 }
 
+static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
+				 struct dpmac_link_state *state)
+{
+	struct phy_device *phydev = NULL;
+	phy_interface_t enet_if;
+	int err;
+
+	/* let's start off with maximum capabilities
+	 */
+	enet_if = wriop_get_enet_if(priv->dpmac_id);
+	switch (enet_if) {
+	case PHY_INTERFACE_MODE_XGMII:
+		state->rate = SPEED_10000;
+		break;
+	default:
+		state->rate = SPEED_1000;
+		break;
+	}
+	state->up = 1;
+
+#ifdef CONFIG_PHYLIB
+	state->options |= DPMAC_LINK_OPT_AUTONEG;
+
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
+		if (err) {
+			printf("%s: Could not initialize\n", phydev->dev->name);
+			state->up = 0;
+		}
+		if (phydev->link) {
+			state->rate = min(state->rate, (uint32_t)phydev->speed);
+			if (!phydev->duplex)
+				state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
+			if (!phydev->autoneg)
+				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+		} else {
+			state->up = 0;
+		}
+	}
+#endif
+	if (!phydev)
+		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+
+	if (!state->up) {
+		state->rate = 0;
+		state->options = 0;
+		return -ENOLINK;
+	}
+
+	return 0;
+}
+
 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
@@ -393,10 +446,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct dpni_link_state link_state;
 #endif
 	int err = 0;
-	struct mii_dev *bus;
-	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
-	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -416,45 +466,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (err < 0)
 		goto err_dpmac_setup;
 
-#ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
-		err = phy_startup(phydev);
-		if (err) {
-			printf("%s: Could not initialize\n",
-			       phydev->dev->name);
-			goto err_dpmac_bind;
-		}
-	}
-#else
-	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(phydev, 0, sizeof(struct phy_device));
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-	phydev->speed = SPEED_1000;
-	phydev->link = 1;
-	phydev->duplex = DUPLEX_FULL;
-#endif
-
-	bus = wriop_get_mdio(priv->dpmac_id);
-	enet_if = wriop_get_enet_if(priv->dpmac_id);
-	if ((bus == NULL) &&
-	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		phydev = (struct phy_device *)
-				malloc(sizeof(struct phy_device));
-		memset(phydev, 0, sizeof(struct phy_device));
-		wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-		phydev->speed = SPEED_10000;
-		phydev->link = 1;
-		phydev->duplex = DUPLEX_FULL;
-	}
-
-	if (!phydev->link) {
-		printf("%s: No link.\n", phydev->dev->name);
-		err = -1;
+	err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
+	if (err < 0)
 		goto err_dpmac_bind;
-	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
@@ -488,18 +502,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = phydev->speed;
-
-	if (phydev->autoneg == AUTONEG_DISABLE)
-		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
-	else
-		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
-
-	if (phydev->duplex == DUPLEX_HALF)
-		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
-
-	dpmac_link_state.up = phydev->link;
-
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
 	if (err < 0) {
@@ -542,7 +544,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return phydev->link;
+	return dpmac_link_state.up;
 
 err_qdid:
 err_get_queue:
@@ -565,9 +567,6 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
-#ifdef CONFIG_PHYLIB
-	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
-#endif
 	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
@@ -602,12 +601,8 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 
 #ifdef CONFIG_PHYLIB
 	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev && bus)
+	if (phydev)
 		phy_shutdown(phydev);
-	else {
-		free(phydev);
-		wriop_set_phy_dev(priv->dpmac_id, NULL);
-	}
 #endif
 
 	/* Free DPBP handle and reset. */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
                     ` (3 preceding siblings ...)
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
@ 2018-07-30 13:15   ` Pankaj Bansal
  2018-07-30 20:36     ` Joe Hershberger
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
                     ` (2 subsequent siblings)
  7 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30 13:15 UTC (permalink / raw)
  To: u-boot

The dpmac initalization should not depend on phy.
As the phy is not necessary to be present for dpmac to function.
Therefore, remove dpmac initialization dependency from phy.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---

Notes:
    V2:
    - No Change

 drivers/net/fsl-mc/mc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c
index 982024e31e..e2341a2e3c 100644
--- a/drivers/net/fsl-mc/mc.c
+++ b/drivers/net/fsl-mc/mc.c
@@ -327,8 +327,7 @@ static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
 		/* port not enabled */
-		if ((wriop_is_enabled_dpmac(i) != 1) ||
-		    (wriop_get_phy_address(i) == -1))
+		if (wriop_is_enabled_dpmac(i) != 1)
 			continue;
 
 		sprintf(ethname, "DPMAC%d@%s", i,
@@ -845,8 +844,7 @@ int fsl_mc_ldpaa_init(bd_t *bis)
 	int i;
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
-		if ((wriop_is_enabled_dpmac(i) == 1) &&
-		    (wriop_get_phy_address(i) != -1))
+		if (wriop_is_enabled_dpmac(i) == 1)
 			ldpaa_eth_init(i, wriop_get_enet_if(i));
 	return 0;
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
                     ` (4 preceding siblings ...)
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
@ 2018-07-30 13:15   ` Pankaj Bansal
  2018-07-30  8:05     ` Pankaj Bansal
                       ` (2 more replies)
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
  7 siblings, 3 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-07-30 13:15 UTC (permalink / raw)
  To: u-boot

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where there
are sometimes two phy devices for one dpmac. One phy for TX lanes and
one phy for RX lanes. to handle such cases, add the support for multiple
phys in ethernet driver. The ethernet link is up if all the phy devices
connected to one dpmac report link up. also the link capabilities are
limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G without
autoneg and other operate at 1G with autoneg. Then the ethernet interface
will operate at 1G without autoneg.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---

Notes:
    V2:
    - use single-line comment format.
    - use WRIOP_MAX_PHY_NUM.
    - use -ENODEV or -EINVAL instead of -1 wherever appropriate
    - include the variable names in the headers too.
    - Change the return type of some functions from void to int so that
      a meaningful error message can be returned

 board/freescale/ls1088a/eth_ls1088aqds.c   | 18 +++---
 board/freescale/ls1088a/eth_ls1088ardb.c   | 21 ++++---
 board/freescale/ls2080aqds/eth.c           | 26 ++++----
 board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 66 ++++++++++++++------
 drivers/net/ldpaa_eth/ldpaa_wriop.c        | 61 +++++++++++-------
 include/fsl-mc/ldpaa_wriop.h               | 45 ++++++-------
 7 files changed, 152 insertions(+), 109 deletions(-)

diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c b/board/freescale/ls1088a/eth_ls1088aqds.c
index 40b1a0e631..f16b78cf03 100644
--- a/board/freescale/ls1088a/eth_ls1088aqds.c
+++ b/board/freescale/ls1088a/eth_ls1088aqds.c
@@ -487,16 +487,16 @@ void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
 	case 0x3A:
 		switch (dpmac_id) {
 		case 1:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[1]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
 			break;
 		case 2:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[0]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
 			break;
 		case 3:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[3]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
 			break;
 		case 7:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[2]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
 			break;
 		default:
 			printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
@@ -532,13 +532,13 @@ void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
 		case 4:
 		case 5:
 		case 6:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 9);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
 			break;
 		case 7:
 		case 8:
 		case 9:
 		case 10:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
 			break;
 		}
 
@@ -567,7 +567,7 @@ void ls1088a_handle_phy_interface_xsgmii(int i)
 	case 0x15:
 	case 0x1D:
 	case 0x1E:
-		wriop_set_phy_address(i, i + 26);
+		wriop_set_phy_address(i, 0, i + 26);
 		ls1088a_qds_enable_SFP_TX(SFP_TX);
 		break;
 	default:
@@ -590,13 +590,13 @@ static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
 
 	switch (dpmac_id) {
 	case 4:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY1_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
 		bus = mii_dev_for_muxval(EMI1_RGMII1);
 		wriop_set_mdio(dpmac_id, bus);
 		break;
 	case 5:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY2_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
 		bus = mii_dev_for_muxval(EMI1_RGMII2);
 		wriop_set_mdio(dpmac_id, bus);
diff --git a/board/freescale/ls1088a/eth_ls1088ardb.c b/board/freescale/ls1088a/eth_ls1088ardb.c
index 418f362e9a..a2b52a879b 100644
--- a/board/freescale/ls1088a/eth_ls1088ardb.c
+++ b/board/freescale/ls1088a/eth_ls1088ardb.c
@@ -55,16 +55,17 @@ int board_eth_init(bd_t *bis)
 		 * a MAC has no PHY address, we give a PHY address to XFI
 		 * MAC error.
 		 */
-		wriop_set_phy_address(WRIOP1_DPMAC1, 0x0a);
-		wriop_set_phy_address(WRIOP1_DPMAC2, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC3, QSGMII1_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC4, QSGMII1_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC5, QSGMII1_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC6, QSGMII1_PORT4_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC7, QSGMII2_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC8, QSGMII2_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC9, QSGMII2_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC10, QSGMII2_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, 0x0a);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, QSGMII1_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, QSGMII1_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, QSGMII1_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, QSGMII1_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, QSGMII2_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, QSGMII2_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC9, 0, QSGMII2_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC10, 0,
+				      QSGMII2_PORT4_PHY_ADDR);
 
 		break;
 	default:
diff --git a/board/freescale/ls2080aqds/eth.c b/board/freescale/ls2080aqds/eth.c
index 989d57e09b..f706fd4cb6 100644
--- a/board/freescale/ls2080aqds/eth.c
+++ b/board/freescale/ls2080aqds/eth.c
@@ -623,7 +623,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
@@ -631,7 +631,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			break;
 		case 2:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
 			bus = mii_dev_for_muxval(EMI1_SLOT2);
@@ -641,18 +641,18 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			if (slot == EMI_NONE)
 				return;
 			if (serdes1_prtcl == 0x39) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
@@ -691,7 +691,7 @@ serdes2:
 			break;
 		case 4:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 9]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
 			bus = mii_dev_for_muxval(EMI1_SLOT4);
@@ -701,14 +701,14 @@ serdes2:
 			if (slot == EMI_NONE)
 				return;
 			if (serdes2_prtcl == 0x47) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 10]);
 				if (dpmac_id >= 14 && hwconfig_f("xqsgmii",
 								 env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 11]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 11]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
@@ -717,7 +717,7 @@ serdes2:
 			break;
 		case 6:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 13]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
 			bus = mii_dev_for_muxval(EMI1_SLOT6);
@@ -775,7 +775,7 @@ void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a QSGMII riser card? */
-			wriop_set_phy_address(dpmac_id, dpmac_id - 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id - 1);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
 			wriop_set_mdio(dpmac_id, bus);
@@ -819,7 +819,7 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
 		 * the XAUI card is used for the XFI MAC, which will cause
 		 * error.
 		 */
-		wriop_set_phy_address(i, i + 4);
+		wriop_set_phy_address(i, 0, i + 4);
 		ls2080a_qds_enable_SFP_TX(SFP_TX);
 
 		break;
diff --git a/board/freescale/ls2080ardb/eth_ls2080rdb.c b/board/freescale/ls2080ardb/eth_ls2080rdb.c
index 45f1d60322..62c7a7a315 100644
--- a/board/freescale/ls2080ardb/eth_ls2080rdb.c
+++ b/board/freescale/ls2080ardb/eth_ls2080rdb.c
@@ -50,21 +50,21 @@ int board_eth_init(bd_t *bis)
 
 	switch (srds_s1) {
 	case 0x2A:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
-		wriop_set_phy_address(WRIOP1_DPMAC5, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC6, AQ_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC7, AQ_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC8, AQ_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, AQ_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, AQ_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, AQ_PHY_ADDR4);
 
 		break;
 	case 0x4B:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
 
 		break;
 	default:
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index d2bec31dd7..4fc5a0626b 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,26 +23,40 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
-	int ret;
+	int phy_addr, phy_num;
+	int ret = 0;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
 		return 0;
 
-	phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
-			     dev, wriop_get_enet_if(priv->dpmac_id));
-	if (!phydev) {
-		printf("Failed to connect\n");
-		return -1;
-	}
-
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phy_addr = wriop_get_phy_address(priv->dpmac_id, phy_num);
+		if (phy_addr < 0)
+			continue;
 
-	ret = phy_config(phydev);
+		phydev = phy_connect(bus, phy_addr, dev,
+				     wriop_get_enet_if(priv->dpmac_id));
+		if (!phydev) {
+			printf("Failed to connect\n");
+			ret = -ENODEV;
+			break;
+		}
+		wriop_set_phy_dev(priv->dpmac_id, phy_num, phydev);
+		ret = phy_config(phydev);
+		if (ret)
+			break;
+	}
 
 	if (ret) {
-		free(phydev);
-		wriop_set_phy_dev(priv->dpmac_id, NULL);
+		for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+			phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+			if (!phydev)
+				continue;
+
+			free(phydev);
+			wriop_set_phy_dev(priv->dpmac_id, phy_num, NULL);
+		}
 	}
 
 	return ret;
@@ -390,10 +404,10 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 {
 	struct phy_device *phydev = NULL;
 	phy_interface_t enet_if;
+	int phy_num, phys_detected;
 	int err;
 
-	/* let's start off with maximum capabilities
-	 */
+	/* let's start off with maximum capabilities */
 	enet_if = wriop_get_enet_if(priv->dpmac_id);
 	switch (enet_if) {
 	case PHY_INTERFACE_MODE_XGMII:
@@ -405,15 +419,22 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 	}
 	state->up = 1;
 
+	phys_detected = 0;
 #ifdef CONFIG_PHYLIB
 	state->options |= DPMAC_LINK_OPT_AUTONEG;
 
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
+	/* start the phy devices one by one and update the dpmac state */
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (!phydev)
+			continue;
+
+		phys_detected++;
 		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n", phydev->dev->name);
 			state->up = 0;
+			break;
 		}
 		if (phydev->link) {
 			state->rate = min(state->rate, (uint32_t)phydev->speed);
@@ -422,11 +443,13 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 			if (!phydev->autoneg)
 				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 		} else {
+			/* break out of loop even if one phy is down */
 			state->up = 0;
+			break;
 		}
 	}
 #endif
-	if (!phydev)
+	if (!phys_detected)
 		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 
 	if (!state->up) {
@@ -568,6 +591,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
 	struct phy_device *phydev = NULL;
+	int phy_num;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -600,9 +624,11 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev)
-		phy_shutdown(phydev);
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (phydev)
+			phy_shutdown(phydev);
+	}
 #endif
 
 	/* Free DPBP handle and reset. */
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index afbb1ca91e..be3101d26a 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -22,11 +22,10 @@ __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
 void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 {
 	phy_interface_t enet_if;
+	int phy_num;
 
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
-	dpmac_info[dpmac_id].phy_addr = -1;
-	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -35,15 +34,23 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 		dpmac_info[dpmac_id].id = dpmac_id;
 		dpmac_info[dpmac_id].enet_if = enet_if;
 	}
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 {
+	int phy_num;
+
 	dpmac_info[dpmac_id].enabled = 1;
 	dpmac_info[dpmac_id].id = dpmac_id;
-	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
-	dpmac_info[dpmac_id].phydev = NULL;
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 
@@ -60,45 +67,45 @@ static int wriop_dpmac_to_index(int dpmac_id)
 	return -1;
 }
 
-void wriop_disable_dpmac(int dpmac_id)
+int wriop_disable_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].enabled = 0;
 	wriop_dpmac_disable(dpmac_id);
 }
 
-void wriop_enable_dpmac(int dpmac_id)
+int wriop_enable_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].enabled = 1;
 	wriop_dpmac_enable(dpmac_id);
 }
 
-u8 wriop_is_enabled_dpmac(int dpmac_id)
+int wriop_is_enabled_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return -1;
+		return -ENODEV;
 
 	return dpmac_info[i].enabled;
 }
 
 
-void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
+int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].bus = bus;
 }
@@ -113,44 +120,52 @@ struct mii_dev *wriop_get_mdio(int dpmac_id)
 	return dpmac_info[i].bus;
 }
 
-void wriop_set_phy_address(int dpmac_id, int address)
+int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
 
-	dpmac_info[i].phy_addr = address;
+	dpmac_info[i].phy_addr[phy_num] = address;
 }
 
-int wriop_get_phy_address(int dpmac_id)
+int wriop_get_phy_address(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return -1;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
 
-	return dpmac_info[i].phy_addr;
+	return dpmac_info[i].phy_addr[phy_num];
 }
 
-void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
+int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
 
-	dpmac_info[i].phydev = phydev;
+	dpmac_info[i].phydev[phy_num] = phydev;
 }
 
-struct phy_device *wriop_get_phy_dev(int dpmac_id)
+struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
 		return NULL;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return NULL;
 
-	return dpmac_info[i].phydev;
+	return dpmac_info[i].phydev[phy_num];
 }
 
 phy_interface_t wriop_get_enet_if(int dpmac_id)
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 8971c6c55b..b55c39cbb2 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -6,7 +6,11 @@
 #ifndef __LDPAA_WRIOP_H
 #define __LDPAA_WRIOP_H
 
- #include <phy.h>
+#include <phy.h>
+
+#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
+#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
+#define WRIOP_MAX_PHY_NUM        2
 
 enum wriop_port {
 	WRIOP1_DPMAC1 = 1,
@@ -40,33 +44,30 @@ struct wriop_dpmac_info {
 	u8 enabled;
 	u8 id;
 	u8 board_mux;
-	int phy_addr;
+	int phy_addr[WRIOP_MAX_PHY_NUM];
 	phy_interface_t enet_if;
-	struct phy_device *phydev;
+	struct phy_device *phydev[WRIOP_MAX_PHY_NUM];
 	struct mii_dev *bus;
 };
 
 extern struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
 
-#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
-#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
-
-void wriop_init_dpmac(int, int, int);
-void wriop_disable_dpmac(int);
-void wriop_enable_dpmac(int);
-u8 wriop_is_enabled_dpmac(int dpmac_id);
-void wriop_set_mdio(int, struct mii_dev *);
-struct mii_dev *wriop_get_mdio(int);
-void wriop_set_phy_address(int, int);
-int wriop_get_phy_address(int);
-void wriop_set_phy_dev(int, struct phy_device *);
-struct phy_device *wriop_get_phy_dev(int);
-phy_interface_t wriop_get_enet_if(int);
+void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl);
+void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if);
+int wriop_disable_dpmac(int dpmac_id);
+int wriop_enable_dpmac(int dpmac_id);
+int wriop_is_enabled_dpmac(int dpmac_id);
+int wriop_set_mdio(int dpmac_id, struct mii_dev *bus);
+struct mii_dev *wriop_get_mdio(int dpmac_id);
+int wriop_set_phy_address(int dpmac_id, int phy_num, int address);
+int wriop_get_phy_address(int dpmac_id, int phy_num);
+int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev);
+struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num);
+phy_interface_t wriop_get_enet_if(int dpmac_id);
 
-void wriop_dpmac_disable(int);
-void wriop_dpmac_enable(int);
-phy_interface_t wriop_dpmac_enet_if(int, int);
-void wriop_init_dpmac_qsgmii(int, int);
+void wriop_dpmac_disable(int dpmac_id);
+void wriop_dpmac_enable(int dpmac_id);
+phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl);
+void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl);
 void wriop_init_rgmii(void);
-void wriop_init_dpmac_enet_if(int , phy_interface_t);
 #endif	/* __LDPAA_WRIOP_H */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-07-30 20:19     ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-30 20:19 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 30, 2018 at 8:15 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> The phydev structure is present in both ldpaa_eth_priv and
> wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used
>
> As the phydev is created based on phy_addr and bus members of
> wriop_dpmac_info, it is appropriate to keep phydev in wriop_dpmac_info.
>
> Also phy_regs is not being used, therefore remove it
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 1/6] driver: net: fsl-mc: modify the label name
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
@ 2018-07-30 20:20     ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-30 20:20 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 30, 2018 at 8:15 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> The goto label name is misspelled it should be DPMAC not DPAMC
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 3/6] driver: net: fsl-mc: fix error handing in init_phy
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
@ 2018-07-30 20:26     ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-30 20:26 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 30, 2018 at 8:15 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> if an error occurs during init_phy, we should free the phydev structure
> which has been allocated by phy_connect.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 4/6] driver: net: fsl-mc: Modify the dpmac link detection method
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
@ 2018-07-30 20:35     ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-30 20:35 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 30, 2018 at 8:15 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> when there is no phy present for a dpmac, a dummy phy device is created.
> when we move to multiple phy method, we need to create as many dummy phy
> devices.
>
> Change this method so that we don't need to create dummy phy devices.
> We always report linkup if no phy is present.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
@ 2018-07-30 20:36     ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-30 20:36 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 30, 2018 at 8:15 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> The dpmac initalization should not depend on phy.
> As the phy is not necessary to be present for dpmac to function.
> Therefore, remove dpmac initialization dependency from phy.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  2018-07-30  8:05     ` Pankaj Bansal
@ 2018-07-30 21:43     ` Joe Hershberger
  2018-10-09 21:32     ` Joe Hershberger
  2 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-07-30 21:43 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 30, 2018 at 8:15 AM, Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
> Till now we have had cases where we had one phy device per dpmac.
> Now, with the upcoming products (LX2160AQDS), we have cases, where there
> are sometimes two phy devices for one dpmac. One phy for TX lanes and
> one phy for RX lanes. to handle such cases, add the support for multiple
> phys in ethernet driver. The ethernet link is up if all the phy devices
> connected to one dpmac report link up. also the link capabilities are
> limited by the weakest phy device.
>
> i.e. say if there are two phys for one dpmac. one operates at 10G without
> autoneg and other operate at 1G with autoneg. Then the ethernet interface
> will operate at 1G without autoneg.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  2018-07-30  8:05     ` Pankaj Bansal
  2018-07-30 21:43     ` Joe Hershberger
@ 2018-10-09 21:32     ` Joe Hershberger
  2018-10-10  2:59       ` Pankaj Bansal
  2 siblings, 1 reply; 54+ messages in thread
From: Joe Hershberger @ 2018-10-09 21:32 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 30, 2018 at 2:48 AM Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
>
> Till now we have had cases where we had one phy device per dpmac.
> Now, with the upcoming products (LX2160AQDS), we have cases, where there
> are sometimes two phy devices for one dpmac. One phy for TX lanes and
> one phy for RX lanes. to handle such cases, add the support for multiple
> phys in ethernet driver. The ethernet link is up if all the phy devices
> connected to one dpmac report link up. also the link capabilities are
> limited by the weakest phy device.
>
> i.e. say if there are two phys for one dpmac. one operates at 10G without
> autoneg and other operate at 1G with autoneg. Then the ethernet interface
> will operate at 1G without autoneg.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>
> Notes:
>     V2:
>     - use single-line comment format.
>     - use WRIOP_MAX_PHY_NUM.
>     - use -ENODEV or -EINVAL instead of -1 wherever appropriate
>     - include the variable names in the headers too.
>     - Change the return type of some functions from void to int so that
>       a meaningful error message can be returned
>
>  board/freescale/ls1088a/eth_ls1088aqds.c   | 18 +++---
>  board/freescale/ls1088a/eth_ls1088ardb.c   | 21 ++++---
>  board/freescale/ls2080aqds/eth.c           | 26 ++++----
>  board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
>  drivers/net/ldpaa_eth/ldpaa_eth.c          | 66 ++++++++++++++------
>  drivers/net/ldpaa_eth/ldpaa_wriop.c        | 61 +++++++++++-------
>  include/fsl-mc/ldpaa_wriop.h               | 45 ++++++-------
>  7 files changed, 152 insertions(+), 109 deletions(-)
>

[ ... ]

> diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> index afbb1ca91e..be3101d26a 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> @@ -22,11 +22,10 @@ __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
>  void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
>  {
>         phy_interface_t enet_if;
> +       int phy_num;
>
>         dpmac_info[dpmac_id].enabled = 0;
>         dpmac_info[dpmac_id].id = 0;
> -       dpmac_info[dpmac_id].phy_addr = -1;
> -       dpmac_info[dpmac_id].phydev = NULL;
>         dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
>
>         enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
> @@ -35,15 +34,23 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
>                 dpmac_info[dpmac_id].id = dpmac_id;
>                 dpmac_info[dpmac_id].enet_if = enet_if;
>         }
> +       for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
> +               dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> +               dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
> +       }
>  }
>
>  void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
>  {
> +       int phy_num;
> +
>         dpmac_info[dpmac_id].enabled = 1;
>         dpmac_info[dpmac_id].id = dpmac_id;
> -       dpmac_info[dpmac_id].phy_addr = -1;
>         dpmac_info[dpmac_id].enet_if = enet_if;
> -       dpmac_info[dpmac_id].phydev = NULL;
> +       for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
> +               dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> +               dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
> +       }
>  }
>
>
> @@ -60,45 +67,45 @@ static int wriop_dpmac_to_index(int dpmac_id)
>         return -1;
>  }
>
> -void wriop_disable_dpmac(int dpmac_id)
> +int wriop_disable_dpmac(int dpmac_id)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
> -               return;
> +               return -ENODEV;
>
>         dpmac_info[i].enabled = 0;
>         wriop_dpmac_disable(dpmac_id);

These functions all warn since you don't return 0 at the end of them.
Now I'll have to back this series out of the release and wait for an
update. Patches need to build without warnings.

>  }
>
> -void wriop_enable_dpmac(int dpmac_id)
> +int wriop_enable_dpmac(int dpmac_id)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
> -               return;
> +               return -ENODEV;
>
>         dpmac_info[i].enabled = 1;
>         wriop_dpmac_enable(dpmac_id);
>  }
>
> -u8 wriop_is_enabled_dpmac(int dpmac_id)
> +int wriop_is_enabled_dpmac(int dpmac_id)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
> -               return -1;
> +               return -ENODEV;
>
>         return dpmac_info[i].enabled;
>  }
>
>
> -void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
> +int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
> -               return;
> +               return -ENODEV;
>
>         dpmac_info[i].bus = bus;
>  }
> @@ -113,44 +120,52 @@ struct mii_dev *wriop_get_mdio(int dpmac_id)
>         return dpmac_info[i].bus;
>  }
>
> -void wriop_set_phy_address(int dpmac_id, int address)
> +int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
> -               return;
> +               return -ENODEV;
> +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +               return -EINVAL;
>
> -       dpmac_info[i].phy_addr = address;
> +       dpmac_info[i].phy_addr[phy_num] = address;
>  }
>
> -int wriop_get_phy_address(int dpmac_id)
> +int wriop_get_phy_address(int dpmac_id, int phy_num)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
> -               return -1;
> +               return -ENODEV;
> +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +               return -EINVAL;
>
> -       return dpmac_info[i].phy_addr;
> +       return dpmac_info[i].phy_addr[phy_num];
>  }
>
> -void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
> +int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
> -               return;
> +               return -ENODEV;
> +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +               return -EINVAL;
>
> -       dpmac_info[i].phydev = phydev;
> +       dpmac_info[i].phydev[phy_num] = phydev;
>  }
>
> -struct phy_device *wriop_get_phy_dev(int dpmac_id)
> +struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
>  {
>         int i = wriop_dpmac_to_index(dpmac_id);
>
>         if (i == -1)
>                 return NULL;
> +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> +               return NULL;
>
> -       return dpmac_info[i].phydev;
> +       return dpmac_info[i].phydev[phy_num];
>  }
>
>  phy_interface_t wriop_get_enet_if(int dpmac_id)

[ ... ]

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-10-09 21:32     ` Joe Hershberger
@ 2018-10-10  2:59       ` Pankaj Bansal
  0 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  2:59 UTC (permalink / raw)
  To: u-boot



> -----Original Message-----
> From: Joe Hershberger [mailto:joe.hershberger at ni.com]
> Sent: Wednesday, October 10, 2018 3:02 AM
> To: Pankaj Bansal <pankaj.bansal@nxp.com>
> Cc: u-boot <u-boot@lists.denx.de>; Joseph Hershberger
> <joseph.hershberger@ni.com>; Priyanka Jain <priyanka.jain@nxp.com>;
> Varun Sethi <V.Sethi@nxp.com>
> Subject: Re: [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of
> multiple phys for dpmac
> 
> On Mon, Jul 30, 2018 at 2:48 AM Pankaj Bansal <pankaj.bansal@nxp.com>
> wrote:
> >
> > Till now we have had cases where we had one phy device per dpmac.
> > Now, with the upcoming products (LX2160AQDS), we have cases, where
> > there are sometimes two phy devices for one dpmac. One phy for TX
> > lanes and one phy for RX lanes. to handle such cases, add the support
> > for multiple phys in ethernet driver. The ethernet link is up if all
> > the phy devices connected to one dpmac report link up. also the link
> > capabilities are limited by the weakest phy device.
> >
> > i.e. say if there are two phys for one dpmac. one operates at 10G
> > without autoneg and other operate at 1G with autoneg. Then the
> > ethernet interface will operate at 1G without autoneg.
> >
> > Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> > ---
> >
> > Notes:
> >     V2:
> >     - use single-line comment format.
> >     - use WRIOP_MAX_PHY_NUM.
> >     - use -ENODEV or -EINVAL instead of -1 wherever appropriate
> >     - include the variable names in the headers too.
> >     - Change the return type of some functions from void to int so that
> >       a meaningful error message can be returned
> >
> >  board/freescale/ls1088a/eth_ls1088aqds.c   | 18 +++---
> >  board/freescale/ls1088a/eth_ls1088ardb.c   | 21 ++++---
> >  board/freescale/ls2080aqds/eth.c           | 26 ++++----
> >  board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
> >  drivers/net/ldpaa_eth/ldpaa_eth.c          | 66 ++++++++++++++------
> >  drivers/net/ldpaa_eth/ldpaa_wriop.c        | 61 +++++++++++-------
> >  include/fsl-mc/ldpaa_wriop.h               | 45 ++++++-------
> >  7 files changed, 152 insertions(+), 109 deletions(-)
> >
> 
> [ ... ]
> 
> > diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > index afbb1ca91e..be3101d26a 100644
> > --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > @@ -22,11 +22,10 @@ __weak phy_interface_t
> wriop_dpmac_enet_if(int
> > dpmac_id, int lane_prtc)  void wriop_init_dpmac(int sd, int dpmac_id,
> > int lane_prtcl)  {
> >         phy_interface_t enet_if;
> > +       int phy_num;
> >
> >         dpmac_info[dpmac_id].enabled = 0;
> >         dpmac_info[dpmac_id].id = 0;
> > -       dpmac_info[dpmac_id].phy_addr = -1;
> > -       dpmac_info[dpmac_id].phydev = NULL;
> >         dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
> >
> >         enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); @@ -35,15
> > +34,23 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
> >                 dpmac_info[dpmac_id].id = dpmac_id;
> >                 dpmac_info[dpmac_id].enet_if = enet_if;
> >         }
> > +       for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> > +               dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> > +               dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
> > +       }
> >  }
> >
> >  void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
> > {
> > +       int phy_num;
> > +
> >         dpmac_info[dpmac_id].enabled = 1;
> >         dpmac_info[dpmac_id].id = dpmac_id;
> > -       dpmac_info[dpmac_id].phy_addr = -1;
> >         dpmac_info[dpmac_id].enet_if = enet_if;
> > -       dpmac_info[dpmac_id].phydev = NULL;
> > +       for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM;
> phy_num++) {
> > +               dpmac_info[dpmac_id].phydev[phy_num] = NULL;
> > +               dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
> > +       }
> >  }
> >
> >
> > @@ -60,45 +67,45 @@ static int wriop_dpmac_to_index(int dpmac_id)
> >         return -1;
> >  }
> >
> > -void wriop_disable_dpmac(int dpmac_id)
> > +int wriop_disable_dpmac(int dpmac_id)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> > -               return;
> > +               return -ENODEV;
> >
> >         dpmac_info[i].enabled = 0;
> >         wriop_dpmac_disable(dpmac_id);
> 
> These functions all warn since you don't return 0 at the end of them.
> Now I'll have to back this series out of the release and wait for an update.
> Patches need to build without warnings.

My apologies for this oversight on my part.
I have sent V3 of these patches with the return 0 at the end of all functions, whose return type changed.
I have also tested these patches for build warning after compiling for "ls2080aqds"

> 
> >  }
> >
> > -void wriop_enable_dpmac(int dpmac_id)
> > +int wriop_enable_dpmac(int dpmac_id)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> > -               return;
> > +               return -ENODEV;
> >
> >         dpmac_info[i].enabled = 1;
> >         wriop_dpmac_enable(dpmac_id);
> >  }
> >
> > -u8 wriop_is_enabled_dpmac(int dpmac_id)
> > +int wriop_is_enabled_dpmac(int dpmac_id)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> > -               return -1;
> > +               return -ENODEV;
> >
> >         return dpmac_info[i].enabled;
> >  }
> >
> >
> > -void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
> > +int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> > -               return;
> > +               return -ENODEV;
> >
> >         dpmac_info[i].bus = bus;
> >  }
> > @@ -113,44 +120,52 @@ struct mii_dev *wriop_get_mdio(int
> dpmac_id)
> >         return dpmac_info[i].bus;
> >  }
> >
> > -void wriop_set_phy_address(int dpmac_id, int address)
> > +int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> > -               return;
> > +               return -ENODEV;
> > +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> > +               return -EINVAL;
> >
> > -       dpmac_info[i].phy_addr = address;
> > +       dpmac_info[i].phy_addr[phy_num] = address;
> >  }
> >
> > -int wriop_get_phy_address(int dpmac_id)
> > +int wriop_get_phy_address(int dpmac_id, int phy_num)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> > -               return -1;
> > +               return -ENODEV;
> > +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> > +               return -EINVAL;
> >
> > -       return dpmac_info[i].phy_addr;
> > +       return dpmac_info[i].phy_addr[phy_num];
> >  }
> >
> > -void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
> > +int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device
> > +*phydev)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> > -               return;
> > +               return -ENODEV;
> > +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> > +               return -EINVAL;
> >
> > -       dpmac_info[i].phydev = phydev;
> > +       dpmac_info[i].phydev[phy_num] = phydev;
> >  }
> >
> > -struct phy_device *wriop_get_phy_dev(int dpmac_id)
> > +struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
> >  {
> >         int i = wriop_dpmac_to_index(dpmac_id);
> >
> >         if (i == -1)
> >                 return NULL;
> > +       if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
> > +               return NULL;
> >
> > -       return dpmac_info[i].phydev;
> > +       return dpmac_info[i].phydev[phy_num];
> >  }
> >
> >  phy_interface_t wriop_get_enet_if(int dpmac_id)
> 
> [ ... ]

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-10-10  8:27     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-10-10  3:59       ` Joe Hershberger
  2018-10-10  5:10         ` Pankaj Bansal
  0 siblings, 1 reply; 54+ messages in thread
From: Joe Hershberger @ 2018-10-10  3:59 UTC (permalink / raw)
  To: u-boot

On Tue, Oct 9, 2018 at 9:59 PM Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
>
> The phydev structure is present in both ldpaa_eth_priv and
> wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used
>
> As the phydev is created based on phy_addr and bus members of
> wriop_dpmac_info, it is appropriate to keep phydev in wriop_dpmac_info.
>
> Also phy_regs is not being used, therefore remove it
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> ---
>
> Notes:
>     V3:
>     - No change

Please be sure you are running scripts/checkpatch.pl on your patches.
v2 had a number of issues I had to fix up. I'm pretty sure this was
one of them.

You would do yourself a favor to use tools/patman/patman.

>     V2:
>     - change (phydev && bus != NULL) to (phydev && bus)
>     - after free phydev just pass NULL into wriop_set_phy_dev()
>
>  drivers/net/ldpaa_eth/ldpaa_eth.c   | 56 +++++++++++++++------------
>  drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
>  drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
>  include/fsl-mc/ldpaa_wriop.h        |  1 -
>  4 files changed, 33 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index 82a684bea2..ca3459cc33 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
>                 return -1;
>         }
>
> -       priv->phydev = phydev;
> +       wriop_set_phy_dev(priv->dpmac_id, phydev);
>
>         return phy_config(phydev);
>  }
> @@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>         struct mii_dev *bus;
>         phy_interface_t enet_if;
>         struct dpni_queue d_queue;
> +       struct phy_device *phydev = NULL;
>
>         if (net_dev->state == ETH_STATE_ACTIVE)
>                 return 0;
> @@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 goto err_dpmac_setup;
>
>  #ifdef CONFIG_PHYLIB
> -       if (priv->phydev) {
> -               err = phy_startup(priv->phydev);
> +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> +       if (phydev) {
> +               err = phy_startup(phydev);
>                 if (err) {
>                         printf("%s: Could not initialize\n",
> -                              priv->phydev->dev->name);
> +                              phydev->dev->name);
>                         goto err_dpmac_bind;
>                 }
>         }
>  #else
> -       priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
> -       memset(priv->phydev, 0, sizeof(struct phy_device));
> +       phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
> +       memset(phydev, 0, sizeof(struct phy_device));
> +       wriop_set_phy_dev(priv->dpmac_id, phydev);
>
> -       priv->phydev->speed = SPEED_1000;
> -       priv->phydev->link = 1;
> -       priv->phydev->duplex = DUPLEX_FULL;
> +       phydev->speed = SPEED_1000;
> +       phydev->link = 1;
> +       phydev->duplex = DUPLEX_FULL;
>  #endif
>
>         bus = wriop_get_mdio(priv->dpmac_id);
>         enet_if = wriop_get_enet_if(priv->dpmac_id);
>         if ((bus == NULL) &&
>             (enet_if == PHY_INTERFACE_MODE_XGMII)) {
> -               priv->phydev = (struct phy_device *)
> +               phydev = (struct phy_device *)
>                                 malloc(sizeof(struct phy_device));
> -               memset(priv->phydev, 0, sizeof(struct phy_device));
> +               memset(phydev, 0, sizeof(struct phy_device));
> +               wriop_set_phy_dev(priv->dpmac_id, phydev);
>
> -               priv->phydev->speed = SPEED_10000;
> -               priv->phydev->link = 1;
> -               priv->phydev->duplex = DUPLEX_FULL;
> +               phydev->speed = SPEED_10000;
> +               phydev->link = 1;
> +               phydev->duplex = DUPLEX_FULL;
>         }
>
> -       if (!priv->phydev->link) {
> -               printf("%s: No link.\n", priv->phydev->dev->name);
> +       if (!phydev->link) {
> +               printf("%s: No link.\n", phydev->dev->name);
>                 err = -1;
>                 goto err_dpmac_bind;
>         }
> @@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 return err;
>         }
>
> -       dpmac_link_state.rate = priv->phydev->speed;
> +       dpmac_link_state.rate = phydev->speed;
>
> -       if (priv->phydev->autoneg == AUTONEG_DISABLE)
> +       if (phydev->autoneg == AUTONEG_DISABLE)
>                 dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
>         else
>                 dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
>
> -       if (priv->phydev->duplex == DUPLEX_HALF)
> +       if (phydev->duplex == DUPLEX_HALF)
>                 dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
>
> -       dpmac_link_state.up = priv->phydev->link;
> +       dpmac_link_state.up = phydev->link;
>
>         err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
>                                   priv->dpmac_handle, &dpmac_link_state);
> @@ -530,7 +534,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
>                 goto err_qdid;
>         }
>
> -       return priv->phydev->link;
> +       return phydev->link;
>
>  err_qdid:
>  err_get_queue:
> @@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>  #ifdef CONFIG_PHYLIB
>         struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
>  #endif
> +       struct phy_device *phydev = NULL;
>
>         if ((net_dev->state == ETH_STATE_PASSIVE) ||
>             (net_dev->state == ETH_STATE_INIT))
> @@ -588,11 +593,12 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
>                 printf("dpni_disable() failed\n");
>
>  #ifdef CONFIG_PHYLIB
> -       if (priv->phydev && bus != NULL)
> -               phy_shutdown(priv->phydev);
> +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> +       if (phydev && bus)
> +               phy_shutdown(phydev);
>         else {
> -               free(priv->phydev);
> -               priv->phydev = NULL;
> +               free(phydev);
> +               wriop_set_phy_dev(priv->dpmac_id, NULL);
>         }
>  #endif
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h b/drivers/net/ldpaa_eth/ldpaa_eth.h
> index ee784a55ee..3f9154b5bb 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.h
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
> @@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
>         uint16_t tx_flow_id;
>
>         enum ldpaa_eth_type type;       /* 1G or 10G ethernet */
> -       struct phy_device *phydev;
>  };
>
>  struct dprc_endpoint dpmac_endpoint;
> diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> index 0731a795c8..afbb1ca91e 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> @@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
>         dpmac_info[dpmac_id].enabled = 0;
>         dpmac_info[dpmac_id].id = 0;
>         dpmac_info[dpmac_id].phy_addr = -1;
> +       dpmac_info[dpmac_id].phydev = NULL;
>         dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
>
>         enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
> @@ -42,6 +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
>         dpmac_info[dpmac_id].id = dpmac_id;
>         dpmac_info[dpmac_id].phy_addr = -1;
>         dpmac_info[dpmac_id].enet_if = enet_if;
> +       dpmac_info[dpmac_id].phydev = NULL;
>  }
>
>
> diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
> index 07e5130264..8971c6c55b 100644
> --- a/include/fsl-mc/ldpaa_wriop.h
> +++ b/include/fsl-mc/ldpaa_wriop.h
> @@ -41,7 +41,6 @@ struct wriop_dpmac_info {
>         u8 id;
>         u8 board_mux;
>         int phy_addr;
> -       void *phy_regs;
>         phy_interface_t enet_if;
>         struct phy_device *phydev;
>         struct mii_dev *bus;
> --
> 2.17.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-10-10  3:59       ` Joe Hershberger
@ 2018-10-10  5:10         ` Pankaj Bansal
  2018-10-10 18:35           ` Joe Hershberger
  0 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  5:10 UTC (permalink / raw)
  To: u-boot

Hi Joe,

> -----Original Message-----
> From: Joe Hershberger [mailto:joe.hershberger at ni.com]
> Sent: Wednesday, October 10, 2018 9:29 AM
> To: Pankaj Bansal <pankaj.bansal@nxp.com>
> Cc: Joseph Hershberger <joseph.hershberger@ni.com>; u-boot <u-
> boot at lists.denx.de>
> Subject: Re: [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused
> strcture elements
> 
> On Tue, Oct 9, 2018 at 9:59 PM Pankaj Bansal <pankaj.bansal@nxp.com>
> wrote:
> >
> > The phydev structure is present in both ldpaa_eth_priv and
> > wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used
> >
> > As the phydev is created based on phy_addr and bus members of
> > wriop_dpmac_info, it is appropriate to keep phydev in
> wriop_dpmac_info.
> >
> > Also phy_regs is not being used, therefore remove it
> >
> > Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> > Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> > ---
> >
> > Notes:
> >     V3:
> >     - No change
> 
> Please be sure you are running scripts/checkpatch.pl on your patches.
> v2 had a number of issues I had to fix up. I'm pretty sure this was one of
> them.

I had run checkpatch script on all the versions of patches I sent.
I use this command "./scripts/checkpatch.pl 0001-something.patch"
This "no return at the end of function" issue was not reported by checkpatch script.

Can you please tell me which issues in V2 are you referring to?
Because when I ran checkpatch.pl, it gave me no errors or warnings but 7 checks regarding alignment in board/freescale/ls2080aqds/eth.c.
I did not do any changes for that because that code was not part of my patch and I think that was done
so that line doesn't exceed 80 characters.

> 
> You would do yourself a favor to use tools/patman/patman.

This is a good advice. I will use patman from now onwards to prepare and send patches.

> 
> >     V2:
> >     - change (phydev && bus != NULL) to (phydev && bus)
> >     - after free phydev just pass NULL into wriop_set_phy_dev()
> >
> >  drivers/net/ldpaa_eth/ldpaa_eth.c   | 56 +++++++++++++++------------
> >  drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
> >  drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
> >  include/fsl-mc/ldpaa_wriop.h        |  1 -
> >  4 files changed, 33 insertions(+), 27 deletions(-)
> >
> > diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c
> > b/drivers/net/ldpaa_eth/ldpaa_eth.c
> > index 82a684bea2..ca3459cc33 100644
> > --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> > +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> > @@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
> >                 return -1;
> >         }
> >
> > -       priv->phydev = phydev;
> > +       wriop_set_phy_dev(priv->dpmac_id, phydev);
> >
> >         return phy_config(phydev);
> >  }
> > @@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device
> *net_dev, bd_t *bd)
> >         struct mii_dev *bus;
> >         phy_interface_t enet_if;
> >         struct dpni_queue d_queue;
> > +       struct phy_device *phydev = NULL;
> >
> >         if (net_dev->state == ETH_STATE_ACTIVE)
> >                 return 0;
> > @@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device
> *net_dev, bd_t *bd)
> >                 goto err_dpmac_setup;
> >
> >  #ifdef CONFIG_PHYLIB
> > -       if (priv->phydev) {
> > -               err = phy_startup(priv->phydev);
> > +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> > +       if (phydev) {
> > +               err = phy_startup(phydev);
> >                 if (err) {
> >                         printf("%s: Could not initialize\n",
> > -                              priv->phydev->dev->name);
> > +                              phydev->dev->name);
> >                         goto err_dpmac_bind;
> >                 }
> >         }
> >  #else
> > -       priv->phydev = (struct phy_device *)malloc(sizeof(struct
> phy_device));
> > -       memset(priv->phydev, 0, sizeof(struct phy_device));
> > +       phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
> > +       memset(phydev, 0, sizeof(struct phy_device));
> > +       wriop_set_phy_dev(priv->dpmac_id, phydev);
> >
> > -       priv->phydev->speed = SPEED_1000;
> > -       priv->phydev->link = 1;
> > -       priv->phydev->duplex = DUPLEX_FULL;
> > +       phydev->speed = SPEED_1000;
> > +       phydev->link = 1;
> > +       phydev->duplex = DUPLEX_FULL;
> >  #endif
> >
> >         bus = wriop_get_mdio(priv->dpmac_id);
> >         enet_if = wriop_get_enet_if(priv->dpmac_id);
> >         if ((bus == NULL) &&
> >             (enet_if == PHY_INTERFACE_MODE_XGMII)) {
> > -               priv->phydev = (struct phy_device *)
> > +               phydev = (struct phy_device *)
> >                                 malloc(sizeof(struct phy_device));
> > -               memset(priv->phydev, 0, sizeof(struct phy_device));
> > +               memset(phydev, 0, sizeof(struct phy_device));
> > +               wriop_set_phy_dev(priv->dpmac_id, phydev);
> >
> > -               priv->phydev->speed = SPEED_10000;
> > -               priv->phydev->link = 1;
> > -               priv->phydev->duplex = DUPLEX_FULL;
> > +               phydev->speed = SPEED_10000;
> > +               phydev->link = 1;
> > +               phydev->duplex = DUPLEX_FULL;
> >         }
> >
> > -       if (!priv->phydev->link) {
> > -               printf("%s: No link.\n", priv->phydev->dev->name);
> > +       if (!phydev->link) {
> > +               printf("%s: No link.\n", phydev->dev->name);
> >                 err = -1;
> >                 goto err_dpmac_bind;
> >         }
> > @@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device
> *net_dev, bd_t *bd)
> >                 return err;
> >         }
> >
> > -       dpmac_link_state.rate = priv->phydev->speed;
> > +       dpmac_link_state.rate = phydev->speed;
> >
> > -       if (priv->phydev->autoneg == AUTONEG_DISABLE)
> > +       if (phydev->autoneg == AUTONEG_DISABLE)
> >                 dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
> >         else
> >                 dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
> >
> > -       if (priv->phydev->duplex == DUPLEX_HALF)
> > +       if (phydev->duplex == DUPLEX_HALF)
> >                 dpmac_link_state.options |=
> > DPMAC_LINK_OPT_HALF_DUPLEX;
> >
> > -       dpmac_link_state.up = priv->phydev->link;
> > +       dpmac_link_state.up = phydev->link;
> >
> >         err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
> >                                   priv->dpmac_handle,
> > &dpmac_link_state); @@ -530,7 +534,7 @@ static int
> ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
> >                 goto err_qdid;
> >         }
> >
> > -       return priv->phydev->link;
> > +       return phydev->link;
> >
> >  err_qdid:
> >  err_get_queue:
> > @@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device
> > *net_dev)  #ifdef CONFIG_PHYLIB
> >         struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);  #endif
> > +       struct phy_device *phydev = NULL;
> >
> >         if ((net_dev->state == ETH_STATE_PASSIVE) ||
> >             (net_dev->state == ETH_STATE_INIT)) @@ -588,11 +593,12 @@
> > static void ldpaa_eth_stop(struct eth_device *net_dev)
> >                 printf("dpni_disable() failed\n");
> >
> >  #ifdef CONFIG_PHYLIB
> > -       if (priv->phydev && bus != NULL)
> > -               phy_shutdown(priv->phydev);
> > +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> > +       if (phydev && bus)
> > +               phy_shutdown(phydev);
> >         else {
> > -               free(priv->phydev);
> > -               priv->phydev = NULL;
> > +               free(phydev);
> > +               wriop_set_phy_dev(priv->dpmac_id, NULL);
> >         }
> >  #endif
> >
> > diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h
> > b/drivers/net/ldpaa_eth/ldpaa_eth.h
> > index ee784a55ee..3f9154b5bb 100644
> > --- a/drivers/net/ldpaa_eth/ldpaa_eth.h
> > +++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
> > @@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
> >         uint16_t tx_flow_id;
> >
> >         enum ldpaa_eth_type type;       /* 1G or 10G ethernet */
> > -       struct phy_device *phydev;
> >  };
> >
> >  struct dprc_endpoint dpmac_endpoint;
> > diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > index 0731a795c8..afbb1ca91e 100644
> > --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > @@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int
> lane_prtcl)
> >         dpmac_info[dpmac_id].enabled = 0;
> >         dpmac_info[dpmac_id].id = 0;
> >         dpmac_info[dpmac_id].phy_addr = -1;
> > +       dpmac_info[dpmac_id].phydev = NULL;
> >         dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
> >
> >         enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); @@ -42,6
> > +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t
> enet_if)
> >         dpmac_info[dpmac_id].id = dpmac_id;
> >         dpmac_info[dpmac_id].phy_addr = -1;
> >         dpmac_info[dpmac_id].enet_if = enet_if;
> > +       dpmac_info[dpmac_id].phydev = NULL;
> >  }
> >
> >
> > diff --git a/include/fsl-mc/ldpaa_wriop.h
> > b/include/fsl-mc/ldpaa_wriop.h index 07e5130264..8971c6c55b 100644
> > --- a/include/fsl-mc/ldpaa_wriop.h
> > +++ b/include/fsl-mc/ldpaa_wriop.h
> > @@ -41,7 +41,6 @@ struct wriop_dpmac_info {
> >         u8 id;
> >         u8 board_mux;
> >         int phy_addr;
> > -       void *phy_regs;
> >         phy_interface_t enet_if;
> >         struct phy_device *phydev;
> >         struct mii_dev *bus;
> > --
> > 2.17.1
> >
> > _______________________________________________
> > U-Boot mailing list
> > U-Boot at lists.denx.de
> >
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flis
> > ts.denx.de%2Flistinfo%2Fu-
> boot&amp;data=02%7C01%7Cpankaj.bansal%40nxp.
> >
> com%7Cbced1ce32f8e455148d408d62e64c7f5%7C686ea1d3bc2b4c6fa92c
> d99c5c301
> >
> 635%7C0%7C0%7C636747407731429023&amp;sdata=4cwaAt8C4V91TNo
> iNFGcoznoGEn
> > POsCGDmh9maFv%2FOA%3D&amp;reserved=0

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
                     ` (5 preceding siblings ...)
  2018-07-30 13:15   ` [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
@ 2018-10-10  8:27   ` Pankaj Bansal
  2018-10-10  8:27     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
                       ` (5 more replies)
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
  7 siblings, 6 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:27 UTC (permalink / raw)
  To: u-boot

This patch set adds support of multiple phys for one dpmac

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where there
are sometimes two phy devices for one dpmac. One phy for TX lanes and one
phy for RX lanes. To handle such cases, add the support for multiple phys
in ethernet driver. The ethernet link is up if all the phy devices
connected to one dpmac report link up. also the link capabilities are
limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G without
autoneg and other operate at 1G with autoneg. Then the ethernet interface
will operate at 1G without autoneg.

Cc: Varun Sethi <V.Sethi@nxp.com>

Pankaj Bansal (6):
  driver: net: fsl-mc: modify the label name
  driver: net: fsl-mc: remove unused strcture elements
  driver: net: fsl-mc: fix error handing in init_phy
  driver: net: fsl-mc: Modify the dpmac link detection method
  driver: net: fsl-mc: initialize dpmac irrespective of phy
  driver: net: fsl-mc: Add support of multiple phys for dpmac

 board/freescale/ls1088a/eth_ls1088aqds.c   |  18 +--
 board/freescale/ls1088a/eth_ls1088ardb.c   |  21 +--
 board/freescale/ls2080aqds/eth.c           |  26 ++--
 board/freescale/ls2080ardb/eth_ls2080rdb.c |  24 +--
 drivers/net/fsl-mc/mc.c                    |   6 +-
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 171 +++++++++++++--------
 drivers/net/ldpaa_eth/ldpaa_eth.h          |   1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c        |  71 ++++++---
 include/fsl-mc/ldpaa_wriop.h               |  46 +++---
 9 files changed, 223 insertions(+), 161 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
@ 2018-10-10  8:27     ` Pankaj Bansal
  2018-10-10  8:27     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
                       ` (4 subsequent siblings)
  5 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:27 UTC (permalink / raw)
  To: u-boot

The goto label name is misspelled it should be DPMAC not DPAMC

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
    - No change
    V2:
    - No change

 drivers/net/ldpaa_eth/ldpaa_eth.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index a25b7cd906..82a684bea2 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -413,7 +413,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		if (err) {
 			printf("%s: Could not initialize\n",
 			       priv->phydev->dev->name);
-			goto err_dpamc_bind;
+			goto err_dpmac_bind;
 		}
 	}
 #else
@@ -441,13 +441,13 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (!priv->phydev->link) {
 		printf("%s: No link.\n", priv->phydev->dev->name);
 		err = -1;
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
 	if (err)
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 
 	/* DPNI initialization */
 	err = ldpaa_dpni_setup(priv);
@@ -540,7 +540,7 @@ err_dpni_bind:
 err_dpbp_setup:
 	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
 err_dpni_setup:
-err_dpamc_bind:
+err_dpmac_bind:
 	dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
 	dpmac_destroy(dflt_mc_io,
 		      dflt_dprc_handle,
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
  2018-10-10  8:27     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
@ 2018-10-10  8:27     ` Pankaj Bansal
  2018-10-10  3:59       ` Joe Hershberger
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
                       ` (3 subsequent siblings)
  5 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:27 UTC (permalink / raw)
  To: u-boot

The phydev structure is present in both ldpaa_eth_priv and
wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used

As the phydev is created based on phy_addr and bus members of
wriop_dpmac_info, it is appropriate to keep phydev in wriop_dpmac_info.

Also phy_regs is not being used, therefore remove it

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
    - No change
    V2:
    - change (phydev && bus != NULL) to (phydev && bus)
    - after free phydev just pass NULL into wriop_set_phy_dev()

 drivers/net/ldpaa_eth/ldpaa_eth.c   | 56 +++++++++++++++------------
 drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
 include/fsl-mc/ldpaa_wriop.h        |  1 -
 4 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 82a684bea2..ca3459cc33 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
 		return -1;
 	}
 
-	priv->phydev = phydev;
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
 	return phy_config(phydev);
 }
@@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct mii_dev *bus;
 	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
+	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_dpmac_setup;
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev) {
-		err = phy_startup(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n",
-			       priv->phydev->dev->name);
+			       phydev->dev->name);
 			goto err_dpmac_bind;
 		}
 	}
 #else
-	priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(priv->phydev, 0, sizeof(struct phy_device));
+	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
+	memset(phydev, 0, sizeof(struct phy_device));
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	priv->phydev->speed = SPEED_1000;
-	priv->phydev->link = 1;
-	priv->phydev->duplex = DUPLEX_FULL;
+	phydev->speed = SPEED_1000;
+	phydev->link = 1;
+	phydev->duplex = DUPLEX_FULL;
 #endif
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	enet_if = wriop_get_enet_if(priv->dpmac_id);
 	if ((bus == NULL) &&
 	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		priv->phydev = (struct phy_device *)
+		phydev = (struct phy_device *)
 				malloc(sizeof(struct phy_device));
-		memset(priv->phydev, 0, sizeof(struct phy_device));
+		memset(phydev, 0, sizeof(struct phy_device));
+		wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-		priv->phydev->speed = SPEED_10000;
-		priv->phydev->link = 1;
-		priv->phydev->duplex = DUPLEX_FULL;
+		phydev->speed = SPEED_10000;
+		phydev->link = 1;
+		phydev->duplex = DUPLEX_FULL;
 	}
 
-	if (!priv->phydev->link) {
-		printf("%s: No link.\n", priv->phydev->dev->name);
+	if (!phydev->link) {
+		printf("%s: No link.\n", phydev->dev->name);
 		err = -1;
 		goto err_dpmac_bind;
 	}
@@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = priv->phydev->speed;
+	dpmac_link_state.rate = phydev->speed;
 
-	if (priv->phydev->autoneg == AUTONEG_DISABLE)
+	if (phydev->autoneg == AUTONEG_DISABLE)
 		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
 	else
 		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
 
-	if (priv->phydev->duplex == DUPLEX_HALF)
+	if (phydev->duplex == DUPLEX_HALF)
 		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
 
-	dpmac_link_state.up = priv->phydev->link;
+	dpmac_link_state.up = phydev->link;
 
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
@@ -530,7 +534,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return priv->phydev->link;
+	return phydev->link;
 
 err_qdid:
 err_get_queue:
@@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 #ifdef CONFIG_PHYLIB
 	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
 #endif
+	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -588,11 +593,12 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev && bus != NULL)
-		phy_shutdown(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev && bus)
+		phy_shutdown(phydev);
 	else {
-		free(priv->phydev);
-		priv->phydev = NULL;
+		free(phydev);
+		wriop_set_phy_dev(priv->dpmac_id, NULL);
 	}
 #endif
 
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h b/drivers/net/ldpaa_eth/ldpaa_eth.h
index ee784a55ee..3f9154b5bb 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.h
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
@@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
 	uint16_t tx_flow_id;
 
 	enum ldpaa_eth_type type;	/* 1G or 10G ethernet */
-	struct phy_device *phydev;
 };
 
 struct dprc_endpoint dpmac_endpoint;
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index 0731a795c8..afbb1ca91e 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
 	dpmac_info[dpmac_id].phy_addr = -1;
+	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -42,6 +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 	dpmac_info[dpmac_id].id = dpmac_id;
 	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
+	dpmac_info[dpmac_id].phydev = NULL;
 }
 
 
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 07e5130264..8971c6c55b 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -41,7 +41,6 @@ struct wriop_dpmac_info {
 	u8 id;
 	u8 board_mux;
 	int phy_addr;
-	void *phy_regs;
 	phy_interface_t enet_if;
 	struct phy_device *phydev;
 	struct mii_dev *bus;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
  2018-10-10  8:27     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
  2018-10-10  8:27     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-10-10  8:28     ` Pankaj Bansal
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
                       ` (2 subsequent siblings)
  5 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:28 UTC (permalink / raw)
  To: u-boot

if an error occurs during init_phy, we should free the phydev structure
which has been allocated by phy_connect.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - No change
    V2:
     - after free phydev just pass NULL into wriop_set_phy_dev()

 drivers/net/ldpaa_eth/ldpaa_eth.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index ca3459cc33..f122e945a4 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,6 +23,7 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
+	int ret;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
@@ -37,7 +38,14 @@ static int init_phy(struct eth_device *dev)
 
 	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	return phy_config(phydev);
+	ret = phy_config(phydev);
+
+	if (ret) {
+		free(phydev);
+		wriop_set_phy_dev(priv->dpmac_id, NULL);
+	}
+
+	return ret;
 }
 #endif
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
                       ` (2 preceding siblings ...)
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
@ 2018-10-10  8:28     ` Pankaj Bansal
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  5 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:28 UTC (permalink / raw)
  To: u-boot

when there is no phy present for a dpmac, a dummy phy device is created.
when we move to multiple phy method, we need to create as many dummy phy
devices.

Change this method so that we don't need to create dummy phy devices.
We always report linkup if no phy is present.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - No change
    V2:
     - Change (phydev->link == 1) to (phydev->link)
     - Use min macro instead of ternary operator
     - return -ENOLINK instead of -1 from ldpaa_get_dpmac_state
     - Change (state->up == 0) to (!state->up)

 drivers/net/ldpaa_eth/ldpaa_eth.c | 119 +++++++++++++---------------
 1 file changed, 57 insertions(+), 62 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index f122e945a4..4f0b977449 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -385,6 +385,59 @@ error:
 	return err;
 }
 
+static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
+				 struct dpmac_link_state *state)
+{
+	struct phy_device *phydev = NULL;
+	phy_interface_t enet_if;
+	int err;
+
+	/* let's start off with maximum capabilities
+	 */
+	enet_if = wriop_get_enet_if(priv->dpmac_id);
+	switch (enet_if) {
+	case PHY_INTERFACE_MODE_XGMII:
+		state->rate = SPEED_10000;
+		break;
+	default:
+		state->rate = SPEED_1000;
+		break;
+	}
+	state->up = 1;
+
+#ifdef CONFIG_PHYLIB
+	state->options |= DPMAC_LINK_OPT_AUTONEG;
+
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
+		if (err) {
+			printf("%s: Could not initialize\n", phydev->dev->name);
+			state->up = 0;
+		}
+		if (phydev->link) {
+			state->rate = min(state->rate, (uint32_t)phydev->speed);
+			if (!phydev->duplex)
+				state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
+			if (!phydev->autoneg)
+				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+		} else {
+			state->up = 0;
+		}
+	}
+#endif
+	if (!phydev)
+		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+
+	if (!state->up) {
+		state->rate = 0;
+		state->options = 0;
+		return -ENOLINK;
+	}
+
+	return 0;
+}
+
 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
@@ -393,10 +446,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct dpni_link_state link_state;
 #endif
 	int err = 0;
-	struct mii_dev *bus;
-	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
-	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -416,45 +466,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (err < 0)
 		goto err_dpmac_setup;
 
-#ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
-		err = phy_startup(phydev);
-		if (err) {
-			printf("%s: Could not initialize\n",
-			       phydev->dev->name);
-			goto err_dpmac_bind;
-		}
-	}
-#else
-	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(phydev, 0, sizeof(struct phy_device));
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-	phydev->speed = SPEED_1000;
-	phydev->link = 1;
-	phydev->duplex = DUPLEX_FULL;
-#endif
-
-	bus = wriop_get_mdio(priv->dpmac_id);
-	enet_if = wriop_get_enet_if(priv->dpmac_id);
-	if ((bus == NULL) &&
-	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		phydev = (struct phy_device *)
-				malloc(sizeof(struct phy_device));
-		memset(phydev, 0, sizeof(struct phy_device));
-		wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-		phydev->speed = SPEED_10000;
-		phydev->link = 1;
-		phydev->duplex = DUPLEX_FULL;
-	}
-
-	if (!phydev->link) {
-		printf("%s: No link.\n", phydev->dev->name);
-		err = -1;
+	err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
+	if (err < 0)
 		goto err_dpmac_bind;
-	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
@@ -488,18 +502,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = phydev->speed;
-
-	if (phydev->autoneg == AUTONEG_DISABLE)
-		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
-	else
-		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
-
-	if (phydev->duplex == DUPLEX_HALF)
-		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
-
-	dpmac_link_state.up = phydev->link;
-
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
 	if (err < 0) {
@@ -542,7 +544,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return phydev->link;
+	return dpmac_link_state.up;
 
 err_qdid:
 err_get_queue:
@@ -565,9 +567,6 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
-#ifdef CONFIG_PHYLIB
-	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
-#endif
 	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
@@ -602,12 +601,8 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 
 #ifdef CONFIG_PHYLIB
 	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev && bus)
+	if (phydev)
 		phy_shutdown(phydev);
-	else {
-		free(phydev);
-		wriop_set_phy_dev(priv->dpmac_id, NULL);
-	}
 #endif
 
 	/* Free DPBP handle and reset. */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
                       ` (3 preceding siblings ...)
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
@ 2018-10-10  8:28     ` Pankaj Bansal
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  5 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:28 UTC (permalink / raw)
  To: u-boot

The dpmac initalization should not depend on phy.
As the phy is not necessary to be present for dpmac to function.
Therefore, remove dpmac initialization dependency from phy.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - No change
    V2:
     - No Change

 drivers/net/fsl-mc/mc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c
index d9a897dc86..b245fbc681 100644
--- a/drivers/net/fsl-mc/mc.c
+++ b/drivers/net/fsl-mc/mc.c
@@ -363,8 +363,7 @@ static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
 		/* port not enabled */
-		if ((wriop_is_enabled_dpmac(i) != 1) ||
-		    (wriop_get_phy_address(i) == -1))
+		if (wriop_is_enabled_dpmac(i) != 1)
 			continue;
 
 		snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
@@ -886,8 +885,7 @@ int fsl_mc_ldpaa_init(bd_t *bis)
 	int i;
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
-		if ((wriop_is_enabled_dpmac(i) == 1) &&
-		    (wriop_get_phy_address(i) != -1))
+		if (wriop_is_enabled_dpmac(i) == 1)
 			ldpaa_eth_init(i, wriop_get_enet_if(i));
 	return 0;
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
                       ` (4 preceding siblings ...)
  2018-10-10  8:28     ` [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
@ 2018-10-10  8:28     ` Pankaj Bansal
  5 siblings, 0 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:28 UTC (permalink / raw)
  To: u-boot

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where there
are sometimes two phy devices for one dpmac. One phy for TX lanes and
one phy for RX lanes. to handle such cases, add the support for multiple
phys in ethernet driver. The ethernet link is up if all the phy devices
connected to one dpmac report link up. also the link capabilities are
limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G without
autoneg and other operate at 1G with autoneg. Then the ethernet interface
will operate at 1G without autoneg.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - return 0 from end of functions whose return type has been changed
       from void to int
    V2:
     - use single-line comment format.
     - use WRIOP_MAX_PHY_NUM.
     - use -ENODEV or -EINVAL instead of -1 wherever appropriate
     - include the variable names in the headers too.
     - Change the return type of some functions from void to int so that
       a meaningful error message can be returned

 board/freescale/ls1088a/eth_ls1088aqds.c   | 18 ++---
 board/freescale/ls1088a/eth_ls1088ardb.c   | 21 +++---
 board/freescale/ls2080aqds/eth.c           | 26 +++----
 board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 66 ++++++++++++------
 drivers/net/ldpaa_eth/ldpaa_wriop.c        | 73 ++++++++++++++------
 include/fsl-mc/ldpaa_wriop.h               | 45 ++++++------
 7 files changed, 164 insertions(+), 109 deletions(-)

diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c b/board/freescale/ls1088a/eth_ls1088aqds.c
index 40b1a0e631..f16b78cf03 100644
--- a/board/freescale/ls1088a/eth_ls1088aqds.c
+++ b/board/freescale/ls1088a/eth_ls1088aqds.c
@@ -487,16 +487,16 @@ void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
 	case 0x3A:
 		switch (dpmac_id) {
 		case 1:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[1]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
 			break;
 		case 2:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[0]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
 			break;
 		case 3:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[3]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
 			break;
 		case 7:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[2]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
 			break;
 		default:
 			printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
@@ -532,13 +532,13 @@ void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
 		case 4:
 		case 5:
 		case 6:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 9);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
 			break;
 		case 7:
 		case 8:
 		case 9:
 		case 10:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
 			break;
 		}
 
@@ -567,7 +567,7 @@ void ls1088a_handle_phy_interface_xsgmii(int i)
 	case 0x15:
 	case 0x1D:
 	case 0x1E:
-		wriop_set_phy_address(i, i + 26);
+		wriop_set_phy_address(i, 0, i + 26);
 		ls1088a_qds_enable_SFP_TX(SFP_TX);
 		break;
 	default:
@@ -590,13 +590,13 @@ static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
 
 	switch (dpmac_id) {
 	case 4:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY1_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
 		bus = mii_dev_for_muxval(EMI1_RGMII1);
 		wriop_set_mdio(dpmac_id, bus);
 		break;
 	case 5:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY2_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
 		bus = mii_dev_for_muxval(EMI1_RGMII2);
 		wriop_set_mdio(dpmac_id, bus);
diff --git a/board/freescale/ls1088a/eth_ls1088ardb.c b/board/freescale/ls1088a/eth_ls1088ardb.c
index 418f362e9a..a2b52a879b 100644
--- a/board/freescale/ls1088a/eth_ls1088ardb.c
+++ b/board/freescale/ls1088a/eth_ls1088ardb.c
@@ -55,16 +55,17 @@ int board_eth_init(bd_t *bis)
 		 * a MAC has no PHY address, we give a PHY address to XFI
 		 * MAC error.
 		 */
-		wriop_set_phy_address(WRIOP1_DPMAC1, 0x0a);
-		wriop_set_phy_address(WRIOP1_DPMAC2, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC3, QSGMII1_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC4, QSGMII1_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC5, QSGMII1_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC6, QSGMII1_PORT4_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC7, QSGMII2_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC8, QSGMII2_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC9, QSGMII2_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC10, QSGMII2_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, 0x0a);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, QSGMII1_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, QSGMII1_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, QSGMII1_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, QSGMII1_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, QSGMII2_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, QSGMII2_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC9, 0, QSGMII2_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC10, 0,
+				      QSGMII2_PORT4_PHY_ADDR);
 
 		break;
 	default:
diff --git a/board/freescale/ls2080aqds/eth.c b/board/freescale/ls2080aqds/eth.c
index 989d57e09b..f706fd4cb6 100644
--- a/board/freescale/ls2080aqds/eth.c
+++ b/board/freescale/ls2080aqds/eth.c
@@ -623,7 +623,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
@@ -631,7 +631,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			break;
 		case 2:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
 			bus = mii_dev_for_muxval(EMI1_SLOT2);
@@ -641,18 +641,18 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			if (slot == EMI_NONE)
 				return;
 			if (serdes1_prtcl == 0x39) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
@@ -691,7 +691,7 @@ serdes2:
 			break;
 		case 4:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 9]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
 			bus = mii_dev_for_muxval(EMI1_SLOT4);
@@ -701,14 +701,14 @@ serdes2:
 			if (slot == EMI_NONE)
 				return;
 			if (serdes2_prtcl == 0x47) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 10]);
 				if (dpmac_id >= 14 && hwconfig_f("xqsgmii",
 								 env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 11]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 11]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
@@ -717,7 +717,7 @@ serdes2:
 			break;
 		case 6:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 13]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
 			bus = mii_dev_for_muxval(EMI1_SLOT6);
@@ -775,7 +775,7 @@ void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a QSGMII riser card? */
-			wriop_set_phy_address(dpmac_id, dpmac_id - 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id - 1);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
 			wriop_set_mdio(dpmac_id, bus);
@@ -819,7 +819,7 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
 		 * the XAUI card is used for the XFI MAC, which will cause
 		 * error.
 		 */
-		wriop_set_phy_address(i, i + 4);
+		wriop_set_phy_address(i, 0, i + 4);
 		ls2080a_qds_enable_SFP_TX(SFP_TX);
 
 		break;
diff --git a/board/freescale/ls2080ardb/eth_ls2080rdb.c b/board/freescale/ls2080ardb/eth_ls2080rdb.c
index 45f1d60322..62c7a7a315 100644
--- a/board/freescale/ls2080ardb/eth_ls2080rdb.c
+++ b/board/freescale/ls2080ardb/eth_ls2080rdb.c
@@ -50,21 +50,21 @@ int board_eth_init(bd_t *bis)
 
 	switch (srds_s1) {
 	case 0x2A:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
-		wriop_set_phy_address(WRIOP1_DPMAC5, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC6, AQ_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC7, AQ_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC8, AQ_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, AQ_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, AQ_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, AQ_PHY_ADDR4);
 
 		break;
 	case 0x4B:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
 
 		break;
 	default:
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 4f0b977449..fe1c03e9e4 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,26 +23,40 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
-	int ret;
+	int phy_addr, phy_num;
+	int ret = 0;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
 		return 0;
 
-	phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
-			     dev, wriop_get_enet_if(priv->dpmac_id));
-	if (!phydev) {
-		printf("Failed to connect\n");
-		return -1;
-	}
-
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phy_addr = wriop_get_phy_address(priv->dpmac_id, phy_num);
+		if (phy_addr < 0)
+			continue;
 
-	ret = phy_config(phydev);
+		phydev = phy_connect(bus, phy_addr, dev,
+				     wriop_get_enet_if(priv->dpmac_id));
+		if (!phydev) {
+			printf("Failed to connect\n");
+			ret = -ENODEV;
+			break;
+		}
+		wriop_set_phy_dev(priv->dpmac_id, phy_num, phydev);
+		ret = phy_config(phydev);
+		if (ret)
+			break;
+	}
 
 	if (ret) {
-		free(phydev);
-		wriop_set_phy_dev(priv->dpmac_id, NULL);
+		for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+			phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+			if (!phydev)
+				continue;
+
+			free(phydev);
+			wriop_set_phy_dev(priv->dpmac_id, phy_num, NULL);
+		}
 	}
 
 	return ret;
@@ -390,10 +404,10 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 {
 	struct phy_device *phydev = NULL;
 	phy_interface_t enet_if;
+	int phy_num, phys_detected;
 	int err;
 
-	/* let's start off with maximum capabilities
-	 */
+	/* let's start off with maximum capabilities */
 	enet_if = wriop_get_enet_if(priv->dpmac_id);
 	switch (enet_if) {
 	case PHY_INTERFACE_MODE_XGMII:
@@ -405,15 +419,22 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 	}
 	state->up = 1;
 
+	phys_detected = 0;
 #ifdef CONFIG_PHYLIB
 	state->options |= DPMAC_LINK_OPT_AUTONEG;
 
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
+	/* start the phy devices one by one and update the dpmac state */
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (!phydev)
+			continue;
+
+		phys_detected++;
 		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n", phydev->dev->name);
 			state->up = 0;
+			break;
 		}
 		if (phydev->link) {
 			state->rate = min(state->rate, (uint32_t)phydev->speed);
@@ -422,11 +443,13 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 			if (!phydev->autoneg)
 				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 		} else {
+			/* break out of loop even if one phy is down */
 			state->up = 0;
+			break;
 		}
 	}
 #endif
-	if (!phydev)
+	if (!phys_detected)
 		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 
 	if (!state->up) {
@@ -568,6 +591,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
 	struct phy_device *phydev = NULL;
+	int phy_num;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -600,9 +624,11 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev)
-		phy_shutdown(phydev);
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (phydev)
+			phy_shutdown(phydev);
+	}
 #endif
 
 	/* Free DPBP handle and reset. */
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index afbb1ca91e..514cd64c18 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -22,11 +22,10 @@ __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
 void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 {
 	phy_interface_t enet_if;
+	int phy_num;
 
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
-	dpmac_info[dpmac_id].phy_addr = -1;
-	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -35,15 +34,23 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 		dpmac_info[dpmac_id].id = dpmac_id;
 		dpmac_info[dpmac_id].enet_if = enet_if;
 	}
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 {
+	int phy_num;
+
 	dpmac_info[dpmac_id].enabled = 1;
 	dpmac_info[dpmac_id].id = dpmac_id;
-	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
-	dpmac_info[dpmac_id].phydev = NULL;
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 
@@ -60,47 +67,55 @@ static int wriop_dpmac_to_index(int dpmac_id)
 	return -1;
 }
 
-void wriop_disable_dpmac(int dpmac_id)
+int wriop_disable_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].enabled = 0;
 	wriop_dpmac_disable(dpmac_id);
+
+	return 0;
 }
 
-void wriop_enable_dpmac(int dpmac_id)
+int wriop_enable_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].enabled = 1;
 	wriop_dpmac_enable(dpmac_id);
+
+	return 0;
 }
 
-u8 wriop_is_enabled_dpmac(int dpmac_id)
+int wriop_is_enabled_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return -1;
+		return -ENODEV;
 
 	return dpmac_info[i].enabled;
+
+	return 0;
 }
 
 
-void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
+int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].bus = bus;
+
+	return 0;
 }
 
 struct mii_dev *wriop_get_mdio(int dpmac_id)
@@ -113,44 +128,56 @@ struct mii_dev *wriop_get_mdio(int dpmac_id)
 	return dpmac_info[i].bus;
 }
 
-void wriop_set_phy_address(int dpmac_id, int address)
+int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
+
+	dpmac_info[i].phy_addr[phy_num] = address;
 
-	dpmac_info[i].phy_addr = address;
+	return 0;
 }
 
-int wriop_get_phy_address(int dpmac_id)
+int wriop_get_phy_address(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return -1;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
 
-	return dpmac_info[i].phy_addr;
+	return dpmac_info[i].phy_addr[phy_num];
 }
 
-void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
+int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
 
-	dpmac_info[i].phydev = phydev;
+	dpmac_info[i].phydev[phy_num] = phydev;
+
+	return 0;
 }
 
-struct phy_device *wriop_get_phy_dev(int dpmac_id)
+struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
 		return NULL;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return NULL;
 
-	return dpmac_info[i].phydev;
+	return dpmac_info[i].phydev[phy_num];
 }
 
 phy_interface_t wriop_get_enet_if(int dpmac_id)
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 8971c6c55b..b55c39cbb2 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -6,7 +6,11 @@
 #ifndef __LDPAA_WRIOP_H
 #define __LDPAA_WRIOP_H
 
- #include <phy.h>
+#include <phy.h>
+
+#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
+#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
+#define WRIOP_MAX_PHY_NUM        2
 
 enum wriop_port {
 	WRIOP1_DPMAC1 = 1,
@@ -40,33 +44,30 @@ struct wriop_dpmac_info {
 	u8 enabled;
 	u8 id;
 	u8 board_mux;
-	int phy_addr;
+	int phy_addr[WRIOP_MAX_PHY_NUM];
 	phy_interface_t enet_if;
-	struct phy_device *phydev;
+	struct phy_device *phydev[WRIOP_MAX_PHY_NUM];
 	struct mii_dev *bus;
 };
 
 extern struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
 
-#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
-#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
-
-void wriop_init_dpmac(int, int, int);
-void wriop_disable_dpmac(int);
-void wriop_enable_dpmac(int);
-u8 wriop_is_enabled_dpmac(int dpmac_id);
-void wriop_set_mdio(int, struct mii_dev *);
-struct mii_dev *wriop_get_mdio(int);
-void wriop_set_phy_address(int, int);
-int wriop_get_phy_address(int);
-void wriop_set_phy_dev(int, struct phy_device *);
-struct phy_device *wriop_get_phy_dev(int);
-phy_interface_t wriop_get_enet_if(int);
+void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl);
+void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if);
+int wriop_disable_dpmac(int dpmac_id);
+int wriop_enable_dpmac(int dpmac_id);
+int wriop_is_enabled_dpmac(int dpmac_id);
+int wriop_set_mdio(int dpmac_id, struct mii_dev *bus);
+struct mii_dev *wriop_get_mdio(int dpmac_id);
+int wriop_set_phy_address(int dpmac_id, int phy_num, int address);
+int wriop_get_phy_address(int dpmac_id, int phy_num);
+int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev);
+struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num);
+phy_interface_t wriop_get_enet_if(int dpmac_id);
 
-void wriop_dpmac_disable(int);
-void wriop_dpmac_enable(int);
-phy_interface_t wriop_dpmac_enet_if(int, int);
-void wriop_init_dpmac_qsgmii(int, int);
+void wriop_dpmac_disable(int dpmac_id);
+void wriop_dpmac_enable(int dpmac_id);
+phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl);
+void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl);
 void wriop_init_rgmii(void);
-void wriop_init_dpmac_enet_if(int , phy_interface_t);
 #endif	/* __LDPAA_WRIOP_H */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
                     ` (6 preceding siblings ...)
  2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
@ 2018-10-10  8:38   ` Pankaj Bansal
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
                       ` (5 more replies)
  7 siblings, 6 replies; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:38 UTC (permalink / raw)
  To: u-boot

This patch set adds support of multiple phys for one dpmac

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where
there are sometimes two phy devices for one dpmac. One phy for TX
lanes and one phy for RX lanes. To handle such cases, add the support
for multiple phys in ethernet driver. The ethernet link is up if all
the phy devices connected to one dpmac report link up. also the link
capabilities are limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G
without autoneg and other operate at 1G with autoneg. Then the ethernet
interface will operate at 1G without autoneg.

Cc: Varun Sethi <V.Sethi@nxp.com>

Pankaj Bansal (6):
  driver: net: fsl-mc: modify the label name
  driver: net: fsl-mc: remove unused strcture elements
  driver: net: fsl-mc: fix error handing in init_phy
  driver: net: fsl-mc: Modify the dpmac link detection method
  driver: net: fsl-mc: initialize dpmac irrespective of phy
  driver: net: fsl-mc: Add support of multiple phys for dpmac

 board/freescale/ls1088a/eth_ls1088aqds.c   |  18 +--
 board/freescale/ls1088a/eth_ls1088ardb.c   |  21 +--
 board/freescale/ls2080aqds/eth.c           |  26 ++--
 board/freescale/ls2080ardb/eth_ls2080rdb.c |  24 +--
 drivers/net/fsl-mc/mc.c                    |   6 +-
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 171 +++++++++++++--------
 drivers/net/ldpaa_eth/ldpaa_eth.h          |   1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c        |  69 ++++++---
 include/fsl-mc/ldpaa_wriop.h               |  46 +++---
 9 files changed, 221 insertions(+), 161 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
@ 2018-10-10  8:38     ` Pankaj Bansal
  2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
                       ` (4 subsequent siblings)
  5 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:38 UTC (permalink / raw)
  To: u-boot

The goto label name is misspelled it should be DPMAC not DPAMC

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
    - No change
    V2:
    - No change

 drivers/net/ldpaa_eth/ldpaa_eth.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index a25b7cd906..82a684bea2 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -413,7 +413,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		if (err) {
 			printf("%s: Could not initialize\n",
 			       priv->phydev->dev->name);
-			goto err_dpamc_bind;
+			goto err_dpmac_bind;
 		}
 	}
 #else
@@ -441,13 +441,13 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (!priv->phydev->link) {
 		printf("%s: No link.\n", priv->phydev->dev->name);
 		err = -1;
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
 	if (err)
-		goto err_dpamc_bind;
+		goto err_dpmac_bind;
 
 	/* DPNI initialization */
 	err = ldpaa_dpni_setup(priv);
@@ -540,7 +540,7 @@ err_dpni_bind:
 err_dpbp_setup:
 	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
 err_dpni_setup:
-err_dpamc_bind:
+err_dpmac_bind:
 	dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
 	dpmac_destroy(dflt_mc_io,
 		      dflt_dprc_handle,
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
@ 2018-10-10  8:38     ` Pankaj Bansal
  2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
                       ` (3 subsequent siblings)
  5 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:38 UTC (permalink / raw)
  To: u-boot

The phydev structure is present in both ldpaa_eth_priv and
wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used

As the phydev is created based on phy_addr and bus members of
wriop_dpmac_info, it is appropriate to keep phydev in wriop_dpmac_info.

Also phy_regs is not being used, therefore remove it

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
    - No change
    V2:
    - change (phydev && bus != NULL) to (phydev && bus)
    - after free phydev just pass NULL into wriop_set_phy_dev()

 drivers/net/ldpaa_eth/ldpaa_eth.c   | 56 +++++++++++++++------------
 drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
 drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
 include/fsl-mc/ldpaa_wriop.h        |  1 -
 4 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 82a684bea2..ca3459cc33 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
 		return -1;
 	}
 
-	priv->phydev = phydev;
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
 	return phy_config(phydev);
 }
@@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct mii_dev *bus;
 	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
+	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_dpmac_setup;
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev) {
-		err = phy_startup(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n",
-			       priv->phydev->dev->name);
+			       phydev->dev->name);
 			goto err_dpmac_bind;
 		}
 	}
 #else
-	priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(priv->phydev, 0, sizeof(struct phy_device));
+	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
+	memset(phydev, 0, sizeof(struct phy_device));
+	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	priv->phydev->speed = SPEED_1000;
-	priv->phydev->link = 1;
-	priv->phydev->duplex = DUPLEX_FULL;
+	phydev->speed = SPEED_1000;
+	phydev->link = 1;
+	phydev->duplex = DUPLEX_FULL;
 #endif
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	enet_if = wriop_get_enet_if(priv->dpmac_id);
 	if ((bus == NULL) &&
 	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		priv->phydev = (struct phy_device *)
+		phydev = (struct phy_device *)
 				malloc(sizeof(struct phy_device));
-		memset(priv->phydev, 0, sizeof(struct phy_device));
+		memset(phydev, 0, sizeof(struct phy_device));
+		wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-		priv->phydev->speed = SPEED_10000;
-		priv->phydev->link = 1;
-		priv->phydev->duplex = DUPLEX_FULL;
+		phydev->speed = SPEED_10000;
+		phydev->link = 1;
+		phydev->duplex = DUPLEX_FULL;
 	}
 
-	if (!priv->phydev->link) {
-		printf("%s: No link.\n", priv->phydev->dev->name);
+	if (!phydev->link) {
+		printf("%s: No link.\n", phydev->dev->name);
 		err = -1;
 		goto err_dpmac_bind;
 	}
@@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = priv->phydev->speed;
+	dpmac_link_state.rate = phydev->speed;
 
-	if (priv->phydev->autoneg == AUTONEG_DISABLE)
+	if (phydev->autoneg == AUTONEG_DISABLE)
 		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
 	else
 		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
 
-	if (priv->phydev->duplex == DUPLEX_HALF)
+	if (phydev->duplex == DUPLEX_HALF)
 		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
 
-	dpmac_link_state.up = priv->phydev->link;
+	dpmac_link_state.up = phydev->link;
 
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
@@ -530,7 +534,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return priv->phydev->link;
+	return phydev->link;
 
 err_qdid:
 err_get_queue:
@@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 #ifdef CONFIG_PHYLIB
 	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
 #endif
+	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -588,11 +593,12 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	if (priv->phydev && bus != NULL)
-		phy_shutdown(priv->phydev);
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev && bus)
+		phy_shutdown(phydev);
 	else {
-		free(priv->phydev);
-		priv->phydev = NULL;
+		free(phydev);
+		wriop_set_phy_dev(priv->dpmac_id, NULL);
 	}
 #endif
 
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h b/drivers/net/ldpaa_eth/ldpaa_eth.h
index ee784a55ee..3f9154b5bb 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.h
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
@@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
 	uint16_t tx_flow_id;
 
 	enum ldpaa_eth_type type;	/* 1G or 10G ethernet */
-	struct phy_device *phydev;
 };
 
 struct dprc_endpoint dpmac_endpoint;
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index 0731a795c8..afbb1ca91e 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
 	dpmac_info[dpmac_id].phy_addr = -1;
+	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -42,6 +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 	dpmac_info[dpmac_id].id = dpmac_id;
 	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
+	dpmac_info[dpmac_id].phydev = NULL;
 }
 
 
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 07e5130264..8971c6c55b 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -41,7 +41,6 @@ struct wriop_dpmac_info {
 	u8 id;
 	u8 board_mux;
 	int phy_addr;
-	void *phy_regs;
 	phy_interface_t enet_if;
 	struct phy_device *phydev;
 	struct mii_dev *bus;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-10-10  8:38     ` Pankaj Bansal
  2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
                       ` (2 subsequent siblings)
  5 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:38 UTC (permalink / raw)
  To: u-boot

if an error occurs during init_phy, we should free the phydev structure
which has been allocated by phy_connect.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - No change
    V2:
     - after free phydev just pass NULL into wriop_set_phy_dev()

 drivers/net/ldpaa_eth/ldpaa_eth.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index ca3459cc33..f122e945a4 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,6 +23,7 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
+	int ret;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
@@ -37,7 +38,14 @@ static int init_phy(struct eth_device *dev)
 
 	wriop_set_phy_dev(priv->dpmac_id, phydev);
 
-	return phy_config(phydev);
+	ret = phy_config(phydev);
+
+	if (ret) {
+		free(phydev);
+		wriop_set_phy_dev(priv->dpmac_id, NULL);
+	}
+
+	return ret;
 }
 #endif
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
                       ` (2 preceding siblings ...)
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
@ 2018-10-10  8:38     ` Pankaj Bansal
  2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  5 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:38 UTC (permalink / raw)
  To: u-boot

when there is no phy present for a dpmac, a dummy phy device is created.
when we move to multiple phy method, we need to create as many dummy phy
devices.

Change this method so that we don't need to create dummy phy devices.
We always report linkup if no phy is present.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - No change
    V2:
     - Change (phydev->link == 1) to (phydev->link)
     - Use min macro instead of ternary operator
     - return -ENOLINK instead of -1 from ldpaa_get_dpmac_state
     - Change (state->up == 0) to (!state->up)

 drivers/net/ldpaa_eth/ldpaa_eth.c | 119 +++++++++++++---------------
 1 file changed, 57 insertions(+), 62 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index f122e945a4..4f0b977449 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -385,6 +385,59 @@ error:
 	return err;
 }
 
+static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
+				 struct dpmac_link_state *state)
+{
+	struct phy_device *phydev = NULL;
+	phy_interface_t enet_if;
+	int err;
+
+	/* let's start off with maximum capabilities
+	 */
+	enet_if = wriop_get_enet_if(priv->dpmac_id);
+	switch (enet_if) {
+	case PHY_INTERFACE_MODE_XGMII:
+		state->rate = SPEED_10000;
+		break;
+	default:
+		state->rate = SPEED_1000;
+		break;
+	}
+	state->up = 1;
+
+#ifdef CONFIG_PHYLIB
+	state->options |= DPMAC_LINK_OPT_AUTONEG;
+
+	phydev = wriop_get_phy_dev(priv->dpmac_id);
+	if (phydev) {
+		err = phy_startup(phydev);
+		if (err) {
+			printf("%s: Could not initialize\n", phydev->dev->name);
+			state->up = 0;
+		}
+		if (phydev->link) {
+			state->rate = min(state->rate, (uint32_t)phydev->speed);
+			if (!phydev->duplex)
+				state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
+			if (!phydev->autoneg)
+				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+		} else {
+			state->up = 0;
+		}
+	}
+#endif
+	if (!phydev)
+		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
+
+	if (!state->up) {
+		state->rate = 0;
+		state->options = 0;
+		return -ENOLINK;
+	}
+
+	return 0;
+}
+
 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
@@ -393,10 +446,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	struct dpni_link_state link_state;
 #endif
 	int err = 0;
-	struct mii_dev *bus;
-	phy_interface_t enet_if;
 	struct dpni_queue d_queue;
-	struct phy_device *phydev = NULL;
 
 	if (net_dev->state == ETH_STATE_ACTIVE)
 		return 0;
@@ -416,45 +466,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 	if (err < 0)
 		goto err_dpmac_setup;
 
-#ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
-		err = phy_startup(phydev);
-		if (err) {
-			printf("%s: Could not initialize\n",
-			       phydev->dev->name);
-			goto err_dpmac_bind;
-		}
-	}
-#else
-	phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
-	memset(phydev, 0, sizeof(struct phy_device));
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-	phydev->speed = SPEED_1000;
-	phydev->link = 1;
-	phydev->duplex = DUPLEX_FULL;
-#endif
-
-	bus = wriop_get_mdio(priv->dpmac_id);
-	enet_if = wriop_get_enet_if(priv->dpmac_id);
-	if ((bus == NULL) &&
-	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
-		phydev = (struct phy_device *)
-				malloc(sizeof(struct phy_device));
-		memset(phydev, 0, sizeof(struct phy_device));
-		wriop_set_phy_dev(priv->dpmac_id, phydev);
-
-		phydev->speed = SPEED_10000;
-		phydev->link = 1;
-		phydev->duplex = DUPLEX_FULL;
-	}
-
-	if (!phydev->link) {
-		printf("%s: No link.\n", phydev->dev->name);
-		err = -1;
+	err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
+	if (err < 0)
 		goto err_dpmac_bind;
-	}
 
 	/* DPMAC binding DPNI */
 	err = ldpaa_dpmac_bind(priv);
@@ -488,18 +502,6 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		return err;
 	}
 
-	dpmac_link_state.rate = phydev->speed;
-
-	if (phydev->autoneg == AUTONEG_DISABLE)
-		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
-	else
-		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
-
-	if (phydev->duplex == DUPLEX_HALF)
-		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
-
-	dpmac_link_state.up = phydev->link;
-
 	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
 				  priv->dpmac_handle, &dpmac_link_state);
 	if (err < 0) {
@@ -542,7 +544,7 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
 		goto err_qdid;
 	}
 
-	return phydev->link;
+	return dpmac_link_state.up;
 
 err_qdid:
 err_get_queue:
@@ -565,9 +567,6 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 {
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
-#ifdef CONFIG_PHYLIB
-	struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
-#endif
 	struct phy_device *phydev = NULL;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
@@ -602,12 +601,8 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 
 #ifdef CONFIG_PHYLIB
 	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev && bus)
+	if (phydev)
 		phy_shutdown(phydev);
-	else {
-		free(phydev);
-		wriop_set_phy_dev(priv->dpmac_id, NULL);
-	}
 #endif
 
 	/* Free DPBP handle and reset. */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
                       ` (3 preceding siblings ...)
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
@ 2018-10-10  8:38     ` Pankaj Bansal
  2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
  5 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:38 UTC (permalink / raw)
  To: u-boot

The dpmac initalization should not depend on phy.
As the phy is not necessary to be present for dpmac to function.
Therefore, remove dpmac initialization dependency from phy.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - No change
    V2:
     - No Change

 drivers/net/fsl-mc/mc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c
index d9a897dc86..b245fbc681 100644
--- a/drivers/net/fsl-mc/mc.c
+++ b/drivers/net/fsl-mc/mc.c
@@ -363,8 +363,7 @@ static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
 		/* port not enabled */
-		if ((wriop_is_enabled_dpmac(i) != 1) ||
-		    (wriop_get_phy_address(i) == -1))
+		if (wriop_is_enabled_dpmac(i) != 1)
 			continue;
 
 		snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
@@ -886,8 +885,7 @@ int fsl_mc_ldpaa_init(bd_t *bis)
 	int i;
 
 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
-		if ((wriop_is_enabled_dpmac(i) == 1) &&
-		    (wriop_get_phy_address(i) != -1))
+		if (wriop_is_enabled_dpmac(i) == 1)
 			ldpaa_eth_init(i, wriop_get_enet_if(i));
 	return 0;
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
                       ` (4 preceding siblings ...)
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
@ 2018-10-10  8:38     ` Pankaj Bansal
  2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
  5 siblings, 1 reply; 54+ messages in thread
From: Pankaj Bansal @ 2018-10-10  8:38 UTC (permalink / raw)
  To: u-boot

Till now we have had cases where we had one phy device per dpmac.
Now, with the upcoming products (LX2160AQDS), we have cases, where there
are sometimes two phy devices for one dpmac. One phy for TX lanes and
one phy for RX lanes. to handle such cases, add the support for multiple
phys in ethernet driver. The ethernet link is up if all the phy devices
connected to one dpmac report link up. also the link capabilities are
limited by the weakest phy device.

i.e. say if there are two phys for one dpmac. one operates at 10G without
autoneg and other operate at 1G with autoneg. Then the ethernet interface
will operate at 1G without autoneg.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Notes:
    V3:
     - return 0 from end of functions whose return type has been changed
       from void to int
    V2:
     - use single-line comment format.
     - use WRIOP_MAX_PHY_NUM.
     - use -ENODEV or -EINVAL instead of -1 wherever appropriate
     - include the variable names in the headers too.
     - Change the return type of some functions from void to int so that
       a meaningful error message can be returned

 board/freescale/ls1088a/eth_ls1088aqds.c   | 18 ++---
 board/freescale/ls1088a/eth_ls1088ardb.c   | 21 +++---
 board/freescale/ls2080aqds/eth.c           | 26 +++----
 board/freescale/ls2080ardb/eth_ls2080rdb.c | 24 +++----
 drivers/net/ldpaa_eth/ldpaa_eth.c          | 66 ++++++++++++------
 drivers/net/ldpaa_eth/ldpaa_wriop.c        | 71 +++++++++++++-------
 include/fsl-mc/ldpaa_wriop.h               | 45 +++++++------
 7 files changed, 162 insertions(+), 109 deletions(-)

diff --git a/board/freescale/ls1088a/eth_ls1088aqds.c b/board/freescale/ls1088a/eth_ls1088aqds.c
index 40b1a0e631..f16b78cf03 100644
--- a/board/freescale/ls1088a/eth_ls1088aqds.c
+++ b/board/freescale/ls1088a/eth_ls1088aqds.c
@@ -487,16 +487,16 @@ void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
 	case 0x3A:
 		switch (dpmac_id) {
 		case 1:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[1]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
 			break;
 		case 2:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[0]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
 			break;
 		case 3:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[3]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
 			break;
 		case 7:
-			wriop_set_phy_address(dpmac_id, riser_phy_addr[2]);
+			wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
 			break;
 		default:
 			printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
@@ -532,13 +532,13 @@ void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
 		case 4:
 		case 5:
 		case 6:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 9);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
 			break;
 		case 7:
 		case 8:
 		case 9:
 		case 10:
-			wriop_set_phy_address(dpmac_id, dpmac_id + 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
 			break;
 		}
 
@@ -567,7 +567,7 @@ void ls1088a_handle_phy_interface_xsgmii(int i)
 	case 0x15:
 	case 0x1D:
 	case 0x1E:
-		wriop_set_phy_address(i, i + 26);
+		wriop_set_phy_address(i, 0, i + 26);
 		ls1088a_qds_enable_SFP_TX(SFP_TX);
 		break;
 	default:
@@ -590,13 +590,13 @@ static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
 
 	switch (dpmac_id) {
 	case 4:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY1_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
 		bus = mii_dev_for_muxval(EMI1_RGMII1);
 		wriop_set_mdio(dpmac_id, bus);
 		break;
 	case 5:
-		wriop_set_phy_address(dpmac_id, RGMII_PHY2_ADDR);
+		wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
 		dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
 		bus = mii_dev_for_muxval(EMI1_RGMII2);
 		wriop_set_mdio(dpmac_id, bus);
diff --git a/board/freescale/ls1088a/eth_ls1088ardb.c b/board/freescale/ls1088a/eth_ls1088ardb.c
index 418f362e9a..a2b52a879b 100644
--- a/board/freescale/ls1088a/eth_ls1088ardb.c
+++ b/board/freescale/ls1088a/eth_ls1088ardb.c
@@ -55,16 +55,17 @@ int board_eth_init(bd_t *bis)
 		 * a MAC has no PHY address, we give a PHY address to XFI
 		 * MAC error.
 		 */
-		wriop_set_phy_address(WRIOP1_DPMAC1, 0x0a);
-		wriop_set_phy_address(WRIOP1_DPMAC2, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC3, QSGMII1_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC4, QSGMII1_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC5, QSGMII1_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC6, QSGMII1_PORT4_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC7, QSGMII2_PORT1_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC8, QSGMII2_PORT2_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC9, QSGMII2_PORT3_PHY_ADDR);
-		wriop_set_phy_address(WRIOP1_DPMAC10, QSGMII2_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, 0x0a);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, QSGMII1_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, QSGMII1_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, QSGMII1_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, QSGMII1_PORT4_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, QSGMII2_PORT1_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, QSGMII2_PORT2_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC9, 0, QSGMII2_PORT3_PHY_ADDR);
+		wriop_set_phy_address(WRIOP1_DPMAC10, 0,
+				      QSGMII2_PORT4_PHY_ADDR);
 
 		break;
 	default:
diff --git a/board/freescale/ls2080aqds/eth.c b/board/freescale/ls2080aqds/eth.c
index 989d57e09b..f706fd4cb6 100644
--- a/board/freescale/ls2080aqds/eth.c
+++ b/board/freescale/ls2080aqds/eth.c
@@ -623,7 +623,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
@@ -631,7 +631,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			break;
 		case 2:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 1]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
 			bus = mii_dev_for_muxval(EMI1_SLOT2);
@@ -641,18 +641,18 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 			if (slot == EMI_NONE)
 				return;
 			if (serdes1_prtcl == 0x39) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 2]);
 				if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
 								env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 3]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
@@ -691,7 +691,7 @@ serdes2:
 			break;
 		case 4:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 9]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
 			bus = mii_dev_for_muxval(EMI1_SLOT4);
@@ -701,14 +701,14 @@ serdes2:
 			if (slot == EMI_NONE)
 				return;
 			if (serdes2_prtcl == 0x47) {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 10]);
 				if (dpmac_id >= 14 && hwconfig_f("xqsgmii",
 								 env_hwconfig))
-					wriop_set_phy_address(dpmac_id,
+					wriop_set_phy_address(dpmac_id, 0,
 						riser_phy_addr[dpmac_id - 11]);
 			} else {
-				wriop_set_phy_address(dpmac_id,
+				wriop_set_phy_address(dpmac_id, 0,
 					riser_phy_addr[dpmac_id - 11]);
 			}
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
@@ -717,7 +717,7 @@ serdes2:
 			break;
 		case 6:
 			/* Slot housing a SGMII riser card? */
-			wriop_set_phy_address(dpmac_id,
+			wriop_set_phy_address(dpmac_id, 0,
 					      riser_phy_addr[dpmac_id - 13]);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
 			bus = mii_dev_for_muxval(EMI1_SLOT6);
@@ -775,7 +775,7 @@ void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
 		switch (++slot) {
 		case 1:
 			/* Slot housing a QSGMII riser card? */
-			wriop_set_phy_address(dpmac_id, dpmac_id - 1);
+			wriop_set_phy_address(dpmac_id, 0, dpmac_id - 1);
 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
 			bus = mii_dev_for_muxval(EMI1_SLOT1);
 			wriop_set_mdio(dpmac_id, bus);
@@ -819,7 +819,7 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
 		 * the XAUI card is used for the XFI MAC, which will cause
 		 * error.
 		 */
-		wriop_set_phy_address(i, i + 4);
+		wriop_set_phy_address(i, 0, i + 4);
 		ls2080a_qds_enable_SFP_TX(SFP_TX);
 
 		break;
diff --git a/board/freescale/ls2080ardb/eth_ls2080rdb.c b/board/freescale/ls2080ardb/eth_ls2080rdb.c
index 45f1d60322..62c7a7a315 100644
--- a/board/freescale/ls2080ardb/eth_ls2080rdb.c
+++ b/board/freescale/ls2080ardb/eth_ls2080rdb.c
@@ -50,21 +50,21 @@ int board_eth_init(bd_t *bis)
 
 	switch (srds_s1) {
 	case 0x2A:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
-		wriop_set_phy_address(WRIOP1_DPMAC5, AQ_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC6, AQ_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC7, AQ_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC8, AQ_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC5, 0, AQ_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC6, 0, AQ_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC7, 0, AQ_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC8, 0, AQ_PHY_ADDR4);
 
 		break;
 	case 0x4B:
-		wriop_set_phy_address(WRIOP1_DPMAC1, CORTINA_PHY_ADDR1);
-		wriop_set_phy_address(WRIOP1_DPMAC2, CORTINA_PHY_ADDR2);
-		wriop_set_phy_address(WRIOP1_DPMAC3, CORTINA_PHY_ADDR3);
-		wriop_set_phy_address(WRIOP1_DPMAC4, CORTINA_PHY_ADDR4);
+		wriop_set_phy_address(WRIOP1_DPMAC1, 0, CORTINA_PHY_ADDR1);
+		wriop_set_phy_address(WRIOP1_DPMAC2, 0, CORTINA_PHY_ADDR2);
+		wriop_set_phy_address(WRIOP1_DPMAC3, 0, CORTINA_PHY_ADDR3);
+		wriop_set_phy_address(WRIOP1_DPMAC4, 0, CORTINA_PHY_ADDR4);
 
 		break;
 	default:
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 4f0b977449..fe1c03e9e4 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -23,26 +23,40 @@ static int init_phy(struct eth_device *dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
 	struct phy_device *phydev = NULL;
 	struct mii_dev *bus;
-	int ret;
+	int phy_addr, phy_num;
+	int ret = 0;
 
 	bus = wriop_get_mdio(priv->dpmac_id);
 	if (bus == NULL)
 		return 0;
 
-	phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
-			     dev, wriop_get_enet_if(priv->dpmac_id));
-	if (!phydev) {
-		printf("Failed to connect\n");
-		return -1;
-	}
-
-	wriop_set_phy_dev(priv->dpmac_id, phydev);
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phy_addr = wriop_get_phy_address(priv->dpmac_id, phy_num);
+		if (phy_addr < 0)
+			continue;
 
-	ret = phy_config(phydev);
+		phydev = phy_connect(bus, phy_addr, dev,
+				     wriop_get_enet_if(priv->dpmac_id));
+		if (!phydev) {
+			printf("Failed to connect\n");
+			ret = -ENODEV;
+			break;
+		}
+		wriop_set_phy_dev(priv->dpmac_id, phy_num, phydev);
+		ret = phy_config(phydev);
+		if (ret)
+			break;
+	}
 
 	if (ret) {
-		free(phydev);
-		wriop_set_phy_dev(priv->dpmac_id, NULL);
+		for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+			phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+			if (!phydev)
+				continue;
+
+			free(phydev);
+			wriop_set_phy_dev(priv->dpmac_id, phy_num, NULL);
+		}
 	}
 
 	return ret;
@@ -390,10 +404,10 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 {
 	struct phy_device *phydev = NULL;
 	phy_interface_t enet_if;
+	int phy_num, phys_detected;
 	int err;
 
-	/* let's start off with maximum capabilities
-	 */
+	/* let's start off with maximum capabilities */
 	enet_if = wriop_get_enet_if(priv->dpmac_id);
 	switch (enet_if) {
 	case PHY_INTERFACE_MODE_XGMII:
@@ -405,15 +419,22 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 	}
 	state->up = 1;
 
+	phys_detected = 0;
 #ifdef CONFIG_PHYLIB
 	state->options |= DPMAC_LINK_OPT_AUTONEG;
 
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev) {
+	/* start the phy devices one by one and update the dpmac state */
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (!phydev)
+			continue;
+
+		phys_detected++;
 		err = phy_startup(phydev);
 		if (err) {
 			printf("%s: Could not initialize\n", phydev->dev->name);
 			state->up = 0;
+			break;
 		}
 		if (phydev->link) {
 			state->rate = min(state->rate, (uint32_t)phydev->speed);
@@ -422,11 +443,13 @@ static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
 			if (!phydev->autoneg)
 				state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 		} else {
+			/* break out of loop even if one phy is down */
 			state->up = 0;
+			break;
 		}
 	}
 #endif
-	if (!phydev)
+	if (!phys_detected)
 		state->options &= ~DPMAC_LINK_OPT_AUTONEG;
 
 	if (!state->up) {
@@ -568,6 +591,7 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
 	int err = 0;
 	struct phy_device *phydev = NULL;
+	int phy_num;
 
 	if ((net_dev->state == ETH_STATE_PASSIVE) ||
 	    (net_dev->state == ETH_STATE_INIT))
@@ -600,9 +624,11 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
 		printf("dpni_disable() failed\n");
 
 #ifdef CONFIG_PHYLIB
-	phydev = wriop_get_phy_dev(priv->dpmac_id);
-	if (phydev)
-		phy_shutdown(phydev);
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
+		if (phydev)
+			phy_shutdown(phydev);
+	}
 #endif
 
 	/* Free DPBP handle and reset. */
diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c
index afbb1ca91e..06a284ad68 100644
--- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
+++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
@@ -22,11 +22,10 @@ __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
 void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 {
 	phy_interface_t enet_if;
+	int phy_num;
 
 	dpmac_info[dpmac_id].enabled = 0;
 	dpmac_info[dpmac_id].id = 0;
-	dpmac_info[dpmac_id].phy_addr = -1;
-	dpmac_info[dpmac_id].phydev = NULL;
 	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
 
 	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
@@ -35,15 +34,23 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
 		dpmac_info[dpmac_id].id = dpmac_id;
 		dpmac_info[dpmac_id].enet_if = enet_if;
 	}
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
 {
+	int phy_num;
+
 	dpmac_info[dpmac_id].enabled = 1;
 	dpmac_info[dpmac_id].id = dpmac_id;
-	dpmac_info[dpmac_id].phy_addr = -1;
 	dpmac_info[dpmac_id].enet_if = enet_if;
-	dpmac_info[dpmac_id].phydev = NULL;
+	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
+		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
+		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
+	}
 }
 
 
@@ -60,47 +67,53 @@ static int wriop_dpmac_to_index(int dpmac_id)
 	return -1;
 }
 
-void wriop_disable_dpmac(int dpmac_id)
+int wriop_disable_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].enabled = 0;
 	wriop_dpmac_disable(dpmac_id);
+
+	return 0;
 }
 
-void wriop_enable_dpmac(int dpmac_id)
+int wriop_enable_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].enabled = 1;
 	wriop_dpmac_enable(dpmac_id);
+
+	return 0;
 }
 
-u8 wriop_is_enabled_dpmac(int dpmac_id)
+int wriop_is_enabled_dpmac(int dpmac_id)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return -1;
+		return -ENODEV;
 
 	return dpmac_info[i].enabled;
 }
 
 
-void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
+int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
 
 	dpmac_info[i].bus = bus;
+
+	return 0;
 }
 
 struct mii_dev *wriop_get_mdio(int dpmac_id)
@@ -113,44 +126,56 @@ struct mii_dev *wriop_get_mdio(int dpmac_id)
 	return dpmac_info[i].bus;
 }
 
-void wriop_set_phy_address(int dpmac_id, int address)
+int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
+
+	dpmac_info[i].phy_addr[phy_num] = address;
 
-	dpmac_info[i].phy_addr = address;
+	return 0;
 }
 
-int wriop_get_phy_address(int dpmac_id)
+int wriop_get_phy_address(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return -1;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
 
-	return dpmac_info[i].phy_addr;
+	return dpmac_info[i].phy_addr[phy_num];
 }
 
-void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
+int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
-		return;
+		return -ENODEV;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return -EINVAL;
 
-	dpmac_info[i].phydev = phydev;
+	dpmac_info[i].phydev[phy_num] = phydev;
+
+	return 0;
 }
 
-struct phy_device *wriop_get_phy_dev(int dpmac_id)
+struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
 {
 	int i = wriop_dpmac_to_index(dpmac_id);
 
 	if (i == -1)
 		return NULL;
+	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
+		return NULL;
 
-	return dpmac_info[i].phydev;
+	return dpmac_info[i].phydev[phy_num];
 }
 
 phy_interface_t wriop_get_enet_if(int dpmac_id)
diff --git a/include/fsl-mc/ldpaa_wriop.h b/include/fsl-mc/ldpaa_wriop.h
index 8971c6c55b..b55c39cbb2 100644
--- a/include/fsl-mc/ldpaa_wriop.h
+++ b/include/fsl-mc/ldpaa_wriop.h
@@ -6,7 +6,11 @@
 #ifndef __LDPAA_WRIOP_H
 #define __LDPAA_WRIOP_H
 
- #include <phy.h>
+#include <phy.h>
+
+#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
+#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
+#define WRIOP_MAX_PHY_NUM        2
 
 enum wriop_port {
 	WRIOP1_DPMAC1 = 1,
@@ -40,33 +44,30 @@ struct wriop_dpmac_info {
 	u8 enabled;
 	u8 id;
 	u8 board_mux;
-	int phy_addr;
+	int phy_addr[WRIOP_MAX_PHY_NUM];
 	phy_interface_t enet_if;
-	struct phy_device *phydev;
+	struct phy_device *phydev[WRIOP_MAX_PHY_NUM];
 	struct mii_dev *bus;
 };
 
 extern struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
 
-#define DEFAULT_WRIOP_MDIO1_NAME "FSL_MDIO0"
-#define DEFAULT_WRIOP_MDIO2_NAME "FSL_MDIO1"
-
-void wriop_init_dpmac(int, int, int);
-void wriop_disable_dpmac(int);
-void wriop_enable_dpmac(int);
-u8 wriop_is_enabled_dpmac(int dpmac_id);
-void wriop_set_mdio(int, struct mii_dev *);
-struct mii_dev *wriop_get_mdio(int);
-void wriop_set_phy_address(int, int);
-int wriop_get_phy_address(int);
-void wriop_set_phy_dev(int, struct phy_device *);
-struct phy_device *wriop_get_phy_dev(int);
-phy_interface_t wriop_get_enet_if(int);
+void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl);
+void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if);
+int wriop_disable_dpmac(int dpmac_id);
+int wriop_enable_dpmac(int dpmac_id);
+int wriop_is_enabled_dpmac(int dpmac_id);
+int wriop_set_mdio(int dpmac_id, struct mii_dev *bus);
+struct mii_dev *wriop_get_mdio(int dpmac_id);
+int wriop_set_phy_address(int dpmac_id, int phy_num, int address);
+int wriop_get_phy_address(int dpmac_id, int phy_num);
+int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev);
+struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num);
+phy_interface_t wriop_get_enet_if(int dpmac_id);
 
-void wriop_dpmac_disable(int);
-void wriop_dpmac_enable(int);
-phy_interface_t wriop_dpmac_enet_if(int, int);
-void wriop_init_dpmac_qsgmii(int, int);
+void wriop_dpmac_disable(int dpmac_id);
+void wriop_dpmac_enable(int dpmac_id);
+phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl);
+void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl);
 void wriop_init_rgmii(void);
-void wriop_init_dpmac_enet_if(int , phy_interface_t);
 #endif	/* __LDPAA_WRIOP_H */
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements
  2018-10-10  5:10         ` Pankaj Bansal
@ 2018-10-10 18:35           ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-10-10 18:35 UTC (permalink / raw)
  To: u-boot

On Wed, Oct 10, 2018 at 12:11 AM Pankaj Bansal <pankaj.bansal@nxp.com> wrote:
>
> Hi Joe,
>
> > -----Original Message-----
> > From: Joe Hershberger [mailto:joe.hershberger at ni.com]
> > Sent: Wednesday, October 10, 2018 9:29 AM
> > To: Pankaj Bansal <pankaj.bansal@nxp.com>
> > Cc: Joseph Hershberger <joseph.hershberger@ni.com>; u-boot <u-
> > boot at lists.denx.de>
> > Subject: Re: [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused
> > strcture elements
> >
> > On Tue, Oct 9, 2018 at 9:59 PM Pankaj Bansal <pankaj.bansal@nxp.com>
> > wrote:
> > >
> > > The phydev structure is present in both ldpaa_eth_priv and
> > > wriop_dpmac_info. the phydev in wriop_dpmac_info is not being used
> > >
> > > As the phydev is created based on phy_addr and bus members of
> > > wriop_dpmac_info, it is appropriate to keep phydev in
> > wriop_dpmac_info.
> > >
> > > Also phy_regs is not being used, therefore remove it
> > >
> > > Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> > > Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> > > ---
> > >
> > > Notes:
> > >     V3:
> > >     - No change
> >
> > Please be sure you are running scripts/checkpatch.pl on your patches.
> > v2 had a number of issues I had to fix up. I'm pretty sure this was one of
> > them.
>
> I had run checkpatch script on all the versions of patches I sent.
> I use this command "./scripts/checkpatch.pl 0001-something.patch"
> This "no return at the end of function" issue was not reported by checkpatch script.
>
> Can you please tell me which issues in V2 are you referring to?
> Because when I ran checkpatch.pl, it gave me no errors or warnings but 7 checks regarding alignment in board/freescale/ls2080aqds/eth.c.
> I did not do any changes for that because that code was not part of my patch and I think that was done
> so that line doesn't exceed 80 characters.

This patch specifically had a complaint "CHECK: braces {} should be
used on all arms of this statement" that I fixed up.

This issue doesn't last long, since the code in question is fixed in
"driver: net: fsl-mc: Modify the dpmac link detection method", but we
prefer not to have patches that have issues. patman will tell you
about it.

I've applied v3 and it looks like "Freescale AArch64" is still warning
( https://travis-ci.org/jhershbe/u-boot/jobs/439762814 ) ...

---------

   aarch64:  +   ls2080a_emu
+drivers/net/ldpaa_eth/ldpaa_eth.c: In function 'ldpaa_get_dpmac_state':
+drivers/net/ldpaa_eth/ldpaa_eth.c:408:6: error: unused variable 'err'
[-Werror=unused-variable]
+  int err;
+      ^~~
+drivers/net/ldpaa_eth/ldpaa_eth.c:407:6: error: unused variable
'phy_num' [-Werror=unused-variable]
+  int phy_num, phys_detected;
+      ^~~~~~~
+drivers/net/ldpaa_eth/ldpaa_eth.c:405:21: error: unused variable
'phydev' [-Werror=unused-variable]
+  struct phy_device *phydev = NULL;
+                     ^~~~~~
+drivers/net/ldpaa_eth/ldpaa_eth.c: In function 'ldpaa_eth_stop':
+drivers/net/ldpaa_eth/ldpaa_eth.c:594:6: error: unused variable
'phy_num' [-Werror=unused-variable]
+  int phy_num;
+drivers/net/ldpaa_eth/ldpaa_eth.c:593:21: error: unused variable
'phydev' [-Werror=unused-variable]
+cc1: all warnings being treated as errors
+make[3]: *** [drivers/net/ldpaa_eth/ldpaa_eth.o] Error 1
+make[2]: *** [drivers/net/ldpaa_eth] Error 2
+make[1]: *** [drivers/net] Error 2
+make: *** [sub-make] Error 2

---------

Both "driver: net: fsl-mc: Modify the dpmac link detection method" and
"driver: net: fsl-mc: Add support of multiple phys for dpmac"
introduce unused variable warnings on ls2080a_emu.

-Joe

>
> >
> > You would do yourself a favor to use tools/patman/patman.
>
> This is a good advice. I will use patman from now onwards to prepare and send patches.
>
> >
> > >     V2:
> > >     - change (phydev && bus != NULL) to (phydev && bus)
> > >     - after free phydev just pass NULL into wriop_set_phy_dev()
> > >
> > >  drivers/net/ldpaa_eth/ldpaa_eth.c   | 56 +++++++++++++++------------
> > >  drivers/net/ldpaa_eth/ldpaa_eth.h   |  1 -
> > >  drivers/net/ldpaa_eth/ldpaa_wriop.c |  2 +
> > >  include/fsl-mc/ldpaa_wriop.h        |  1 -
> > >  4 files changed, 33 insertions(+), 27 deletions(-)
> > >
> > > diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c
> > > b/drivers/net/ldpaa_eth/ldpaa_eth.c
> > > index 82a684bea2..ca3459cc33 100644
> > > --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> > > +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> > > @@ -35,7 +35,7 @@ static int init_phy(struct eth_device *dev)
> > >                 return -1;
> > >         }
> > >
> > > -       priv->phydev = phydev;
> > > +       wriop_set_phy_dev(priv->dpmac_id, phydev);
> > >
> > >         return phy_config(phydev);
> > >  }
> > > @@ -388,6 +388,7 @@ static int ldpaa_eth_open(struct eth_device
> > *net_dev, bd_t *bd)
> > >         struct mii_dev *bus;
> > >         phy_interface_t enet_if;
> > >         struct dpni_queue d_queue;
> > > +       struct phy_device *phydev = NULL;
> > >
> > >         if (net_dev->state == ETH_STATE_ACTIVE)
> > >                 return 0;
> > > @@ -408,38 +409,41 @@ static int ldpaa_eth_open(struct eth_device
> > *net_dev, bd_t *bd)
> > >                 goto err_dpmac_setup;
> > >
> > >  #ifdef CONFIG_PHYLIB
> > > -       if (priv->phydev) {
> > > -               err = phy_startup(priv->phydev);
> > > +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> > > +       if (phydev) {
> > > +               err = phy_startup(phydev);
> > >                 if (err) {
> > >                         printf("%s: Could not initialize\n",
> > > -                              priv->phydev->dev->name);
> > > +                              phydev->dev->name);
> > >                         goto err_dpmac_bind;
> > >                 }
> > >         }
> > >  #else
> > > -       priv->phydev = (struct phy_device *)malloc(sizeof(struct
> > phy_device));
> > > -       memset(priv->phydev, 0, sizeof(struct phy_device));
> > > +       phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
> > > +       memset(phydev, 0, sizeof(struct phy_device));
> > > +       wriop_set_phy_dev(priv->dpmac_id, phydev);
> > >
> > > -       priv->phydev->speed = SPEED_1000;
> > > -       priv->phydev->link = 1;
> > > -       priv->phydev->duplex = DUPLEX_FULL;
> > > +       phydev->speed = SPEED_1000;
> > > +       phydev->link = 1;
> > > +       phydev->duplex = DUPLEX_FULL;
> > >  #endif
> > >
> > >         bus = wriop_get_mdio(priv->dpmac_id);
> > >         enet_if = wriop_get_enet_if(priv->dpmac_id);
> > >         if ((bus == NULL) &&
> > >             (enet_if == PHY_INTERFACE_MODE_XGMII)) {
> > > -               priv->phydev = (struct phy_device *)
> > > +               phydev = (struct phy_device *)
> > >                                 malloc(sizeof(struct phy_device));
> > > -               memset(priv->phydev, 0, sizeof(struct phy_device));
> > > +               memset(phydev, 0, sizeof(struct phy_device));
> > > +               wriop_set_phy_dev(priv->dpmac_id, phydev);
> > >
> > > -               priv->phydev->speed = SPEED_10000;
> > > -               priv->phydev->link = 1;
> > > -               priv->phydev->duplex = DUPLEX_FULL;
> > > +               phydev->speed = SPEED_10000;
> > > +               phydev->link = 1;
> > > +               phydev->duplex = DUPLEX_FULL;
> > >         }
> > >
> > > -       if (!priv->phydev->link) {
> > > -               printf("%s: No link.\n", priv->phydev->dev->name);
> > > +       if (!phydev->link) {
> > > +               printf("%s: No link.\n", phydev->dev->name);
> > >                 err = -1;
> > >                 goto err_dpmac_bind;
> > >         }
> > > @@ -476,17 +480,17 @@ static int ldpaa_eth_open(struct eth_device
> > *net_dev, bd_t *bd)
> > >                 return err;
> > >         }
> > >
> > > -       dpmac_link_state.rate = priv->phydev->speed;
> > > +       dpmac_link_state.rate = phydev->speed;
> > >
> > > -       if (priv->phydev->autoneg == AUTONEG_DISABLE)
> > > +       if (phydev->autoneg == AUTONEG_DISABLE)
> > >                 dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
> > >         else
> > >                 dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
> > >
> > > -       if (priv->phydev->duplex == DUPLEX_HALF)
> > > +       if (phydev->duplex == DUPLEX_HALF)
> > >                 dpmac_link_state.options |=
> > > DPMAC_LINK_OPT_HALF_DUPLEX;
> > >
> > > -       dpmac_link_state.up = priv->phydev->link;
> > > +       dpmac_link_state.up = phydev->link;
> > >
> > >         err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
> > >                                   priv->dpmac_handle,
> > > &dpmac_link_state); @@ -530,7 +534,7 @@ static int
> > ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
> > >                 goto err_qdid;
> > >         }
> > >
> > > -       return priv->phydev->link;
> > > +       return phydev->link;
> > >
> > >  err_qdid:
> > >  err_get_queue:
> > > @@ -556,6 +560,7 @@ static void ldpaa_eth_stop(struct eth_device
> > > *net_dev)  #ifdef CONFIG_PHYLIB
> > >         struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);  #endif
> > > +       struct phy_device *phydev = NULL;
> > >
> > >         if ((net_dev->state == ETH_STATE_PASSIVE) ||
> > >             (net_dev->state == ETH_STATE_INIT)) @@ -588,11 +593,12 @@
> > > static void ldpaa_eth_stop(struct eth_device *net_dev)
> > >                 printf("dpni_disable() failed\n");
> > >
> > >  #ifdef CONFIG_PHYLIB
> > > -       if (priv->phydev && bus != NULL)
> > > -               phy_shutdown(priv->phydev);
> > > +       phydev = wriop_get_phy_dev(priv->dpmac_id);
> > > +       if (phydev && bus)
> > > +               phy_shutdown(phydev);
> > >         else {
> > > -               free(priv->phydev);
> > > -               priv->phydev = NULL;
> > > +               free(phydev);
> > > +               wriop_set_phy_dev(priv->dpmac_id, NULL);
> > >         }
> > >  #endif
> > >
> > > diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.h
> > > b/drivers/net/ldpaa_eth/ldpaa_eth.h
> > > index ee784a55ee..3f9154b5bb 100644
> > > --- a/drivers/net/ldpaa_eth/ldpaa_eth.h
> > > +++ b/drivers/net/ldpaa_eth/ldpaa_eth.h
> > > @@ -127,7 +127,6 @@ struct ldpaa_eth_priv {
> > >         uint16_t tx_flow_id;
> > >
> > >         enum ldpaa_eth_type type;       /* 1G or 10G ethernet */
> > > -       struct phy_device *phydev;
> > >  };
> > >
> > >  struct dprc_endpoint dpmac_endpoint;
> > > diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > > b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > > index 0731a795c8..afbb1ca91e 100644
> > > --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > > +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c
> > > @@ -26,6 +26,7 @@ void wriop_init_dpmac(int sd, int dpmac_id, int
> > lane_prtcl)
> > >         dpmac_info[dpmac_id].enabled = 0;
> > >         dpmac_info[dpmac_id].id = 0;
> > >         dpmac_info[dpmac_id].phy_addr = -1;
> > > +       dpmac_info[dpmac_id].phydev = NULL;
> > >         dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
> > >
> > >         enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); @@ -42,6
> > > +43,7 @@ void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t
> > enet_if)
> > >         dpmac_info[dpmac_id].id = dpmac_id;
> > >         dpmac_info[dpmac_id].phy_addr = -1;
> > >         dpmac_info[dpmac_id].enet_if = enet_if;
> > > +       dpmac_info[dpmac_id].phydev = NULL;
> > >  }
> > >
> > >
> > > diff --git a/include/fsl-mc/ldpaa_wriop.h
> > > b/include/fsl-mc/ldpaa_wriop.h index 07e5130264..8971c6c55b 100644
> > > --- a/include/fsl-mc/ldpaa_wriop.h
> > > +++ b/include/fsl-mc/ldpaa_wriop.h
> > > @@ -41,7 +41,6 @@ struct wriop_dpmac_info {
> > >         u8 id;
> > >         u8 board_mux;
> > >         int phy_addr;
> > > -       void *phy_regs;
> > >         phy_interface_t enet_if;
> > >         struct phy_device *phydev;
> > >         struct mii_dev *bus;
> > > --
> > > 2.17.1
> > >
> > > _______________________________________________
> > > U-Boot mailing list
> > > U-Boot at lists.denx.de
> > >
> > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flis
> > > ts.denx.de%2Flistinfo%2Fu-
> > boot&amp;data=02%7C01%7Cpankaj.bansal%40nxp.
> > >
> > com%7Cbced1ce32f8e455148d408d62e64c7f5%7C686ea1d3bc2b4c6fa92c
> > d99c5c301
> > >
> > 635%7C0%7C0%7C636747407731429023&amp;sdata=4cwaAt8C4V91TNo
> > iNFGcoznoGEn
> > > POsCGDmh9maFv%2FOA%3D&amp;reserved=0
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] driver: net: fsl-mc: modify the label name
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
@ 2018-10-22 19:28       ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-10-22 19:28 UTC (permalink / raw)
  To: u-boot

Hi Pankaj,

https://patchwork.ozlabs.org/patch/981665/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] driver: net: fsl-mc: remove unused strcture elements
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
@ 2018-10-22 19:28       ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-10-22 19:28 UTC (permalink / raw)
  To: u-boot

Hi Pankaj,

https://patchwork.ozlabs.org/patch/981668/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] driver: net: fsl-mc: fix error handing in init_phy
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
@ 2018-10-22 19:28       ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-10-22 19:28 UTC (permalink / raw)
  To: u-boot

Hi Pankaj,

https://patchwork.ozlabs.org/patch/981669/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] driver: net: fsl-mc: Modify the dpmac link detection method
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
@ 2018-10-22 19:28       ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-10-22 19:28 UTC (permalink / raw)
  To: u-boot

Hi Pankaj,

https://patchwork.ozlabs.org/patch/981670/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] driver: net: fsl-mc: initialize dpmac irrespective of phy
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
@ 2018-10-22 19:28       ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-10-22 19:28 UTC (permalink / raw)
  To: u-boot

Hi Pankaj,

https://patchwork.ozlabs.org/patch/981672/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [U-Boot] driver: net: fsl-mc: Add support of multiple phys for dpmac
  2018-10-10  8:38     ` [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
@ 2018-10-22 19:28       ` Joe Hershberger
  0 siblings, 0 replies; 54+ messages in thread
From: Joe Hershberger @ 2018-10-22 19:28 UTC (permalink / raw)
  To: u-boot

Hi Pankaj,

https://patchwork.ozlabs.org/patch/981671/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2018-10-22 19:28 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-13 14:40 [U-Boot] [PATCH 0/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
2018-07-13 14:40 ` [U-Boot] [PATCH 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
2018-07-25 19:39   ` Joe Hershberger
2018-07-13 14:40 ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
2018-07-25 20:03   ` Joe Hershberger
2018-07-13 14:40 ` [U-Boot] [PATCH 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
2018-07-25 20:04   ` Joe Hershberger
2018-07-13 14:40 ` [U-Boot] [PATCH 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
2018-07-25 20:13   ` Joe Hershberger
2018-07-13 14:40 ` [U-Boot] [PATCH 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
2018-07-25 20:14   ` Joe Hershberger
2018-07-13 14:40 ` [U-Boot] [PATCH 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
2018-07-25 20:52   ` Joe Hershberger
2018-07-19  3:35 ` [U-Boot] [PATCH 0/6] " Prabhakar Kushwaha
2018-07-25  3:03   ` Pankaj Bansal
2018-07-30 13:14 ` [U-Boot] [PATCH v2 " Pankaj Bansal
2018-07-30 13:15   ` [U-Boot] [PATCH v2 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
2018-07-30 20:20     ` Joe Hershberger
2018-07-30 13:15   ` [U-Boot] [PATCH v2 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
2018-07-30 20:19     ` Joe Hershberger
2018-07-30 13:15   ` [U-Boot] [PATCH v2 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
2018-07-30 20:26     ` Joe Hershberger
2018-07-30 13:15   ` [U-Boot] [PATCH v2 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
2018-07-30 20:35     ` Joe Hershberger
2018-07-30 13:15   ` [U-Boot] [PATCH v2 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
2018-07-30 20:36     ` Joe Hershberger
2018-07-30 13:15   ` [U-Boot] [PATCH v2 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
2018-07-30  8:05     ` Pankaj Bansal
2018-07-30 21:43     ` Joe Hershberger
2018-10-09 21:32     ` Joe Hershberger
2018-10-10  2:59       ` Pankaj Bansal
2018-10-10  8:27   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
2018-10-10  8:27     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
2018-10-10  8:27     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
2018-10-10  3:59       ` Joe Hershberger
2018-10-10  5:10         ` Pankaj Bansal
2018-10-10 18:35           ` Joe Hershberger
2018-10-10  8:28     ` [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
2018-10-10  8:28     ` [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
2018-10-10  8:28     ` [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
2018-10-10  8:28     ` [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
2018-10-10  8:38   ` [U-Boot] [PATCH v3 0/6] " Pankaj Bansal
2018-10-10  8:38     ` [U-Boot] [PATCH v3 1/6] driver: net: fsl-mc: modify the label name Pankaj Bansal
2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
2018-10-10  8:38     ` [U-Boot] [PATCH v3 2/6] driver: net: fsl-mc: remove unused strcture elements Pankaj Bansal
2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
2018-10-10  8:38     ` [U-Boot] [PATCH v3 3/6] driver: net: fsl-mc: fix error handing in init_phy Pankaj Bansal
2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
2018-10-10  8:38     ` [U-Boot] [PATCH v3 4/6] driver: net: fsl-mc: Modify the dpmac link detection method Pankaj Bansal
2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
2018-10-10  8:38     ` [U-Boot] [PATCH v3 5/6] driver: net: fsl-mc: initialize dpmac irrespective of phy Pankaj Bansal
2018-10-22 19:28       ` [U-Boot] " Joe Hershberger
2018-10-10  8:38     ` [U-Boot] [PATCH v3 6/6] driver: net: fsl-mc: Add support of multiple phys for dpmac Pankaj Bansal
2018-10-22 19:28       ` [U-Boot] " Joe Hershberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.