blob: 62cdb8a6ce671a5739f2231e425447e31849ba72 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From d2591ea5520e2ee8fa557f96bb64c23cafac4b20 Mon Sep 17 00:00:00 2001
2From: Russell King <rmk+kernel@armlinux.org.uk>
3Date: Tue, 15 Oct 2019 10:33:13 +0100
4Subject: [PATCH 621/660] net: sfp: handle module remove outside state machine
5
6Removing a module resets the module state machine back to its initial
7state. Rather than explicitly handling this in every state, handle it
8early on outside of the state machine.
9
10Signed-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@@ -1565,6 +1565,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@@ -1574,9 +1582,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@@ -1598,10 +1604,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 }