Skip to content

Commit

Permalink
fsm: Make the transition out of INITIALIZING part of the FSM code.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
richardcochran committed Jan 8, 2017
1 parent 01ee947 commit b738afb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
22 changes: 20 additions & 2 deletions fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 7 additions & 8 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b738afb

Please sign in to comment.