Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: sfp: rework the RollBall PHY waiting code

RollBall SFP modules allow the access to PHY registers only after a
certain time has passed. Until then, the registers read 0xffff.

Currently we have quirks for modules where we need to wait either 25
seconds or 4 seconds, but recently I got hands on another module where
the wait is even shorter.

Instead of hardcoding different wait times, lets rework the code:
- increase the PHY retry count to 25
- when RollBall module is detected, increase the PHY retry time from
50ms to 1s

Signed-off-by: Marek Behún <kabel@kernel.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Marek Behún and committed by
David S. Miller
2f3ce7a5 53775da0

+21 -20
+21 -20
drivers/net/phy/sfp.c
··· 191 191 * R_PHY_RETRY is the number of attempts. 192 192 */ 193 193 #define T_PHY_RETRY msecs_to_jiffies(50) 194 - #define R_PHY_RETRY 12 194 + #define R_PHY_RETRY 25 195 195 196 196 /* SFP module presence detection is poor: the three MOD DEF signals are 197 197 * the same length on the PCB, which means it's possible for MOD DEF 0 to ··· 274 274 struct sfp_eeprom_id id; 275 275 unsigned int module_power_mW; 276 276 unsigned int module_t_start_up; 277 - unsigned int module_t_wait; 277 + unsigned int phy_t_retry; 278 278 279 279 unsigned int rate_kbd; 280 280 unsigned int rs_threshold_kbd; ··· 372 372 sfp->id.base.extended_cc = SFF8024_ECC_10GBASE_T_SR; 373 373 } 374 374 375 - static void sfp_fixup_rollball_proto(struct sfp *sfp, unsigned int secs) 375 + static void sfp_fixup_rollball(struct sfp *sfp) 376 376 { 377 377 sfp->mdio_protocol = MDIO_I2C_ROLLBALL; 378 - sfp->module_t_wait = msecs_to_jiffies(secs * 1000); 378 + 379 + /* RollBall modules may disallow access to PHY registers for up to 25 380 + * seconds, and the reads return 0xffff before that. Increase the time 381 + * between PHY probe retries from 50ms to 1s so that we will wait for 382 + * the PHY for a sufficient amount of time. 383 + */ 384 + sfp->phy_t_retry = msecs_to_jiffies(1000); 379 385 } 380 386 381 387 static void sfp_fixup_fs_10gt(struct sfp *sfp) 382 388 { 383 389 sfp_fixup_10gbaset_30m(sfp); 384 - 385 - // These SFPs need 4 seconds before the PHY can be accessed 386 - sfp_fixup_rollball_proto(sfp, 4); 390 + sfp_fixup_rollball(sfp); 387 391 } 388 392 389 393 static void sfp_fixup_halny_gsfp(struct sfp *sfp) ··· 397 393 * module, e.g. a serial port. 398 394 */ 399 395 sfp->state_hw_mask &= ~(SFP_F_TX_FAULT | SFP_F_LOS); 400 - } 401 - 402 - static void sfp_fixup_rollball(struct sfp *sfp) 403 - { 404 - // Rollball SFPs need 25 seconds before the PHY can be accessed 405 - sfp_fixup_rollball_proto(sfp, 25); 406 396 } 407 397 408 398 static void sfp_fixup_rollball_cc(struct sfp *sfp) ··· 2329 2331 mask |= SFP_F_RS1; 2330 2332 2331 2333 sfp->module_t_start_up = T_START_UP; 2332 - sfp->module_t_wait = T_WAIT; 2334 + sfp->phy_t_retry = T_PHY_RETRY; 2333 2335 2334 2336 sfp->state_ignore_mask = 0; 2335 2337 ··· 2566 2568 2567 2569 /* We need to check the TX_FAULT state, which is not defined 2568 2570 * while TX_DISABLE is asserted. The earliest we want to do 2569 - * anything (such as probe for a PHY) is 50ms (or more on 2570 - * specific modules). 2571 + * anything (such as probe for a PHY) is 50ms. 2571 2572 */ 2572 - sfp_sm_next(sfp, SFP_S_WAIT, sfp->module_t_wait); 2573 + sfp_sm_next(sfp, SFP_S_WAIT, T_WAIT); 2573 2574 break; 2574 2575 2575 2576 case SFP_S_WAIT: ··· 2582 2585 * deasserting. 2583 2586 */ 2584 2587 timeout = sfp->module_t_start_up; 2585 - if (timeout > sfp->module_t_wait) 2586 - timeout -= sfp->module_t_wait; 2588 + if (timeout > T_WAIT) 2589 + timeout -= T_WAIT; 2587 2590 else 2588 2591 timeout = 1; 2589 2592 ··· 2626 2629 ret = sfp_sm_probe_for_phy(sfp); 2627 2630 if (ret == -ENODEV) { 2628 2631 if (--sfp->sm_phy_retries) { 2629 - sfp_sm_next(sfp, SFP_S_INIT_PHY, T_PHY_RETRY); 2632 + sfp_sm_next(sfp, SFP_S_INIT_PHY, 2633 + sfp->phy_t_retry); 2634 + dev_dbg(sfp->dev, 2635 + "no PHY detected, %u tries left\n", 2636 + sfp->sm_phy_retries); 2630 2637 break; 2631 2638 } else { 2632 2639 dev_info(sfp->dev, "no PHY detected\n");