03415fb6e7780937812e56bd0efd6b91f9f9cf34
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 731-v5.5-net-sfp-ensure-TX_FAULT-has-deasserted-before-probin.patch
1 From 38b62a12231be4b86fc5ca5477579d29831c02a5 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Fri, 18 Oct 2019 10:31:07 +0100
4 Subject: [PATCH 629/660] net: sfp: ensure TX_FAULT has deasserted before
5 probing the PHY
6
7 TX_FAULT should be deasserted to indicate that the module has completed
8 its initialisation. This may include the on-board PHY, so wait until
9 the module has deasserted TX_FAULT before probing the PHY.
10
11 This means that we need an extra state to handle a TX_FAULT that
12 remains set for longer than t_init, since using the existing handling
13 state would bypass the PHY probe.
14
15 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
16 ---
17 drivers/net/phy/sfp.c | 31 +++++++++++++++++++++++++------
18 1 file changed, 25 insertions(+), 6 deletions(-)
19
20 --- a/drivers/net/phy/sfp.c
21 +++ b/drivers/net/phy/sfp.c
22 @@ -54,6 +54,7 @@ enum {
23 SFP_S_DOWN = 0,
24 SFP_S_WAIT,
25 SFP_S_INIT,
26 + SFP_S_INIT_TX_FAULT,
27 SFP_S_WAIT_LOS,
28 SFP_S_LINK_UP,
29 SFP_S_TX_FAULT,
30 @@ -111,6 +112,7 @@ static const char * const sm_state_strin
31 [SFP_S_DOWN] = "down",
32 [SFP_S_WAIT] = "wait",
33 [SFP_S_INIT] = "init",
34 + [SFP_S_INIT_TX_FAULT] = "init_tx_fault",
35 [SFP_S_WAIT_LOS] = "wait_los",
36 [SFP_S_LINK_UP] = "link_up",
37 [SFP_S_TX_FAULT] = "tx_fault",
38 @@ -1595,8 +1597,6 @@ static void sfp_sm_main(struct sfp *sfp,
39 if (event != SFP_E_TIMEOUT)
40 break;
41
42 - sfp_sm_probe_for_phy(sfp);
43 -
44 if (sfp->state & SFP_F_TX_FAULT) {
45 /* Wait t_init before indicating that the link is up,
46 * provided the current state indicates no TX_FAULT. If
47 @@ -1618,10 +1618,29 @@ static void sfp_sm_main(struct sfp *sfp,
48 break;
49
50 case SFP_S_INIT:
51 - if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT)
52 - sfp_sm_fault(sfp, SFP_S_TX_FAULT, true);
53 - else if (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR)
54 - init_done: sfp_sm_link_check_los(sfp);
55 + if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) {
56 + /* TX_FAULT is still asserted after t_init, so assume
57 + * there is a fault.
58 + */
59 + sfp_sm_fault(sfp, SFP_S_INIT_TX_FAULT,
60 + sfp->sm_retries == 5);
61 + } else if (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR) {
62 + init_done: /* TX_FAULT deasserted or we timed out with TX_FAULT
63 + * clear. Probe for the PHY and check the LOS state.
64 + */
65 + sfp_sm_probe_for_phy(sfp);
66 + sfp_sm_link_check_los(sfp);
67 +
68 + /* Reset the fault retry count */
69 + sfp->sm_retries = 5;
70 + }
71 + break;
72 +
73 + case SFP_S_INIT_TX_FAULT:
74 + if (event == SFP_E_TIMEOUT) {
75 + sfp_module_tx_fault_reset(sfp);
76 + sfp_sm_next(sfp, SFP_S_INIT, T_INIT_JIFFIES);
77 + }
78 break;
79
80 case SFP_S_WAIT_LOS: