mvebu: add missing patch for reprobing SFP phys for 4.14
[openwrt/staging/jow.git] / target / linux / mvebu / patches-4.14 / 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 @@ -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 @@ -497,12 +497,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 err = sfp_add_phy(sfp->sfp_bus, phy);
43 @@ -510,11 +510,13 @@ static void sfp_sm_probe_phy(struct sfp
44 phy_device_remove(phy);
45 phy_device_free(phy);
46 dev_err(sfp->dev, "sfp_add_phy failed: %d\n", err);
47 - return;
48 + return err;
49 }
50
51 sfp->mod_phy = phy;
52 phy_start(phy);
53 +
54 + return 0;
55 }
56
57 static void sfp_sm_link_up(struct sfp *sfp)
58 @@ -560,14 +562,9 @@ static void sfp_sm_fault(struct sfp *sfp
59
60 static void sfp_sm_mod_init(struct sfp *sfp)
61 {
62 - sfp_module_tx_enable(sfp);
63 + int ret = 0;
64
65 - /* Wait t_init before indicating that the link is up, provided the
66 - * current state indicates no TX_FAULT. If TX_FAULT clears before
67 - * this time, that's fine too.
68 - */
69 - sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
70 - sfp->sm_retries = 5;
71 + sfp_module_tx_enable(sfp);
72
73 /* Setting the serdes link mode is guesswork: there's no
74 * field in the EEPROM which indicates what mode should
75 @@ -581,7 +578,22 @@ static void sfp_sm_mod_init(struct sfp *
76 if (sfp->id.base.e1000_base_t ||
77 sfp->id.base.e100_base_lx ||
78 sfp->id.base.e100_base_fx)
79 - sfp_sm_probe_phy(sfp);
80 + ret = sfp_sm_probe_phy(sfp);
81 +
82 + if (!ret) {
83 + /* Wait t_init before indicating that the link is up, provided
84 + * the current state indicates no TX_FAULT. If TX_FAULT clears
85 + * this time, that's fine too.
86 + */
87 + sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
88 + sfp->sm_retries = 5;
89 + return;
90 + }
91 +
92 + if (ret == -EAGAIN)
93 + sfp_sm_set_timer(sfp, T_PROBE_RETRY);
94 + else
95 + sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
96 }
97
98 static int sfp_sm_mod_probe(struct sfp *sfp)