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