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