2024-04-24 07:16:54

by Ravi Gunasekaran

[permalink] [raw]
Subject: [PATCH net v2] net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets

From: Jason Reeder <[email protected]>

The CPTS, by design, captures the messageType (Sync, Delay_Req, etc.)
field from the second nibble of the PTP header which is defined in the
PTPv2 (1588-2008) specification. In the PTPv1 (1588-2002) specification
the first two bytes of the PTP header are defined as the versionType
which is always 0x0001. This means that any PTPv1 packets that are
tagged for TX timestamping by the CPTS will have their messageType set
to 0x0 which corresponds to a Sync message type. This causes issues
when a PTPv1 stack is expecting a Delay_Req (messageType: 0x1)
timestamp that never appears.

Fix this by checking if the ptp_class of the timestamped TX packet is
PTP_CLASS_V1 and then matching the PTP sequence ID to the stored
sequence ID in the skb->cb data structure. If the sequence IDs match
and the packet is of type PTPv1 then there is a chance that the
messageType has been incorrectly stored by the CPTS so overwrite the
messageType stored by the CPTS with the messageType from the skb->cb
data structure. This allows the PTPv1 stack to receive TX timestamps
for Delay_Req packets which are necessary to lock onto a PTP Leader.

Fixes: f6bd59526ca5 ("net: ethernet: ti: introduce am654 common platform time sync driver")
Signed-off-by: Jason Reeder <[email protected]>
Signed-off-by: Ravi Gunasekaran <[email protected]>
---
Changes since v1:
-----------------
* Added Fixes tag as per Paolo's suggestion
* Rebased to latest tip

v1: https://lore.kernel.org/all/[email protected]/

drivers/net/ethernet/ti/am65-cpts.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c
index c66618d91c28..f89716b1cfb6 100644
--- a/drivers/net/ethernet/ti/am65-cpts.c
+++ b/drivers/net/ethernet/ti/am65-cpts.c
@@ -784,6 +784,11 @@ static bool am65_cpts_match_tx_ts(struct am65_cpts *cpts,
struct am65_cpts_skb_cb_data *skb_cb =
(struct am65_cpts_skb_cb_data *)skb->cb;

+ if ((ptp_classify_raw(skb) & PTP_CLASS_V1) &&
+ ((mtype_seqid & AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK) ==
+ (skb_cb->skb_mtype_seqid & AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK)))
+ mtype_seqid = skb_cb->skb_mtype_seqid;
+
if (mtype_seqid == skb_cb->skb_mtype_seqid) {
u64 ns = event->timestamp;


base-commit: a59668a9397e7245b26e9be85d23f242ff757ae8
--
2.17.1



2024-04-25 01:38:54

by Trexel, Ed

[permalink] [raw]
Subject: RE: [PATCH net v2] net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets

From: Ravi Gunasekaran <[email protected]>
Sent: Wednesday, April 24, 2024 1:16 AM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Trexel, Ed <[email protected]>
Subject: [PATCH net v2] net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets

CAUTION: External Email
From: Jason Reeder <mailto:[email protected]>

The CPTS, by design, captures the messageType (Sync, Delay_Req, etc.)
field from the second nibble of the PTP header which is defined in the
PTPv2 (1588-2008) specification. In the PTPv1 (1588-2002) specification
the first two bytes of the PTP header are defined as the versionType
which is always 0x0001. This means that any PTPv1 packets that are
tagged for TX timestamping by the CPTS will have their messageType set
to 0x0 which corresponds to a Sync message type. This causes issues
when a PTPv1 stack is expecting a Delay_Req (messageType: 0x1)
timestamp that never appears.

Fix this by checking if the ptp_class of the timestamped TX packet is
PTP_CLASS_V1 and then matching the PTP sequence ID to the stored
sequence ID in the skb->cb data structure. If the sequence IDs match
and the packet is of type PTPv1 then there is a chance that the
messageType has been incorrectly stored by the CPTS so overwrite the
messageType stored by the CPTS with the messageType from the skb->cb
data structure. This allows the PTPv1 stack to receive TX timestamps
for Delay_Req packets which are necessary to lock onto a PTP Leader.

Fixes: f6bd59526ca5 ("net: ethernet: ti: introduce am654 common platform time sync driver")
Signed-off-by: Jason Reeder <mailto:[email protected]>
Signed-off-by: Ravi Gunasekaran <mailto:[email protected]>
Tested-by: Ed Trexel <[email protected]>
---
Changes since v1:
-----------------
* Added Fixes tag as per Paolo's suggestion
* Rebased to latest tip

v1: https://lore.kernel.org/all/[email protected]

drivers/net/ethernet/ti/am65-cpts.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c
index c66618d91c28..f89716b1cfb6 100644
--- a/drivers/net/ethernet/ti/am65-cpts.c
+++ b/drivers/net/ethernet/ti/am65-cpts.c
@@ -784,6 +784,11 @@ static bool am65_cpts_match_tx_ts(struct am65_cpts *cpts,
struct am65_cpts_skb_cb_data *skb_cb =
(struct am65_cpts_skb_cb_data *)skb->cb;

+ if ((ptp_classify_raw(skb) & PTP_CLASS_V1) &&
+ ((mtype_seqid & AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK) ==
+ (skb_cb->skb_mtype_seqid & AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK)))
+ mtype_seqid = skb_cb->skb_mtype_seqid;
+
if (mtype_seqid == skb_cb->skb_mtype_seqid) {
u64 ns = event->timestamp;


base-commit: a59668a9397e7245b26e9be85d23f242ff757ae8
--
2.17.1


2024-04-25 05:09:48

by Ravi Gunasekaran

[permalink] [raw]
Subject: Re: [PATCH net v2] net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets

Ed,

On 4/25/24 7:06 AM, Trexel, Ed wrote:
> From: Ravi Gunasekaran <[email protected]>
> Sent: Wednesday, April 24, 2024 1:16 AM
> To: [email protected]; [email protected]; [email protected]
> Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Trexel, Ed <[email protected]>
> Subject: [PATCH net v2] net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets
>
> CAUTION: External Email
> From: Jason Reeder <mailto:[email protected]>
>
> The CPTS, by design, captures the messageType (Sync, Delay_Req, etc.)
> field from the second nibble of the PTP header which is defined in the
> PTPv2 (1588-2008) specification. In the PTPv1 (1588-2002) specification
> the first two bytes of the PTP header are defined as the versionType
> which is always 0x0001. This means that any PTPv1 packets that are
> tagged for TX timestamping by the CPTS will have their messageType set
> to 0x0 which corresponds to a Sync message type. This causes issues
> when a PTPv1 stack is expecting a Delay_Req (messageType: 0x1)
> timestamp that never appears.
>
> Fix this by checking if the ptp_class of the timestamped TX packet is
> PTP_CLASS_V1 and then matching the PTP sequence ID to the stored
> sequence ID in the skb->cb data structure. If the sequence IDs match
> and the packet is of type PTPv1 then there is a chance that the
> messageType has been incorrectly stored by the CPTS so overwrite the
> messageType stored by the CPTS with the messageType from the skb->cb
> data structure. This allows the PTPv1 stack to receive TX timestamps
> for Delay_Req packets which are necessary to lock onto a PTP Leader.
>
> Fixes: f6bd59526ca5 ("net: ethernet: ti: introduce am654 common platform time sync driver")
> Signed-off-by: Jason Reeder <mailto:[email protected]>
> Signed-off-by: Ravi Gunasekaran <mailto:[email protected]>
> Tested-by: Ed Trexel <[email protected]>

Seems like your email client is not configured as per guidelines [1].
Also Tested-by reply is not inline with norm.

Once your mail client is configured correctly, could you please reply
with your "Tested-by" tag to the original patch mail?

[1] - https://www.kernel.org/doc/html/v4.10/process/email-clients.html

--
Regards,
Ravi

2024-04-25 16:00:26

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net v2] net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

On Wed, 24 Apr 2024 12:46:26 +0530 you wrote:
> From: Jason Reeder <[email protected]>
>
> The CPTS, by design, captures the messageType (Sync, Delay_Req, etc.)
> field from the second nibble of the PTP header which is defined in the
> PTPv2 (1588-2008) specification. In the PTPv1 (1588-2002) specification
> the first two bytes of the PTP header are defined as the versionType
> which is always 0x0001. This means that any PTPv1 packets that are
> tagged for TX timestamping by the CPTS will have their messageType set
> to 0x0 which corresponds to a Sync message type. This causes issues
> when a PTPv1 stack is expecting a Delay_Req (messageType: 0x1)
> timestamp that never appears.
>
> [...]

Here is the summary with links:
- [net,v2] net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets
https://git.kernel.org/netdev/net/c/1b9e743e923b

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html