Skip to content

Commit

Permalink
tlv: Add PORT_HWCLOCK_NP.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mlichvar authored and richardcochran committed Mar 8, 2022
1 parent 9b9c2c5 commit 16f8f8f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "
Expand Down
1 change: 1 addition & 0 deletions pmc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 15 additions & 1 deletion tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
10 changes: 10 additions & 0 deletions tlv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 16f8f8f

Please sign in to comment.