Add a new command to get the PHC index associated with the port. This
will be needed for phc2sys -a to use the correct PHC for synchronization
if ptp4l is using a virtual clock.

The TLV also contains a flag indicating a virtual clock.

To follow the PORT_PROPERTIES_NP access policy, PORT_HWCLOCK_NP is
limited to the UDS-RW port.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 clock.c      |  1 +
 pmc.c        | 11 +++++++++++
 pmc_common.c |  1 +
 port.c       |  9 +++++++++
 tlv.c        | 16 +++++++++++++++-
 tlv.h        | 10 ++++++++++
 6 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/clock.c b/clock.c
index 36ce4d8..f808b35 100644
--- a/clock.c
+++ b/clock.c
@@ -1486,6 +1486,7 @@ int clock_manage(struct clock *c, struct port *p, struct 
ptp_message *msg)
 
        switch (mgt->id) {
        case MID_PORT_PROPERTIES_NP:
+       case MID_PORT_HWCLOCK_NP:
                if (p != c->uds_rw_port) {
                        /* Only the UDS-RW port allowed. */
                        clock_management_send_error(p, msg, MID_NOT_SUPPORTED);
diff --git a/pmc.c b/pmc.c
index 7916153..0591dd1 100644
--- a/pmc.c
+++ b/pmc.c
@@ -165,6 +165,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
        struct unicast_master_entry *ume;
        struct subscribe_events_np *sen;
        struct port_properties_np *ppn;
+       struct port_hwclock_np *phn;
        struct timePropertiesDS *tp;
        struct management_tlv *mgt;
        struct time_status_np *tsn;
@@ -561,6 +562,16 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
                        buf += sizeof(*ume) + ume->address.addressLength;
                }
                break;
+       case MID_PORT_HWCLOCK_NP:
+               phn = (struct port_hwclock_np *) mgt->data;
+               fprintf(fp, "PORT_HWCLOCK_NP "
+                       IFMT "portIdentity            %s"
+                       IFMT "phcIndex                %d"
+                       IFMT "flags                   %hhu",
+                       pid2str(&phn->portIdentity),
+                       phn->phc_index,
+                       phn->flags);
+               break;
        case MID_LOG_ANNOUNCE_INTERVAL:
                mtd = (struct management_tlv_datum *) mgt->data;
                fprintf(fp, "LOG_ANNOUNCE_INTERVAL "
diff --git a/pmc_common.c b/pmc_common.c
index 017a4f7..1141957 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -134,6 +134,7 @@ struct management_id idtab[] = {
        { "PORT_STATS_NP", MID_PORT_STATS_NP, do_get_action },
        { "PORT_SERVICE_STATS_NP", MID_PORT_SERVICE_STATS_NP, do_get_action },
        { "UNICAST_MASTER_TABLE_NP", MID_UNICAST_MASTER_TABLE_NP, do_get_action 
},
+       { "PORT_HWCLOCK_NP", MID_PORT_HWCLOCK_NP, do_get_action },
 };
 
 static void do_get_action(struct pmc *pmc, int action, int index, char *str)
diff --git a/port.c b/port.c
index ced09ae..f2b666c 100644
--- a/port.c
+++ b/port.c
@@ -802,6 +802,7 @@ static int port_management_fill_response(struct port 
*target,
        struct unicast_master_entry *ume;
        struct clock_description *desc;
        struct port_properties_np *ppn;
+       struct port_hwclock_np *phn;
        struct management_tlv *tlv;
        struct port_stats_np *psn;
        struct foreign_clock *fc;
@@ -1021,6 +1022,14 @@ static int port_management_fill_response(struct port 
*target,
                }
                datalen = buf - tlv->data;
                break;
+       case MID_PORT_HWCLOCK_NP:
+               phn = (struct port_hwclock_np *)tlv->data;
+               phn->portIdentity = target->portIdentity;
+               phn->phc_index = target->phc_index;
+               phn->flags = interface_get_vclock(target->iface) >= 0 ?
+                       PORT_HWCLOCK_VCLOCK : 0;
+               datalen = sizeof(*phn);
+               break;
        default:
                /* The caller should *not* respond to this message. */
                tlv_extra_recycle(extra);
diff --git a/tlv.c b/tlv.c
index 4b74fe7..1c13460 100644
--- a/tlv.c
+++ b/tlv.c
@@ -120,6 +120,7 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t 
data_len,
        struct unicast_master_entry *ume;
        struct subscribe_events_np *sen;
        struct port_properties_np *ppn;
+       struct port_hwclock_np *phn;
        struct timePropertiesDS *tp;
        struct time_status_np *tsn;
        struct port_stats_np *psn;
@@ -388,7 +389,14 @@ static int mgt_post_recv(struct management_tlv *m, 
uint16_t data_len,
                                goto bad_length;
                        buf += sizeof(*ume) + ume->address.addressLength;
                }
-
+               break;
+       case MID_PORT_HWCLOCK_NP:
+               if (data_len < sizeof(struct port_hwclock_np))
+                       goto bad_length;
+               phn = (struct port_hwclock_np *)m->data;
+               phn->portIdentity.portNumber = 
ntohs(phn->portIdentity.portNumber);
+               phn->phc_index = ntohl(phn->phc_index);
+               extra_len = sizeof(struct port_hwclock_np);
                break;
        case MID_SAVE_IN_NON_VOLATILE_STORAGE:
        case MID_RESET_NON_VOLATILE_STORAGE:
@@ -420,6 +428,7 @@ static void mgt_pre_send(struct management_tlv *m, struct 
tlv_extra *extra)
        struct unicast_master_entry *ume;
        struct subscribe_events_np *sen;
        struct port_properties_np *ppn;
+       struct port_hwclock_np *phn;
        struct timePropertiesDS *tp;
        struct time_status_np *tsn;
        struct port_stats_np *psn;
@@ -555,6 +564,11 @@ static void mgt_pre_send(struct management_tlv *m, struct 
tlv_extra *extra)
                umtn->actual_table_size =
                        htons(umtn->actual_table_size);
                break;
+       case MID_PORT_HWCLOCK_NP:
+               phn = (struct port_hwclock_np *)m->data;
+               phn->portIdentity.portNumber = 
htons(phn->portIdentity.portNumber);
+               phn->phc_index = htonl(phn->phc_index);
+               break;
        }
 }
 
diff --git a/tlv.h b/tlv.h
index 915b9fc..60a9edb 100644
--- a/tlv.h
+++ b/tlv.h
@@ -127,6 +127,7 @@ enum management_action {
 #define MID_PORT_STATS_NP                              0xC005
 #define MID_PORT_SERVICE_STATS_NP                      0xC007
 #define MID_UNICAST_MASTER_TABLE_NP                    0xC008
+#define MID_PORT_HWCLOCK_NP                            0xC009
 
 /* Management error ID values */
 #define MID_RESPONSE_TOO_BIG                           0x0001
@@ -146,6 +147,9 @@ enum management_action {
 #define CANCEL_UNICAST_MAINTAIN_GRANT  (1 << 1)
 #define GRANT_UNICAST_RENEWAL_INVITED  (1 << 0)
 
+/* Flags in PORT_HWCLOCK_NP */
+#define PORT_HWCLOCK_VCLOCK            (1 << 0)
+
 struct ack_cancel_unicast_xmit_tlv {
        Enumeration16   type;
        UInteger16      length;
@@ -346,6 +350,12 @@ struct port_properties_np {
        struct PTPText interface;
 } PACKED;
 
+struct port_hwclock_np {
+       struct PortIdentity portIdentity;
+       Integer32 phc_index;
+       UInteger8 flags;
+} PACKED;
+
 struct port_stats_np {
        struct PortIdentity portIdentity;
        struct PortStats stats;
-- 
2.35.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to