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