net_tstamp.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 gets an integer bit field comprised of these values */
  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_LAST = SOF_TIMESTAMPING_OPT_TX_SWHW,
  31. SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
  32. SOF_TIMESTAMPING_LAST
  33. };
  34. /*
  35. * SO_TIMESTAMPING flags are either for recording a packet timestamp or for
  36. * reporting the timestamp to user space.
  37. * Recording flags can be set both via socket options and control messages.
  38. */
  39. #define SOF_TIMESTAMPING_TX_RECORD_MASK (SOF_TIMESTAMPING_TX_HARDWARE | \
  40. SOF_TIMESTAMPING_TX_SOFTWARE | \
  41. SOF_TIMESTAMPING_TX_SCHED | \
  42. SOF_TIMESTAMPING_TX_ACK)
  43. /**
  44. * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
  45. *
  46. * @flags: no flags defined right now, must be zero for %SIOCSHWTSTAMP
  47. * @tx_type: one of HWTSTAMP_TX_*
  48. * @rx_filter: one of HWTSTAMP_FILTER_*
  49. *
  50. * %SIOCGHWTSTAMP and %SIOCSHWTSTAMP expect a &struct ifreq with a
  51. * ifr_data pointer to this structure. For %SIOCSHWTSTAMP, if the
  52. * driver or hardware does not support the requested @rx_filter value,
  53. * the driver may use a more general filter mode. In this case
  54. * @rx_filter will indicate the actual mode on return.
  55. */
  56. struct hwtstamp_config {
  57. int flags;
  58. int tx_type;
  59. int rx_filter;
  60. };
  61. /* possible values for hwtstamp_config->tx_type */
  62. enum hwtstamp_tx_types {
  63. /*
  64. * No outgoing packet will need hardware time stamping;
  65. * should a packet arrive which asks for it, no hardware
  66. * time stamping will be done.
  67. */
  68. HWTSTAMP_TX_OFF,
  69. /*
  70. * Enables hardware time stamping for outgoing packets;
  71. * the sender of the packet decides which are to be
  72. * time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE
  73. * before sending the packet.
  74. */
  75. HWTSTAMP_TX_ON,
  76. /*
  77. * Enables time stamping for outgoing packets just as
  78. * HWTSTAMP_TX_ON does, but also enables time stamp insertion
  79. * directly into Sync packets. In this case, transmitted Sync
  80. * packets will not received a time stamp via the socket error
  81. * queue.
  82. */
  83. HWTSTAMP_TX_ONESTEP_SYNC,
  84. };
  85. /* possible values for hwtstamp_config->rx_filter */
  86. enum hwtstamp_rx_filters {
  87. /* time stamp no incoming packet at all */
  88. HWTSTAMP_FILTER_NONE,
  89. /* time stamp any incoming packet */
  90. HWTSTAMP_FILTER_ALL,
  91. /* return value: time stamp all packets requested plus some others */
  92. HWTSTAMP_FILTER_SOME,
  93. /* PTP v1, UDP, any kind of event packet */
  94. HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
  95. /* PTP v1, UDP, Sync packet */
  96. HWTSTAMP_FILTER_PTP_V1_L4_SYNC,
  97. /* PTP v1, UDP, Delay_req packet */
  98. HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ,
  99. /* PTP v2, UDP, any kind of event packet */
  100. HWTSTAMP_FILTER_PTP_V2_L4_EVENT,
  101. /* PTP v2, UDP, Sync packet */
  102. HWTSTAMP_FILTER_PTP_V2_L4_SYNC,
  103. /* PTP v2, UDP, Delay_req packet */
  104. HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ,
  105. /* 802.AS1, Ethernet, any kind of event packet */
  106. HWTSTAMP_FILTER_PTP_V2_L2_EVENT,
  107. /* 802.AS1, Ethernet, Sync packet */
  108. HWTSTAMP_FILTER_PTP_V2_L2_SYNC,
  109. /* 802.AS1, Ethernet, Delay_req packet */
  110. HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ,
  111. /* PTP v2/802.AS1, any layer, any kind of event packet */
  112. HWTSTAMP_FILTER_PTP_V2_EVENT,
  113. /* PTP v2/802.AS1, any layer, Sync packet */
  114. HWTSTAMP_FILTER_PTP_V2_SYNC,
  115. /* PTP v2/802.AS1, any layer, Delay_req packet */
  116. HWTSTAMP_FILTER_PTP_V2_DELAY_REQ,
  117. /* NTP, UDP, all versions and packet modes */
  118. HWTSTAMP_FILTER_NTP_ALL,
  119. };
  120. /* SCM_TIMESTAMPING_PKTINFO control message */
  121. struct scm_ts_pktinfo {
  122. __u32 if_index;
  123. __u32 pkt_length;
  124. __u32 reserved[2];
  125. };
  126. /*
  127. * SO_TXTIME gets a struct sock_txtime with flags being an integer bit
  128. * field comprised of these values.
  129. */
  130. enum txtime_flags {
  131. SOF_TXTIME_DEADLINE_MODE = (1 << 0),
  132. SOF_TXTIME_REPORT_ERRORS = (1 << 1),
  133. SOF_TXTIME_FLAGS_LAST = SOF_TXTIME_REPORT_ERRORS,
  134. SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST - 1) |
  135. SOF_TXTIME_FLAGS_LAST
  136. };
  137. struct sock_txtime {
  138. __kernel_clockid_t clockid;/* reference clockid */
  139. __u32 flags; /* as defined by enum txtime_flags */
  140. };
  141. #endif /* _NET_TIMESTAMPING_H */