Commit 63873358 authored by Alessandro Rubini's avatar Alessandro Rubini

general: add port_name to ppi, use it for diagnostics (not iface_name)

Otherwise, if we have two PTP ports for the same interface, like
Ethernet and UDP, we are not able to tell which message is for which.

This now works as expected:

./ppsi -C "port eth0;  iface eth0; role master; proto raw; diagnostics 111" \
       -C "port eth0u; iface eth0; role master; proto udp; diagnostics 111"
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 722e00ad
...@@ -139,6 +139,7 @@ int main(int argc, char **argv) ...@@ -139,6 +139,7 @@ int main(int argc, char **argv)
ppi = INST(ppg, i); ppi = INST(ppg, i);
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;
if (ppi->cfg.proto == PPSI_PROTO_RAW) if (ppi->cfg.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");
......
...@@ -80,6 +80,7 @@ int main(int argc, char **argv) ...@@ -80,6 +80,7 @@ int main(int argc, char **argv)
ppi->glbs = ppg; ppi->glbs = ppg;
ppi->iface_name = ppi->cfg.iface_name; ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
/* this old-fashioned "ethernet_mode" is a single bit */ /* this old-fashioned "ethernet_mode" is a single bit */
ppi->ethernet_mode = (ppi->cfg.proto == PPSI_PROTO_RAW); ppi->ethernet_mode = (ppi->cfg.proto == PPSI_PROTO_RAW);
if (ppi->cfg.role == PPSI_ROLE_MASTER) { if (ppi->cfg.role == PPSI_ROLE_MASTER) {
......
...@@ -74,7 +74,8 @@ struct pp_instance ppi_static = { ...@@ -74,7 +74,8 @@ struct pp_instance ppi_static = {
.portDS = &portDS, .portDS = &portDS,
.n_ops = &wrpc_net_ops, .n_ops = &wrpc_net_ops,
.t_ops = &wrpc_time_ops, .t_ops = &wrpc_time_ops,
.iface_name = "wr1", .iface_name = "wr1",
.port_name = "wr1",
}; };
/* We now have a structure with all globals, and multiple ppi inside */ /* We now have a structure with all globals, and multiple ppi inside */
......
...@@ -154,6 +154,7 @@ int main(int argc, char **argv) ...@@ -154,6 +154,7 @@ int main(int argc, char **argv)
ppi->glbs = ppg; ppi->glbs = ppg;
ppi->iface_name = ppi->cfg.iface_name; ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
/* this old-fashioned "ethernet_mode" is a single bit */ /* this old-fashioned "ethernet_mode" is a single bit */
ppi->ethernet_mode = (ppi->cfg.proto == PPSI_PROTO_RAW); ppi->ethernet_mode = (ppi->cfg.proto == PPSI_PROTO_RAW);
if (ppi->cfg.role == PPSI_ROLE_MASTER) { if (ppi->cfg.role == PPSI_ROLE_MASTER) {
......
...@@ -22,7 +22,7 @@ void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th, ...@@ -22,7 +22,7 @@ void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th,
int level, char *fmt, ...) int level, char *fmt, ...)
{ {
va_list args; va_list args;
char *name = ppi ? ppi->iface_name : "ppsi"; char *name = ppi ? ppi->port_name : "ppsi";
if (!__PP_DIAG_ALLOW(ppi, th, level)) if (!__PP_DIAG_ALLOW(ppi, th, level))
return; return;
......
...@@ -27,7 +27,7 @@ static void pp_fsm_printf(struct pp_instance *ppi, char *fmt, ...) ...@@ -27,7 +27,7 @@ static void pp_fsm_printf(struct pp_instance *ppi, char *fmt, ...)
ppi->t_ops->get(ppi, &t); ppi->t_ops->get(ppi, &t);
pp_global_flags = oflags; pp_global_flags = oflags;
pp_printf("diag-fsm-1-%s: %09d.%03d: ", ppi->iface_name, pp_printf("diag-fsm-1-%s: %09d.%03d: ", ppi->port_name,
(int)t.seconds, (int)t.nanoseconds / 1000000); (int)t.seconds, (int)t.nanoseconds / 1000000);
va_start(args, fmt); va_start(args, fmt);
pp_vprintf(fmt, args); pp_vprintf(fmt, args);
...@@ -113,7 +113,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen) ...@@ -113,7 +113,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
err = ip->f1(ppi, packet, plen); err = ip->f1(ppi, packet, plen);
if (err) if (err)
pp_printf("fsm for %s: Error %i in %s\n", pp_printf("fsm for %s: Error %i in %s\n",
ppi->iface_name, err, ip->name); ppi->port_name, err, ip->name);
/* done: if new state mark it, and enter it now (0 ms) */ /* done: if new state mark it, and enter it now (0 ms) */
if (ppi->state != ppi->next_state) { if (ppi->state != ppi->next_state) {
...@@ -127,6 +127,6 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen) ...@@ -127,6 +127,6 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
return ppi->next_delay; return ppi->next_delay;
} }
/* Unknwon state, can't happen */ /* Unknwon state, can't happen */
pp_printf("fsm: Unknown state for iface %s\n", ppi->iface_name); pp_printf("fsm: Unknown state for port %s\n", ppi->port_name);
return 10000; /* No way out. Repeat message every 10s */ return 10000; /* No way out. Repeat message every 10s */
} }
...@@ -177,7 +177,8 @@ struct pp_instance { ...@@ -177,7 +177,8 @@ struct pp_instance {
slave_only:1, slave_only:1,
master_only:1, master_only:1,
ethernet_mode:1; ethernet_mode:1;
char *iface_name; char *iface_name; /* for direct actions on hardware */
char *port_name; /* for diagnostics, mainly */
int port_idx; int port_idx;
struct pp_instance_cfg cfg; struct pp_instance_cfg cfg;
......
...@@ -38,6 +38,7 @@ static struct pp_instance ppi_static = { ...@@ -38,6 +38,7 @@ static struct pp_instance ppi_static = {
.n_ops = &bare_net_ops, .n_ops = &bare_net_ops,
.t_ops = &bare_time_ops, .t_ops = &bare_time_ops,
.iface_name = "eth0", .iface_name = "eth0",
.port_name = "eth0",
.ethernet_mode = PP_DEFAULT_ETHERNET_MODE, .ethernet_mode = PP_DEFAULT_ETHERNET_MODE,
}; };
......
...@@ -159,9 +159,10 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv) ...@@ -159,9 +159,10 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
break; break;
case 'b': case 'b':
a = argv[++i]; a = argv[++i];
if (ppg->nlinks == 1) if (ppg->nlinks == 1) {
INST(ppg, 0)->iface_name = a; INST(ppg, 0)->iface_name = a;
else { INST(ppg, 0)->port_name = a;
} else {
/* If ppsi.conf exists and more than one link is /* If ppsi.conf exists and more than one link is
* configured, it makes no sense trying to set an iface * configured, it makes no sense trying to set an iface
* name */ * name */
......
...@@ -309,7 +309,7 @@ static int sim_net_init(struct pp_instance *ppi) ...@@ -309,7 +309,7 @@ static int sim_net_init(struct pp_instance *ppi)
/* only UDP, RAW is not supported */ /* only UDP, RAW is not supported */
pp_diag(ppi, frames, 1, "sim_net_init UDP\n"); pp_diag(ppi, frames, 1, "sim_net_init UDP\n");
for (i = PP_NP_GEN; i <= PP_NP_EVT; i++) { for (i = PP_NP_GEN; i <= PP_NP_EVT; i++) {
if (sim_open_ch(ppi, ppi->iface_name, i)) if (sim_open_ch(ppi, ppi->port_name, i))
return -1; return -1;
} }
return 0; return 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