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 <[email protected]>
---
 clock.c      |  1 +
 pmc.c        | 11 +++++++++++
 pmc_common.c |  1 +
 port.c       |  9 +++++++++
 tlv.c        | 15 +++++++++++++++
 tlv.h        | 10 ++++++++++
 6 files changed, 47 insertions(+)

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 a1ee787..d1ef484 100644
--- a/pmc.c
+++ b/pmc.c
@@ -144,6 +144,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
        struct subscribe_events_np *sen;
        struct management_tlv_datum *mtd;
        struct port_properties_np *ppn;
+       struct port_hwclock_np *phn;
        struct timePropertiesDS *tp;
        struct management_tlv *mgt;
        struct time_status_np *tsn;
@@ -495,6 +496,16 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
                        pcp->stats.txMsgType[SIGNALING],
                        pcp->stats.txMsgType[MANAGEMENT]);
                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 7a1dbb4..fbc5ae8 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -132,6 +132,7 @@ struct management_id idtab[] = {
        { "PORT_DATA_SET_NP", MID_PORT_DATA_SET_NP, do_set_action },
        { "PORT_STATS_NP", MID_PORT_STATS_NP, do_get_action },
        { "PORT_PROPERTIES_NP", MID_PORT_PROPERTIES_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 5a5741d..5acbd9f 100644
--- a/port.c
+++ b/port.c
@@ -797,6 +797,7 @@ static int port_management_fill_response(struct port 
*target,
        struct management_tlv_datum *mtd;
        struct clock_description *desc;
        struct port_properties_np *ppn;
+       struct port_hwclock_np *phn;
        struct port_stats_np *psn;
        struct management_tlv *tlv;
        struct port_ds_np *pdsnp;
@@ -966,6 +967,14 @@ static int port_management_fill_response(struct port 
*target,
                psn->stats = target->stats;
                datalen = sizeof(*psn);
                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 cc8d507..f49363c 100644
--- a/tlv.c
+++ b/tlv.c
@@ -117,6 +117,7 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t 
data_len,
        struct mgmt_clock_description *cd;
        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;
@@ -331,6 +332,14 @@ static int mgt_post_recv(struct management_tlv *m, 
uint16_t data_len,
                }
                extra_len = sizeof(struct port_stats_np);
                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:
        case MID_INITIALIZE:
@@ -358,6 +367,7 @@ static void mgt_pre_send(struct management_tlv *m, struct 
tlv_extra *extra)
        struct mgmt_clock_description *cd;
        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;
@@ -448,6 +458,11 @@ static void mgt_pre_send(struct management_tlv *m, struct 
tlv_extra *extra)
                        psn->stats.txMsgType[i] = 
__cpu_to_le64(psn->stats.txMsgType[i]);
                }
                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 97615fd..b309686 100644
--- a/tlv.h
+++ b/tlv.h
@@ -125,6 +125,7 @@ enum management_action {
 #define MID_PORT_DATA_SET_NP                           0xC002
 #define MID_PORT_PROPERTIES_NP                         0xC004
 #define MID_PORT_STATS_NP                              0xC005
+#define MID_PORT_HWCLOCK_NP                            0xC007
 
 /* Management error ID values */
 #define MID_RESPONSE_TOO_BIG                           0x0001
@@ -144,6 +145,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;
@@ -344,6 +348,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.34.1



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

Reply via email to