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 @@ -491,7 +491,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 @@ -500,12 +500,12 @@ static void sfp_sm_probe_phy(struct sfp
27 phy = mdiobus_scan(sfp->i2c_mii, SFP_PHY_ADDR);
29 + if (PTR_ERR(phy) == -ENODEV) {
30 + dev_dbg(sfp->dev, "no PHY detected\n");
33 dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
37 - dev_info(sfp->dev, "no PHY detected\n");
39 + return PTR_ERR(phy);
43 @@ -515,12 +515,14 @@ static void sfp_sm_probe_phy(struct sfp
45 dev_err(sfp->dev, "phylink_connect_phy failed: %d\n",
58 static void sfp_sm_link_up(struct sfp *sfp)
59 @@ -569,30 +571,41 @@ static void sfp_sm_fault(struct sfp *sfp
61 static void sfp_sm_mod_init(struct sfp *sfp)
65 sfp_module_tx_enable(sfp);
67 - /* Wait t_init before indicating that the link is up, provided the
68 - * current state indicates no TX_FAULT. If TX_FAULT clears before
69 - * this time, that's fine too.
71 - sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
72 - sfp->sm_retries = 5;
77 - /* Setting the serdes link mode is guesswork: there's no
78 - * field in the EEPROM which indicates what mode should
81 - * If it's a gigabit-only fiber module, it probably does
82 - * not have a PHY, so switch to 802.3z negotiation mode.
83 - * Otherwise, switch to SGMII mode (which is required to
84 - * support non-gigabit speeds) and probe for a PHY.
85 + /* Setting the serdes link mode is guesswork: there's no
86 + * field in the EEPROM which indicates what mode should
89 + * If it's a gigabit-only fiber module, it probably does
90 + * not have a PHY, so switch to 802.3z negotiation mode.
91 + * Otherwise, switch to SGMII mode (which is required to
92 + * support non-gigabit speeds) and probe for a PHY.
94 + if (sfp->id.base.e1000_base_t ||
95 + sfp->id.base.e100_base_lx ||
96 + sfp->id.base.e100_base_fx)
97 + ret = sfp_sm_probe_phy(sfp);
100 + /* Wait t_init before indicating that the link is up, provided
101 + * the current state indicates no TX_FAULT. If TX_FAULT clears
102 + * this time, that's fine too.
104 - if (sfp->id.base.e1000_base_t ||
105 - sfp->id.base.e100_base_lx ||
106 - sfp->id.base.e100_base_fx)
107 - sfp_sm_probe_phy(sfp);
108 + sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
109 + sfp->sm_retries = 5;
113 + if (ret == -EAGAIN)
114 + sfp_sm_set_timer(sfp, T_PROBE_RETRY);
116 + sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
119 static int sfp_sm_mod_probe(struct sfp *sfp)