16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2607ca46eSDavid Howells /* 3607ca46eSDavid Howells * Userspace API for hardware time stamping of network packets 4607ca46eSDavid Howells * 5607ca46eSDavid Howells * Copyright (C) 2008,2009 Intel Corporation 6607ca46eSDavid Howells * Author: Patrick Ohly <[email protected]> 7607ca46eSDavid Howells * 8607ca46eSDavid Howells */ 9607ca46eSDavid Howells 10607ca46eSDavid Howells #ifndef _NET_TIMESTAMPING_H 11607ca46eSDavid Howells #define _NET_TIMESTAMPING_H 12607ca46eSDavid Howells 13aad9c8c4SMiroslav Lichvar #include <linux/types.h> 14607ca46eSDavid Howells #include <linux/socket.h> /* for SO_TIMESTAMPING */ 15607ca46eSDavid Howells 1635f7cad1SKory Maincent /* 1735f7cad1SKory Maincent * Possible type of hwtstamp provider. Mainly "precise" the default one 1835f7cad1SKory Maincent * is for IEEE 1588 quality and "approx" is for NICs DMA point. 1935f7cad1SKory Maincent */ 2035f7cad1SKory Maincent enum hwtstamp_provider_qualifier { 2135f7cad1SKory Maincent HWTSTAMP_PROVIDER_QUALIFIER_PRECISE, 2235f7cad1SKory Maincent HWTSTAMP_PROVIDER_QUALIFIER_APPROX, 2335f7cad1SKory Maincent 2435f7cad1SKory Maincent HWTSTAMP_PROVIDER_QUALIFIER_CNT, 2535f7cad1SKory Maincent }; 2635f7cad1SKory Maincent 27d463126eSYangbo Lu /* SO_TIMESTAMPING flags */ 28607ca46eSDavid Howells enum { 29607ca46eSDavid Howells SOF_TIMESTAMPING_TX_HARDWARE = (1<<0), 30607ca46eSDavid Howells SOF_TIMESTAMPING_TX_SOFTWARE = (1<<1), 31607ca46eSDavid Howells SOF_TIMESTAMPING_RX_HARDWARE = (1<<2), 32607ca46eSDavid Howells SOF_TIMESTAMPING_RX_SOFTWARE = (1<<3), 33607ca46eSDavid Howells SOF_TIMESTAMPING_SOFTWARE = (1<<4), 34607ca46eSDavid Howells SOF_TIMESTAMPING_SYS_HARDWARE = (1<<5), 35607ca46eSDavid Howells SOF_TIMESTAMPING_RAW_HARDWARE = (1<<6), 3609c2d251SWillem de Bruijn SOF_TIMESTAMPING_OPT_ID = (1<<7), 37e7fd2885SWillem de Bruijn SOF_TIMESTAMPING_TX_SCHED = (1<<8), 38e1c8a607SWillem de Bruijn SOF_TIMESTAMPING_TX_ACK = (1<<9), 39829ae9d6SWillem de Bruijn SOF_TIMESTAMPING_OPT_CMSG = (1<<10), 4049ca0d8bSWillem de Bruijn SOF_TIMESTAMPING_OPT_TSONLY = (1<<11), 411c885808SFrancis Yan SOF_TIMESTAMPING_OPT_STATS = (1<<12), 42aad9c8c4SMiroslav Lichvar SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13), 43b50a5c70SMiroslav Lichvar SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14), 44d463126eSYangbo Lu SOF_TIMESTAMPING_BIND_PHC = (1 << 15), 45b534dc46SWillem de Bruijn SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16), 46be8e9eb3SJason Xing SOF_TIMESTAMPING_OPT_RX_FILTER = (1 << 17), 47*983e0e4eSPauli Virtanen SOF_TIMESTAMPING_TX_COMPLETION = (1 << 18), 4809c2d251SWillem de Bruijn 49*983e0e4eSPauli Virtanen SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_TX_COMPLETION, 5009c2d251SWillem de Bruijn SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) | 5109c2d251SWillem de Bruijn SOF_TIMESTAMPING_LAST 52607ca46eSDavid Howells }; 53607ca46eSDavid Howells 543dd17e63SSoheil Hassas Yeganeh /* 553dd17e63SSoheil Hassas Yeganeh * SO_TIMESTAMPING flags are either for recording a packet timestamp or for 563dd17e63SSoheil Hassas Yeganeh * reporting the timestamp to user space. 573dd17e63SSoheil Hassas Yeganeh * Recording flags can be set both via socket options and control messages. 583dd17e63SSoheil Hassas Yeganeh */ 593dd17e63SSoheil Hassas Yeganeh #define SOF_TIMESTAMPING_TX_RECORD_MASK (SOF_TIMESTAMPING_TX_HARDWARE | \ 603dd17e63SSoheil Hassas Yeganeh SOF_TIMESTAMPING_TX_SOFTWARE | \ 613dd17e63SSoheil Hassas Yeganeh SOF_TIMESTAMPING_TX_SCHED | \ 62*983e0e4eSPauli Virtanen SOF_TIMESTAMPING_TX_ACK | \ 63*983e0e4eSPauli Virtanen SOF_TIMESTAMPING_TX_COMPLETION) 643dd17e63SSoheil Hassas Yeganeh 65607ca46eSDavid Howells /** 66d463126eSYangbo Lu * struct so_timestamping - SO_TIMESTAMPING parameter 67d463126eSYangbo Lu * 68d463126eSYangbo Lu * @flags: SO_TIMESTAMPING flags 69d463126eSYangbo Lu * @bind_phc: Index of PTP virtual clock bound to sock. This is available 70d463126eSYangbo Lu * if flag SOF_TIMESTAMPING_BIND_PHC is set. 71d463126eSYangbo Lu */ 72d463126eSYangbo Lu struct so_timestamping { 73d463126eSYangbo Lu int flags; 74d463126eSYangbo Lu int bind_phc; 75d463126eSYangbo Lu }; 76d463126eSYangbo Lu 77d463126eSYangbo Lu /** 78fd468c74SBen Hutchings * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter 79607ca46eSDavid Howells * 809c9211a3SHangbin Liu * @flags: one of HWTSTAMP_FLAG_* 81607ca46eSDavid Howells * @tx_type: one of HWTSTAMP_TX_* 82e1bd1dc2SBen Hutchings * @rx_filter: one of HWTSTAMP_FILTER_* 83607ca46eSDavid Howells * 84fd468c74SBen Hutchings * %SIOCGHWTSTAMP and %SIOCSHWTSTAMP expect a &struct ifreq with a 85fd468c74SBen Hutchings * ifr_data pointer to this structure. For %SIOCSHWTSTAMP, if the 86fd468c74SBen Hutchings * driver or hardware does not support the requested @rx_filter value, 87fd468c74SBen Hutchings * the driver may use a more general filter mode. In this case 88fd468c74SBen Hutchings * @rx_filter will indicate the actual mode on return. 89607ca46eSDavid Howells */ 90607ca46eSDavid Howells struct hwtstamp_config { 91607ca46eSDavid Howells int flags; 92607ca46eSDavid Howells int tx_type; 93607ca46eSDavid Howells int rx_filter; 94607ca46eSDavid Howells }; 95607ca46eSDavid Howells 969c9211a3SHangbin Liu /* possible values for hwtstamp_config->flags */ 979c9211a3SHangbin Liu enum hwtstamp_flags { 989c9211a3SHangbin Liu /* 999c9211a3SHangbin Liu * With this flag, the user could get bond active interface's 1009c9211a3SHangbin Liu * PHC index. Note this PHC index is not stable as when there 1019c9211a3SHangbin Liu * is a failover, the bond active interface will be changed, so 1029c9211a3SHangbin Liu * will be the PHC index. 1039c9211a3SHangbin Liu */ 1049c9211a3SHangbin Liu HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0), 1051bb412d4SHangbin Liu #define HWTSTAMP_FLAG_BONDED_PHC_INDEX HWTSTAMP_FLAG_BONDED_PHC_INDEX 1069c9211a3SHangbin Liu 1079c9211a3SHangbin Liu HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX, 1089c9211a3SHangbin Liu HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST 1099c9211a3SHangbin Liu }; 1109c9211a3SHangbin Liu 111607ca46eSDavid Howells /* possible values for hwtstamp_config->tx_type */ 112607ca46eSDavid Howells enum hwtstamp_tx_types { 113607ca46eSDavid Howells /* 114607ca46eSDavid Howells * No outgoing packet will need hardware time stamping; 115607ca46eSDavid Howells * should a packet arrive which asks for it, no hardware 116607ca46eSDavid Howells * time stamping will be done. 117607ca46eSDavid Howells */ 118607ca46eSDavid Howells HWTSTAMP_TX_OFF, 119607ca46eSDavid Howells 120607ca46eSDavid Howells /* 121607ca46eSDavid Howells * Enables hardware time stamping for outgoing packets; 122607ca46eSDavid Howells * the sender of the packet decides which are to be 123607ca46eSDavid Howells * time stamped by setting %SOF_TIMESTAMPING_TX_SOFTWARE 124607ca46eSDavid Howells * before sending the packet. 125607ca46eSDavid Howells */ 126607ca46eSDavid Howells HWTSTAMP_TX_ON, 127607ca46eSDavid Howells 128607ca46eSDavid Howells /* 129607ca46eSDavid Howells * Enables time stamping for outgoing packets just as 130607ca46eSDavid Howells * HWTSTAMP_TX_ON does, but also enables time stamp insertion 131607ca46eSDavid Howells * directly into Sync packets. In this case, transmitted Sync 132607ca46eSDavid Howells * packets will not received a time stamp via the socket error 133607ca46eSDavid Howells * queue. 134607ca46eSDavid Howells */ 135607ca46eSDavid Howells HWTSTAMP_TX_ONESTEP_SYNC, 136b6fd7b96SRichard Cochran 137b6fd7b96SRichard Cochran /* 138b6fd7b96SRichard Cochran * Same as HWTSTAMP_TX_ONESTEP_SYNC, but also enables time 139b6fd7b96SRichard Cochran * stamp insertion directly into PDelay_Resp packets. In this 140b6fd7b96SRichard Cochran * case, neither transmitted Sync nor PDelay_Resp packets will 141b6fd7b96SRichard Cochran * receive a time stamp via the socket error queue. 142b6fd7b96SRichard Cochran */ 143b6fd7b96SRichard Cochran HWTSTAMP_TX_ONESTEP_P2P, 144f76510b4SMichal Kubecek 145f76510b4SMichal Kubecek /* add new constants above here */ 146f76510b4SMichal Kubecek __HWTSTAMP_TX_CNT 147607ca46eSDavid Howells }; 148607ca46eSDavid Howells 149607ca46eSDavid Howells /* possible values for hwtstamp_config->rx_filter */ 150607ca46eSDavid Howells enum hwtstamp_rx_filters { 151607ca46eSDavid Howells /* time stamp no incoming packet at all */ 152607ca46eSDavid Howells HWTSTAMP_FILTER_NONE, 153607ca46eSDavid Howells 154607ca46eSDavid Howells /* time stamp any incoming packet */ 155607ca46eSDavid Howells HWTSTAMP_FILTER_ALL, 156607ca46eSDavid Howells 157607ca46eSDavid Howells /* return value: time stamp all packets requested plus some others */ 158607ca46eSDavid Howells HWTSTAMP_FILTER_SOME, 159607ca46eSDavid Howells 160607ca46eSDavid Howells /* PTP v1, UDP, any kind of event packet */ 161607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V1_L4_EVENT, 162607ca46eSDavid Howells /* PTP v1, UDP, Sync packet */ 163607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V1_L4_SYNC, 164607ca46eSDavid Howells /* PTP v1, UDP, Delay_req packet */ 165607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ, 166607ca46eSDavid Howells /* PTP v2, UDP, any kind of event packet */ 167607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_L4_EVENT, 168607ca46eSDavid Howells /* PTP v2, UDP, Sync packet */ 169607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_L4_SYNC, 170607ca46eSDavid Howells /* PTP v2, UDP, Delay_req packet */ 171607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ, 172607ca46eSDavid Howells 173607ca46eSDavid Howells /* 802.AS1, Ethernet, any kind of event packet */ 174607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_L2_EVENT, 175607ca46eSDavid Howells /* 802.AS1, Ethernet, Sync packet */ 176607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_L2_SYNC, 177607ca46eSDavid Howells /* 802.AS1, Ethernet, Delay_req packet */ 178607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ, 179607ca46eSDavid Howells 180607ca46eSDavid Howells /* PTP v2/802.AS1, any layer, any kind of event packet */ 181607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_EVENT, 182607ca46eSDavid Howells /* PTP v2/802.AS1, any layer, Sync packet */ 183607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_SYNC, 184607ca46eSDavid Howells /* PTP v2/802.AS1, any layer, Delay_req packet */ 185607ca46eSDavid Howells HWTSTAMP_FILTER_PTP_V2_DELAY_REQ, 186b8210a9eSMiroslav Lichvar 187b8210a9eSMiroslav Lichvar /* NTP, UDP, all versions and packet modes */ 188b8210a9eSMiroslav Lichvar HWTSTAMP_FILTER_NTP_ALL, 189f76510b4SMichal Kubecek 190f76510b4SMichal Kubecek /* add new constants above here */ 191f76510b4SMichal Kubecek __HWTSTAMP_FILTER_CNT 192607ca46eSDavid Howells }; 193607ca46eSDavid Howells 194aad9c8c4SMiroslav Lichvar /* SCM_TIMESTAMPING_PKTINFO control message */ 195aad9c8c4SMiroslav Lichvar struct scm_ts_pktinfo { 196aad9c8c4SMiroslav Lichvar __u32 if_index; 197aad9c8c4SMiroslav Lichvar __u32 pkt_length; 198aad9c8c4SMiroslav Lichvar __u32 reserved[2]; 199aad9c8c4SMiroslav Lichvar }; 200aad9c8c4SMiroslav Lichvar 20180b14deeSRichard Cochran /* 20280b14deeSRichard Cochran * SO_TXTIME gets a struct sock_txtime with flags being an integer bit 20380b14deeSRichard Cochran * field comprised of these values. 20480b14deeSRichard Cochran */ 20580b14deeSRichard Cochran enum txtime_flags { 20680b14deeSRichard Cochran SOF_TXTIME_DEADLINE_MODE = (1 << 0), 2074b15c707SJesus Sanchez-Palencia SOF_TXTIME_REPORT_ERRORS = (1 << 1), 20880b14deeSRichard Cochran 2094b15c707SJesus Sanchez-Palencia SOF_TXTIME_FLAGS_LAST = SOF_TXTIME_REPORT_ERRORS, 2104b15c707SJesus Sanchez-Palencia SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST - 1) | 2114b15c707SJesus Sanchez-Palencia SOF_TXTIME_FLAGS_LAST 21280b14deeSRichard Cochran }; 21380b14deeSRichard Cochran 21480b14deeSRichard Cochran struct sock_txtime { 215e2c4cf7fSDavide Caratti __kernel_clockid_t clockid;/* reference clockid */ 21652b50921SJesus Sanchez-Palencia __u32 flags; /* as defined by enum txtime_flags */ 21780b14deeSRichard Cochran }; 21880b14deeSRichard Cochran 219607ca46eSDavid Howells #endif /* _NET_TIMESTAMPING_H */ 220