Signed-off-by: Hangbin Liu <liuhang...@gmail.com>
---
 phc2sys.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
 port.c    |  2 +-
 2 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/phc2sys.c b/phc2sys.c
index b6f6719..35df731 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -128,6 +128,11 @@ static int clock_handle_leap(struct node *node, struct 
clock *clock,
 static int run_pmc_get_utc_offset(struct node *node, int timeout);
 static void run_pmc_events(struct node *node);
 
+static int normalize_state(int state);
+static int run_pmc_port_properties(struct node *node, int timeout,
+                                  unsigned int port,
+                                  int *state, int *tstamping, char *iface);
+
 static clockid_t clock_open(char *device, int *phc_index)
 {
        struct sk_ts_info ts_info;
@@ -294,8 +299,47 @@ static struct port *port_add(struct node *node, unsigned 
int number,
        return p;
 }
 
-static void clock_reinit(struct clock *clock)
+static void clock_reinit(struct node *node, struct clock *clock)
 {
+       struct port *p;
+       int state, timestamping, ret;
+       int phc_index = -1;
+       char iface[IFNAMSIZ];
+       clockid_t clkid = CLOCK_INVALID;
+
+       LIST_FOREACH(p, &node->ports, list) {
+               if (p->clock == clock) {
+                       ret = run_pmc_port_properties(node, 1000, p->number,
+                                                     &state, &timestamping,
+                                                     iface);
+                       if (ret == -1) {
+                               /* port does not exist, ignore the port */
+                               continue;
+                       }
+                       if (ret <= 0) {
+                               pr_err("failed to get port properties");
+                               return;
+                       }
+                       if (timestamping == TS_SOFTWARE) {
+                               /* ignore ports with software time stamping */
+                               continue;
+                       }
+
+                       p->state = normalize_state(state);
+               }
+       }
+
+       if (strcmp(clock->device, iface)) {
+               free(clock->device);
+               clock->device = strdup(iface);
+               clkid = clock_open(clock->device, &phc_index);
+               if (clkid == CLOCK_INVALID)
+                       return;
+               phc_close(clock->clkid);
+               clock->clkid = clkid;
+               clock->phc_index = phc_index;
+       }
+
        servo_reset(clock->servo);
        clock->servo_state = SERVO_UNLOCKED;
 
@@ -322,7 +366,7 @@ static void reconfigure(struct node *node)
 
                if (c->new_state) {
                        if (c->new_state == PS_MASTER)
-                               clock_reinit(c);
+                               clock_reinit(node, c);
 
                        c->state = c->new_state;
                        c->new_state = 0;
@@ -388,7 +432,7 @@ static void reconfigure(struct node *node)
        } else if (rt) {
                if (rt->state != PS_MASTER) {
                        rt->state = PS_MASTER;
-                       clock_reinit(rt);
+                       clock_reinit(node, rt);
                }
                pr_info("selecting %s for synchronization", rt->device);
        }
diff --git a/port.c b/port.c
index b5fec20..a22d031 100644
--- a/port.c
+++ b/port.c
@@ -854,7 +854,7 @@ static int port_management_fill_response(struct port 
*target,
                else
                        ppn->port_state = target->state;
                ppn->timestamping = target->timestamping;
-               ptp_text_set(&ppn->interface, target->name);
+               ptp_text_set(&ppn->interface, target->iface->ts_iface);
                datalen = sizeof(*ppn) + ppn->interface.length;
                respond = 1;
                break;
-- 
2.5.5


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to