Add tracking of which ports have been added and to which clock they belong.
Signed-off-by: Jiri Benc <jb...@redhat.com> --- phc2sys.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 62e9b8c19e17..ece4560e0c67 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -75,6 +75,12 @@ struct clock { struct clockcheck *sanity_check; }; +struct port { + LIST_ENTRY(port) list; + unsigned int number; + struct clock *clock; +}; + struct node { unsigned int stats_max_count; int sanity_freq_limit; @@ -89,6 +95,7 @@ struct node { struct pmc *pmc; int pmc_ds_requested; uint64_t pmc_last_update; + LIST_HEAD(port_head, port) ports; LIST_HEAD(clock_head, clock) clocks; struct clock *master; }; @@ -206,6 +213,50 @@ static struct clock *clock_add(struct node *node, char *device) return c; } +static struct port *port_get(struct node *node, unsigned int number) +{ + struct port *p; + + LIST_FOREACH(p, &node->ports, list) { + if (p->number == number) + return p; + } + return NULL; +} + +static struct port *port_add(struct node *node, unsigned int number, + char *device) +{ + struct port *p; + struct clock *c = NULL, *tmp; + + p = port_get(node, number); + if (p) + return p; + /* port is a new one, look whether we have the device already on + * a different port */ + LIST_FOREACH(tmp, &node->clocks, list) { + if (!strcmp(tmp->device, device)) { + c = tmp; + break; + } + } + if (!c) { + c = clock_add(node, device); + if (!c) + return NULL; + } + p = malloc(sizeof(*p)); + if (!p) { + pr_err("failed to allocate memory for a port"); + return NULL; + } + p->number = number; + p->clock = c; + LIST_INSERT_HEAD(&node->ports, p, list); + return p; +} + static int read_phc(clockid_t clkid, clockid_t sysclk, int readings, int64_t *offset, uint64_t *ts, int64_t *delay) { -- 1.7.6.5 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel