1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Userspace API for hardware time stamping of network packets
4 *
5 * Copyright (C) 2008,2009 Intel Corporation
6 * Author: Patrick Ohly <patrick.ohly@intel.com>
7 *
8 */
9
10#ifndef _NET_TIMESTAMPING_H
11#define _NET_TIMESTAMPING_H
12
13#include <linux/types.h>
14#include <linux/socket.h> /* for SO_TIMESTAMPING */
15
16/* SO_TIMESTAMPING flags */
17enum {
18 SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
19 SOF_TIMESTAMPING_TX_SOFTWARE = (1<<1),
20 SOF_TIMESTAMPING_RX_HARDWARE = (1<<2),
21 SOF_TIMESTAMPING_RX_SOFTWARE = (1<<3),
22 SOF_TIMESTAMPING_SOFTWARE = (1<<4),
23 SOF_TIMESTAMPING_SYS_HARDWARE = (1<<5),
24 SOF_TIMESTAMPING_RAW_HARDWARE = (1<<6),
25 SOF_TIMESTAMPING_OPT_ID = (1<<7),
26 SOF_TIMESTAMPING_TX_SCHED = (1<<8),
27 SOF_TIMESTAMPING_TX_ACK = (1<<9),
28 SOF_TIMESTAMPING_OPT_CMSG = (1<<10),
29 SOF_TIMESTAMPING_OPT_TSONLY = (1<<11),
30 SOF_TIMESTAMPING_OPT_STATS = (1<<12),
31 SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13),
32 SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14),
33 SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
34 SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16),
35
36 SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_ID_TCP,
37 SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
38 SOF_TIMESTAMPING_LAST
39};
40
41/*
42 * SO_TIMESTAMPING flags are either for recording a packet timestamp or for
43 * reporting the timestamp to user space.
44 * Recording flags can be set both via socket options and control messages.
45 */
46#define SOF_TIMESTAMPING_TX_RECORD_MASK (SOF_TIMESTAMPING_TX_HARDWARE | \
47 SOF_TIMESTAMPING_TX_SOFTWARE | \
48 SOF_TIMESTAMPING_TX_SCHED | \
49 SOF_TIMESTAMPING_TX_ACK)
50
51/**
52 * struct so_timestamping - SO_TIMESTAMPING parameter
53 *
54 * @flags: SO_TIMESTAMPING flags
55 * @bind_phc: Index of PTP virtual clock bound to sock. This is available
56 * if flag SOF_TIMESTAMPING_BIND_PHC is set.
57 */
58struct so_timestamping {
59 int flags;
60 int bind_phc;
61};
62
63/**
64 * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
65 *
66 * @flags: one of HWTSTAMP_FLAG_*
67 * @tx_type: one of HWTSTAMP_TX_*
68 * @rx_filter: one of HWTSTAMP_FILTER_*
69 *
70 * %SIOCGHWTSTAMP and %SIOCSHWTSTAMP expect a &struct ifreq with a
71 * ifr_data pointer to this structure. For %SIOCSHWTSTAMP, if the
72 * driver or hardware does not support the requested @rx_filter value,
73 * the driver may use a more general filter mode. In this case
74 * @rx_filter will indicate the actual mode on return.
75 */
76struct hwtstamp_config {
77 int flags;
78 int tx_type;
79 int rx_filter;
80};
81
82/* possible values for hwtstamp_config->flags */
83enum hwtstamp_flags {
84 /*
85 * With this flag, the user could get bond active interface's
86 * PHC index. Note this PHC index is not stable as when there
87 * is a failover, the bond active interface will be changed, so
88 * will be the PHC index.
89 */
90 HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0),
91#define HWTSTAMP_FLAG_BONDED_PHC_INDEX HWTSTAMP_FLAG_BONDED_PHC_INDEX
92
93 HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX,
94 HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST
95};
96
97/* possible values for hwtstamp_config->tx_type */
98enum hwtstamp_tx_types {
99 /*
100 * No outgoing packet will need hardware time stamping;
101 * should a packet arrive which asks for it, no hardware
102 * time stamping will be done.
103 */
104 HWTSTAMP_TX_OFF,
105
106 /*
107 * Enables hardware time stamping for outgoing packets;
108 * the sender of the packet decides which are to be
109 * time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE
110 * before sending the packet.
111 */
112 HWTSTAMP_TX_ON,
113
114 /*
115 * Enables time stamping for outgoing packets just as
116 * HWTSTAMP_TX_ON does, but also enables time stamp insertion
117 * directly into Sync packets. In this case, transmitted Sync
118 * packets will not received a time stamp via the socket error
119 * queue.
120 */
121 HWTSTAMP_TX_ONESTEP_SYNC,
122
123 /*
124 * Same as HWTSTAMP_TX_ONESTEP_SYNC, but also enables time
125 * stamp insertion directly into PDelay_Resp packets. In this
126 * case, neither transmitted Sync nor PDelay_Resp packets will
127 * receive a time stamp via the socket error queue.
128 */
129 HWTSTAMP_TX_ONESTEP_P2P,
130
131 /* add new constants above here */
132 __HWTSTAMP_TX_CNT
133};
134
135/* possible values for hwtstamp_config->rx_filter */
136enum hwtstamp_rx_filters {
137 /* time stamp no incoming packet at all */
138 HWTSTAMP_FILTER_NONE,
139
140 /* time stamp any incoming packet */
141 HWTSTAMP_FILTER_ALL,
142
143 /* return value: time stamp all packets requested plus some others */
144 HWTSTAMP_FILTER_SOME,
145
146 /* PTP v1, UDP, any kind of event packet */
147 HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
148 /* PTP v1, UDP, Sync packet */
149 HWTSTAMP_FILTER_PTP_V1_L4_SYNC,
150 /* PTP v1, UDP, Delay_req packet */
151 HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ,
152 /* PTP v2, UDP, any kind of event packet */
153 HWTSTAMP_FILTER_PTP_V2_L4_EVENT,
154 /* PTP v2, UDP, Sync packet */
155 HWTSTAMP_FILTER_PTP_V2_L4_SYNC,
156 /* PTP v2, UDP, Delay_req packet */
157 HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ,
158
159 /* 802.AS1, Ethernet, any kind of event packet */
160 HWTSTAMP_FILTER_PTP_V2_L2_EVENT,
161 /* 802.AS1, Ethernet, Sync packet */
162 HWTSTAMP_FILTER_PTP_V2_L2_SYNC,
163 /* 802.AS1, Ethernet, Delay_req packet */
164 HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ,
165
166 /* PTP v2/802.AS1, any layer, any kind of event packet */
167 HWTSTAMP_FILTER_PTP_V2_EVENT,
168 /* PTP v2/802.AS1, any layer, Sync packet */
169 HWTSTAMP_FILTER_PTP_V2_SYNC,
170 /* PTP v2/802.AS1, any layer, Delay_req packet */
171 HWTSTAMP_FILTER_PTP_V2_DELAY_REQ,
172
173 /* NTP, UDP, all versions and packet modes */
174 HWTSTAMP_FILTER_NTP_ALL,
175
176 /* add new constants above here */
177 __HWTSTAMP_FILTER_CNT
178};
179
180/* SCM_TIMESTAMPING_PKTINFO control message */
181struct scm_ts_pktinfo {
182 __u32 if_index;
183 __u32 pkt_length;
184 __u32 reserved[2];
185};
186
187/*
188 * SO_TXTIME gets a struct sock_txtime with flags being an integer bit
189 * field comprised of these values.
190 */
191enum txtime_flags {
192 SOF_TXTIME_DEADLINE_MODE = (1 << 0),
193 SOF_TXTIME_REPORT_ERRORS = (1 << 1),
194
195 SOF_TXTIME_FLAGS_LAST = SOF_TXTIME_REPORT_ERRORS,
196 SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST - 1) |
197 SOF_TXTIME_FLAGS_LAST
198};
199
200struct sock_txtime {
201 __kernel_clockid_t clockid;/* reference clockid */
202 __u32 flags; /* as defined by enum txtime_flags */
203};
204
205#endif /* _NET_TIMESTAMPING_H */
206

source code of linux/include/uapi/linux/net_tstamp.h