Skip to content

Commit 1cb89a1

Browse files
Russell Kingdavem330
authored andcommitted
net: sfp: re-attempt probing for phy
Some 1000BASE-T PHY modules take a while for the PHY to wake up. Retry the probe a number of times before deciding that the module has no PHY. Tested with: Sourcephotonics SPGBTXCNFC - PHY takes less than 50ms to respond. Champion One 1000SFPT - PHY takes about 200ms to respond. Mikrotik S-RJ01 - no PHY Signed-off-by: Russell King <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 256e43c commit 1cb89a1

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

drivers/net/phy/sfp.c

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ enum {
6262
SFP_S_FAIL,
6363
SFP_S_WAIT,
6464
SFP_S_INIT,
65+
SFP_S_INIT_PHY,
6566
SFP_S_INIT_TX_FAULT,
6667
SFP_S_WAIT_LOS,
6768
SFP_S_LINK_UP,
@@ -126,6 +127,7 @@ static const char * const sm_state_strings[] = {
126127
[SFP_S_FAIL] = "fail",
127128
[SFP_S_WAIT] = "wait",
128129
[SFP_S_INIT] = "init",
130+
[SFP_S_INIT_PHY] = "init_phy",
129131
[SFP_S_INIT_TX_FAULT] = "init_tx_fault",
130132
[SFP_S_WAIT_LOS] = "wait_los",
131133
[SFP_S_LINK_UP] = "link_up",
@@ -180,6 +182,12 @@ static const enum gpiod_flags gpio_flags[] = {
180182
#define N_FAULT_INIT 5
181183
#define N_FAULT 5
182184

185+
/* T_PHY_RETRY is the time interval between attempts to probe the PHY.
186+
* R_PHY_RETRY is the number of attempts.
187+
*/
188+
#define T_PHY_RETRY msecs_to_jiffies(50)
189+
#define R_PHY_RETRY 12
190+
183191
/* SFP module presence detection is poor: the three MOD DEF signals are
184192
* the same length on the PCB, which means it's possible for MOD DEF 0 to
185193
* connect before the I2C bus on MOD DEF 1/2.
@@ -235,6 +243,7 @@ struct sfp {
235243
unsigned char sm_dev_state;
236244
unsigned short sm_state;
237245
unsigned char sm_fault_retries;
246+
unsigned char sm_phy_retries;
238247

239248
struct sfp_eeprom_id id;
240249
unsigned int module_power_mW;
@@ -1416,10 +1425,8 @@ static int sfp_sm_probe_phy(struct sfp *sfp, bool is_c45)
14161425
int err;
14171426

14181427
phy = get_phy_device(sfp->i2c_mii, SFP_PHY_ADDR, is_c45);
1419-
if (phy == ERR_PTR(-ENODEV)) {
1420-
dev_info(sfp->dev, "no PHY detected\n");
1421-
return 0;
1422-
}
1428+
if (phy == ERR_PTR(-ENODEV))
1429+
return PTR_ERR(phy);
14231430
if (IS_ERR(phy)) {
14241431
dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
14251432
return PTR_ERR(phy);
@@ -1867,6 +1874,7 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
18671874
static void sfp_sm_main(struct sfp *sfp, unsigned int event)
18681875
{
18691876
unsigned long timeout;
1877+
int ret;
18701878

18711879
/* Some events are global */
18721880
if (sfp->sm_state != SFP_S_DOWN &&
@@ -1940,22 +1948,39 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event)
19401948
sfp_sm_fault(sfp, SFP_S_INIT_TX_FAULT,
19411949
sfp->sm_fault_retries == N_FAULT_INIT);
19421950
} else if (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR) {
1943-
init_done: /* TX_FAULT deasserted or we timed out with TX_FAULT
1944-
* clear. Probe for the PHY and check the LOS state.
1945-
*/
1946-
if (sfp_sm_probe_for_phy(sfp)) {
1947-
sfp_sm_next(sfp, SFP_S_FAIL, 0);
1948-
break;
1949-
}
1950-
if (sfp_module_start(sfp->sfp_bus)) {
1951-
sfp_sm_next(sfp, SFP_S_FAIL, 0);
1951+
init_done:
1952+
sfp->sm_phy_retries = R_PHY_RETRY;
1953+
goto phy_probe;
1954+
}
1955+
break;
1956+
1957+
case SFP_S_INIT_PHY:
1958+
if (event != SFP_E_TIMEOUT)
1959+
break;
1960+
phy_probe:
1961+
/* TX_FAULT deasserted or we timed out with TX_FAULT
1962+
* clear. Probe for the PHY and check the LOS state.
1963+
*/
1964+
ret = sfp_sm_probe_for_phy(sfp);
1965+
if (ret == -ENODEV) {
1966+
if (--sfp->sm_phy_retries) {
1967+
sfp_sm_next(sfp, SFP_S_INIT_PHY, T_PHY_RETRY);
19521968
break;
1969+
} else {
1970+
dev_info(sfp->dev, "no PHY detected\n");
19531971
}
1954-
sfp_sm_link_check_los(sfp);
1955-
1956-
/* Reset the fault retry count */
1957-
sfp->sm_fault_retries = N_FAULT;
1972+
} else if (ret) {
1973+
sfp_sm_next(sfp, SFP_S_FAIL, 0);
1974+
break;
19581975
}
1976+
if (sfp_module_start(sfp->sfp_bus)) {
1977+
sfp_sm_next(sfp, SFP_S_FAIL, 0);
1978+
break;
1979+
}
1980+
sfp_sm_link_check_los(sfp);
1981+
1982+
/* Reset the fault retry count */
1983+
sfp->sm_fault_retries = N_FAULT;
19591984
break;
19601985

19611986
case SFP_S_INIT_TX_FAULT:

0 commit comments

Comments
 (0)