|
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",
|
@@ -180,6 +182,12 @@ static const enum gpiod_flags gpio_flags[] = {
|
180 | 182 | #define N_FAULT_INIT 5
|
181 | 183 | #define N_FAULT 5
|
182 | 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 | + |
183 | 191 | /* SFP module presence detection is poor: the three MOD DEF signals are
|
184 | 192 | * the same length on the PCB, which means it's possible for MOD DEF 0 to
|
185 | 193 | * connect before the I2C bus on MOD DEF 1/2.
|
@@ -235,6 +243,7 @@ struct sfp {
|
235 | 243 | unsigned char sm_dev_state;
|
236 | 244 | unsigned short sm_state;
|
237 | 245 | unsigned char sm_fault_retries;
|
| 246 | + unsigned char sm_phy_retries; |
238 | 247 |
|
239 | 248 | struct sfp_eeprom_id id;
|
240 | 249 | unsigned int module_power_mW;
|
@@ -1416,10 +1425,8 @@ static int sfp_sm_probe_phy(struct sfp *sfp, bool is_c45)
|
1416 | 1425 | int err;
|
1417 | 1426 |
|
1418 | 1427 | 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); |
1423 | 1430 | if (IS_ERR(phy)) {
|
1424 | 1431 | dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy));
|
1425 | 1432 | return PTR_ERR(phy);
|
@@ -1867,6 +1874,7 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
|
1867 | 1874 | static void sfp_sm_main(struct sfp *sfp, unsigned int event)
|
1868 | 1875 | {
|
1869 | 1876 | unsigned long timeout;
|
| 1877 | + int ret; |
1870 | 1878 |
|
1871 | 1879 | /* Some events are global */
|
1872 | 1880 | if (sfp->sm_state != SFP_S_DOWN &&
|
@@ -1940,22 +1948,39 @@ static void sfp_sm_main(struct sfp *sfp, unsigned int event)
|
1940 | 1948 | sfp_sm_fault(sfp, SFP_S_INIT_TX_FAULT,
|
1941 | 1949 | sfp->sm_fault_retries == N_FAULT_INIT);
|
1942 | 1950 | } 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); |
1952 | 1968 | break;
|
| 1969 | + } else { |
| 1970 | + dev_info(sfp->dev, "no PHY detected\n"); |
1953 | 1971 | }
|
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; |
1958 | 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; |
1959 | 1984 | break;
|
1960 | 1985 |
|
1961 | 1986 | case SFP_S_INIT_TX_FAULT:
|
|
0 commit comments