1 From b9d6ed5cdb67533feda7f221eb06f2f9f1ff5047 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Fri, 11 Oct 2019 19:33:58 +0100
4 Subject: [PATCH 618/660] net: sfp: move sfp sub-state machines into separate
7 Move the SFP sub-state machines out of the main state machine function,
8 in preparation for it doing a bit more with the device state. By doing
9 so, we ensure that our debug after the main state machine is always
12 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
14 drivers/net/phy/sfp.c | 74 +++++++++++++++++++++++++------------------
15 1 file changed, 43 insertions(+), 31 deletions(-)
17 --- a/drivers/net/phy/sfp.c
18 +++ b/drivers/net/phy/sfp.c
19 @@ -1479,19 +1479,34 @@ static void sfp_sm_mod_remove(struct sfp
20 dev_info(sfp->dev, "module removed\n");
23 -static void sfp_sm_event(struct sfp *sfp, unsigned int event)
24 +/* This state machine tracks the netdev up/down state */
25 +static void sfp_sm_device(struct sfp *sfp, unsigned int event)
27 - mutex_lock(&sfp->sm_mutex);
28 + switch (sfp->sm_dev_state) {
30 + if (event == SFP_E_DEV_UP)
31 + sfp->sm_dev_state = SFP_DEV_UP;
34 - dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n",
35 - mod_state_to_str(sfp->sm_mod_state),
36 - dev_state_to_str(sfp->sm_dev_state),
37 - sm_state_to_str(sfp->sm_state),
38 - event_to_str(event));
40 + if (event == SFP_E_DEV_DOWN) {
41 + /* If the module has a PHY, avoid raising TX disable
42 + * as this resets the PHY. Otherwise, raise it to
43 + * turn the laser off.
46 + sfp_module_tx_disable(sfp);
47 + sfp->sm_dev_state = SFP_DEV_DOWN;
53 - /* This state machine tracks the insert/remove state of
54 - * the module, and handles probing the on-board EEPROM.
56 +/* This state machine tracks the insert/remove state of
57 + * the module, and handles probing the on-board EEPROM.
59 +static void sfp_sm_module(struct sfp *sfp, unsigned int event)
61 switch (sfp->sm_mod_state) {
63 if (event == SFP_E_INSERT && sfp->attached) {
64 @@ -1531,27 +1546,10 @@ static void sfp_sm_event(struct sfp *sfp
70 - /* This state machine tracks the netdev up/down state */
71 - switch (sfp->sm_dev_state) {
73 - if (event == SFP_E_DEV_UP)
74 - sfp->sm_dev_state = SFP_DEV_UP;
78 - if (event == SFP_E_DEV_DOWN) {
79 - /* If the module has a PHY, avoid raising TX disable
80 - * as this resets the PHY. Otherwise, raise it to
81 - * turn the laser off.
84 - sfp_module_tx_disable(sfp);
85 - sfp->sm_dev_state = SFP_DEV_DOWN;
90 +static void sfp_sm_main(struct sfp *sfp, unsigned int event)
92 /* Some events are global */
93 if (sfp->sm_state != SFP_S_DOWN &&
94 (sfp->sm_mod_state != SFP_MOD_PRESENT ||
95 @@ -1562,7 +1560,6 @@ static void sfp_sm_event(struct sfp *sfp
97 sfp_sm_phy_detach(sfp);
98 sfp_sm_next(sfp, SFP_S_DOWN, 0);
99 - mutex_unlock(&sfp->sm_mutex);
103 @@ -1617,6 +1614,21 @@ static void sfp_sm_event(struct sfp *sfp
104 case SFP_S_TX_DISABLE:
109 +static void sfp_sm_event(struct sfp *sfp, unsigned int event)
111 + mutex_lock(&sfp->sm_mutex);
113 + dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n",
114 + mod_state_to_str(sfp->sm_mod_state),
115 + dev_state_to_str(sfp->sm_dev_state),
116 + sm_state_to_str(sfp->sm_state),
117 + event_to_str(event));
119 + sfp_sm_module(sfp, event);
120 + sfp_sm_device(sfp, event);
121 + sfp_sm_main(sfp, event);
123 dev_dbg(sfp->dev, "SM: exit %s:%s:%s\n",
124 mod_state_to_str(sfp->sm_mod_state),