xref: /linux/include/uapi/linux/net_tstamp.h (revision 289354f21b2c3fac93e956efd45f256a88a4d997)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells /*
3607ca46eSDavid Howells  * Userspace API for hardware time stamping of network packets
4607ca46eSDavid Howells  *
5607ca46eSDavid Howells  * Copyright (C) 2008,2009 Intel Corporation
6607ca46eSDavid Howells  * Author: Patrick Ohly <patrick.ohly@intel.com>
7607ca46eSDavid Howells  *
8607ca46eSDavid Howells  */
9607ca46eSDavid Howells 
10607ca46eSDavid Howells #ifndef _NET_TIMESTAMPING_H
11607ca46eSDavid Howells #define _NET_TIMESTAMPING_H
12607ca46eSDavid Howells 
13aad9c8c4SMiroslav Lichvar #include <linux/types.h>
14607ca46eSDavid Howells #include <linux/socket.h>   /* for SO_TIMESTAMPING */
15607ca46eSDavid Howells 
16d463126eSYangbo Lu /* SO_TIMESTAMPING flags */
17607ca46eSDavid Howells enum {
18607ca46eSDavid Howells 	SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
19607ca46eSDavid Howells 	SOF_TIMESTAMPING_TX_SOFTWARE = (1<<1),
20607ca46eSDavid Howells 	SOF_TIMESTAMPING_RX_HARDWARE = (1<<2),
21607ca46eSDavid Howells 	SOF_TIMESTAMPING_RX_SOFTWARE = (1<<3),
22607ca46eSDavid Howells 	SOF_TIMESTAMPING_SOFTWARE = (1<<4),
23607ca46eSDavid Howells 	SOF_TIMESTAMPING_SYS_HARDWARE = (1<<5),
24607ca46eSDavid Howells 	SOF_TIMESTAMPING_RAW_HARDWARE = (1<<6),
2509c2d251SWillem de Bruijn 	SOF_TIMESTAMPING_OPT_ID = (1<<7),
26e7fd2885SWillem de Bruijn 	SOF_TIMESTAMPING_TX_SCHED = (1<<8),
27e1c8a607SWillem de Bruijn 	SOF_TIMESTAMPING_TX_ACK = (1<<9),
28829ae9d6SWillem de Bruijn 	SOF_TIMESTAMPING_OPT_CMSG = (1<<10),
2949ca0d8bSWillem de Bruijn 	SOF_TIMESTAMPING_OPT_TSONLY = (1<<11),
301c885808SFrancis Yan 	SOF_TIMESTAMPING_OPT_STATS = (1<<12),
31aad9c8c4SMiroslav Lichvar 	SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13),
32b50a5c70SMiroslav Lichvar 	SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14),
33d463126eSYangbo Lu 	SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
34*b534dc46SWillem de Bruijn 	SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16),
3509c2d251SWillem de Bruijn 
36*b534dc46SWillem de Bruijn 	SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_ID_TCP,
3709c2d251SWillem de Bruijn 	SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
3809c2d251SWillem de Bruijn 				 SOF_TIMESTAMPING_LAST
39607ca46eSDavid Howells };
40607ca46eSDavid Howells 
413dd17e63SSoheil Hassas Yeganeh /*
423dd17e63SSoheil Hassas Yeganeh  * SO_TIMESTAMPING flags are either for recording a packet timestamp or for
433dd17e63SSoheil Hassas Yeganeh  * reporting the timestamp to user space.
443dd17e63SSoheil Hassas Yeganeh  * Recording flags can be set both via socket options and control messages.
453dd17e63SSoheil Hassas Yeganeh  */
463dd17e63SSoheil Hassas Yeganeh #define SOF_TIMESTAMPING_TX_RECORD_MASK	(SOF_TIMESTAMPING_TX_HARDWARE | \
473dd17e63SSoheil Hassas Yeganeh 					 SOF_TIMESTAMPING_TX_SOFTWARE | \
483dd17e63SSoheil Hassas Yeganeh 					 SOF_TIMESTAMPING_TX_SCHED | \
493dd17e63SSoheil Hassas Yeganeh 					 SOF_TIMESTAMPING_TX_ACK)
503dd17e63SSoheil Hassas Yeganeh 
51607ca46eSDavid Howells /**
52d463126eSYangbo Lu  * struct so_timestamping - SO_TIMESTAMPING parameter
53d463126eSYangbo Lu  *
54d463126eSYangbo Lu  * @flags:	SO_TIMESTAMPING flags
55d463126eSYangbo Lu  * @bind_phc:	Index of PTP virtual clock bound to sock. This is available
56d463126eSYangbo Lu  *		if flag SOF_TIMESTAMPING_BIND_PHC is set.
57d463126eSYangbo Lu  */
58d463126eSYangbo Lu struct so_timestamping {
59d463126eSYangbo Lu 	int flags;
60d463126eSYangbo Lu 	int bind_phc;
61d463126eSYangbo Lu };
62d463126eSYangbo Lu 
63d463126eSYangbo Lu /**
64fd468c74SBen Hutchings  * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
65607ca46eSDavid Howells  *
669c9211a3SHangbin Liu  * @flags:	one of HWTSTAMP_FLAG_*
67607ca46eSDavid Howells  * @tx_type:	one of HWTSTAMP_TX_*
68e1bd1dc2SBen Hutchings  * @rx_filter:	one of HWTSTAMP_FILTER_*
69607ca46eSDavid Howells  *
70fd468c74SBen Hutchings  * %SIOCGHWTSTAMP and %SIOCSHWTSTAMP expect a &struct ifreq with a
71fd468c74SBen Hutchings  * ifr_data pointer to this structure.  For %SIOCSHWTSTAMP, if the
72fd468c74SBen Hutchings  * driver or hardware does not support the requested @rx_filter value,
73fd468c74SBen Hutchings  * the driver may use a more general filter mode.  In this case
74fd468c74SBen Hutchings  * @rx_filter will indicate the actual mode on return.
75607ca46eSDavid Howells  */
76607ca46eSDavid Howells struct hwtstamp_config {
77607ca46eSDavid Howells 	int flags;
78607ca46eSDavid Howells 	int tx_type;
79607ca46eSDavid Howells 	int rx_filter;
80607ca46eSDavid Howells };
81607ca46eSDavid Howells 
829c9211a3SHangbin Liu /* possible values for hwtstamp_config->flags */
839c9211a3SHangbin Liu enum hwtstamp_flags {
849c9211a3SHangbin Liu 	/*
859c9211a3SHangbin Liu 	 * With this flag, the user could get bond active interface's
869c9211a3SHangbin Liu 	 * PHC index. Note this PHC index is not stable as when there
879c9211a3SHangbin Liu 	 * is a failover, the bond active interface will be changed, so
889c9211a3SHangbin Liu 	 * will be the PHC index.
899c9211a3SHangbin Liu 	 */
909c9211a3SHangbin Liu 	HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0),
911bb412d4SHangbin Liu #define HWTSTAMP_FLAG_BONDED_PHC_INDEX	HWTSTAMP_FLAG_BONDED_PHC_INDEX
929c9211a3SHangbin Liu 
939c9211a3SHangbin Liu 	HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX,
949c9211a3SHangbin Liu 	HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST
959c9211a3SHangbin Liu };
969c9211a3SHangbin Liu 
97607ca46eSDavid Howells /* possible values for hwtstamp_config->tx_type */
98607ca46eSDavid Howells enum hwtstamp_tx_types {
99607ca46eSDavid Howells 	/*
100607ca46eSDavid Howells 	 * No outgoing packet will need hardware time stamping;
101607ca46eSDavid Howells 	 * should a packet arrive which asks for it, no hardware
102607ca46eSDavid Howells 	 * time stamping will be done.
103607ca46eSDavid Howells 	 */
104607ca46eSDavid Howells 	HWTSTAMP_TX_OFF,
105607ca46eSDavid Howells 
106607ca46eSDavid Howells 	/*
107607ca46eSDavid Howells 	 * Enables hardware time stamping for outgoing packets;
108607ca46eSDavid Howells 	 * the sender of the packet decides which are to be
109607ca46eSDavid Howells 	 * time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE
110607ca46eSDavid Howells 	 * before sending the packet.
111607ca46eSDavid Howells 	 */
112607ca46eSDavid Howells 	HWTSTAMP_TX_ON,
113607ca46eSDavid Howells 
114607ca46eSDavid Howells 	/*
115607ca46eSDavid Howells 	 * Enables time stamping for outgoing packets just as
116607ca46eSDavid Howells 	 * HWTSTAMP_TX_ON does, but also enables time stamp insertion
117607ca46eSDavid Howells 	 * directly into Sync packets. In this case, transmitted Sync
118607ca46eSDavid Howells 	 * packets will not received a time stamp via the socket error
119607ca46eSDavid Howells 	 * queue.
120607ca46eSDavid Howells 	 */
121607ca46eSDavid Howells 	HWTSTAMP_TX_ONESTEP_SYNC,
122b6fd7b96SRichard Cochran 
123b6fd7b96SRichard Cochran 	/*
124b6fd7b96SRichard Cochran 	 * Same as HWTSTAMP_TX_ONESTEP_SYNC, but also enables time
125b6fd7b96SRichard Cochran 	 * stamp insertion directly into PDelay_Resp packets. In this
126b6fd7b96SRichard Cochran 	 * case, neither transmitted Sync nor PDelay_Resp packets will
127b6fd7b96SRichard Cochran 	 * receive a time stamp via the socket error queue.
128b6fd7b96SRichard Cochran 	 */
129b6fd7b96SRichard Cochran 	HWTSTAMP_TX_ONESTEP_P2P,
130f76510b4SMichal Kubecek 
131f76510b4SMichal Kubecek 	/* add new constants above here */
132f76510b4SMichal Kubecek 	__HWTSTAMP_TX_CNT
133607ca46eSDavid Howells };
134607ca46eSDavid Howells 
135607ca46eSDavid Howells /* possible values for hwtstamp_config->rx_filter */
136607ca46eSDavid Howells enum hwtstamp_rx_filters {
137607ca46eSDavid Howells 	/* time stamp no incoming packet at all */
138607ca46eSDavid Howells 	HWTSTAMP_FILTER_NONE,
139607ca46eSDavid Howells 
140607ca46eSDavid Howells 	/* time stamp any incoming packet */
141607ca46eSDavid Howells 	HWTSTAMP_FILTER_ALL,
142607ca46eSDavid Howells 
143607ca46eSDavid Howells 	/* return value: time stamp all packets requested plus some others */
144607ca46eSDavid Howells 	HWTSTAMP_FILTER_SOME,
145607ca46eSDavid Howells 
146607ca46eSDavid Howells 	/* PTP v1, UDP, any kind of event packet */
147607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
148607ca46eSDavid Howells 	/* PTP v1, UDP, Sync packet */
149607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V1_L4_SYNC,
150607ca46eSDavid Howells 	/* PTP v1, UDP, Delay_req packet */
151607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ,
152607ca46eSDavid Howells 	/* PTP v2, UDP, any kind of event packet */
153607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L4_EVENT,
154607ca46eSDavid Howells 	/* PTP v2, UDP, Sync packet */
155607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L4_SYNC,
156607ca46eSDavid Howells 	/* PTP v2, UDP, Delay_req packet */
157607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ,
158607ca46eSDavid Howells 
159607ca46eSDavid Howells 	/* 802.AS1, Ethernet, any kind of event packet */
160607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L2_EVENT,
161607ca46eSDavid Howells 	/* 802.AS1, Ethernet, Sync packet */
162607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L2_SYNC,
163607ca46eSDavid Howells 	/* 802.AS1, Ethernet, Delay_req packet */
164607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ,
165607ca46eSDavid Howells 
166607ca46eSDavid Howells 	/* PTP v2/802.AS1, any layer, any kind of event packet */
167607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_EVENT,
168607ca46eSDavid Howells 	/* PTP v2/802.AS1, any layer, Sync packet */
169607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_SYNC,
170607ca46eSDavid Howells 	/* PTP v2/802.AS1, any layer, Delay_req packet */
171607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_DELAY_REQ,
172b8210a9eSMiroslav Lichvar 
173b8210a9eSMiroslav Lichvar 	/* NTP, UDP, all versions and packet modes */
174b8210a9eSMiroslav Lichvar 	HWTSTAMP_FILTER_NTP_ALL,
175f76510b4SMichal Kubecek 
176f76510b4SMichal Kubecek 	/* add new constants above here */
177f76510b4SMichal Kubecek 	__HWTSTAMP_FILTER_CNT
178607ca46eSDavid Howells };
179607ca46eSDavid Howells 
180aad9c8c4SMiroslav Lichvar /* SCM_TIMESTAMPING_PKTINFO control message */
181aad9c8c4SMiroslav Lichvar struct scm_ts_pktinfo {
182aad9c8c4SMiroslav Lichvar 	__u32 if_index;
183aad9c8c4SMiroslav Lichvar 	__u32 pkt_length;
184aad9c8c4SMiroslav Lichvar 	__u32 reserved[2];
185aad9c8c4SMiroslav Lichvar };
186aad9c8c4SMiroslav Lichvar 
18780b14deeSRichard Cochran /*
18880b14deeSRichard Cochran  * SO_TXTIME gets a struct sock_txtime with flags being an integer bit
18980b14deeSRichard Cochran  * field comprised of these values.
19080b14deeSRichard Cochran  */
19180b14deeSRichard Cochran enum txtime_flags {
19280b14deeSRichard Cochran 	SOF_TXTIME_DEADLINE_MODE = (1 << 0),
1934b15c707SJesus Sanchez-Palencia 	SOF_TXTIME_REPORT_ERRORS = (1 << 1),
19480b14deeSRichard Cochran 
1954b15c707SJesus Sanchez-Palencia 	SOF_TXTIME_FLAGS_LAST = SOF_TXTIME_REPORT_ERRORS,
1964b15c707SJesus Sanchez-Palencia 	SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST - 1) |
1974b15c707SJesus Sanchez-Palencia 				 SOF_TXTIME_FLAGS_LAST
19880b14deeSRichard Cochran };
19980b14deeSRichard Cochran 
20080b14deeSRichard Cochran struct sock_txtime {
201e2c4cf7fSDavide Caratti 	__kernel_clockid_t	clockid;/* reference clockid */
20252b50921SJesus Sanchez-Palencia 	__u32			flags;	/* as defined by enum txtime_flags */
20380b14deeSRichard Cochran };
20480b14deeSRichard Cochran 
205607ca46eSDavid Howells #endif /* _NET_TIMESTAMPING_H */
206