Some hardware can't properly timestamp packets with the new PTP
header version 2.1. This patch introduces a global var ptp_hdr_ver
that can be changed externally to allow legacy PTP version to be
advertised.

Forcing 2.1 also breaks interoperability with some older
grandmasters which will ignore packets with ptp_minor version set.

v2: clarify compatibility issue caused by the change
v3: fix subject line

Signed-off-by: Maciek Machnikowski <mac...@machnikowski.net>
---
 msg.c  |  1 +
 msg.h  |  5 +++++
 port.c | 18 +++++++++---------
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/msg.c b/msg.c
index ab841f0..7a7b149 100644
--- a/msg.c
+++ b/msg.c
@@ -29,6 +29,7 @@
 #include "tlv.h"
 
 int assume_two_step = 0;
+uint8_t ptp_hdr_ver = PTP_VERSION;
 
 /*
  * Head room fits a VLAN Ethernet header, and 'msg' is 64 bit aligned.
diff --git a/msg.h b/msg.h
index 484435d..9c80f45 100644
--- a/msg.h
+++ b/msg.h
@@ -441,6 +441,11 @@ static inline Boolean msg_unicast(struct ptp_message *m)
        return field_is_set(m, 0, UNICAST);
 }
 
+/**
+ * Work around HW assuming PTP message version 2.0
+ */
+extern uint8_t ptp_hdr_ver;
+
 /**
  * Work around buggy 802.1AS switches.
  */
diff --git a/port.c b/port.c
index 5803cd3..d79a510 100644
--- a/port.c
+++ b/port.c
@@ -1538,7 +1538,7 @@ static int port_pdelay_request(struct port *p)
        msg->hwts.type = p->timestamping;
 
        msg->header.tsmt               = PDELAY_REQ | p->transportSpecific;
-       msg->header.ver                = PTP_VERSION;
+       msg->header.ver                = ptp_hdr_ver;
        msg->header.messageLength      = sizeof(struct pdelay_req_msg);
        msg->header.domainNumber       = clock_domain_number(p->clock);
        msg->header.correction         = -p->asymmetry;
@@ -1601,7 +1601,7 @@ int port_delay_request(struct port *p)
        msg->hwts.type = p->timestamping;
 
        msg->header.tsmt               = DELAY_REQ | p->transportSpecific;
-       msg->header.ver                = PTP_VERSION;
+       msg->header.ver                = ptp_hdr_ver;
        msg->header.messageLength      = sizeof(struct delay_req_msg);
        msg->header.domainNumber       = clock_domain_number(p->clock);
        msg->header.correction         = -p->asymmetry;
@@ -1653,7 +1653,7 @@ int port_tx_announce(struct port *p, struct address *dst, 
uint16_t sequence_id)
        msg->hwts.type = p->timestamping;
 
        msg->header.tsmt               = ANNOUNCE | p->transportSpecific;
-       msg->header.ver                = PTP_VERSION;
+       msg->header.ver                = ptp_hdr_ver;
        msg->header.messageLength      = sizeof(struct announce_msg);
        msg->header.domainNumber       = clock_domain_number(p->clock);
        msg->header.sourcePortIdentity = p->portIdentity;
@@ -1735,7 +1735,7 @@ int port_tx_sync(struct port *p, struct address *dst, 
uint16_t sequence_id)
        msg->hwts.type = p->timestamping;
 
        msg->header.tsmt               = SYNC | p->transportSpecific;
-       msg->header.ver                = PTP_VERSION;
+       msg->header.ver                = ptp_hdr_ver;
        msg->header.messageLength      = sizeof(struct sync_msg);
        msg->header.domainNumber       = clock_domain_number(p->clock);
        msg->header.sourcePortIdentity = p->portIdentity;
@@ -1770,7 +1770,7 @@ int port_tx_sync(struct port *p, struct address *dst, 
uint16_t sequence_id)
        fup->hwts.type = p->timestamping;
 
        fup->header.tsmt               = FOLLOW_UP | p->transportSpecific;
-       fup->header.ver                = PTP_VERSION;
+       fup->header.ver                = ptp_hdr_ver;
        fup->header.messageLength      = sizeof(struct follow_up_msg);
        fup->header.domainNumber       = clock_domain_number(p->clock);
        fup->header.sourcePortIdentity = p->portIdentity;
@@ -2119,7 +2119,7 @@ static int process_delay_req(struct port *p, struct 
ptp_message *m)
        msg->hwts.type = p->timestamping;
 
        msg->header.tsmt               = DELAY_RESP | p->transportSpecific;
-       msg->header.ver                = PTP_VERSION;
+       msg->header.ver                = ptp_hdr_ver;
        msg->header.messageLength      = sizeof(struct delay_resp_msg);
        msg->header.domainNumber       = m->header.domainNumber;
        msg->header.correction         = m->header.correction;
@@ -2310,7 +2310,7 @@ int process_pdelay_req(struct port *p, struct ptp_message 
*m)
        rsp->hwts.type = p->timestamping;
 
        rsp->header.tsmt               = PDELAY_RESP | p->transportSpecific;
-       rsp->header.ver                = PTP_VERSION;
+       rsp->header.ver                = ptp_hdr_ver;
        rsp->header.messageLength      = sizeof(struct pdelay_resp_msg);
        rsp->header.domainNumber       = m->header.domainNumber;
        rsp->header.sourcePortIdentity = p->portIdentity;
@@ -2356,7 +2356,7 @@ int process_pdelay_req(struct port *p, struct ptp_message 
*m)
        fup->hwts.type = p->timestamping;
 
        fup->header.tsmt               = PDELAY_RESP_FOLLOW_UP | 
p->transportSpecific;
-       fup->header.ver                = PTP_VERSION;
+       fup->header.ver                = ptp_hdr_ver;
        fup->header.messageLength      = sizeof(struct pdelay_resp_fup_msg);
        fup->header.domainNumber       = m->header.domainNumber;
        fup->header.correction         = m->header.correction;
@@ -3204,7 +3204,7 @@ port_management_construct(struct PortIdentity pid, struct 
port *ingress,
        msg->hwts.type = ingress->timestamping;
 
        msg->header.tsmt               = MANAGEMENT | 
ingress->transportSpecific;
-       msg->header.ver                = PTP_VERSION;
+       msg->header.ver                = ptp_hdr_ver;
        msg->header.messageLength      = sizeof(struct management_msg);
        msg->header.domainNumber       = clock_domain_number(ingress->clock);
        msg->header.sourcePortIdentity = pid;
-- 
2.30.2



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

Reply via email to