net_tstamp.h 6.0 KB

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