xref: /linux/include/uapi/linux/net_tstamp.h (revision b8210a9e4bea6354eccc5d8a50ecc21ea7486dc9)
1607ca46eSDavid Howells /*
2607ca46eSDavid Howells  * Userspace API for hardware time stamping of network packets
3607ca46eSDavid Howells  *
4607ca46eSDavid Howells  * Copyright (C) 2008,2009 Intel Corporation
5607ca46eSDavid Howells  * Author: Patrick Ohly <patrick.ohly@intel.com>
6607ca46eSDavid Howells  *
7607ca46eSDavid Howells  */
8607ca46eSDavid Howells 
9607ca46eSDavid Howells #ifndef _NET_TIMESTAMPING_H
10607ca46eSDavid Howells #define _NET_TIMESTAMPING_H
11607ca46eSDavid Howells 
12607ca46eSDavid Howells #include <linux/socket.h>   /* for SO_TIMESTAMPING */
13607ca46eSDavid Howells 
14607ca46eSDavid Howells /* SO_TIMESTAMPING gets an integer bit field comprised of these values */
15607ca46eSDavid Howells enum {
16607ca46eSDavid Howells 	SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
17607ca46eSDavid Howells 	SOF_TIMESTAMPING_TX_SOFTWARE = (1<<1),
18607ca46eSDavid Howells 	SOF_TIMESTAMPING_RX_HARDWARE = (1<<2),
19607ca46eSDavid Howells 	SOF_TIMESTAMPING_RX_SOFTWARE = (1<<3),
20607ca46eSDavid Howells 	SOF_TIMESTAMPING_SOFTWARE = (1<<4),
21607ca46eSDavid Howells 	SOF_TIMESTAMPING_SYS_HARDWARE = (1<<5),
22607ca46eSDavid Howells 	SOF_TIMESTAMPING_RAW_HARDWARE = (1<<6),
2309c2d251SWillem de Bruijn 	SOF_TIMESTAMPING_OPT_ID = (1<<7),
24e7fd2885SWillem de Bruijn 	SOF_TIMESTAMPING_TX_SCHED = (1<<8),
25e1c8a607SWillem de Bruijn 	SOF_TIMESTAMPING_TX_ACK = (1<<9),
26829ae9d6SWillem de Bruijn 	SOF_TIMESTAMPING_OPT_CMSG = (1<<10),
2749ca0d8bSWillem de Bruijn 	SOF_TIMESTAMPING_OPT_TSONLY = (1<<11),
281c885808SFrancis Yan 	SOF_TIMESTAMPING_OPT_STATS = (1<<12),
2909c2d251SWillem de Bruijn 
301c885808SFrancis Yan 	SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_STATS,
3109c2d251SWillem de Bruijn 	SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
3209c2d251SWillem de Bruijn 				 SOF_TIMESTAMPING_LAST
33607ca46eSDavid Howells };
34607ca46eSDavid Howells 
353dd17e63SSoheil Hassas Yeganeh /*
363dd17e63SSoheil Hassas Yeganeh  * SO_TIMESTAMPING flags are either for recording a packet timestamp or for
373dd17e63SSoheil Hassas Yeganeh  * reporting the timestamp to user space.
383dd17e63SSoheil Hassas Yeganeh  * Recording flags can be set both via socket options and control messages.
393dd17e63SSoheil Hassas Yeganeh  */
403dd17e63SSoheil Hassas Yeganeh #define SOF_TIMESTAMPING_TX_RECORD_MASK	(SOF_TIMESTAMPING_TX_HARDWARE | \
413dd17e63SSoheil Hassas Yeganeh 					 SOF_TIMESTAMPING_TX_SOFTWARE | \
423dd17e63SSoheil Hassas Yeganeh 					 SOF_TIMESTAMPING_TX_SCHED | \
433dd17e63SSoheil Hassas Yeganeh 					 SOF_TIMESTAMPING_TX_ACK)
443dd17e63SSoheil Hassas Yeganeh 
45607ca46eSDavid Howells /**
46fd468c74SBen Hutchings  * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
47607ca46eSDavid Howells  *
48fd468c74SBen Hutchings  * @flags:	no flags defined right now, must be zero for %SIOCSHWTSTAMP
49607ca46eSDavid Howells  * @tx_type:	one of HWTSTAMP_TX_*
50e1bd1dc2SBen Hutchings  * @rx_filter:	one of HWTSTAMP_FILTER_*
51607ca46eSDavid Howells  *
52fd468c74SBen Hutchings  * %SIOCGHWTSTAMP and %SIOCSHWTSTAMP expect a &struct ifreq with a
53fd468c74SBen Hutchings  * ifr_data pointer to this structure.  For %SIOCSHWTSTAMP, if the
54fd468c74SBen Hutchings  * driver or hardware does not support the requested @rx_filter value,
55fd468c74SBen Hutchings  * the driver may use a more general filter mode.  In this case
56fd468c74SBen Hutchings  * @rx_filter will indicate the actual mode on return.
57607ca46eSDavid Howells  */
58607ca46eSDavid Howells struct hwtstamp_config {
59607ca46eSDavid Howells 	int flags;
60607ca46eSDavid Howells 	int tx_type;
61607ca46eSDavid Howells 	int rx_filter;
62607ca46eSDavid Howells };
63607ca46eSDavid Howells 
64607ca46eSDavid Howells /* possible values for hwtstamp_config->tx_type */
65607ca46eSDavid Howells enum hwtstamp_tx_types {
66607ca46eSDavid Howells 	/*
67607ca46eSDavid Howells 	 * No outgoing packet will need hardware time stamping;
68607ca46eSDavid Howells 	 * should a packet arrive which asks for it, no hardware
69607ca46eSDavid Howells 	 * time stamping will be done.
70607ca46eSDavid Howells 	 */
71607ca46eSDavid Howells 	HWTSTAMP_TX_OFF,
72607ca46eSDavid Howells 
73607ca46eSDavid Howells 	/*
74607ca46eSDavid Howells 	 * Enables hardware time stamping for outgoing packets;
75607ca46eSDavid Howells 	 * the sender of the packet decides which are to be
76607ca46eSDavid Howells 	 * time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE
77607ca46eSDavid Howells 	 * before sending the packet.
78607ca46eSDavid Howells 	 */
79607ca46eSDavid Howells 	HWTSTAMP_TX_ON,
80607ca46eSDavid Howells 
81607ca46eSDavid Howells 	/*
82607ca46eSDavid Howells 	 * Enables time stamping for outgoing packets just as
83607ca46eSDavid Howells 	 * HWTSTAMP_TX_ON does, but also enables time stamp insertion
84607ca46eSDavid Howells 	 * directly into Sync packets. In this case, transmitted Sync
85607ca46eSDavid Howells 	 * packets will not received a time stamp via the socket error
86607ca46eSDavid Howells 	 * queue.
87607ca46eSDavid Howells 	 */
88607ca46eSDavid Howells 	HWTSTAMP_TX_ONESTEP_SYNC,
89607ca46eSDavid Howells };
90607ca46eSDavid Howells 
91607ca46eSDavid Howells /* possible values for hwtstamp_config->rx_filter */
92607ca46eSDavid Howells enum hwtstamp_rx_filters {
93607ca46eSDavid Howells 	/* time stamp no incoming packet at all */
94607ca46eSDavid Howells 	HWTSTAMP_FILTER_NONE,
95607ca46eSDavid Howells 
96607ca46eSDavid Howells 	/* time stamp any incoming packet */
97607ca46eSDavid Howells 	HWTSTAMP_FILTER_ALL,
98607ca46eSDavid Howells 
99607ca46eSDavid Howells 	/* return value: time stamp all packets requested plus some others */
100607ca46eSDavid Howells 	HWTSTAMP_FILTER_SOME,
101607ca46eSDavid Howells 
102607ca46eSDavid Howells 	/* PTP v1, UDP, any kind of event packet */
103607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
104607ca46eSDavid Howells 	/* PTP v1, UDP, Sync packet */
105607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V1_L4_SYNC,
106607ca46eSDavid Howells 	/* PTP v1, UDP, Delay_req packet */
107607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ,
108607ca46eSDavid Howells 	/* PTP v2, UDP, any kind of event packet */
109607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L4_EVENT,
110607ca46eSDavid Howells 	/* PTP v2, UDP, Sync packet */
111607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L4_SYNC,
112607ca46eSDavid Howells 	/* PTP v2, UDP, Delay_req packet */
113607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ,
114607ca46eSDavid Howells 
115607ca46eSDavid Howells 	/* 802.AS1, Ethernet, any kind of event packet */
116607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L2_EVENT,
117607ca46eSDavid Howells 	/* 802.AS1, Ethernet, Sync packet */
118607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L2_SYNC,
119607ca46eSDavid Howells 	/* 802.AS1, Ethernet, Delay_req packet */
120607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ,
121607ca46eSDavid Howells 
122607ca46eSDavid Howells 	/* PTP v2/802.AS1, any layer, any kind of event packet */
123607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_EVENT,
124607ca46eSDavid Howells 	/* PTP v2/802.AS1, any layer, Sync packet */
125607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_SYNC,
126607ca46eSDavid Howells 	/* PTP v2/802.AS1, any layer, Delay_req packet */
127607ca46eSDavid Howells 	HWTSTAMP_FILTER_PTP_V2_DELAY_REQ,
128*b8210a9eSMiroslav Lichvar 
129*b8210a9eSMiroslav Lichvar 	/* NTP, UDP, all versions and packet modes */
130*b8210a9eSMiroslav Lichvar 	HWTSTAMP_FILTER_NTP_ALL,
131607ca46eSDavid Howells };
132607ca46eSDavid Howells 
133607ca46eSDavid Howells #endif /* _NET_TIMESTAMPING_H */
134