2f90b004387a87b36f9753ca8527f5dec32485d5
[openwrt/staging/stintel.git] /
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
5 functions
6
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
10 printed.
11
12 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
13 ---
14 drivers/net/phy/sfp.c | 74 +++++++++++++++++++++++++------------------
15 1 file changed, 43 insertions(+), 31 deletions(-)
16
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");
21 }
22
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)
26 {
27 - mutex_lock(&sfp->sm_mutex);
28 + switch (sfp->sm_dev_state) {
29 + default:
30 + if (event == SFP_E_DEV_UP)
31 + sfp->sm_dev_state = SFP_DEV_UP;
32 + break;
33
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));
39 + case SFP_DEV_UP:
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.
44 + */
45 + if (!sfp->mod_phy)
46 + sfp_module_tx_disable(sfp);
47 + sfp->sm_dev_state = SFP_DEV_DOWN;
48 + }
49 + break;
50 + }
51 +}
52
53 - /* This state machine tracks the insert/remove state of
54 - * the module, and handles probing the on-board EEPROM.
55 - */
56 +/* This state machine tracks the insert/remove state of
57 + * the module, and handles probing the on-board EEPROM.
58 + */
59 +static void sfp_sm_module(struct sfp *sfp, unsigned int event)
60 +{
61 switch (sfp->sm_mod_state) {
62 default:
63 if (event == SFP_E_INSERT && sfp->attached) {
64 @@ -1531,27 +1546,10 @@ static void sfp_sm_event(struct sfp *sfp
65 }
66 break;
67 }
68 +}
69
70 - /* This state machine tracks the netdev up/down state */
71 - switch (sfp->sm_dev_state) {
72 - default:
73 - if (event == SFP_E_DEV_UP)
74 - sfp->sm_dev_state = SFP_DEV_UP;
75 - break;
76 -
77 - case 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.
82 - */
83 - if (!sfp->mod_phy)
84 - sfp_module_tx_disable(sfp);
85 - sfp->sm_dev_state = SFP_DEV_DOWN;
86 - }
87 - break;
88 - }
89 -
90 +static void sfp_sm_main(struct sfp *sfp, unsigned int event)
91 +{
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
96 if (sfp->mod_phy)
97 sfp_sm_phy_detach(sfp);
98 sfp_sm_next(sfp, SFP_S_DOWN, 0);
99 - mutex_unlock(&sfp->sm_mutex);
100 return;
101 }
102
103 @@ -1617,6 +1614,21 @@ static void sfp_sm_event(struct sfp *sfp
104 case SFP_S_TX_DISABLE:
105 break;
106 }
107 +}
108 +
109 +static void sfp_sm_event(struct sfp *sfp, unsigned int event)
110 +{
111 + mutex_lock(&sfp->sm_mutex);
112 +
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));
118 +
119 + sfp_sm_module(sfp, event);
120 + sfp_sm_device(sfp, event);
121 + sfp_sm_main(sfp, event);
122
123 dev_dbg(sfp->dev, "SM: exit %s:%s:%s\n",
124 mod_state_to_str(sfp->sm_mod_state),