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