fsm: Make the transition out of INITIALIZING part of the FSM code.

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 <richardcochran@gmail.com>
master
Richard Cochran 2016-10-27 15:20:36 +02:00
parent 01ee947457
commit b738afb604
4 changed files with 29 additions and 10 deletions

22
fsm.c
View File

@ -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:

1
fsm.h
View File

@ -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,

15
port.c
View File

@ -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)

1
util.c
View File

@ -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",