xref: /openbmc/linux/include/uapi/linux/net_tstamp.h (revision 400c2a45)
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 gets an integer bit field comprised of these values */
17 enum {
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 
34 	SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_TX_SWHW,
35 	SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
36 				 SOF_TIMESTAMPING_LAST
37 };
38 
39 /*
40  * SO_TIMESTAMPING flags are either for recording a packet timestamp or for
41  * reporting the timestamp to user space.
42  * Recording flags can be set both via socket options and control messages.
43  */
44 #define SOF_TIMESTAMPING_TX_RECORD_MASK	(SOF_TIMESTAMPING_TX_HARDWARE | \
45 					 SOF_TIMESTAMPING_TX_SOFTWARE | \
46 					 SOF_TIMESTAMPING_TX_SCHED | \
47 					 SOF_TIMESTAMPING_TX_ACK)
48 
49 /**
50  * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
51  *
52  * @flags:	no flags defined right now, must be zero for %SIOCSHWTSTAMP
53  * @tx_type:	one of HWTSTAMP_TX_*
54  * @rx_filter:	one of HWTSTAMP_FILTER_*
55  *
56  * %SIOCGHWTSTAMP and %SIOCSHWTSTAMP expect a &struct ifreq with a
57  * ifr_data pointer to this structure.  For %SIOCSHWTSTAMP, if the
58  * driver or hardware does not support the requested @rx_filter value,
59  * the driver may use a more general filter mode.  In this case
60  * @rx_filter will indicate the actual mode on return.
61  */
62 struct hwtstamp_config {
63 	int flags;
64 	int tx_type;
65 	int rx_filter;
66 };
67 
68 /* possible values for hwtstamp_config->tx_type */
69 enum hwtstamp_tx_types {
70 	/*
71 	 * No outgoing packet will need hardware time stamping;
72 	 * should a packet arrive which asks for it, no hardware
73 	 * time stamping will be done.
74 	 */
75 	HWTSTAMP_TX_OFF,
76 
77 	/*
78 	 * Enables hardware time stamping for outgoing packets;
79 	 * the sender of the packet decides which are to be
80 	 * time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE
81 	 * before sending the packet.
82 	 */
83 	HWTSTAMP_TX_ON,
84 
85 	/*
86 	 * Enables time stamping for outgoing packets just as
87 	 * HWTSTAMP_TX_ON does, but also enables time stamp insertion
88 	 * directly into Sync packets. In this case, transmitted Sync
89 	 * packets will not received a time stamp via the socket error
90 	 * queue.
91 	 */
92 	HWTSTAMP_TX_ONESTEP_SYNC,
93 
94 	/*
95 	 * Same as HWTSTAMP_TX_ONESTEP_SYNC, but also enables time
96 	 * stamp insertion directly into PDelay_Resp packets. In this
97 	 * case, neither transmitted Sync nor PDelay_Resp packets will
98 	 * receive a time stamp via the socket error queue.
99 	 */
100 	HWTSTAMP_TX_ONESTEP_P2P,
101 
102 	/* add new constants above here */
103 	__HWTSTAMP_TX_CNT
104 };
105 
106 /* possible values for hwtstamp_config->rx_filter */
107 enum hwtstamp_rx_filters {
108 	/* time stamp no incoming packet at all */
109 	HWTSTAMP_FILTER_NONE,
110 
111 	/* time stamp any incoming packet */
112 	HWTSTAMP_FILTER_ALL,
113 
114 	/* return value: time stamp all packets requested plus some others */
115 	HWTSTAMP_FILTER_SOME,
116 
117 	/* PTP v1, UDP, any kind of event packet */
118 	HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
119 	/* PTP v1, UDP, Sync packet */
120 	HWTSTAMP_FILTER_PTP_V1_L4_SYNC,
121 	/* PTP v1, UDP, Delay_req packet */
122 	HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ,
123 	/* PTP v2, UDP, any kind of event packet */
124 	HWTSTAMP_FILTER_PTP_V2_L4_EVENT,
125 	/* PTP v2, UDP, Sync packet */
126 	HWTSTAMP_FILTER_PTP_V2_L4_SYNC,
127 	/* PTP v2, UDP, Delay_req packet */
128 	HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ,
129 
130 	/* 802.AS1, Ethernet, any kind of event packet */
131 	HWTSTAMP_FILTER_PTP_V2_L2_EVENT,
132 	/* 802.AS1, Ethernet, Sync packet */
133 	HWTSTAMP_FILTER_PTP_V2_L2_SYNC,
134 	/* 802.AS1, Ethernet, Delay_req packet */
135 	HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ,
136 
137 	/* PTP v2/802.AS1, any layer, any kind of event packet */
138 	HWTSTAMP_FILTER_PTP_V2_EVENT,
139 	/* PTP v2/802.AS1, any layer, Sync packet */
140 	HWTSTAMP_FILTER_PTP_V2_SYNC,
141 	/* PTP v2/802.AS1, any layer, Delay_req packet */
142 	HWTSTAMP_FILTER_PTP_V2_DELAY_REQ,
143 
144 	/* NTP, UDP, all versions and packet modes */
145 	HWTSTAMP_FILTER_NTP_ALL,
146 
147 	/* add new constants above here */
148 	__HWTSTAMP_FILTER_CNT
149 };
150 
151 /* SCM_TIMESTAMPING_PKTINFO control message */
152 struct scm_ts_pktinfo {
153 	__u32 if_index;
154 	__u32 pkt_length;
155 	__u32 reserved[2];
156 };
157 
158 /*
159  * SO_TXTIME gets a struct sock_txtime with flags being an integer bit
160  * field comprised of these values.
161  */
162 enum txtime_flags {
163 	SOF_TXTIME_DEADLINE_MODE = (1 << 0),
164 	SOF_TXTIME_REPORT_ERRORS = (1 << 1),
165 
166 	SOF_TXTIME_FLAGS_LAST = SOF_TXTIME_REPORT_ERRORS,
167 	SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST - 1) |
168 				 SOF_TXTIME_FLAGS_LAST
169 };
170 
171 struct sock_txtime {
172 	__kernel_clockid_t	clockid;/* reference clockid */
173 	__u32			flags;	/* as defined by enum txtime_flags */
174 };
175 
176 #endif /* _NET_TIMESTAMPING_H */
177