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 | 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 2e5e93e..9337a2e 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; @@ -522,6 +523,16 @@ static void pmc_show(struct ptp_message *msg, FILE *fp) pssp->stats.sync_mismatch, pssp->stats.followup_mismatch); 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 b691bbb..be78914 100644 --- a/pmc_common.c +++ b/pmc_common.c @@ -133,6 +133,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 }, { "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 3152dee..38dc840 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 port_service_stats_np *pssn; struct management_tlv *tlv; @@ -973,6 +974,14 @@ static int port_management_fill_response(struct port *target, pssn->stats = target->service_stats; datalen = sizeof(*pssn); 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 df516be..1762d15 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; @@ -360,6 +361,14 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t data_len, __le64_to_cpu(pssn->stats.followup_mismatch); extra_len = sizeof(struct port_service_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: @@ -387,6 +396,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; @@ -503,6 +513,11 @@ static void mgt_pre_send(struct management_tlv *m, struct tlv_extra *extra) pssn->stats.followup_mismatch = __cpu_to_le64(pssn->stats.followup_mismatch); 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 408c22c..8ff9b0f 100644 --- a/tlv.h +++ b/tlv.h @@ -126,6 +126,7 @@ enum management_action { #define MID_PORT_PROPERTIES_NP 0xC004 #define MID_PORT_STATS_NP 0xC005 #define MID_PORT_SERVICE_STATS_NP 0xC007 +#define MID_PORT_HWCLOCK_NP 0xC008 /* Management error ID values */ #define MID_RESPONSE_TOO_BIG 0x0001 @@ -145,6 +146,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; @@ -345,6 +349,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 Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel