aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/mvebu/patches-4.4/300-reprobe_sfp_phy.patch
blob: 42614effb84a82fc855cfd4f6c846b8f162e0f91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
From 28baa5e2635285b178326b301f534ed95c65dd01 Mon Sep 17 00:00:00 2001
From: Jonas Gorski <jonas.gorski@gmail.com>
Date: Thu, 29 Sep 2016 11:44:39 +0200
Subject: [PATCH] sfp: retry phy probe if unsuccessful

Some phys seem to take longer than 50 ms to come out of reset, so retry
until we find a phy.

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
 drivers/net/phy/sfp.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -488,7 +488,7 @@ static void sfp_sm_phy_detach(struct sfp
 	sfp->mod_phy = NULL;
 }
 
-static void sfp_sm_probe_phy(struct sfp *sfp)
+static int sfp_sm_probe_phy(struct sfp *sfp)
 {
 	struct phy_device *phy;
 	int err;
@@ -498,11 +498,11 @@ static void sfp_sm_probe_phy(struct sfp
 	phy = mdiobus_scan(sfp->i2c_mii, SFP_PHY_ADDR);
 	if (IS_ERR(phy)) {
 		dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
-		return;
+		return PTR_ERR(phy);
 	}
 	if (!phy) {
-		dev_info(sfp->dev, "no PHY detected\n");
-		return;
+		dev_dbg(sfp->dev, "no PHY detected\n");
+		return -EAGAIN;
 	}
 
 	err = phylink_connect_phy(sfp->phylink, phy);
@@ -510,11 +510,13 @@ static void sfp_sm_probe_phy(struct sfp
 		phy_device_remove(phy);
 		phy_device_free(phy);
 		dev_err(sfp->dev, "phylink_connect_phy failed: %d\n", err);
-		return;
+		return err;
 	}
 
 	sfp->mod_phy = phy;
 	phy_start(phy);
+
+	return 0;
 }
 
 static void sfp_sm_link_up(struct sfp *sfp)
@@ -565,13 +567,6 @@ static void sfp_sm_mod_init(struct sfp *
 {
 	sfp_module_tx_enable(sfp);
 
-	/* Wait t_init before indicating that the link is up, provided the
-	 * current state indicates no TX_FAULT.  If TX_FAULT clears before
-	 * this time, that's fine too.
-	 */
-	sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
-	sfp->sm_retries = 5;
-
 	if (sfp->phylink) {
 		/* Setting the serdes link mode is guesswork: there's no
 		 * field in the EEPROM which indicates what mode should
@@ -587,9 +582,26 @@ static void sfp_sm_mod_init(struct sfp *
 		    !sfp->id.base.e100_base_fx) {
 			phylink_set_link_an_mode(sfp->phylink, MLO_AN_8023Z);
 		} else {
+			int ret;
+
 			phylink_set_link_an_mode(sfp->phylink, MLO_AN_SGMII);
-			sfp_sm_probe_phy(sfp);
+
+			ret = sfp_sm_probe_phy(sfp);
+			if (ret) {
+				if (ret == -EAGAIN)
+					sfp_sm_set_timer(sfp, T_PROBE_RETRY);
+				else
+					sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
+				return;
+			}
 		}
+
+		/* Wait t_init before indicating that the link is up, provided the
+		 * current state indicates no TX_FAULT.  If TX_FAULT clears before
+		 * this time, that's fine too.
+		 */
+		sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
+		sfp->sm_retries = 5;
 	}
 }