Commit 28093d4b authored by Alessandro Rubini's avatar Alessandro Rubini

state-master: move two more timeout stanzas to fsm-lib

This, btw, made me note that we have a problem with pdelay and
multiple vlans.

Multiple vlan is a hack anyways....
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c90cfd41
...@@ -58,6 +58,8 @@ struct pp_vlanhdr { ...@@ -58,6 +58,8 @@ struct pp_vlanhdr {
}; };
/* Helpers for the fsm (fsm-lib.c) */ /* Helpers for the fsm (fsm-lib.c) */
extern int pp_lib_may_issue_sync(struct pp_instance *ppi);
extern int pp_lib_may_issue_announce(struct pp_instance *ppi);
extern int pp_lib_may_issue_request(struct pp_instance *ppi); extern int pp_lib_may_issue_request(struct pp_instance *ppi);
/* We use data sets a lot, so have these helpers */ /* We use data sets a lot, so have these helpers */
......
...@@ -8,17 +8,103 @@ ...@@ -8,17 +8,103 @@
*/ */
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
int pp_lib_may_issue_request(struct pp_instance *ppi)
/* Local functions that build to nothing when Kconfig selects 0/1 vlans */
static int pp_vlan_issue_announce(struct pp_instance *ppi)
{
int i, vlan = 0;
if (CONFIG_VLAN_ARRAY_SIZE && ppi->nvlans == 1)
vlan = ppi->vlans[0];
if (CONFIG_VLAN_ARRAY_SIZE <= 1 || ppi->nvlans <= 1) {
ppi->peer_vid = vlan;
return msg_issue_announce(ppi);
}
/*
* If Kconfig selected 0/1 vlans, this code is not built.
* If we have several vlans, we replace peer_vid and proceed;
*/
for (i = 0; i < ppi->nvlans; i++) {
ppi->peer_vid = ppi->vlans[i];
msg_issue_announce(ppi);
/* ignore errors: each vlan is separate */
}
return 0;
}
static int pp_vlan_issue_sync_followup(struct pp_instance *ppi)
{
int i, vlan = 0;
if (CONFIG_VLAN_ARRAY_SIZE && ppi->nvlans == 1)
vlan = ppi->vlans[0];
if (CONFIG_VLAN_ARRAY_SIZE <= 1 || ppi->nvlans <= 1) {
ppi->peer_vid = vlan;
return msg_issue_sync_followup(ppi);
}
/*
* If Kconfig selected 0/1 vlans, this code is not built.
* If we have several vlans, we replace peer_vid and proceed;
*/
for (i = 0; i < ppi->nvlans; i++) {
ppi->peer_vid = ppi->vlans[i];
msg_issue_sync_followup(ppi);
/* ignore errors: each vlan is separate */
}
return 0;
}
/*
* The following set of functions help the states in the state machine.
* Ideally, we should manage to get to a completely table-driven fsm
* implementation based on these helpers
*/
int pp_lib_may_issue_sync(struct pp_instance *ppi)
{
int e;
if (!pp_timeout(ppi, PP_TO_SYNC_SEND))
return 0;
pp_timeout_set(ppi, PP_TO_SYNC_SEND);
e = pp_vlan_issue_sync_followup(ppi);
if (e)
pp_diag(ppi, frames, 1, "could not send sync\n");
return e;
}
int pp_lib_may_issue_announce(struct pp_instance *ppi)
{ {
int e; int e;
if (!pp_timeout(ppi, PP_TO_ANN_SEND))
return 0;
pp_timeout_set(ppi, PP_TO_ANN_SEND);
e = pp_vlan_issue_announce(ppi);
if (e)
pp_diag(ppi, frames, 1, "could not send announce\n");
return e;
}
int pp_lib_may_issue_request(struct pp_instance *ppi)
{
int e = 0;
if (!pp_timeout(ppi, PP_TO_REQUEST)) if (!pp_timeout(ppi, PP_TO_REQUEST))
return 0; return 0;
pp_timeout_set(ppi, PP_TO_REQUEST); pp_timeout_set(ppi, PP_TO_REQUEST);
e = msg_issue_request(ppi); e = msg_issue_request(ppi); /* FIXME: what about multiple vlans? */
if (e) if (e) {
pp_diag(ppi, frames, 1, "could not send request\n");
return e; return e;
}
ppi->t3 = ppi->last_snt_time; ppi->t3 = ppi->last_snt_time;
return 0; return 0;
} }
...@@ -9,57 +9,6 @@ ...@@ -9,57 +9,6 @@
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "common-fun.h" #include "common-fun.h"
/* Local functions that build to nothing when Kconfig selects 0/1 vlans */
static int pp_master_issue_announce(struct pp_instance *ppi)
{
int i, vlan = 0;
if (CONFIG_VLAN_ARRAY_SIZE && ppi->nvlans == 1)
vlan = ppi->vlans[0];
if (CONFIG_VLAN_ARRAY_SIZE <= 1 || ppi->nvlans <= 1) {
ppi->peer_vid = vlan;
return msg_issue_announce(ppi);
}
/*
* If Kconfig selected 0/1 vlans, this code is not built.
* If we have several vlans, we replace peer_vid and proceed;
*/
for (i = 0; i < ppi->nvlans; i++) {
ppi->peer_vid = ppi->vlans[i];
msg_issue_announce(ppi);
/* ignore errors: each vlan is separate */
}
return 0;
}
static int pp_master_issue_sync_followup(struct pp_instance *ppi)
{
int i, vlan = 0;
if (CONFIG_VLAN_ARRAY_SIZE && ppi->nvlans == 1)
vlan = ppi->vlans[0];
if (CONFIG_VLAN_ARRAY_SIZE <= 1 || ppi->nvlans <= 1) {
ppi->peer_vid = vlan;
return msg_issue_sync_followup(ppi);
}
/*
* If Kconfig selected 0/1 vlans, this code is not built.
* If we have several vlans, we replace peer_vid and proceed;
*/
for (i = 0; i < ppi->nvlans; i++) {
ppi->peer_vid = ppi->vlans[i];
msg_issue_sync_followup(ppi);
/* ignore errors: each vlan is separate */
}
return 0;
}
/* The real state function, relying on the two above for sending */
int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen) int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
int msgtype, d1, d2; int msgtype, d1, d2;
...@@ -67,26 +16,13 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -67,26 +16,13 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
MsgHeader *hdr = &ppi->received_ptp_header; MsgHeader *hdr = &ppi->received_ptp_header;
MsgPDelayRespFollowUp respFllw; MsgPDelayRespFollowUp respFllw;
if (pp_timeout_z(ppi, PP_TO_SYNC_SEND)) { /* ignore errors; we are not getting FAULTY if not transmitting */
/* Restart the timeout for next time */ pp_lib_may_issue_sync(ppi);
pp_timeout_set(ppi, PP_TO_SYNC_SEND); pp_lib_may_issue_announce(ppi);
if ((e = pp_master_issue_sync_followup(ppi) < 0))
goto out;
}
if (pp_timeout_z(ppi, PP_TO_ANN_SEND)) {
if ((e = pp_master_issue_announce(ppi) < 0))
goto out;
/* Restart the timeout for next time */
pp_timeout_set(ppi, PP_TO_ANN_SEND);
}
/* when the clock is using peer-delay, the muster mast send it too */ /* when the clock is using peer-delay, the muster mast send it too */
if (ppi->glbs->delay_mech == PP_P2P_MECH) if (ppi->glbs->delay_mech == PP_P2P_MECH)
e = pp_lib_may_issue_request(ppi); pp_lib_may_issue_request(ppi);
if (plen == 0) if (plen == 0)
goto out; goto out;
......
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