Skip to content

Commit b922694

Browse files
SAI PTP Enhancements
Signed-off-by: Archisman Maitra <[email protected]>
1 parent f56f534 commit b922694

File tree

8 files changed

+230
-0
lines changed

8 files changed

+230
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# SAI PTP enhancement
2+
-------------------------------------------------------------------------------
3+
Title | SAI PTP Enhancement
4+
-------------|-----------------------------------------------------------------
5+
Authors | Archisman Maitra, Sree Shankar S, Ravindranath C K (Marvell)
6+
Status | In review
7+
Type | Standards track
8+
Created | 2025-09-11
9+
SAI-Version | 1.18
10+
-------------------------------------------------------------------------------
11+
12+
13+
## 1.0 Introduction
14+
15+
This proposal enhances the current PTP support in SAI.
16+
17+
## 2.0 Overview
18+
19+
### 2.1 Clocks managed by SAI
20+
21+
PTP enabled devices are organized into a master−slave synchronization hierarchy with the clock at the top of the hierarchy (the grandmaster clock) determining the reference time for the entire system. SAI can configure timestamp mode (one-step/two-step) per port/switch with abstracted clock source. As part of PTP protocol, the slave computes the offset from the master. Today, this offset correction/frequency adjustment is not done via SAI. New SAI attributes are provided to program local clock (e.g. on-chip oscillator driving a PTP Hardware Clock (PHC) within the ASIC) of a PTP slave device when the clock is managed by SAI.
22+
23+
**1. PTP Time Offset Adjustment**: This provides the functionality to apply time offset between master and slave device (PTP device is configured as non transparent clock) and should be applied in the slave device.
24+
25+
**2. PTP Syntonization Adjustment**: This provides the functionality to apply frequency rate adjustments for slave clocks to match the master clock frequency (PTP device is configured as non transparent clock) preventing drift over time. This should be applied in the slave device.
26+
27+
### 2.2 Peer-to-Peer transparent clock support
28+
29+
Today SAI lacks support for Peer-to-Peer transparent clock.
30+
31+
**1. PTP Peer Mean Path Delay**: This attribute allows application to configure one-way link propagation delay (in nanoseconds) from a port. The device uses this attribute value to adjust correction field in PTP event messages (e.g., Sync messages) to account for peer delay along with residence time.
32+
33+
**2: Hostif Trap for PTP Peer Delay Messages**: This trap facilitates handling of Pdelay messages independent of other PTP messages. Non-Pdelay PTP messages should be forwarded, while Pdelay messages should terminate at the Peer-to-Peer Transparent Clock.
34+
35+
## 3.0 SAI Spec Enhancement
36+
37+
**New attributes defined for setting ptp time offset and ptp syntonize adjust**
38+
39+
saiswitch.h
40+
```c
41+
typedef enum _sai_switch_attr_t
42+
{
43+
/**
44+
* @brief Time correction offset from epoch applied by NOS on system
45+
* clock to sync with master clock
46+
*
47+
* @type sai_timespec_t
48+
* @flags CREATE_AND_SET
49+
* @default 0
50+
*/
51+
SAI_SWITCH_ATTR_PTP_TIME_OFFSET,
52+
53+
/**
54+
* @brief Used by NOS to program the delta value that needs to be
55+
* added to existing clock frequency.
56+
* Unit is Parts Per Trillion
57+
*
58+
* @type sai_int32_t
59+
* @flags CREATE_AND_SET
60+
* @default 0
61+
*/
62+
SAI_SWITCH_ATTR_PTP_SYNTONIZE_ADJUST,
63+
} sai_switch_attr_t;
64+
```
65+
**New attribute defined for setting ptp peer mean path delay**
66+
67+
saiport.h
68+
```c
69+
typedef enum _sai_port_attr_t
70+
{
71+
/**
72+
* @brief One-way (From port to neighbor) link propagation delay in nanoseconds
73+
*
74+
* Device adds this value to PTP header correction-field along with residence time
75+
* in Peer Delay Mechanism in Peer-to-Peer TC.
76+
*
77+
* @type sai_uint32_t
78+
* @flags CREATE_AND_SET
79+
* @default 0
80+
*/
81+
SAI_PORT_ATTR_PTP_PEER_MEAN_PATH_DELAY
82+
} sai_port_attr_t;
83+
```
84+
**New attribute defined for trapping ptp peerdelay packets**
85+
86+
saihostif.h
87+
```c
88+
typedef enum _sai_hostif_trap_type_t
89+
{
90+
/**
91+
* @brief Peer Delay PTP traffic.
92+
* ((EtherType == 0x88F7 or UDP dst port == 319 or UDP dst port == 320)
93+
* and (PTP messageType == 0x2 or PTP messageType == 0x3 or PTP messageType == 0x10))
94+
* Recommended priority: Higher than SAI_HOSTIF_TRAP_TYPE_PTP
95+
* (default packet action is drop)
96+
*/
97+
SAI_HOSTIF_TRAP_TYPE_PTP_PEER_DELAY
98+
} sai_hostif_trap_type_t;
99+
```
100+
101+
## 4.0 API Workflow and Example
102+
103+
### 4.1 PTP Time Offset and Syntonization Adjustment
104+
105+
![PTP-DelayReq-DelayResp](slave_offset_master.jpg)
106+
The diagram above shows PTP control message exchanges (one step timestamping) between a master and slave device using the delay request-response mechanism. After the control messages are exchanged, slave NOS can compute the clock offset from master and configure SAI_SWITCH_ATTR_PTP_TIME_OFFSET to synchronize the slave device clock with master.
107+
108+
Example:-
109+
A time offset adjustment of 5 seconds and 80,000 nanoseconds is applied in the slave PTP device.
110+
111+
```c
112+
attr_count = 0;
113+
attr_list[attr_count].id = SAI_SWITCH_ATTR_PTP_TIME_OFFSET;
114+
attr_list[attr_count].value.timespec.tv_sec = 5;
115+
attr_list[attr_count++].value.timespec.tv_nsec = 80000;
116+
sai_set_switch_attribute_fn(switch_id, attr_list);
117+
```
118+
The slave clock may tick at a different rate than the master, resulting in time drift. Slave NOS can compute the frequency factor to align with the frequency of master clock and configure SAI_SWITCH_ATTR_PTP_SYNTONIZE_ADJUST to syntonize the slave clock with master.
119+
120+
Example:-
121+
A syntonization adjustment of 5000 parts per trillion is applied in the slave PTP device.
122+
123+
```c
124+
attr_count = 0;
125+
attr_list[attr_count].id = SAI_SWITCH_ATTR_PTP_SYNTONIZE_ADJUST;
126+
attr_list[attr_count++].value.value.s32 = 5000;
127+
sai_set_switch_attribute_fn(switch_id, attr_list);
128+
```
129+
130+
### 4.3 PTP Peer Mean Path Delay
131+
132+
![PTP-Peer-Delay](p2p_tc.jpg)
133+
134+
The diagram above illustrates the exchange of PTP control messages (using one-step timestamping) between a master and a slave device, with a Peer-to-Peer Transparent Clock (P2PTC) acting as an intermediary. This setup uses the peer delay mechanism. The P2PTC NOS calculates the peer mean path delay for each port by exchanging peer delay messages with its immediate neighbor. Once computed, this delay is configured on the port using the SAI_PORT_ATTR_PTP_PEER_MEAN_PATH_DELAY attribute.
135+
136+
Subsequently, the NPU adds both the configured peer mean path delay and the residence time to the correction field of the PTP header for event messages (such as Sync and Delay_Req) that are forwarded through the port.
137+
138+
Example:-
139+
PTP peer mean path delay of 14000 nsec is applied to the port for PTP device configured as peer to peer transparent clock. For all PTP event messages received on this port, this peer mean path delay will be added along with the residence time in the correction field of the PTP header.
140+
141+
```c
142+
attr_count = 0;
143+
attr_list[attr_count].id = SAI_PORT_ATTR_PTP_PEER_MEAN_PATH_DELAY;
144+
attr_list[attr_count++].value.u32 = 14000;
145+
sai_set_port_attribute_fn(port_id, attr_list);
146+
```
147+
148+
### 4.4 Hostif Trap for PTP Peer Delay Messages
149+
150+
For Peer-to-peer transparent clock, peer delay PTP packets are terminated at the device and non-peer delay PTP packets are forwarded. The P2PTC NOS should configure SAI_HOSTIF_TRAP_TYPE_PTP_PEER_DELAY with the action set to TRAP with higher priority than SAI_HOSTIF_TRAP_TYPE_PTP with the action set as FORWARD to facilitate this behavior.
151+
152+
```c
153+
...
154+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION;
155+
attr_list[attr_count++].value.u32 = SAI_PACKET_ACTION_FORWARD; // Action for non-pdelay PTP pkts in P2P TC
156+
157+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE;
158+
attr_list[attr_count++].value.u32 = SAI_HOSTIF_TRAP_TYPE_PTP;
159+
160+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY;
161+
attr_list[attr_count++].value.u32 = 1; // Lower priority for non-pdelay PTP packets
162+
163+
sai_create_hostif_trap_fn(&ptp_trap_id, switch_id, attr_count, attr_list);
164+
165+
...
166+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION;
167+
attr_list[attr_count++].value.u32 = SAI_PACKET_ACTION_TRAP; // Action for pdelay PTP pkts in P2P TC
168+
169+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE;
170+
attr_list[attr_count++].value.u32 = SAI_HOSTIF_TRAP_TYPE_PTP_PEER_DELAY;
171+
172+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY;
173+
attr_list[attr_count++].value.u32 = 2; // Higher priority for pdelay PTP packets
174+
175+
sai_create_hostif_trap_fn(&ptp_peer_trap_id, switch_id, attr_count, attr_list);
176+
```
177+
178+
## 5.0 References
179+
IEEE 1588-2008 Standard for a Precision Clock Synchronization Protocol for Networked Measurement and Control Systems
180+
181+
## 6.0 Warmboot Implications
182+
None
183+

doc/PTP/p2p_tc.jpg

117 KB
Loading

doc/PTP/slave_offset_master.jpg

67.1 KB
Loading

inc/saihostif.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ typedef enum _sai_hostif_trap_type_t
258258
*/
259259
SAI_HOSTIF_TRAP_TYPE_ESMC = 0x00000014,
260260

261+
/**
262+
* @brief Peer Delay PTP traffic.
263+
* ((EtherType == 0x88F7 or UDP dst port == 319 or UDP dst port == 320)
264+
* and (PTP messageType == 0x2 or PTP messageType == 0x3 or PTP messageType == 0x10))
265+
* Recommended priority: Higher than SAI_HOSTIF_TRAP_TYPE_PTP
266+
* (default packet action is drop)
267+
*/
268+
SAI_HOSTIF_TRAP_TYPE_PTP_PEER_DELAY,
269+
261270
/** Switch traps custom range start */
262271
SAI_HOSTIF_TRAP_TYPE_SWITCH_CUSTOM_RANGE_BASE = 0x00001000,
263272

inc/saiport.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,18 @@ typedef enum _sai_port_attr_t
27122712
*/
27132713
SAI_PORT_ATTR_PAM4_EYE_VALUES,
27142714

2715+
/**
2716+
* @brief One-way (From port to neighbor) link propagation delay in nanoseconds
2717+
*
2718+
* Device adds this value to PTP header correction-field along with residence time
2719+
* in Peer Delay Mechanism in Peer-to-Peer TC.
2720+
*
2721+
* @type sai_uint32_t
2722+
* @flags CREATE_AND_SET
2723+
* @default 0
2724+
*/
2725+
SAI_PORT_ATTR_PTP_PEER_MEAN_PATH_DELAY,
2726+
27152727
/**
27162728
* @brief End of attributes
27172729
*/

inc/saiswitch.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,6 +3468,27 @@ typedef enum _sai_switch_attr_t
34683468
*/
34693469
SAI_SWITCH_ATTR_NEXT_HOP_USER_META_DATA_RANGE,
34703470

3471+
/**
3472+
* @brief Time correction offset from epoch applied by NOS on system
3473+
* clock to sync with master clock
3474+
*
3475+
* @type sai_timespec_t
3476+
* @flags CREATE_AND_SET
3477+
* @default 0
3478+
*/
3479+
SAI_SWITCH_ATTR_PTP_TIME_OFFSET,
3480+
3481+
/**
3482+
* @brief Used by NOS to program the delta value that needs to be
3483+
* added to existing clock frequency.
3484+
* Unit is Parts Per Trillion
3485+
*
3486+
* @type sai_int32_t
3487+
* @flags CREATE_AND_SET
3488+
* @default 0
3489+
*/
3490+
SAI_SWITCH_ATTR_PTP_SYNTONIZE_ADJUST,
3491+
34713492
/**
34723493
* @brief End of attributes
34733494
*/

meta/aspell.en.pws

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ MCAST
111111
md
112112
Mellanox
113113
MERCHANTABILITY
114+
messageType
114115
metadata
115116
Metadata
116117
microburst

meta/parse.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,10 @@ sub ProcessDefaultValue
17461746
{
17471747
WriteSource "$val = { .mac = { 0, 0, 0, 0, 0, 0 } };";
17481748
}
1749+
elsif ($default =~ /^0$/ and $type =~ /^(sai_timespec_t)/)
1750+
{
1751+
WriteSource "$val = { 0 };";
1752+
}
17491753
else
17501754
{
17511755
LogError "invalid default value '$default' on $attr ($type)";

0 commit comments

Comments
 (0)