542aeaea772763d599bd81b7829a4d8578b8e21c
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 723-v5.5-net-sfp-handle-module-remove-outside-state-machine.patch
1 From d2591ea5520e2ee8fa557f96bb64c23cafac4b20 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 15 Oct 2019 10:33:13 +0100
4 Subject: [PATCH 621/660] net: sfp: handle module remove outside state machine
5
6 Removing a module resets the module state machine back to its initial
7 state. Rather than explicitly handling this in every state, handle it
8 early on outside of the state machine.
9
10 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
11 ---
12 drivers/net/phy/sfp.c | 16 +++++++++-------
13 1 file changed, 9 insertions(+), 7 deletions(-)
14
15 --- a/drivers/net/phy/sfp.c
16 +++ b/drivers/net/phy/sfp.c
17 @@ -1500,6 +1500,14 @@ static void sfp_sm_device(struct sfp *sf
18 */
19 static void sfp_sm_module(struct sfp *sfp, unsigned int event)
20 {
21 + /* Handle remove event globally, it resets this state machine */
22 + if (event == SFP_E_REMOVE) {
23 + if (sfp->sm_mod_state > SFP_MOD_PROBE)
24 + sfp_sm_mod_remove(sfp);
25 + sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
26 + return;
27 + }
28 +
29 switch (sfp->sm_mod_state) {
30 default:
31 if (event == SFP_E_INSERT && sfp->attached) {
32 @@ -1509,9 +1517,7 @@ static void sfp_sm_module(struct sfp *sf
33 break;
34
35 case SFP_MOD_PROBE:
36 - if (event == SFP_E_REMOVE) {
37 - sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
38 - } else if (event == SFP_E_TIMEOUT) {
39 + if (event == SFP_E_TIMEOUT) {
40 int val = sfp_sm_mod_probe(sfp);
41
42 if (val == 0)
43 @@ -1533,10 +1539,6 @@ static void sfp_sm_module(struct sfp *sf
44 /* fallthrough */
45 case SFP_MOD_PRESENT:
46 case SFP_MOD_ERROR:
47 - if (event == SFP_E_REMOVE) {
48 - sfp_sm_mod_remove(sfp);
49 - sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
50 - }
51 break;
52 }
53 }