Skip to content

Commit f4b5f05

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

File tree

8 files changed

+213
-57
lines changed

8 files changed

+213
-57
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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+
* (default packet action is drop)
95+
*/
96+
SAI_HOSTIF_TRAP_TYPE_PTP_PEER_DELAY = 0x00000015
97+
} sai_hostif_trap_type_t;
98+
```
99+
100+
## 4.0 API Workflow and Example
101+
102+
### 4.1 PTP Time Offset and Syntonization Adjustment
103+
104+
![PTP-DelayReq-DelayResp](slave_offset_master.jpg)
105+
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.
106+
107+
Example:-
108+
A time offset adjustment of 5 seconds and 80,000 nanoseconds is applied in the slave PTP device.
109+
110+
```c
111+
attr_count = 0;
112+
attr_list[attr_count].id = SAI_SWITCH_ATTR_PTP_TIME_OFFSET;
113+
attr_list[attr_count].value.timespec.tv_sec = 5;
114+
attr_list[attr_count++].value.timespec.tv_nsec = 80000;
115+
sai_set_switch_attribute_fn(switch_id, attr_list);
116+
```
117+
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.
118+
119+
Example:-
120+
A syntonization adjustment of 5000 parts per trillion is applied in the slave PTP device.
121+
122+
```c
123+
attr_count = 0;
124+
attr_list[attr_count].id = SAI_SWITCH_ATTR_PTP_SYNTONIZE_ADJUST;
125+
attr_list[attr_count++].value.value.s32 = 5000;
126+
sai_set_switch_attribute_fn(switch_id, attr_list);
127+
```
128+
129+
### 4.3 PTP Peer Mean Path Delay
130+
131+
![PTP-Peer-Delay](p2p_tc.jpg)
132+
133+
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.
134+
135+
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.
136+
137+
Example:-
138+
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.
139+
140+
```c
141+
attr_count = 0;
142+
attr_list[attr_count].id = SAI_PORT_ATTR_PTP_PEER_MEAN_PATH_DELAY;
143+
attr_list[attr_count++].value.u32 = 14000;
144+
sai_set_port_attribute_fn(port_id, attr_list);
145+
```
146+
147+
### 4.4 Hostif Trap for PTP Peer Delay Messages
148+
149+
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.
150+
151+
```c
152+
...
153+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION;
154+
attr_list[attr_count++].value.u32 = SAI_PACKET_ACTION_FORWARD; // Action for non-pdelay PTP pkts in P2P TC
155+
156+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE;
157+
attr_list[attr_count++].value.u32 = SAI_HOSTIF_TRAP_TYPE_PTP;
158+
159+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY;
160+
attr_list[attr_count++].value.u32 = 1; // Lower priority for non-pdelay PTP packets
161+
162+
sai_create_hostif_trap_fn(&ptp_trap_id, switch_id, attr_count, attr_list);
163+
164+
...
165+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION;
166+
attr_list[attr_count++].value.u32 = SAI_PACKET_ACTION_TRAP; // Action for pdelay PTP pkts in P2P TC
167+
168+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE;
169+
attr_list[attr_count++].value.u32 = SAI_HOSTIF_TRAP_TYPE_PTP_PEER_DELAY;
170+
171+
attr_list[attr_count].id = SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY;
172+
attr_list[attr_count++].value.u32 = 2; // Higher priority for pdelay PTP packets
173+
174+
sai_create_hostif_trap_fn(&ptp_peer_trap_id, switch_id, attr_count, attr_list);
175+
```
176+
177+
## 5.0 References
178+
IEEE 1588-2008 Standard for a Precision Clock Synchronization Protocol for Networked Measurement and Control Systems
179+
180+
## 6.0 Warmboot Implications
181+
None
182+

doc/PTP/p2p_tc.jpg

117 KB
Loading

doc/PTP/slave_offset_master.jpg

67.1 KB
Loading

inc/saihostif.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ 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+
* (default packet action is drop)
266+
*/
267+
SAI_HOSTIF_TRAP_TYPE_PTP_PEER_DELAY = 0x00000015,
268+
261269
/** Switch traps custom range start */
262270
SAI_HOSTIF_TRAP_TYPE_SWITCH_CUSTOM_RANGE_BASE = 0x00001000,
263271

inc/saiport.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,23 +2713,16 @@ typedef enum _sai_port_attr_t
27132713
SAI_PORT_ATTR_PAM4_EYE_VALUES,
27142714

27152715
/**
2716-
* @brief Enables the fast link-up for a port on port/link recovery. Vendors can use to reduce linkup time on remote link failure
2716+
* @brief One-way (From port to neighbor) link propagation delay in nanoseconds
27172717
*
2718-
* @type bool
2719-
* @flags CREATE_AND_SET
2720-
* @default false
2721-
*/
2722-
SAI_PORT_ATTR_FAST_LINKUP_ENABLED,
2723-
2724-
/**
2725-
* @brief Get port SerDes firmware revision
2718+
* Device adds this value to PTP header correction-field along with residence time
2719+
* in Peer Delay Mechanism in Peer-to-Peer TC.
27262720
*
2727-
* Standard attribute to collect port SerDes firmware rev.
2728-
*
2729-
* @type sai_s8_list_t
2730-
* @flags READ_ONLY
2721+
* @type sai_uint32_t
2722+
* @flags CREATE_AND_SET
2723+
* @default 0
27312724
*/
2732-
SAI_PORT_ATTR_SERDES_FW_REVISION,
2725+
SAI_PORT_ATTR_PTP_PEER_MEAN_PATH_DELAY,
27332726

27342727
/**
27352728
* @brief End of attributes

inc/saiswitch.h

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,57 +3469,25 @@ typedef enum _sai_switch_attr_t
34693469
SAI_SWITCH_ATTR_NEXT_HOP_USER_META_DATA_RANGE,
34703470

34713471
/**
3472-
* @brief Linkup polling time range (in secs)
3472+
* @brief Time correction offset from epoch applied by NOS on system
3473+
* clock to sync with master clock
34733474
*
3474-
* @type sai_u16_range_t
3475-
* @flags READ_ONLY
3476-
*/
3477-
SAI_SWITCH_ATTR_FAST_LINKUP_POLLING_TIMEOUT_RANGE,
3478-
3479-
/**
3480-
* @brief Time (in sec) during which the fast link-up is attempted.
3481-
*
3482-
* If this timer expires before the link is UP the regular link-up will be performed
3483-
* Supported range can be obtained using SAI_SWITCH_ATTR_FAST_LINKUP_POLLING_TIMEOUT_RANGE
3484-
*
3485-
* @type sai_uint16_t
3475+
* @type sai_timespec_t
34863476
* @flags CREATE_AND_SET
3487-
* @isvlan false
3488-
* @default 60
3489-
*/
3490-
SAI_SWITCH_ATTR_FAST_LINKUP_POLLING_TIMEOUT,
3491-
3492-
/**
3493-
* @brief Linkup guard time range (in secs)
3494-
*
3495-
* @type sai_u16_range_t
3496-
* @flags READ_ONLY
3497-
*/
3498-
SAI_SWITCH_ATTR_FAST_LINKUP_GUARD_TIMEOUT_RANGE,
3499-
3500-
/**
3501-
* @brief Time (in secs) during which the link must be UP with the BER below the level configured with SAI_SWITCH_ATTR_FAST_LINKUP_BER_THRESHOLD to keep the fast link-up configuration.
3502-
*
3503-
* If either link failures happens within this time or high BER is measured at the end of this period of time the link should undergo regular link up process
3504-
* Supported range can be obtained using SAI_SWITCH_ATTR_FAST_LINKUP_GUARD_TIMEOUT_RANGE
3505-
*
3506-
* @type sai_uint8_t
3507-
* @flags CREATE_AND_SET
3508-
* @default 10
3477+
* @default 0
35093478
*/
3510-
SAI_SWITCH_ATTR_FAST_LINKUP_GUARD_TIMEOUT,
3479+
SAI_SWITCH_ATTR_PTP_TIME_OFFSET,
35113480

35123481
/**
3513-
* @brief Threshold to control regular link-up happened after fast linkup Time-out
3514-
*
3515-
* Configures the BER (negative exponent only, mantissa is always 1) which is if measured during
3516-
* SAI_SWITCH_ATTR_FAST_LINKUP_GUARD_TIMEOUT causes the full link-up flow. For example, value 12 configured here is 1e^-12
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
35173485
*
3518-
* @type sai_uint8_t
3486+
* @type sai_int32_t
35193487
* @flags CREATE_AND_SET
3520-
* @default 12
3488+
* @default 0
35213489
*/
3522-
SAI_SWITCH_ATTR_FAST_LINKUP_BER_THRESHOLD,
3490+
SAI_SWITCH_ATTR_PTP_SYNTONIZE_ADJUST,
35233491

35243492
/**
35253493
* @brief End of attributes

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)