2018-02-25 21:54:39 +00:00
|
|
|
From 28baa5e2635285b178326b301f534ed95c65dd01 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jonas Gorski <jonas.gorski@gmail.com>
|
|
|
|
Date: Thu, 29 Sep 2016 11:44:39 +0200
|
|
|
|
Subject: [PATCH] sfp: retry phy probe if unsuccessful
|
|
|
|
|
|
|
|
Some phys seem to take longer than 50 ms to come out of reset, so retry
|
|
|
|
until we find a phy.
|
|
|
|
|
|
|
|
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
|
|
|
|
---
|
|
|
|
drivers/net/phy/sfp.c | 38 +++++++++++++++++++++++++-------------
|
|
|
|
1 file changed, 25 insertions(+), 13 deletions(-)
|
|
|
|
|
|
|
|
--- a/drivers/net/phy/sfp.c
|
|
|
|
+++ b/drivers/net/phy/sfp.c
|
2019-06-11 16:25:36 +00:00
|
|
|
@@ -505,7 +505,7 @@ static void sfp_sm_phy_detach(struct sfp
|
2018-02-25 21:54:39 +00:00
|
|
|
sfp->mod_phy = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
-static void sfp_sm_probe_phy(struct sfp *sfp)
|
|
|
|
+static int sfp_sm_probe_phy(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
struct phy_device *phy;
|
|
|
|
int err;
|
2019-06-11 16:25:36 +00:00
|
|
|
@@ -515,11 +515,11 @@ static void sfp_sm_probe_phy(struct sfp
|
2018-02-25 21:54:39 +00:00
|
|
|
phy = mdiobus_scan(sfp->i2c_mii, SFP_PHY_ADDR);
|
2018-04-02 14:01:58 +00:00
|
|
|
if (phy == ERR_PTR(-ENODEV)) {
|
|
|
|
dev_info(sfp->dev, "no PHY detected\n");
|
|
|
|
- return;
|
|
|
|
+ return -EAGAIN;
|
|
|
|
}
|
2018-02-25 21:54:39 +00:00
|
|
|
if (IS_ERR(phy)) {
|
|
|
|
dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
|
|
|
|
- return;
|
|
|
|
+ return PTR_ERR(phy);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = sfp_add_phy(sfp->sfp_bus, phy);
|
2019-06-11 16:25:36 +00:00
|
|
|
@@ -527,11 +527,13 @@ static void sfp_sm_probe_phy(struct sfp
|
2018-02-25 21:54:39 +00:00
|
|
|
phy_device_remove(phy);
|
|
|
|
phy_device_free(phy);
|
|
|
|
dev_err(sfp->dev, "sfp_add_phy failed: %d\n", err);
|
|
|
|
- return;
|
|
|
|
+ return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
sfp->mod_phy = phy;
|
|
|
|
phy_start(phy);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sfp_sm_link_up(struct sfp *sfp)
|
2019-06-11 16:25:36 +00:00
|
|
|
@@ -577,14 +579,9 @@ static void sfp_sm_fault(struct sfp *sfp
|
2018-02-25 21:54:39 +00:00
|
|
|
|
|
|
|
static void sfp_sm_mod_init(struct sfp *sfp)
|
|
|
|
{
|
|
|
|
- sfp_module_tx_enable(sfp);
|
|
|
|
+ int ret = 0;
|
|
|
|
|
|
|
|
- /* Wait t_init before indicating that the link is up, provided the
|
|
|
|
- * current state indicates no TX_FAULT. If TX_FAULT clears before
|
|
|
|
- * this time, that's fine too.
|
|
|
|
- */
|
|
|
|
- sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
|
|
|
|
- sfp->sm_retries = 5;
|
|
|
|
+ sfp_module_tx_enable(sfp);
|
|
|
|
|
|
|
|
/* Setting the serdes link mode is guesswork: there's no
|
|
|
|
* field in the EEPROM which indicates what mode should
|
2019-06-11 16:25:36 +00:00
|
|
|
@@ -598,7 +595,22 @@ static void sfp_sm_mod_init(struct sfp *
|
2018-02-25 21:54:39 +00:00
|
|
|
if (sfp->id.base.e1000_base_t ||
|
|
|
|
sfp->id.base.e100_base_lx ||
|
|
|
|
sfp->id.base.e100_base_fx)
|
|
|
|
- sfp_sm_probe_phy(sfp);
|
|
|
|
+ ret = sfp_sm_probe_phy(sfp);
|
|
|
|
+
|
|
|
|
+ if (!ret) {
|
|
|
|
+ /* Wait t_init before indicating that the link is up, provided
|
|
|
|
+ * the current state indicates no TX_FAULT. If TX_FAULT clears
|
|
|
|
+ * this time, that's fine too.
|
|
|
|
+ */
|
|
|
|
+ sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
|
|
|
|
+ sfp->sm_retries = 5;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ret == -EAGAIN)
|
|
|
|
+ sfp_sm_set_timer(sfp, T_PROBE_RETRY);
|
|
|
|
+ else
|
|
|
|
+ sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sfp_sm_mod_probe(struct sfp *sfp)
|