Commit 8699f7d5 authored by Alessandro Rubini's avatar Alessandro Rubini

general: move delay mechanism from global to per-port

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c07764dd
...@@ -98,7 +98,6 @@ int main(int argc, char **argv) ...@@ -98,7 +98,6 @@ int main(int argc, char **argv)
ppg->max_links = 2; // master and slave, nothing else ppg->max_links = 2; // master and slave, nothing else
ppg->arch_data = calloc(1, sizeof(struct sim_ppg_arch_data)); ppg->arch_data = calloc(1, sizeof(struct sim_ppg_arch_data));
ppg->pp_instances = calloc(ppg->max_links, sizeof(struct pp_instance)); ppg->pp_instances = calloc(ppg->max_links, sizeof(struct pp_instance));
ppg->delay_mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH;
if ((!ppg->arch_data) || (!ppg->pp_instances)) if ((!ppg->arch_data) || (!ppg->pp_instances))
return -1; return -1;
...@@ -144,6 +143,7 @@ int main(int argc, char **argv) ...@@ -144,6 +143,7 @@ int main(int argc, char **argv)
sim_set_global_DS(ppi); sim_set_global_DS(ppi);
ppi->iface_name = ppi->cfg.iface_name; ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name; ppi->port_name = ppi->cfg.port_name;
ppi->mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH;
if (ppi->proto == PPSI_PROTO_RAW) if (ppi->proto == PPSI_PROTO_RAW)
pp_printf("Warning: simulator doesn't support raw " pp_printf("Warning: simulator doesn't support raw "
"ethernet. Using UDP\n"); "ethernet. Using UDP\n");
......
...@@ -51,11 +51,6 @@ int main(int argc, char **argv) ...@@ -51,11 +51,6 @@ int main(int argc, char **argv)
ppg->servo = &servo; ppg->servo = &servo;
ppg->rt_opts = &__pp_default_rt_opts; ppg->rt_opts = &__pp_default_rt_opts;
if (CONFIG_HAS_P2P) /* FIXME: should be a run-time configuration */
ppg->delay_mech = PP_P2P_MECH;
else
ppg->delay_mech = PP_E2E_MECH;
/* We are hosted, so we can allocate */ /* We are hosted, so we can allocate */
ppg->max_links = PP_MAX_LINKS; ppg->max_links = PP_MAX_LINKS;
ppg->arch_data = calloc(1, sizeof(struct unix_arch_data)); ppg->arch_data = calloc(1, sizeof(struct unix_arch_data));
...@@ -71,6 +66,7 @@ int main(int argc, char **argv) ...@@ -71,6 +66,7 @@ int main(int argc, char **argv)
ppi = INST(ppg, i); ppi = INST(ppg, i);
ppi->proto = PP_DEFAULT_PROTO; ppi->proto = PP_DEFAULT_PROTO;
ppi->role = PP_DEFAULT_ROLE; ppi->role = PP_DEFAULT_ROLE;
ppi->mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH;
} }
/* Set offset here, so config parsing can override it */ /* Set offset here, so config parsing can override it */
......
...@@ -79,6 +79,7 @@ struct pp_instance ppi_static = { ...@@ -79,6 +79,7 @@ struct pp_instance ppi_static = {
.t_ops = &wrpc_time_ops, .t_ops = &wrpc_time_ops,
.vlans_array_len = CONFIG_VLAN_ARRAY_SIZE, .vlans_array_len = CONFIG_VLAN_ARRAY_SIZE,
.proto = PP_DEFAULT_PROTO, .proto = PP_DEFAULT_PROTO,
.mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH,
.iface_name = "wr1", .iface_name = "wr1",
.port_name = "wr1", .port_name = "wr1",
.__tx_buffer = __tx_buffer, .__tx_buffer = __tx_buffer,
...@@ -94,7 +95,6 @@ static struct pp_globals ppg_static = { ...@@ -94,7 +95,6 @@ static struct pp_globals ppg_static = {
.parentDS = &parentDS, .parentDS = &parentDS,
.timePropertiesDS = &timePropertiesDS, .timePropertiesDS = &timePropertiesDS,
.global_ext_data = &servo_state, .global_ext_data = &servo_state,
.delay_mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH,
}; };
int wrc_ptp_init() int wrc_ptp_init()
...@@ -192,17 +192,15 @@ int wrc_ptp_get_mode() ...@@ -192,17 +192,15 @@ int wrc_ptp_get_mode()
void wrc_ptp_set_sync_mech(int mech) void wrc_ptp_set_sync_mech(int mech)
{ {
struct pp_instance *ppi = &ppi_static; struct pp_instance *ppi = &ppi_static;
struct pp_globals *ppg = ppi->glbs;
wrc_ptp_stop(); wrc_ptp_stop();
ppg->delay_mech = mech; ppi->mech = mech;
} }
int wrc_ptp_get_sync_mech() int wrc_ptp_get_sync_mech()
{ {
struct pp_instance *ppi = &ppi_static; struct pp_instance *ppi = &ppi_static;
struct pp_globals *ppg = ppi->glbs; return ppi->mech;
return ppg->delay_mech;
} }
int wrc_ptp_start() int wrc_ptp_start()
......
...@@ -154,11 +154,6 @@ int main(int argc, char **argv) ...@@ -154,11 +154,6 @@ int main(int argc, char **argv)
ppg->servo = alloc_fn(ppsi_head, sizeof(*ppg->servo)); ppg->servo = alloc_fn(ppsi_head, sizeof(*ppg->servo));
ppg->rt_opts = &__pp_default_rt_opts; ppg->rt_opts = &__pp_default_rt_opts;
if (CONFIG_HAS_P2P) /* FIXME: should be a run-time configuration */
ppg->delay_mech = PP_P2P_MECH;
else
ppg->delay_mech = PP_E2E_MECH;
ppg->max_links = PP_MAX_LINKS; ppg->max_links = PP_MAX_LINKS;
ppg->global_ext_data = alloc_fn(ppsi_head, ppg->global_ext_data = alloc_fn(ppsi_head,
sizeof(struct wr_servo_state)); sizeof(struct wr_servo_state));
...@@ -212,6 +207,7 @@ int main(int argc, char **argv) ...@@ -212,6 +207,7 @@ int main(int argc, char **argv)
ppi->vlans_array_len = CONFIG_VLAN_ARRAY_SIZE; ppi->vlans_array_len = CONFIG_VLAN_ARRAY_SIZE;
ppi->iface_name = ppi->cfg.iface_name; ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name; ppi->port_name = ppi->cfg.port_name;
ppi->mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH;
ppi->portDS = calloc(1, sizeof(*ppi->portDS)); ppi->portDS = calloc(1, sizeof(*ppi->portDS));
if (ppi->portDS) if (ppi->portDS)
ppi->portDS->ext_dsport = ppi->portDS->ext_dsport =
......
...@@ -127,7 +127,8 @@ struct pp_instance { ...@@ -127,7 +127,8 @@ struct pp_instance {
unsigned long d_flags; /* diagnostics, ppi-specific flags */ unsigned long d_flags; /* diagnostics, ppi-specific flags */
unsigned char flags; /* protocol flags (see below) */ unsigned char flags; /* protocol flags (see below) */
int role, /* same as in config file */ int role, /* same as in config file */
proto; /* same as in config file */ proto, /* same as in config file */
mech; /* same as in config file */
/* Pointer to global instance owning this pp_instance*/ /* Pointer to global instance owning this pp_instance*/
struct pp_globals *glbs; struct pp_globals *glbs;
...@@ -211,9 +212,6 @@ struct pp_globals { ...@@ -211,9 +212,6 @@ struct pp_globals {
DSParent *parentDS; /* page 68 */ DSParent *parentDS; /* page 68 */
DSTimeProperties *timePropertiesDS; /* page 70 */ DSTimeProperties *timePropertiesDS; /* page 70 */
/* Sync Mechanism */
int delay_mech; /* PP_E2E_MECH, PP_P2P_MECH */
/* Index of the pp_instance receiving the "Ebest" clock */ /* Index of the pp_instance receiving the "Ebest" clock */
int ebest_idx; int ebest_idx;
int ebest_updated; /* set to 1 when ebest_idx changes */ int ebest_updated; /* set to 1 when ebest_idx changes */
......
...@@ -43,6 +43,7 @@ static struct pp_instance ppi_static = { ...@@ -43,6 +43,7 @@ static struct pp_instance ppi_static = {
.port_name = "eth0", .port_name = "eth0",
.vlans_array_len = CONFIG_VLAN_ARRAY_SIZE, .vlans_array_len = CONFIG_VLAN_ARRAY_SIZE,
.proto = PP_DEFAULT_PROTO, .proto = PP_DEFAULT_PROTO,
.mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH,
.__tx_buffer = __tx_buffer, .__tx_buffer = __tx_buffer,
.__rx_buffer = __rx_buffer, .__rx_buffer = __rx_buffer,
}; };
...@@ -50,7 +51,6 @@ static struct pp_instance ppi_static = { ...@@ -50,7 +51,6 @@ static struct pp_instance ppi_static = {
/* We now have a structure with all globals, and multiple ppi inside */ /* We now have a structure with all globals, and multiple ppi inside */
static struct pp_globals ppg_static = { static struct pp_globals ppg_static = {
.pp_instances = &ppi_static, .pp_instances = &ppi_static,
.delay_mech = CONFIG_HAS_P2P ? PP_P2P_MECH : PP_E2E_MECH,
.nlinks = 1, .nlinks = 1,
.servo = &servo, .servo = &servo,
.defaultDS = &defaultDS, .defaultDS = &defaultDS,
......
...@@ -215,7 +215,7 @@ static int wr_handle_followup(struct pp_instance *ppi, ...@@ -215,7 +215,7 @@ static int wr_handle_followup(struct pp_instance *ppi,
wr_servo_got_sync(ppi, precise_orig_timestamp, wr_servo_got_sync(ppi, precise_orig_timestamp,
&ppi->t2); &ppi->t2);
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
wr_servo_update(ppi); wr_servo_update(ppi);
return 1; /* the caller returns too */ return 1; /* the caller returns too */
......
...@@ -247,7 +247,7 @@ int wr_servo_got_delay(struct pp_instance *ppi, Integer32 cf) ...@@ -247,7 +247,7 @@ int wr_servo_got_delay(struct pp_instance *ppi, Integer32 cf)
s->t4.correct = 1; /* clock->delay_req_receive_time.correct; */ s->t4.correct = 1; /* clock->delay_req_receive_time.correct; */
s->t4.phase = (int64_t) cf * 1000LL / 65536LL; s->t4.phase = (int64_t) cf * 1000LL / 65536LL;
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) { if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH) {
s->t5 = ppi->t5; s->t5 = ppi->t5;
s->t5.correct = 1; s->t5.correct = 1;
s->t5.phase = 0; s->t5.phase = 0;
...@@ -416,7 +416,7 @@ int wr_servo_update(struct pp_instance *ppi) ...@@ -416,7 +416,7 @@ int wr_servo_update(struct pp_instance *ppi)
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN); wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN);
picos_mu_prev = s->picos_mu; picos_mu_prev = s->picos_mu;
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) { if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH) {
if (!wr_p2p_offset(ppi, s, &ts_offset_hw)) if (!wr_p2p_offset(ppi, s, &ts_offset_hw))
goto out; goto out;
} else { } else {
......
...@@ -186,7 +186,7 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf, ...@@ -186,7 +186,7 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
ppi->flags &= ~PPI_FLAG_WAITING_FOR_F_UP; ppi->flags &= ~PPI_FLAG_WAITING_FOR_F_UP;
to_TimeInternal(&ppi->t1, to_TimeInternal(&ppi->t1,
&sync.originTimestamp); &sync.originTimestamp);
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
pp_servo_got_psync(ppi); pp_servo_got_psync(ppi);
else else
pp_servo_got_sync(ppi); pp_servo_got_sync(ppi);
...@@ -355,7 +355,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf, ...@@ -355,7 +355,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
pp_servo_got_psync(ppi); pp_servo_got_psync(ppi);
else else
pp_servo_got_sync(ppi); pp_servo_got_sync(ppi);
......
...@@ -602,7 +602,7 @@ static int msg_issue_pdelay_req(struct pp_instance *ppi) ...@@ -602,7 +602,7 @@ static int msg_issue_pdelay_req(struct pp_instance *ppi)
int msg_issue_request(struct pp_instance *ppi) int msg_issue_request(struct pp_instance *ppi)
{ {
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
return msg_issue_pdelay_req(ppi); return msg_issue_pdelay_req(ppi);
return msg_issue_delay_req(ppi); return msg_issue_delay_req(ppi);
} }
......
...@@ -19,7 +19,7 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -19,7 +19,7 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
goto out; goto out;
/* when the clock is using peer-delay, listening must send it too */ /* when the clock is using peer-delay, listening must send it too */
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
e = pp_lib_may_issue_request(ppi); e = pp_lib_may_issue_request(ppi);
if (plen == 0) if (plen == 0)
......
...@@ -60,7 +60,7 @@ int pp_master(struct pp_instance *ppi, uint8_t *pkt, int plen) ...@@ -60,7 +60,7 @@ int pp_master(struct pp_instance *ppi, uint8_t *pkt, int plen)
} }
/* when the clock is using peer-delay, the master must send it too */ /* when the clock is using peer-delay, the master must send it too */
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
pp_lib_may_issue_request(ppi); pp_lib_may_issue_request(ppi);
else /* please check commit '6d7bf7e3' about below, I'm not sure */ else /* please check commit '6d7bf7e3' about below, I'm not sure */
pp_timeout_set(ppi, PP_TO_REQUEST); pp_timeout_set(ppi, PP_TO_REQUEST);
......
...@@ -14,7 +14,7 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -14,7 +14,7 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
int e = 0; /* error var, to check errors in msg handling */ int e = 0; /* error var, to check errors in msg handling */
/* when the clock is using peer-delay, listening must send it too */ /* when the clock is using peer-delay, listening must send it too */
if (CONFIG_HAS_P2P && ppi->glbs->delay_mech == PP_P2P_MECH) if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
e = pp_lib_may_issue_request(ppi); e = pp_lib_may_issue_request(ppi);
if (plen == 0) if (plen == 0)
......
...@@ -29,7 +29,7 @@ static int wrpc_open_ch(struct pp_instance *ppi) ...@@ -29,7 +29,7 @@ static int wrpc_open_ch(struct pp_instance *ppi)
struct wr_sockaddr addr; struct wr_sockaddr addr;
char *macaddr = PP_MCAST_MACADDRESS; char *macaddr = PP_MCAST_MACADDRESS;
if (ppi->glbs->delay_mech == PP_P2P_MECH) if (ppi->mech == PP_P2P_MECH)
macaddr = PP_PDELAY_MACADDRESS; macaddr = PP_PDELAY_MACADDRESS;
addr.ethertype = ETH_P_1588; addr.ethertype = ETH_P_1588;
memcpy(addr.mac, macaddr, sizeof(mac_addr_t)); memcpy(addr.mac, macaddr, sizeof(mac_addr_t));
......
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