Commit 84fc8c10 authored by baujc's avatar baujc

Improvment of the LinkState management

It has been improvement to make it works with WR extension but the final
mechanism has to be improved to make it more simple.
parent f0227345
......@@ -277,25 +277,20 @@ int pp_state_machine(struct pp_instance *ppi, void *buf, int len)
return pp_leave_current_state(ppi);
if (len) {
if ( ppi->link_state == PP_LSTATE_PROTOCOL_DETECTION ) {
if ( ppi->ptp_msg_received==FALSE ) {
/* First frame received since instance initialization */
int tmo;
ppi->ptp_msg_received=TRUE;
if ( ppi->ext_hooks->get_tmo_lstate_detection!=NULL)
tmo=(*ppi->ext_hooks->get_tmo_lstate_detection)(ppi);
else
tmo= is_externalPortConfigurationEnabled(DSDEF(ppi)) ?
6000 /* JCB: Default value. Is it correct ? */
: pp_timeout_get(ppi,PP_TO_ANN_RECEIPT);
pp_timeout_set(ppi,PP_TO_PROT_STATE, tmo);
}
}
if ( !ppi->ext_enabled && ppi->link_state==PP_LSTATE_PROTOCOL_DETECTION) {
/* Ptp protocol only */
ppi->link_state= PP_LSTATE_IN_PROGRESS;
}
if ( ppi->ext_enabled && !ppi->ptp_msg_received ) {
/* First frame received since instance initialization */
int tmo;
ppi->ptp_msg_received=TRUE;
if (is_ext_hook_available(ppi,get_tmo_lstate_detection) )
tmo=(*ppi->ext_hooks->get_tmo_lstate_detection)(ppi);
else
tmo= is_externalPortConfigurationEnabled(DSDEF(ppi)) ?
6000 /* JCB: Default value. Is it correct ? */
: pp_timeout_get(ppi,PP_TO_ANN_RECEIPT);
pp_timeout_set(ppi,PP_TO_PROT_STATE, tmo);
lstate_set_link_pdetection(ppi);
}
} else
ppi->received_ptp_header.messageType = PPM_NO_MESSAGE;
......@@ -309,17 +304,21 @@ int pp_state_machine(struct pp_instance *ppi, void *buf, int len)
return pp_leave_current_state(ppi);
/* Check protocol state */
if ( ppi->link_state==PP_LSTATE_PROTOCOL_DETECTION ) {
if ( ppi->ptp_msg_received && pp_timeout(ppi, PP_TO_PROT_STATE) ) {
if ( ppi->ptp_support && ppi->ext_enabled ) {
ppi->ext_enabled=FALSE;
ppi->ptp_msg_received=FALSE;
} else
ppi->link_state=PP_LSTATE_FAILURE;
if ( ppi->protocol_extension == PPSI_EXT_NONE ) {
lstate_set_link_none(ppi);
} else {
if ( ppi->ext_enabled ) {
if ( ppi->link_state==PP_LSTATE_PROTOCOL_ERROR ||
( ppi->link_state!=PP_LSTATE_LINKED && ppi->ptp_msg_received && pp_timeout(ppi, PP_TO_PROT_STATE)) ) {
if ( ppi->ptp_support )
lstate_disable_extension(ppi);
else
lstate_set_link_failure(ppi);
}
} else {
lstate_set_link_failure(ppi);
}
}
if (ppi->link_state==PP_LSTATE_FAILURE ) {
}
/* run bmc independent of state, and since not message driven do this
* here 9.2.6.8 */
......@@ -336,14 +335,22 @@ int pp_state_machine(struct pp_instance *ppi, void *buf, int len)
pp_diag_fsm(ppi, ip->name, STATE_LOOP, 0);
/* Run the extension state machine. The extension can provide its own time-out */
if ( ppi->ext_hooks->run_ext_state_machine) {
int delay = ppi->ext_hooks->run_ext_state_machine(ppi);
if ( ppi->link_state==PP_LSTATE_FAILURE && ppi->ptp_support && ppi->ext_enabled ) {
ppi->ext_enabled=FALSE;
ppi->link_state=PP_LSTATE_PROTOCOL_DETECTION;
if ( is_ext_hook_available(ppi,run_ext_state_machine) ) {
int delay = ppi->ext_hooks->run_ext_state_machine(ppi,buf,len);
if ( ppi->ext_enabled && ppi->link_state==PP_LSTATE_PROTOCOL_ERROR) {
if (ppi->ptp_support ) {
lstate_disable_extension(ppi);
}
else
lstate_set_link_failure(ppi);
}
/* if new state mark it, and enter it now (0 ms) */
if (ppi->state != ppi->next_state)
return pp_leave_current_state(ppi);
ppi->next_delay= (delay < ppi->next_delay) ? delay : ppi->next_delay;
if (delay < ppi->next_delay)
ppi->next_delay=delay;
}
return ppi->next_delay;
......
......@@ -190,10 +190,12 @@ struct pp_instance_cfg {
* It is used to decide which instance must be active on a given port.
*/
typedef enum {
PP_LSTATE_NONE, /* Link state not applied : No extension */
PP_LSTATE_PROTOCOL_DETECTION, /* Checking if the peer instance is using the same protocol */
PP_LSTATE_IN_PROGRESS, /* Right protocol detected. Try to establish the link with peer instance */
PP_LSTATE_LINKED, /* Link with peer well established */
PP_LSTATE_FAILURE /* Impossible to connect correctly to a peer instance */
PP_LSTATE_PROTOCOL_ERROR, /* The extension has detected a problem. */
PP_LSTATE_FAILURE, /* Impossible to connect correctly to a peer instance - extension disabled */
} pp_link_state;
/*
......
......@@ -423,6 +423,45 @@ extern void ppsi_drop_init(struct pp_globals *ppg, unsigned long seed);
extern int ppsi_drop_rx(void);
extern int ppsi_drop_tx(void);
/* link state functions to manage the extension (Enable/disable) */
static inline void lstate_enable_extension(struct pp_instance * ppi) {
pp_timeout_reset(ppi,PP_TO_PROT_STATE);
ppi->link_state=PP_LSTATE_PROTOCOL_DETECTION;
ppi->ptp_msg_received=FALSE;
ppi->ext_enabled=TRUE;
}
/* link state functions to manage the extension (Enable/disable) */
static inline void lstate_disable_extension(struct pp_instance * ppi) {
ppi->link_state=PP_LSTATE_FAILURE;
ppi->ptp_msg_received=FALSE;
ppi->ext_enabled=FALSE;
}
static inline void lstate_set_link_established(struct pp_instance * ppi) {
ppi->link_state=PP_LSTATE_LINKED;
}
static inline void lstate_set_link_failure(struct pp_instance * ppi) {
ppi->link_state=PP_LSTATE_FAILURE;
}
static inline void lstate_set_link_in_progress(struct pp_instance * ppi) {
ppi->link_state=PP_LSTATE_IN_PROGRESS;
}
static inline void lstate_set_link_none(struct pp_instance * ppi) {
ppi->link_state=PP_LSTATE_NONE;
}
static inline void lstate_set_link_perror(struct pp_instance * ppi) {
ppi->link_state=PP_LSTATE_PROTOCOL_ERROR;
}
static inline void lstate_set_link_pdetection(struct pp_instance * ppi) {
ppi->link_state=PP_LSTATE_PROTOCOL_DETECTION;
pp_timeout_reset(ppi,PP_TO_PROT_STATE);
}
#include <ppsi/faults.h>
#include <ppsi/timeout_prot.h>
#include <ppsi/conf.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment