Skip to content

Commit

Permalink
Merge branch 'v3_7'
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Sep 13, 2024
2 parents 7c04487 + 5ed04f1 commit bbb6456
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/ptp/ptpd2/datatypes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/* (c) Copyright 2012-2023 Advanced Micro Devices, Inc. */
/* (c) Copyright 2012-2024 Advanced Micro Devices, Inc. */
/* (c) Copyright ptpd2 contributors (see PTPD_COPYRIGHT) */

#ifndef DATATYPES_H_
Expand Down Expand Up @@ -66,6 +66,7 @@ typedef struct {
sfptpd_time_t offset;
bool have_timestamp;
bool have_offset;
bool two_step;
UInteger16 seq;
} ForeignSyncSnapshot;

Expand Down Expand Up @@ -95,6 +96,7 @@ typedef struct

/* Snapshot of Sync for use with discriminator */
ForeignSyncSnapshot syncSnapshot;
ForeignSyncSnapshot nextSyncSnapshot;
} ForeignMasterRecord;

typedef struct {
Expand Down
36 changes: 22 additions & 14 deletions src/ptp/ptpd2/foreign.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*-
* Copyright (c) 2024 Advanced Micro Devices, Inc.
* Copyright (c) 2019 Xilinx, Inc.
* Copyright (c) 2014-2018 Solarflare Communications Inc.
* Copyright (c) 2013 Harlan Stenn,
Expand Down Expand Up @@ -352,7 +353,10 @@ calculateForeignOffset(ForeignSyncSnapshot *syncSnapshot, const Timestamp *syncO
for record->announceTimesCount in order to decide whether to return a
result or not.
*/
struct sfptpd_timespec foreign_offset; /* foreign_offset holds the result. */

struct sfptpd_timespec foreign_offset;
/* foreign_offset holds the result. */

struct sfptpd_timespec local_time;
/* local_time will hold the local timestamp from the NIC that has already
had the applyUtcOffset function called on it.
Expand Down Expand Up @@ -381,8 +385,7 @@ calculateForeignOffset(ForeignSyncSnapshot *syncSnapshot, const Timestamp *syncO
before it has had the applyUtcOffset function called on it.
This approach was considered cleaner as it keeps the special code for this
feature in as few places as possible.
*/
feature in as few places as possible. */

assert(syncSnapshot != NULL);
assert(syncOriginTimestamp != NULL);
Expand Down Expand Up @@ -418,20 +421,21 @@ recordForeignSync(const MsgHeader *header, PtpClock *ptpClock, const struct sfpt
if (ptpClock->discriminator_valid) {
ForeignMasterRecord *record = findForeignMasterRecord(header, &ptpClock->foreign);
if (record) {
ForeignSyncSnapshot *snapshot = &record->syncSnapshot;
ForeignSyncSnapshot *snapshot = &record->nextSyncSnapshot;

snapshot->have_timestamp = true;
snapshot->seq = header->sequenceId;
snapshot->timestamp = *timestamp;
*snapshot = (ForeignSyncSnapshot) {
.have_timestamp = true,
.timestamp = *timestamp,
.seq = header->sequenceId,
.two_step = header->flagField0 & PTPD_FLAG_TWO_STEP,
};

if ((header->flagField0 & PTPD_FLAG_TWO_STEP) == 0) {
if (!snapshot->two_step) {
calculateForeignOffset(snapshot,
&ptpClock->interface->msgTmp.sync.originTimestamp,
record,
ptpClock);

} else {
snapshot->have_offset = false;
record->syncSnapshot = *snapshot;
}
}
}
Expand All @@ -444,15 +448,19 @@ recordForeignFollowUp(const MsgHeader *header, PtpClock *ptpClock, const MsgFoll
if (ptpClock->discriminator_valid) {
ForeignMasterRecord *record = findForeignMasterRecord(header, &ptpClock->foreign);
if (record) {
ForeignSyncSnapshot *snapshot = &record->syncSnapshot;
ForeignSyncSnapshot *snapshot = &record->nextSyncSnapshot;

if (header->sequenceId == snapshot->seq) {
if (snapshot->two_step &&
!snapshot->have_offset &&
header->sequenceId == snapshot->seq) {
calculateForeignOffset(snapshot,
&payload->preciseOriginTimestamp,
record,
ptpClock);
record->syncSnapshot = *snapshot;
} else {
/* Invalidate snapshot if sequence ID of FollowUp does not match Sync */
/* Invalidate pending snapshot if sequence ID of FollowUp
* does not match Sync */
snapshot->have_timestamp = false;
snapshot->have_offset = false;
}
Expand Down

0 comments on commit bbb6456

Please sign in to comment.