A single, external PTP Hardware Clock device may be wired to one or more
MAC devices, providing the MACs with an input clock.  This patch adds
support for such a hardware architecture by letting the command line PHC
override the one discovered via the ethtool ioctl.

Signed-off-by: Richard Cochran <[email protected]>
---
 clock.c | 11 ++++++-----
 port.c  |  8 +++++++-
 port.h  |  4 +++-
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/clock.c b/clock.c
index 8533b39..856ee66 100644
--- a/clock.c
+++ b/clock.c
@@ -771,8 +771,8 @@ struct currentDS *clock_current_dataset(struct clock *c)
        return &c->cur;
 }
 
-static int clock_add_port(struct clock *c, int phc_index,
-                         enum timestamp_type timestamping,
+static int clock_add_port(struct clock *c, const char *phc_device,
+                         int phc_index, enum timestamp_type timestamping,
                          struct interface *iface)
 {
        struct port *p, *piter, *lastp = NULL;
@@ -780,7 +780,8 @@ static int clock_add_port(struct clock *c, int phc_index,
        if (clock_resize_pollfd(c, c->nports + 1)) {
                return -1;
        }
-       p = port_open(phc_index, timestamping, ++c->last_port_number, iface, c);
+       p = port_open(phc_device, phc_index, timestamping,
+                     ++c->last_port_number, iface, c);
        if (!p) {
                /* No need to shrink pollfd */
                return -1;
@@ -1136,7 +1137,7 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
        }
 
        /* Create the UDS interface. */
-       c->uds_port = port_open(phc_index, timestamping, 0, udsif, c);
+       c->uds_port = port_open(phc_device, phc_index, timestamping, 0, udsif, 
c);
        if (!c->uds_port) {
                pr_err("failed to open the UDS port");
                return NULL;
@@ -1145,7 +1146,7 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
 
        /* Create the ports. */
        STAILQ_FOREACH(iface, &config->interfaces, list) {
-               if (clock_add_port(c, phc_index, timestamping, iface)) {
+               if (clock_add_port(c, phc_device, phc_index, timestamping, 
iface)) {
                        pr_err("failed to open port %s", iface->name);
                        return NULL;
                }
diff --git a/port.c b/port.c
index ad9554f..8150981 100644
--- a/port.c
+++ b/port.c
@@ -2862,7 +2862,8 @@ err:
        msg_put(msg);
 }
 
-struct port *port_open(int phc_index,
+struct port *port_open(const char *phc_device,
+                      int phc_index,
                       enum timestamp_type timestamping,
                       int number,
                       struct interface *interface,
@@ -2926,6 +2927,11 @@ struct port *port_open(int phc_index,
                if (p->jbod) {
                        pr_warning("port %d: just a bunch of devices", number);
                        p->phc_index = interface->ts_info.phc_index;
+               } else if (phc_device) {
+                       pr_warning("port %d: taking %s from the command line, "
+                                  "not the attached ptp%d", number, phc_device,
+                                  interface->ts_info.phc_index);
+                       p->phc_index = phc_index;
                } else {
                        pr_err("port %d: PHC device mismatch", number);
                        pr_err("port %d: /dev/ptp%d requested, ptp%d attached",
diff --git a/port.h b/port.h
index aa3b1ec..a45a7a4 100644
--- a/port.h
+++ b/port.h
@@ -192,6 +192,7 @@ void port_notify_event(struct port *p, enum notification 
event);
 
 /**
  * Open a network port.
+ * @param phc_device    The name of PHC device as found on the command line.
  * @param phc_index     The PHC device index for the network device.
  * @param timestamping  The timestamping mode for this port.
  * @param number       An arbitrary number assigned to this port.
@@ -199,7 +200,8 @@ void port_notify_event(struct port *p, enum notification 
event);
  * @param clock         A pointer to the system PTP clock.
  * @return A pointer to an open port on success, or NULL otherwise.
  */
-struct port *port_open(int phc_index,
+struct port *port_open(const char *phc_device,
+                      int phc_index,
                       enum timestamp_type timestamping,
                       int number,
                       struct interface *interface,
-- 
2.11.0



_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to