Date: Tue, 7 Nov 2017 09:29:15 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325506 - in head: sbin/ifconfig sys/net sys/sys Message-ID: <201711070929.vA79TFTc096109@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Tue Nov 7 09:29:14 2017 New Revision: 325506 URL: https://svnweb.freebsd.org/changeset/base/325506 Log: Add a place for a driver to report rx timestamps in nanoseconds from boot for the received packets. The rcv_tstmp field overlaps the place of Ln header length indicators, not used by received packets. The basic pkthdr rearrangement change in sys/mbuf.h was provided by gallatin. There are two accompanying M_ flags: M_TSTMP means that there is the timestamp (and it was generated by hardware). Another flag M_TSTMP_HPREC indicates that the timestamp is high-precision. Practically M_TSTMP_HPREC means that hardware provided additional precision comparing with the stamps when the flag is not set. E.g., for ConnectX all packets are stamped by hardware when PCIe transaction to write out the completion descriptor is performed, but PTP packet are stamped on port. For Intel cards, when PTP assist is enabled, only PTP packets are stamped in the limited number of registers, so if Intel cards ever start support this mechanism, they would always set M_TSTMP | M_TSTMP_HPREC if hardware timestamp is present for the given packet. Add IFCAP_HWRXTSTMP interface capability to indicate the support for hardware rx timestamping, and ifconfig(8) command to toggle it. Based on the patch by: gallatin Reviewed by: gallatin (previous version), hselasky Sponsored by: Mellanox Technologies MFC after: 2 weeks (? mbuf KBI issue) X-Differential revision: https://reviews.freebsd.org/D12638 Modified: head/sbin/ifconfig/ifconfig.c head/sys/net/if.h head/sys/sys/mbuf.h Modified: head/sbin/ifconfig/ifconfig.c ============================================================================== --- head/sbin/ifconfig/ifconfig.c Tue Nov 7 08:39:14 2017 (r325505) +++ head/sbin/ifconfig/ifconfig.c Tue Nov 7 09:29:14 2017 (r325506) @@ -1143,7 +1143,7 @@ unsetifdescr(const char *val, int value, int s, const "\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING" \ "\10VLAN_HWCSUM\11TSO4\12TSO6\13LRO\14WOL_UCAST\15WOL_MCAST\16WOL_MAGIC" \ "\17TOE4\20TOE6\21VLAN_HWFILTER\23VLAN_HWTSO\24LINKSTATE\25NETMAP" \ -"\26RXCSUM_IPV6\27TXCSUM_IPV6\31TXRTLMT" +"\26RXCSUM_IPV6\27TXCSUM_IPV6\31TXRTLMT\32HWRXTSTMP" /* * Print the status of the interface. If an address family was @@ -1456,6 +1456,8 @@ static struct cmd basic_cmds[] = { DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap), DEF_CMD("txrtlmt", IFCAP_TXRTLMT, setifcap), DEF_CMD("-txrtlmt", -IFCAP_TXRTLMT, setifcap), + DEF_CMD("hwrxtsmp", IFCAP_HWRXTSTMP, setifcap), + DEF_CMD("-hwrxtsmp", -IFCAP_HWRXTSTMP, setifcap), DEF_CMD("normal", -IFF_LINK0, setifflags), DEF_CMD("compress", IFF_LINK0, setifflags), DEF_CMD("noicmp", IFF_LINK1, setifflags), Modified: head/sys/net/if.h ============================================================================== --- head/sys/net/if.h Tue Nov 7 08:39:14 2017 (r325505) +++ head/sys/net/if.h Tue Nov 7 09:29:14 2017 (r325506) @@ -240,6 +240,7 @@ struct if_data { #define IFCAP_TXCSUM_IPV6 0x400000 /* can offload checksum on IPv6 TX */ #define IFCAP_HWSTATS 0x800000 /* manages counters internally */ #define IFCAP_TXRTLMT 0x1000000 /* hardware supports TX rate limiting */ +#define IFCAP_HWRXTSTMP 0x2000000 /* hardware rx timestamping */ #define IFCAP_HWCSUM_IPV6 (IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6) Modified: head/sys/sys/mbuf.h ============================================================================== --- head/sys/sys/mbuf.h Tue Nov 7 08:39:14 2017 (r325505) +++ head/sys/sys/mbuf.h Tue Nov 7 09:29:14 2017 (r325506) @@ -154,15 +154,21 @@ struct pkthdr { /* Layer crossing persistent information. */ uint32_t flowid; /* packet's 4-tuple system */ - uint64_t csum_flags; /* checksum and offload features */ + uint32_t csum_flags; /* checksum and offload features */ uint16_t fibnum; /* this packet should use this fib */ uint8_t cosqos; /* class/quality of service */ uint8_t rsstype; /* hash type */ - uint8_t l2hlen; /* layer 2 header length */ - uint8_t l3hlen; /* layer 3 header length */ - uint8_t l4hlen; /* layer 4 header length */ - uint8_t l5hlen; /* layer 5 header length */ union { + uint64_t rcv_tstmp; /* timestamp in ns */ + struct { + uint8_t l2hlen; /* layer 2 hdr len */ + uint8_t l3hlen; /* layer 3 hdr len */ + uint8_t l4hlen; /* layer 4 hdr len */ + uint8_t l5hlen; /* layer 5 hdr len */ + uint32_t spare; + }; + }; + union { uint8_t eight[8]; uint16_t sixteen[4]; uint32_t thirtytwo[2]; @@ -293,6 +299,10 @@ struct mbuf { #define M_VLANTAG 0x00000080 /* ether_vtag is valid */ #define M_UNUSED_8 0x00000100 /* --available-- */ #define M_NOFREE 0x00000200 /* do not free mbuf, embedded in cluster */ +#define M_TSTMP 0x00000400 /* rcv_tstmp field is valid */ +#define M_TSTMP_HPREC 0x00000800 /* rcv_tstmp is high-prec, typically + hw-stamped on port (useful for IEEE 1588 + and 802.1AS) */ #define M_PROTO1 0x00001000 /* protocol-specific */ #define M_PROTO2 0x00002000 /* protocol-specific */ @@ -320,15 +330,15 @@ struct mbuf { * Flags preserved when copying m_pkthdr. */ #define M_COPYFLAGS \ - (M_PKTHDR|M_EOR|M_RDONLY|M_BCAST|M_MCAST|M_PROMISC|M_VLANTAG| \ - M_PROTOFLAGS) + (M_PKTHDR|M_EOR|M_RDONLY|M_BCAST|M_MCAST|M_PROMISC|M_VLANTAG|M_TSTMP| \ + M_TSTMP_HPREC|M_PROTOFLAGS) /* * Mbuf flag description for use with printf(9) %b identifier. */ #define M_FLAG_BITS \ "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_BCAST\6M_MCAST" \ - "\7M_PROMISC\10M_VLANTAG" + "\7M_PROMISC\10M_VLANTAG\13M_TSTMP\14M_TSTMP_HPREC" #define M_FLAG_PROTOBITS \ "\15M_PROTO1\16M_PROTO2\17M_PROTO3\20M_PROTO4\21M_PROTO5" \ "\22M_PROTO6\23M_PROTO7\24M_PROTO8\25M_PROTO9\26M_PROTO10" \ @@ -1347,6 +1357,18 @@ mbufq_concat(struct mbufq *mq_dst, struct mbufq *mq_sr STAILQ_CONCAT(&mq_dst->mq_head, &mq_src->mq_head); mq_src->mq_len = 0; } + +#ifdef _SYS_TIMESPEC_H_ +static inline void +mbuf_tstmp2timespec(struct mbuf *m, struct timespec *ts) +{ + + KASSERT((m->m_flags & M_PKTHDR) != 0, ("mbuf %p no M_PKTHDR", m)); + KASSERT((m->m_flags & M_TSTMP) != 0, ("mbuf %p no M_TSTMP", m)); + ts->tv_sec = m->m_pkthdr.rcv_tstmp / 1000000000; + ts->tv_nsec = m->m_pkthdr.rcv_tstmp % 1000000000; +} +#endif #endif /* _KERNEL */ #endif /* !_SYS_MBUF_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711070929.vA79TFTc096109>