Skip to content

Commit bea0f4a

Browse files
committed
Merge branch 'sfp-slow-to-probe-copper'
Russell King says: ==================== Add support for slow-to-probe-PHY copper SFP modules This series, following on from the previous adding SFP+ copper support, adds support for a range of Copper SFP modules, made by a variety of companies, all of which have a Marvell 88E1111 PHY on them, but take far longer than the Marvell spec'd 15ms to start communicating on the I2C bus. Researching the Champion One 1000SFPT module reveals that TX_DISABLE is routed through a MAX1971 switching regulator and reset IC which adds a 175ms delay to releasing the 88E1111 reset. It is not known whether other modules use a similar setup, but there are a range of modules that are slow for the Marvell PHY to appear. This patch series adds support for these modules by repeatedly trying to probe the PHY for up to 600ms. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents b58e9fd + 1cb89a1 commit bea0f4a

File tree

1 file changed

+66
-25
lines changed

1 file changed

+66
-25
lines changed

drivers/net/phy/sfp.c

Lines changed: 66 additions & 25 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",
@@ -172,6 +174,20 @@ static const enum gpiod_flags gpio_flags[] = {
172174
#define T_RESET_US 10
173175
#define T_FAULT_RECOVER msecs_to_jiffies(1000)
174176

177+
/* N_FAULT_INIT is the number of recovery attempts at module initialisation
178+
* time. If the TX_FAULT signal is not deasserted after this number of
179+
* attempts at clearing it, we decide that the module is faulty.
180+
* N_FAULT is the same but after the module has initialised.
181+
*/
182+
#define N_FAULT_INIT 5
183+
#define N_FAULT 5
184+
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+
175191
/* SFP module presence detection is poor: the three MOD DEF signals are
176192
* the same length on the PCB, which means it's possible for MOD DEF 0 to
177193
* connect before the I2C bus on MOD DEF 1/2.
@@ -226,7 +242,8 @@ struct sfp {
226242
unsigned char sm_mod_tries;
227243
unsigned char sm_dev_state;
228244
unsigned short sm_state;
229-
unsigned int sm_retries;
245+
unsigned char sm_fault_retries;
246+
unsigned char sm_phy_retries;
230247

231248
struct sfp_eeprom_id id;
232249
unsigned int module_power_mW;
@@ -1402,37 +1419,37 @@ static void sfp_sm_phy_detach(struct sfp *sfp)
14021419
sfp->mod_phy = NULL;
14031420
}
14041421

1405-
static void sfp_sm_probe_phy(struct sfp *sfp, bool is_c45)
1422+
static int sfp_sm_probe_phy(struct sfp *sfp, bool is_c45)
14061423
{
14071424
struct phy_device *phy;
14081425
int err;
14091426

14101427
phy = get_phy_device(sfp->i2c_mii, SFP_PHY_ADDR, is_c45);
1411-
if (phy == ERR_PTR(-ENODEV)) {
1412-
dev_info(sfp->dev, "no PHY detected\n");
1413-
return;
1414-
}
1428+
if (phy == ERR_PTR(-ENODEV))
1429+
return PTR_ERR(phy);
14151430
if (IS_ERR(phy)) {
14161431
dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
1417-
return;
1432+
return PTR_ERR(phy);
14181433
}
14191434

14201435
err = phy_device_register(phy);
14211436
if (err) {
14221437
phy_device_free(phy);
14231438
dev_err(sfp->dev, "phy_device_register failed: %d\n", err);
1424-
return;
1439+
return err;
14251440
}
14261441

14271442
err = sfp_add_phy(sfp->sfp_bus, phy);
14281443
if (err) {
14291444
phy_device_remove(phy);
14301445
phy_device_free(phy);
14311446
dev_err(sfp->dev, "sfp_add_phy failed: %d\n", err);
1432-
return;
1447+
return err;
14331448
}
14341449

14351450
sfp->mod_phy = phy;
1451+
1452+
return 0;
14361453
}
14371454

14381455
static void sfp_sm_link_up(struct sfp *sfp)
@@ -1482,7 +1499,7 @@ static bool sfp_los_event_inactive(struct sfp *sfp, unsigned int event)
14821499

14831500
static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn)
14841501
{
1485-
if (sfp->sm_retries && !--sfp->sm_retries) {
1502+
if (sfp->sm_fault_retries && !--sfp->sm_fault_retries) {
14861503
dev_err(sfp->dev,
14871504
"module persistently indicates fault, disabling\n");
14881505
sfp_sm_next(sfp, SFP_S_TX_DISABLE, 0);
@@ -1505,21 +1522,24 @@ static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn)
15051522
* Clause 45 copper SFP+ modules (10G) appear to switch their interface
15061523
* mode according to the negotiated line speed.
15071524
*/
1508-
static void sfp_sm_probe_for_phy(struct sfp *sfp)
1525+
static int sfp_sm_probe_for_phy(struct sfp *sfp)
15091526
{
1527+
int err = 0;
1528+
15101529
switch (sfp->id.base.extended_cc) {
15111530
case SFF8024_ECC_10GBASE_T_SFI:
15121531
case SFF8024_ECC_10GBASE_T_SR:
15131532
case SFF8024_ECC_5GBASE_T:
15141533
case SFF8024_ECC_2_5GBASE_T:
1515-
sfp_sm_probe_phy(sfp, true);
1534+
err = sfp_sm_probe_phy(sfp, true);
15161535
break;
15171536

15181537
default:
15191538
if (sfp->id.base.e1000_base_t)
1520-
sfp_sm_probe_phy(sfp, false);
1539+
err = sfp_sm_probe_phy(sfp, false);
15211540
break;
15221541
}
1542+
return err;
15231543
}
15241544

15251545
static int sfp_module_parse_power(struct sfp *sfp)
@@ -1854,6 +1874,7 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
18541874
static void sfp_sm_main(struct sfp *sfp, unsigned int event)
18551875
{
18561876
unsigned long timeout;
1877+
int ret;
18571878

18581879
/* Some events are global */
18591880
if (sfp->sm_state != SFP_S_DOWN &&
@@ -1885,7 +1906,7 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event)
18851906
sfp_module_tx_enable(sfp);
18861907

18871908
/* Initialise the fault clearance retries */
1888-
sfp->sm_retries = 5;
1909+
sfp->sm_fault_retries = N_FAULT_INIT;
18891910

18901911
/* We need to check the TX_FAULT state, which is not defined
18911912
* while TX_DISABLE is asserted. The earliest we want to do
@@ -1925,21 +1946,41 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event)
19251946
* or t_start_up, so assume there is a fault.
19261947
*/
19271948
sfp_sm_fault(sfp, SFP_S_INIT_TX_FAULT,
1928-
sfp->sm_retries == 5);
1949+
sfp->sm_fault_retries == N_FAULT_INIT);
19291950
} else if (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR) {
1930-
init_done: /* TX_FAULT deasserted or we timed out with TX_FAULT
1931-
* clear. Probe for the PHY and check the LOS state.
1932-
*/
1933-
sfp_sm_probe_for_phy(sfp);
1934-
if (sfp_module_start(sfp->sfp_bus)) {
1935-
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);
19361968
break;
1969+
} else {
1970+
dev_info(sfp->dev, "no PHY detected\n");
19371971
}
1938-
sfp_sm_link_check_los(sfp);
1939-
1940-
/* Reset the fault retry count */
1941-
sfp->sm_retries = 5;
1972+
} else if (ret) {
1973+
sfp_sm_next(sfp, SFP_S_FAIL, 0);
1974+
break;
19421975
}
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;
19431984
break;
19441985

19451986
case SFP_S_INIT_TX_FAULT:

0 commit comments

Comments
 (0)