mvebu: add support for SFP
[openwrt/openwrt.git] / target / linux / mvebu / patches-4.4 / 300-reprobe_sfp_phy.patch
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
5
6 Some phys seem to take longer than 50 ms to come out of reset, so retry
7 until we find a phy.
8
9 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
10 ---
11 drivers/net/phy/sfp.c | 38 +++++++++++++++++++++++++-------------
12 1 file changed, 25 insertions(+), 13 deletions(-)
13
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
17 sfp->mod_phy = NULL;
18 }
19
20 -static void sfp_sm_probe_phy(struct sfp *sfp)
21 +static int sfp_sm_probe_phy(struct sfp *sfp)
22 {
23 struct phy_device *phy;
24 int err;
25 @@ -498,11 +498,11 @@ static void sfp_sm_probe_phy(struct sfp
26 phy = mdiobus_scan(sfp->i2c_mii, SFP_PHY_ADDR);
27 if (IS_ERR(phy)) {
28 dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
29 - return;
30 + return PTR_ERR(phy);
31 }
32 if (!phy) {
33 - dev_info(sfp->dev, "no PHY detected\n");
34 - return;
35 + dev_dbg(sfp->dev, "no PHY detected\n");
36 + return -EAGAIN;
37 }
38
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);
42 phy_device_free(phy);
43 dev_err(sfp->dev, "phylink_connect_phy failed: %d\n", err);
44 - return;
45 + return err;
46 }
47
48 sfp->mod_phy = phy;
49 phy_start(phy);
50 +
51 + return 0;
52 }
53
54 static void sfp_sm_link_up(struct sfp *sfp)
55 @@ -565,13 +567,6 @@ static void sfp_sm_mod_init(struct sfp *
56 {
57 sfp_module_tx_enable(sfp);
58
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.
62 - */
63 - sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
64 - sfp->sm_retries = 5;
65 -
66 if (sfp->phylink) {
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);
72 } else {
73 + int ret;
74 +
75 phylink_set_link_an_mode(sfp->phylink, MLO_AN_SGMII);
76 - sfp_sm_probe_phy(sfp);
77 +
78 + ret = sfp_sm_probe_phy(sfp);
79 + if (ret) {
80 + if (ret == -EAGAIN)
81 + sfp_sm_set_timer(sfp, T_PROBE_RETRY);
82 + else
83 + sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
84 + return;
85 + }
86 }
87 +
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.
91 + */
92 + sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
93 + sfp->sm_retries = 5;
94 }
95 }
96