DPDK 26.07.0-rc1
rte_ptp.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2026 Intel Corporation
3 */
4
5#ifndef _RTE_PTP_H_
6#define _RTE_PTP_H_
7
14#include <stdint.h>
15#include <stdbool.h>
16
17#include <rte_byteorder.h>
18#include <rte_common.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/*
25 * PTP Constants
26 */
27
29#define RTE_IPPORT_PTP_EVENT 319
30
32#define RTE_IPPORT_PTP_GENERAL 320
33
35#define RTE_ETHER_ADDR_PTP_MULTICAST { 0x01, 0x1B, 0x19, 0x00, 0x00, 0x00 }
36
38#define RTE_ETHER_ADDR_PTP_MULTICAST_PDELAY { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E }
39
40/*
41 * PTP Message Types (IEEE 1588-2019 Table 36)
42 */
43
44#define RTE_PTP_MSGTYPE_SYNC 0x0
45#define RTE_PTP_MSGTYPE_DELAY_REQ 0x1
46#define RTE_PTP_MSGTYPE_PDELAY_REQ 0x2
47#define RTE_PTP_MSGTYPE_PDELAY_RESP 0x3
48#define RTE_PTP_MSGTYPE_FU 0x8
49#define RTE_PTP_MSGTYPE_DELAY_RESP 0x9
50#define RTE_PTP_MSGTYPE_PDELAY_RESP_FU 0xA
51#define RTE_PTP_MSGTYPE_ANNOUNCE 0xB
52#define RTE_PTP_MSGTYPE_SIGNALING 0xC
53#define RTE_PTP_MSGTYPE_MANAGEMENT 0xD
55/*
56 * PTP Flag Field Bits (IEEE 1588-2019 Table 37)
57 *
58 * These constants are for use after rte_be_to_cpu_16(hdr->flags).
59 * flagField[0] (octet 6) maps to host bits 8-15.
60 * flagField[1] (octet 7) maps to host bits 0-7.
61 */
62
63#define RTE_PTP_FLAG_TWO_STEP (UINT16_C(1) << 9)
64#define RTE_PTP_FLAG_UNICAST (UINT16_C(1) << 10)
65#define RTE_PTP_FLAG_LI_61 (UINT16_C(1) << 0)
66#define RTE_PTP_FLAG_LI_59 (UINT16_C(1) << 1)
68/*
69 * PTP Header Structures (IEEE 1588-2019)
70 */
71
76 uint8_t clock_id[8];
78} __rte_packed_end;
79
84 __extension__
85 union {
86 uint8_t ts_msgtype;
87 struct {
88#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
89 uint8_t msg_type:4;
90 uint8_t ts:4;
91#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
92 uint8_t ts:4;
93 uint8_t msg_type:4;
94#endif
95 };
96 };
97 __extension__
98 union {
99 uint8_t ver;
100 struct {
101#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
102 uint8_t version:4;
103 uint8_t minor_version:4;
104#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
105 uint8_t minor_version:4;
106 uint8_t version:4;
107#endif
108 };
109 };
112 uint8_t minor_sdo_id;
116 struct rte_ptp_port_id source_port_id;
118 uint8_t control;
120} __rte_packed_end;
121
130} __rte_packed_end;
131
132/*
133 * Inline Helpers
134 */
135
145static inline bool
147{
149}
150
159static inline bool
161{
162 return (hdr->flags & RTE_BE16(RTE_PTP_FLAG_TWO_STEP)) != 0;
163}
164
175static inline void
176rte_ptp_add_correction(struct rte_ptp_hdr *hdr, uint64_t residence_ns)
177{
178 uint64_t cf = rte_be_to_cpu_64(hdr->correction);
179
180 cf += residence_ns << 16;
181 hdr->correction = rte_cpu_to_be_64(cf);
182}
183
192static inline uint64_t
194{
195 uint64_t sec = ((uint64_t)rte_be_to_cpu_16(ts->seconds_hi) << 32) |
197
198 return sec * UINT64_C(1000000000) + rte_be_to_cpu_32(ts->nanoseconds);
199}
200
201#ifdef __cplusplus
202}
203#endif
204
205#endif /* _RTE_PTP_H_ */
static uint16_t rte_be_to_cpu_16(rte_be16_t x)
static uint32_t rte_be_to_cpu_32(rte_be32_t x)
static uint64_t rte_be_to_cpu_64(rte_be64_t x)
uint32_t rte_be32_t
uint64_t rte_be64_t
static rte_be64_t rte_cpu_to_be_64(uint64_t x)
uint16_t rte_be16_t
#define __rte_packed_begin
Definition: rte_common.h:158
static uint64_t rte_ptp_timestamp_to_ns(const struct rte_ptp_timestamp *ts)
Definition: rte_ptp.h:193
static void rte_ptp_add_correction(struct rte_ptp_hdr *hdr, uint64_t residence_ns)
Definition: rte_ptp.h:176
#define RTE_PTP_MSGTYPE_PDELAY_RESP
Definition: rte_ptp.h:47
static bool rte_ptp_is_two_step(const struct rte_ptp_hdr *hdr)
Definition: rte_ptp.h:160
static bool rte_ptp_is_event(const struct rte_ptp_hdr *hdr)
Definition: rte_ptp.h:146
#define RTE_PTP_FLAG_TWO_STEP
Definition: rte_ptp.h:63
rte_be16_t flags
Definition: rte_ptp.h:113
int8_t log_msg_interval
Definition: rte_ptp.h:119
uint8_t minor_version
Definition: rte_ptp.h:103
rte_be32_t msg_type_specific
Definition: rte_ptp.h:115
uint8_t minor_sdo_id
Definition: rte_ptp.h:112
rte_be16_t msg_length
Definition: rte_ptp.h:110
uint8_t domain_number
Definition: rte_ptp.h:111
uint8_t version
Definition: rte_ptp.h:102
rte_be16_t sequence_id
Definition: rte_ptp.h:117
uint8_t ts
Definition: rte_ptp.h:90
uint8_t ts_msgtype
Definition: rte_ptp.h:86
uint8_t ver
Definition: rte_ptp.h:99
uint8_t control
Definition: rte_ptp.h:118
rte_be64_t correction
Definition: rte_ptp.h:114
uint8_t msg_type
Definition: rte_ptp.h:89
rte_be16_t port_number
Definition: rte_ptp.h:77
rte_be32_t nanoseconds
Definition: rte_ptp.h:129
rte_be32_t seconds_lo
Definition: rte_ptp.h:128
rte_be16_t seconds_hi
Definition: rte_ptp.h:127