From: Richard Cochran <[email protected]>

The state machines in 1588 do not specify an event that causes a transition
out of the initializing state.  This was left as a local issue.  For this
transition, the current code assigns the next state outside of the FSM.  But
doing so prevents an alternative FSM to handle this transition differently.

By introducing a new event, this patch places this transition where it
belongs, namely under the control of the FSM code,

Signed-off-by: Richard Cochran <[email protected]>
---
 fsm.c  | 22 ++++++++++++++++++++--
 fsm.h  |  1 +
 port.c | 15 +++++++--------
 util.c |  1 +
 4 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/fsm.c b/fsm.c
index d1423e7..ce6efad 100644
--- a/fsm.c
+++ b/fsm.c
@@ -27,7 +27,16 @@ enum port_state ptp_fsm(enum port_state state, enum 
fsm_event event, int mdiff)
 
        switch (state) {
        case PS_INITIALIZING:
-               next = PS_LISTENING;
+               switch (event) {
+               case EV_FAULT_DETECTED:
+                       next = PS_FAULTY;
+                       break;
+               case EV_INIT_COMPLETE:
+                       next = PS_LISTENING;
+                       break;
+               default:
+                       break;
+               }
                break;
 
        case PS_FAULTY:
@@ -220,7 +229,16 @@ enum port_state ptp_slave_fsm(enum port_state state, enum 
fsm_event event,
 
        switch (state) {
        case PS_INITIALIZING:
-               next = PS_LISTENING;
+               switch (event) {
+               case EV_FAULT_DETECTED:
+                       next = PS_FAULTY;
+                       break;
+               case EV_INIT_COMPLETE:
+                       next = PS_LISTENING;
+                       break;
+               default:
+                       break;
+               }
                break;
 
        case PS_FAULTY:
diff --git a/fsm.h b/fsm.h
index 5d4ae91..0616daa 100644
--- a/fsm.h
+++ b/fsm.h
@@ -48,6 +48,7 @@ enum fsm_event {
        EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
        EV_SYNCHRONIZATION_FAULT,
        EV_MASTER_CLOCK_SELECTED,
+       EV_INIT_COMPLETE,
        EV_RS_MASTER,
        EV_RS_GRAND_MASTER,
        EV_RS_SLAVE,
diff --git a/port.c b/port.c
index ebe7342..5f1646b 100644
--- a/port.c
+++ b/port.c
@@ -2120,6 +2120,7 @@ static void port_p2p_transition(struct port *p, enum 
port_state next)
                break;
        case PS_LISTENING:
                port_set_announce_tmo(p);
+               port_set_delay_tmo(p);
                break;
        case PS_PRE_MASTER:
                port_set_qualification_tmo(p);
@@ -2158,7 +2159,7 @@ int port_dispatch(struct port *p, enum fsm_event event, 
int mdiff)
                fault_interval(p, last_fault_type(p), &i);
                if (clear_fault_asap(&i)) {
                        pr_notice("port %hu: clearing fault immediately", 
portnum(p));
-                       next = PS_INITIALIZING;
+                       next = p->state_machine(next, EV_FAULT_CLEARED, 0);
                }
        }
        if (PS_INITIALIZING == next) {
@@ -2170,14 +2171,12 @@ int port_dispatch(struct port *p, enum fsm_event event, 
int mdiff)
                if (port_is_enabled(p)) {
                        port_disable(p);
                }
-               next = port_initialize(p) ? PS_FAULTY : PS_LISTENING;
-               port_show_transition(p, next, event);
-               p->state = next;
-               if (next == PS_LISTENING && p->delayMechanism == DM_P2P) {
-                       port_set_delay_tmo(p);
+               if (port_initialize(p)) {
+                       event = EV_FAULT_DETECTED;
+               } else {
+                       event = EV_INIT_COMPLETE;
                }
-               port_notify_event(p, NOTIFY_PORT_STATE);
-               return 1;
+               next = p->state_machine(next, event, 0);
        }
 
        if (next == p->state)
diff --git a/util.c b/util.c
index 594b49f..2b880ff 100644
--- a/util.c
+++ b/util.c
@@ -61,6 +61,7 @@ const char *ev_str[] = {
        "ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES",
        "SYNCHRONIZATION_FAULT",
        "MASTER_CLOCK_SELECTED",
+       "INIT_COMPLETE",
        "RS_MASTER",
        "RS_GRAND_MASTER",
        "RS_SLAVE",
-- 
2.1.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to