62
62
SFP_S_FAIL ,
63
63
SFP_S_WAIT ,
64
64
SFP_S_INIT ,
65
+ SFP_S_INIT_PHY ,
65
66
SFP_S_INIT_TX_FAULT ,
66
67
SFP_S_WAIT_LOS ,
67
68
SFP_S_LINK_UP ,
@@ -126,6 +127,7 @@ static const char * const sm_state_strings[] = {
126
127
[SFP_S_FAIL ] = "fail" ,
127
128
[SFP_S_WAIT ] = "wait" ,
128
129
[SFP_S_INIT ] = "init" ,
130
+ [SFP_S_INIT_PHY ] = "init_phy" ,
129
131
[SFP_S_INIT_TX_FAULT ] = "init_tx_fault" ,
130
132
[SFP_S_WAIT_LOS ] = "wait_los" ,
131
133
[SFP_S_LINK_UP ] = "link_up" ,
@@ -172,6 +174,20 @@ static const enum gpiod_flags gpio_flags[] = {
172
174
#define T_RESET_US 10
173
175
#define T_FAULT_RECOVER msecs_to_jiffies(1000)
174
176
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
+
175
191
/* SFP module presence detection is poor: the three MOD DEF signals are
176
192
* the same length on the PCB, which means it's possible for MOD DEF 0 to
177
193
* connect before the I2C bus on MOD DEF 1/2.
@@ -226,7 +242,8 @@ struct sfp {
226
242
unsigned char sm_mod_tries ;
227
243
unsigned char sm_dev_state ;
228
244
unsigned short sm_state ;
229
- unsigned int sm_retries ;
245
+ unsigned char sm_fault_retries ;
246
+ unsigned char sm_phy_retries ;
230
247
231
248
struct sfp_eeprom_id id ;
232
249
unsigned int module_power_mW ;
@@ -1402,37 +1419,37 @@ static void sfp_sm_phy_detach(struct sfp *sfp)
1402
1419
sfp -> mod_phy = NULL ;
1403
1420
}
1404
1421
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 )
1406
1423
{
1407
1424
struct phy_device * phy ;
1408
1425
int err ;
1409
1426
1410
1427
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 );
1415
1430
if (IS_ERR (phy )) {
1416
1431
dev_err (sfp -> dev , "mdiobus scan returned %ld\n" , PTR_ERR (phy ));
1417
- return ;
1432
+ return PTR_ERR ( phy ) ;
1418
1433
}
1419
1434
1420
1435
err = phy_device_register (phy );
1421
1436
if (err ) {
1422
1437
phy_device_free (phy );
1423
1438
dev_err (sfp -> dev , "phy_device_register failed: %d\n" , err );
1424
- return ;
1439
+ return err ;
1425
1440
}
1426
1441
1427
1442
err = sfp_add_phy (sfp -> sfp_bus , phy );
1428
1443
if (err ) {
1429
1444
phy_device_remove (phy );
1430
1445
phy_device_free (phy );
1431
1446
dev_err (sfp -> dev , "sfp_add_phy failed: %d\n" , err );
1432
- return ;
1447
+ return err ;
1433
1448
}
1434
1449
1435
1450
sfp -> mod_phy = phy ;
1451
+
1452
+ return 0 ;
1436
1453
}
1437
1454
1438
1455
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)
1482
1499
1483
1500
static void sfp_sm_fault (struct sfp * sfp , unsigned int next_state , bool warn )
1484
1501
{
1485
- if (sfp -> sm_retries && !-- sfp -> sm_retries ) {
1502
+ if (sfp -> sm_fault_retries && !-- sfp -> sm_fault_retries ) {
1486
1503
dev_err (sfp -> dev ,
1487
1504
"module persistently indicates fault, disabling\n" );
1488
1505
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)
1505
1522
* Clause 45 copper SFP+ modules (10G) appear to switch their interface
1506
1523
* mode according to the negotiated line speed.
1507
1524
*/
1508
- static void sfp_sm_probe_for_phy (struct sfp * sfp )
1525
+ static int sfp_sm_probe_for_phy (struct sfp * sfp )
1509
1526
{
1527
+ int err = 0 ;
1528
+
1510
1529
switch (sfp -> id .base .extended_cc ) {
1511
1530
case SFF8024_ECC_10GBASE_T_SFI :
1512
1531
case SFF8024_ECC_10GBASE_T_SR :
1513
1532
case SFF8024_ECC_5GBASE_T :
1514
1533
case SFF8024_ECC_2_5GBASE_T :
1515
- sfp_sm_probe_phy (sfp , true);
1534
+ err = sfp_sm_probe_phy (sfp , true);
1516
1535
break ;
1517
1536
1518
1537
default :
1519
1538
if (sfp -> id .base .e1000_base_t )
1520
- sfp_sm_probe_phy (sfp , false);
1539
+ err = sfp_sm_probe_phy (sfp , false);
1521
1540
break ;
1522
1541
}
1542
+ return err ;
1523
1543
}
1524
1544
1525
1545
static int sfp_module_parse_power (struct sfp * sfp )
@@ -1854,6 +1874,7 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
1854
1874
static void sfp_sm_main (struct sfp * sfp , unsigned int event )
1855
1875
{
1856
1876
unsigned long timeout ;
1877
+ int ret ;
1857
1878
1858
1879
/* Some events are global */
1859
1880
if (sfp -> sm_state != SFP_S_DOWN &&
@@ -1885,7 +1906,7 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event)
1885
1906
sfp_module_tx_enable (sfp );
1886
1907
1887
1908
/* Initialise the fault clearance retries */
1888
- sfp -> sm_retries = 5 ;
1909
+ sfp -> sm_fault_retries = N_FAULT_INIT ;
1889
1910
1890
1911
/* We need to check the TX_FAULT state, which is not defined
1891
1912
* 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)
1925
1946
* or t_start_up, so assume there is a fault.
1926
1947
*/
1927
1948
sfp_sm_fault (sfp , SFP_S_INIT_TX_FAULT ,
1928
- sfp -> sm_retries == 5 );
1949
+ sfp -> sm_fault_retries == N_FAULT_INIT );
1929
1950
} 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 );
1936
1968
break ;
1969
+ } else {
1970
+ dev_info (sfp -> dev , "no PHY detected\n" );
1937
1971
}
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 ;
1942
1975
}
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 ;
1943
1984
break ;
1944
1985
1945
1986
case SFP_S_INIT_TX_FAULT :
0 commit comments