summaryrefslogtreecommitdiffstats
path: root/drivers/net/phy/sfp.c
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@armlinux.org.uk>2019-11-10 14:06:28 +0000
committerDavid S. Miller <davem@davemloft.net>2019-11-11 16:17:00 -0800
commitd2e816c0293fc263b3f168c14992a5f1a50d7593 (patch)
tree9a45992e90b536fcd201ebfbbc7e8cf0d9ffd093 /drivers/net/phy/sfp.c
parent0936ebc42f5909da7cf4c58468d4107f7029fe29 (diff)
downloadlinux-d2e816c0293fc263b3f168c14992a5f1a50d7593.tar.bz2
net: sfp: handle module remove outside state machine
Removing a module resets the module state machine back to its initial state. Rather than explicitly handling this in every state, handle it early on outside of the state machine. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/sfp.c')
-rw-r--r--drivers/net/phy/sfp.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 7bcb9a8c0bcd..2f3073164333 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -1565,6 +1565,14 @@ static void sfp_sm_device(struct sfp *sfp, unsigned int event)
*/
static void sfp_sm_module(struct sfp *sfp, unsigned int event)
{
+ /* Handle remove event globally, it resets this state machine */
+ if (event == SFP_E_REMOVE) {
+ if (sfp->sm_mod_state > SFP_MOD_PROBE)
+ sfp_sm_mod_remove(sfp);
+ sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
+ return;
+ }
+
switch (sfp->sm_mod_state) {
default:
if (event == SFP_E_INSERT && sfp->attached) {
@@ -1574,9 +1582,7 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
break;
case SFP_MOD_PROBE:
- if (event == SFP_E_REMOVE) {
- sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
- } else if (event == SFP_E_TIMEOUT) {
+ if (event == SFP_E_TIMEOUT) {
int val = sfp_sm_mod_probe(sfp);
if (val == 0)
@@ -1598,10 +1604,6 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
/* fallthrough */
case SFP_MOD_PRESENT:
case SFP_MOD_ERROR:
- if (event == SFP_E_REMOVE) {
- sfp_sm_mod_remove(sfp);
- sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0);
- }
break;
}
}