Commit e1e3935d authored by Sven Meier's avatar Sven Meier Committed by Adam Wujek

bmc: handshake started on state base and announce change

The calibration handshake is now started on the slave state base
Announce messages from the same device are handled differnetly for a BC
parent 0b21e2c6
......@@ -170,6 +170,14 @@ int wr_execute_slave(struct pp_instance *ppi)
if (pp_timeout(ppi, PP_TO_FAULT))
wr_servo_reset(ppi); /* the caller handles ptp state machine */
if ((ppi->state == PPS_SLAVE) &&
(WR_DSPOR(ppi)->wrConfig & WR_S_ONLY) &&
(WR_DSPOR(ppi)->parentWrConfig & WR_M_ONLY) &&
(!WR_DSPOR(ppi)->wrModeOn || !WR_DSPOR(ppi)->parentWrModeOn)) {
/* We must start the handshake as a WR slave */
wr_handshake_init(ppi, PPS_SLAVE);
}
/* The doRestart thing is not used, it seems */
if (!WR_DSPOR(ppi)->doRestart)
return 0;
......@@ -181,13 +189,8 @@ int wr_execute_slave(struct pp_instance *ppi)
static int wr_handle_announce(struct pp_instance *ppi)
{
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if ((WR_DSPOR(ppi)->wrConfig & WR_S_ONLY) &&
(1 /* FIXME: Recommended State, see page 33*/) &&
(WR_DSPOR(ppi)->parentWrConfig & WR_M_ONLY) &&
(!WR_DSPOR(ppi)->wrModeOn || !WR_DSPOR(ppi)->parentWrModeOn)) {
/* We must start the handshake as a WR slave */
wr_handshake_init(ppi, PPS_SLAVE);
}
/* handshake is started in slave mode */
return 0;
}
......@@ -263,6 +266,10 @@ static void wr_unpack_announce(void *buf, MsgAnnounce *ann)
/* State decision algorithm 9.3.3 Fig 26 with extension for wr */
static int wr_bmc_state_decision(struct pp_instance *ppi, int next_state)
{
struct wr_dsport *wrp = WR_DSPOR(ppi);
struct pp_globals *ppg = GLBS(ppi);
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
/*
......@@ -279,6 +286,21 @@ static int wr_bmc_state_decision(struct pp_instance *ppi, int next_state)
(ppi->state == WRS_WR_LINK_ON))
return ppi->state;
/* if we are leaving the WR locked states reset the WR process */
if ((next_state != ppi->state) &&
(WR_DSPOR(ppi)->wrModeOn == TRUE) &&
((ppi->state == PPS_SLAVE) ||
(ppi->state == PPS_MASTER))) {
wrp->wrModeOn = FALSE;
wrp->parentWrConfig = NON_WR;
wrp->parentWrModeOn = FALSE;
wrp->calibrated = !WR_DEFAULT_PHY_CALIBRATION_REQUIRED;
if ((ppi->state == PPS_SLAVE) &&
(ppg->ebest_idx == ppi->port_idx))
wr_servo_reset(ppi);
}
/* else do the normal statemachine */
return next_state;
}
......
......@@ -35,7 +35,6 @@ int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
}
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(wrp->msgTmpWrMessageID));
......@@ -43,6 +42,7 @@ int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
ppi->next_state = WRS_CALIBRATION;
}
ppi->next_delay = wrp->wrStateTimeout;
return e;
......
......@@ -38,7 +38,6 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
}
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(wrp->msgTmpWrMessageID));
......
......@@ -16,7 +16,7 @@ int wr_s_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
int poll_ret;
if (ppi->is_new_state) {
wrp->wrStateRetry = WR_STATE_RETRY;
wrp->wrStateRetry = WR_STATE_RETRY;
enable = 1;
} else if (pp_timeout(ppi, PP_TO_EXT_0)) {
wrp->ops->locking_disable(ppi);
......
......@@ -151,7 +151,8 @@ void bmc_copy_d0(struct pp_instance *ppi, struct pp_frgn_master *m)
ann->grandmasterPriority2 = defds->priority2;
ann->stepsRemoved = 0;
hdr->sourcePortIdentity.clockIdentity = defds->clockIdentity;
//hdr->sourcePortIdentity.clockIdentity = defds->clockIdentity;
hdr->sourcePortIdentity = DSPOR(ppi)->portIdentity;
}
int bmc_idcmp(struct ClockIdentity *a, struct ClockIdentity *b)
......@@ -430,7 +431,6 @@ static int bmc_state_decision(struct pp_instance *ppi)
}
}
/* if there is a foreign master take it otherwise just go to master */
if (ppg->ebest_idx >= 0) {
ppi_best = INST(ppg, ppg->ebest_idx);
......@@ -452,6 +452,19 @@ static int bmc_state_decision(struct pp_instance *ppi)
if (cmpres > 0)
goto passive_p1;
} else {
/* when a boundary clock, check if from own port
* and set into passive mode according to 9.5.2.3
*/
if (DSDEF(ppi)->numberPorts > 1) {
/* message received from the own clock */
if (!bmc_idcmp(&erbest->hdr.sourcePortIdentity.clockIdentity, &DSDEF(ppi)->clockIdentity)) {
/* is this port worse than the other */
cmpres = bmc_pidcmp(&erbest->hdr.sourcePortIdentity, &DSPOR(ppi)->portIdentity);
if (cmpres > 0)
goto passive_p1;
}
}
/* dataset_cmp D0 with Ebest */
cmpres = bmc_dataset_cmp(ppi, &d0, ebest);
if (cmpres < 0)
......@@ -463,6 +476,7 @@ static int bmc_state_decision(struct pp_instance *ppi)
else
goto check_boundary_clk;
}
}
pp_diag(ppi, bmc, 1, "%s: error\n", __func__);
......
......@@ -135,14 +135,29 @@ static void __lib_add_foreign(struct pp_instance *ppi, unsigned char *buf)
memcpy(&frgn_master.source_id,
&DSPOR(ppi)->portIdentity, sizeof(DSPOR(ppi)->portIdentity));
/* Check if announce from a port from this clock 9.3.2.5 a) */
if (!memcmp(&hdr->sourcePortIdentity.clockIdentity,
&DSDEF(ppi)->clockIdentity,
sizeof(DSDEF(ppi)->clockIdentity))) {
pp_diag(ppi, bmc, 2, "Announce frame from this clock\n");
return;
if (DSDEF(ppi)->numberPorts > 1) {
/* Check if announce from the same port from this clock 9.3.2.5 a)
* from another port of this clock we still handle even though it
* states something different in IEEE1588 because in 9.5.2.3
* there is a special handling described for boundary clocks
* which is done in the BMC
*/
if (!memcmp(&hdr->sourcePortIdentity,
&DSPOR(ppi)->portIdentity,
sizeof(DSPOR(ppi)->portIdentity))) {
pp_diag(ppi, bmc, 2, "Announce frame from this port\n");
return;
}
} else {
/* Check if announce from a port from this clock 9.3.2.5 a) */
if (!memcmp(&hdr->sourcePortIdentity.clockIdentity,
&DSDEF(ppi)->clockIdentity,
sizeof(DSDEF(ppi)->clockIdentity))) {
pp_diag(ppi, bmc, 2, "Announce frame from this clock\n");
return;
}
}
/* Check if announce has steps removed larger than 255 9.3.2.5 d) */
if (frgn_master.ann.stepsRemoved >= 255) {
pp_diag(ppi, bmc, 2, "Announce frame steps removed"
......
......@@ -11,10 +11,10 @@
#include <ppsi/ppsi.h>
#include "common-fun.h"
int slave_handle_sync(struct pp_instance *ppi, unsigned char *buf, int len);
int slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
static int slave_handle_sync(struct pp_instance *ppi, unsigned char *buf, int len);
static int slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int len);
int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt,
static int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt,
int plen);
static pp_action *actions[] = {
......@@ -31,7 +31,7 @@ static pp_action *actions[] = {
/* skip signaling and management, for binary size */
};
int slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
static int slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int len)
{
MsgHeader *hdr = &ppi->received_ptp_header;
......@@ -63,7 +63,7 @@ int slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
return 0;
}
int slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
static int slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int len)
{
MsgFollowUp follow;
......@@ -113,7 +113,7 @@ int slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
return 0;
}
int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt,
static int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt,
int plen)
{
int e = 0;
......@@ -158,7 +158,7 @@ int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt,
return 0;
}
int slave_execute(struct pp_instance *ppi)
static int slave_execute(struct pp_instance *ppi)
{
int ret = 0;
......
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