1 From 28baa5e2635285b178326b301f534ed95c65dd01 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Thu, 29 Sep 2016 11:44:39 +0200
4 Subject: [PATCH] sfp: retry phy probe if unsuccessful
6 Some phys seem to take longer than 50 ms to come out of reset, so retry
9 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
11 drivers/net/phy/sfp.c | 38 +++++++++++++++++++++++++-------------
12 1 file changed, 25 insertions(+), 13 deletions(-)
14 --- a/drivers/net/phy/sfp.c
15 +++ b/drivers/net/phy/sfp.c
16 @@ -488,7 +488,7 @@ static void sfp_sm_phy_detach(struct sfp
20 -static void sfp_sm_probe_phy(struct sfp *sfp)
21 +static int sfp_sm_probe_phy(struct sfp *sfp)
23 struct phy_device *phy;
25 @@ -498,11 +498,11 @@ static void sfp_sm_probe_phy(struct sfp
26 phy = mdiobus_scan(sfp->i2c_mii, SFP_PHY_ADDR);
28 dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
30 + return PTR_ERR(phy);
33 - dev_info(sfp->dev, "no PHY detected\n");
35 + dev_dbg(sfp->dev, "no PHY detected\n");
39 err = phylink_connect_phy(sfp->phylink, phy);
40 @@ -510,11 +510,13 @@ static void sfp_sm_probe_phy(struct sfp
41 phy_device_remove(phy);
43 dev_err(sfp->dev, "phylink_connect_phy failed: %d\n", err);
54 static void sfp_sm_link_up(struct sfp *sfp)
55 @@ -565,13 +567,6 @@ static void sfp_sm_mod_init(struct sfp *
57 sfp_module_tx_enable(sfp);
59 - /* Wait t_init before indicating that the link is up, provided the
60 - * current state indicates no TX_FAULT. If TX_FAULT clears before
61 - * this time, that's fine too.
63 - sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
64 - sfp->sm_retries = 5;
67 /* Setting the serdes link mode is guesswork: there's no
68 * field in the EEPROM which indicates what mode should
69 @@ -587,9 +582,26 @@ static void sfp_sm_mod_init(struct sfp *
70 !sfp->id.base.e100_base_fx) {
71 phylink_set_link_an_mode(sfp->phylink, MLO_AN_8023Z);
75 phylink_set_link_an_mode(sfp->phylink, MLO_AN_SGMII);
76 - sfp_sm_probe_phy(sfp);
78 + ret = sfp_sm_probe_phy(sfp);
81 + sfp_sm_set_timer(sfp, T_PROBE_RETRY);
83 + sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
88 + /* Wait t_init before indicating that the link is up, provided the
89 + * current state indicates no TX_FAULT. If TX_FAULT clears before
90 + * this time, that's fine too.
92 + sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
93 + sfp->sm_retries = 5;