Skip to content

Commit d682bbc

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

18 files changed

+472
-11
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

doc/SAI-Proposal-Fast-Linkup.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Fast Link-Up
2+
-------------------------------------------------------------------------------
3+
Title | Fast Link-Up
4+
-------------|-----------------------------------------------------------------
5+
Authors | Eddy Kvetny, Nvidia
6+
Status | In review
7+
Type | Standards track
8+
Created | 2025-09-09
9+
SAI-Version | 1.17
10+
-------------------------------------------------------------------------------
11+
12+
# 1. Overview
13+
In some cases the equalization parameters from the previous session can be used for a new link-up process. It can significantly reduce time of the Link-Up process
14+
15+
# 2. Scope
16+
This approach is applicable to devices (switch-to-switch or switch-to-NIC) supporting this process, usually from the same vendor or from different vendors aligned on the process.
17+
18+
Can be applied to cold/fast boot or link recovery flows (vendor decision)
19+
20+
# 3. Architecture
21+
This feature shall be enabled per-port using a new SAI attribute - SAI_PORT_ATTR_FAST_LINKUP_ENABLED (default status - disabled/false)
22+
23+
On ports with the enabled feature the ASIC FW shall try first to bring a link up using the equalization parameter stored from the previous successul session. The time given to ASIC to try to bring a link up with the old EQ parameters is limited by the Fast Link-Up Polling Timer. The time value is configured using a new SAI attribute - SAI_SWITCH_ATTR_FAST_LINKUP_POLLING_TIMEOUT. The supported range for this value (in secs) can be read by NOS using a new SAI attribute SAI_SWITCH_ATTR_FAST_LINKUP_POLLING_TIMEOUT_RANGE
24+
25+
If the process of brining a link up with the previosly used EQ parameters doesn't succeed the regular link-up process is triggered
26+
27+
If the link succeeds moving to the Operation UP state then the BER level shall be checked to make sure that the establish link has a good quality. To do that another timer called Guard Timer is used. Its value is also configurable using a new SAI attribute (SAI_SWITCH_ATTR_FAST_LINKUP_GUARD_TIMEOUT)
28+
29+
30+
When the Guard Timer expires the BER is measured and compared with the "good" BER value configured using a new SAI attribure SAI_SWITCH_ATTR_FAST_LINKUP_BER_THRESHOLD. Only if the measured BER is equal or better than the configured BER threshold the process is considered completed. Otherwise, the fallback to the regular link-up process is done and link's Oper status changes to DOWN
31+
32+
If the remote side doesn't support the Fast Link-up then the fallback to regular process will happen
33+
34+
Note that the State Machine is implemented by ASIC FW and can vary between vendors. The proposal just defines just high level flow and SAI configuration for this flow
35+
36+
The following State Machine is proposed for the Fast Link-UP process described above
37+
38+
![](figures/sai_fast_linkup_state_machine.png)

doc/SAI-Proposal-Packet-Trimming.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,15 @@ typedef enum _sai_packet_trim_dscp_resolution_mode_t
212212
*/
213213
SAI_SWITCH_ATTR_PACKET_TRIM_DSCP_RESOLUTION_MODE,
214214
```
215+
216+
## Counter
217+
|Header file|SAI attribute|Description|
218+
|-----------|-------------|-----------|
219+
|saiswitch.h|SAI_SWITCH_STAT_DROPPED_TRIM_PACKETS|Global counter (aggregated value of all ports) of packets trimmed but dropped due to failed shared buffer admission on a trim queue|
220+
| |SAI_SWITCH_STAT_TX_TRIM_PACKETS|Global counter (aggregated value of all ports) of packets trimmed and successfully sent via a trim queue|
221+
|saiport.h |SAI_PORT_STAT_TRIM_PACKETS|Per-port counter of packets trimmed due to failed shared buffer admission|
222+
| |SAI_PORT_STAT_DROPPED_TRIM_PACKETS|Per-port counter of packets trimmed but dropped due to failed shared buffer admission on a trim queue|
223+
| |SAI_PORT_STAT_TX_TRIM_PACKETS|Per-port counter of packets trimmed and successfully sent via a trim queue|
224+
|saiqueue.h |SAI_QUEUE_STAT_TRIM_PACKETS|Per-queue counter of packets trimmed on trimming-eligible queue due to failed shared buffer admission|
225+
| |SAI_QUEUE_STAT_DROPPED_TRIM_PACKETS|Per-queue counter of packets trimmed on trimming-eligible queue but dropped due to failed shared buffer admission on a trim queue|
226+
| |SAI_QUEUE_STAT_TX_TRIM_PACKETS|Per-queue counter of packets trimmed on trimming-eligible queue and successfully sent via a trim queue|
80.8 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

0 commit comments

Comments
 (0)