All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 net] net: macb: fix for fixed-link mode
@ 2020-01-10 13:25 Milind Parab
  2020-01-11 23:33 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Milind Parab @ 2020-01-10 13:25 UTC (permalink / raw)
  To: nicolas.ferre, jakub.kicinski, andrew, antoine.tenart, rmk+kernel
  Cc: Claudiu.Beznea, f.fainelli, davem, netdev, hkallweit1,
	linux-kernel, dkangude, a.fatoum, brad.mouring, pthombar,
	Milind Parab

This patch fix the issue with fixed link. With fixed-link
device opening fails due to macb_phylink_connect not
handling fixed-link mode, in which case no MAC-PHY connection
is needed and phylink_connect return success (0), however
in current driver attempt is made to search and connect to
PHY even for fixed-link.

Fixes: 7897b071ac3b ("net: macb: convert to phylink")
Signed-off-by: Milind Parab <mparab@cadence.com>
---
Changes in v2:
1. Code refactoring to remove extra if condition
---
 drivers/net/ethernet/cadence/macb_main.c | 30 ++++++++++++++----------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index c5ee363ca5dc..f8fd45d69e9a 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -611,21 +611,24 @@ static const struct phylink_mac_ops macb_phylink_ops = {
 	.mac_link_up = macb_mac_link_up,
 };
 
+static bool macb_phy_handle_exists(struct device_node *dn)
+{
+	dn = of_parse_phandle(dn, "phy-handle", 0);
+	of_node_put(dn);
+	return dn != NULL;
+}
+
 static int macb_phylink_connect(struct macb *bp)
 {
 	struct net_device *dev = bp->dev;
 	struct phy_device *phydev;
+	struct device_node *dn = bp->pdev->dev.of_node;
 	int ret;
 
-	if (bp->pdev->dev.of_node &&
-	    of_parse_phandle(bp->pdev->dev.of_node, "phy-handle", 0)) {
-		ret = phylink_of_phy_connect(bp->phylink, bp->pdev->dev.of_node,
-					     0);
-		if (ret) {
-			netdev_err(dev, "Could not attach PHY (%d)\n", ret);
-			return ret;
-		}
-	} else {
+	if (dn)
+		ret = phylink_of_phy_connect(bp->phylink, dn, 0);
+
+	if (!dn || (ret && !macb_phy_handle_exists(dn))) {
 		phydev = phy_find_first(bp->mii_bus);
 		if (!phydev) {
 			netdev_err(dev, "no PHY found\n");
@@ -634,10 +637,11 @@ static int macb_phylink_connect(struct macb *bp)
 
 		/* attach the mac to the phy */
 		ret = phylink_connect_phy(bp->phylink, phydev);
-		if (ret) {
-			netdev_err(dev, "Could not attach to PHY (%d)\n", ret);
-			return ret;
-		}
+	}
+
+	if (ret) {
+		netdev_err(dev, "Could not attach PHY (%d)\n", ret);
+		return ret;
 	}
 
 	phylink_start(bp->phylink);
-- 
2.17.1


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

* Re: [PATCH v2 net] net: macb: fix for fixed-link mode
  2020-01-10 13:25 [PATCH v2 net] net: macb: fix for fixed-link mode Milind Parab
@ 2020-01-11 23:33 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-01-11 23:33 UTC (permalink / raw)
  To: mparab
  Cc: nicolas.ferre, jakub.kicinski, andrew, antoine.tenart,
	rmk+kernel, Claudiu.Beznea, f.fainelli, netdev, hkallweit1,
	linux-kernel, dkangude, a.fatoum, brad.mouring, pthombar

From: Milind Parab <mparab@cadence.com>
Date: Fri, 10 Jan 2020 13:25:27 +0000

>  static int macb_phylink_connect(struct macb *bp)
>  {
>  	struct net_device *dev = bp->dev;
>  	struct phy_device *phydev;
> +	struct device_node *dn = bp->pdev->dev.of_node;
>  	int ret;

Please retain the reverse christmas tree ordering of local variables
here.

Thank you.

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

end of thread, other threads:[~2020-01-11 23:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10 13:25 [PATCH v2 net] net: macb: fix for fixed-link mode Milind Parab
2020-01-11 23:33 ` David Miller

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.