69eaa3773ee87a7b8bb8ef281eb00acede2b511b
[openwrt/staging/jogo.git] / target / linux / mvebu / patches-4.9 / 450-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 @@ -491,7 +491,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 @@ -500,12 +500,12 @@ static void sfp_sm_probe_phy(struct sfp
26
27 phy = mdiobus_scan(sfp->i2c_mii, SFP_PHY_ADDR);
28 if (IS_ERR(phy)) {
29 + if (PTR_ERR(phy) == -ENODEV) {
30 + dev_dbg(sfp->dev, "no PHY detected\n");
31 + return -EAGAIN;
32 + }
33 dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
34 - return;
35 - }
36 - if (!phy) {
37 - dev_info(sfp->dev, "no PHY detected\n");
38 - return;
39 + return PTR_ERR(phy);
40 }
41
42 if (sfp->phylink) {
43 @@ -515,12 +515,14 @@ static void sfp_sm_probe_phy(struct sfp
44 phy_device_free(phy);
45 dev_err(sfp->dev, "phylink_connect_phy failed: %d\n",
46 err);
47 - return;
48 + return err;
49 }
50 }
51
52 sfp->mod_phy = phy;
53 phy_start(phy);
54 +
55 + return 0;
56 }
57
58 static void sfp_sm_link_up(struct sfp *sfp)
59 @@ -569,30 +571,41 @@ static void sfp_sm_fault(struct sfp *sfp
60
61 static void sfp_sm_mod_init(struct sfp *sfp)
62 {
63 + int ret = 0;
64 +
65 sfp_module_tx_enable(sfp);
66
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.
70 - */
71 - sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
72 - sfp->sm_retries = 5;
73 + if (!sfp->phylink)
74 + return;
75
76 - if (sfp->phylink) {
77 - /* Setting the serdes link mode is guesswork: there's no
78 - * field in the EEPROM which indicates what mode should
79 - * be used.
80 - *
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
87 + * be used.
88 + *
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.
93 + */
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);
98 +
99 + if (!ret) {
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.
103 */
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;
110 + return;
111 }
112 +
113 + if (ret == -EAGAIN)
114 + sfp_sm_set_timer(sfp, T_PROBE_RETRY);
115 + else
116 + sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
117 }
118
119 static int sfp_sm_mod_probe(struct sfp *sfp)