1
0
Fork 0
alistair23-linux/drivers/net
Vladimir Oltean c92cbaea3c net: dsa: sja1105: fix PTP timestamping with large tc-taprio cycles
It isn't actually described clearly at all in UM10944.pdf, but on TX of
a management frame (such as PTP), this needs to happen:

- The destination MAC address (i.e. 01-80-c2-00-00-0e), along with the
  desired destination port, need to be installed in one of the 4
  management slots of the switch, over SPI.
- The host can poll over SPI for that management slot's ENFPORT field.
  That gets unset when the switch has matched the slot to the frame.

And therein lies the problem. ENFPORT does not mean that the packet has
been transmitted. Just that it has been received over the CPU port, and
that the mgmt slot is yet again available.

This is relevant because of what we are doing in sja1105_ptp_txtstamp_skb,
which is called right after sja1105_mgmt_xmit. We are in a hard
real-time deadline, since the hardware only gives us 24 bits of TX
timestamp, so we need to read the full PTP clock to reconstruct it.
Because we're in a hurry (in an attempt to make sure that we have a full
64-bit PTP time which is as close as possible to the actual transmission
time of the frame, to avoid 24-bit wraparounds), first we read the PTP
clock, then we poll for the TX timestamp to become available.

But of course, we don't know for sure that the frame has been
transmitted when we read the full PTP clock. We had assumed that ENFPORT
means it has, but the assumption is incorrect. And while in most
real-life scenarios this has never been caught due to software delays,
nowhere is this fact more obvious than with a tc-taprio offload, where
PTP traffic gets a small timeslot very rarely (example: 1 packet per 10
ms). In that case, we will be reading the PTP clock for timestamp
reconstruction too early (before the packet has been transmitted), and
this renders the reconstruction procedure incorrect (see the assumptions
described in the comments found on function sja1105_tstamp_reconstruct).
So the PTP TX timestamps will be off by 1<<24 clock ticks, or 135 ms
(1 tick is 8 ns).

So fix this case of premature optimization by simply reordering the
sja1105_ptpegr_ts_poll and the sja1105_ptpclkval_read function calls. It
turns out that in practice, the 135 ms hard deadline for PTP timestamp
wraparound is not so hard, since even the most bandwidth-intensive PTP
profiles, such as 802.1AS-2011, have a sync frame interval of 125 ms.
So if we couldn't deliver a timestamp in 135 ms (which we can), we're
toast and have much bigger problems anyway.

Fixes: 47ed985e97 ("net: dsa: sja1105: Add logic for TX timestamping")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-06-15 13:45:59 -07:00
..
appletalk treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
arcnet treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
bonding net: change addr_list_lock back to static key 2020-06-09 12:59:45 -07:00
caif treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
can treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
dsa net: dsa: sja1105: fix PTP timestamping with large tc-taprio cycles 2020-06-15 13:45:59 -07:00
ethernet mvpp2: ethtool rxtx stats fix 2020-06-15 13:43:49 -07:00
fddi treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
fjes
hamradio Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-06-13 16:27:13 -07:00
hippi treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
hyperv Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-06-03 16:27:18 -07:00
ieee802154 treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
ipa net: ipa: header pad field only valid for AP->modem endpoint 2020-06-11 18:39:08 -07:00
ipvlan net: partially revert dynamic lockdep key changes 2020-05-04 12:05:56 -07:00
netdevsim netdevsim: Register control traps 2020-06-01 11:49:23 -07:00
phy treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
plip treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
ppp treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
slip treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
team treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
usb treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
vmxnet3 vmxnet3: allow rx flow hash ops only when rss is enabled 2020-06-02 15:12:33 -07:00
wan treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
wimax wimax/i2400m: Fix potential urb refcnt leak 2020-04-18 15:00:22 -07:00
wireguard wireguard: noise: separate receive counter from send counter 2020-05-20 20:55:09 -07:00
wireless Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-06-13 16:27:13 -07:00
xen-netback
Kconfig treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
LICENSE.SRC
Makefile
Space.c
bareudp.c net: bareudp: avoid uninitialized variable warning 2020-05-07 17:28:18 -07:00
dummy.c
eql.c
geneve.c geneve: change from tx_error to tx_dropped on missing metadata 2020-06-04 15:45:15 -07:00
gtp.c gtp: set NLM_F_MULTI flag in gtp_genl_dump_pdp() 2020-05-01 15:34:09 -07:00
ifb.c
loopback.c
macsec.c net: change addr_list_lock back to static key 2020-06-09 12:59:45 -07:00
macvlan.c net: change addr_list_lock back to static key 2020-06-09 12:59:45 -07:00
macvtap.c
mdio.c
mii.c
net_failover.c net_failover: fixed rollback in net_failover_open() 2020-06-02 15:35:53 -07:00
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c rionet: Fix use correct return type for ndo_start_xmit() 2020-04-30 12:15:13 -07:00
sb1000.c
sungem_phy.c
tap.c
thunderbolt.c
tun.c xdp: Rename convert_to_xdp_frame in xdp_convert_buff_to_frame 2020-06-01 15:02:53 -07:00
veth.c xdp: Rename convert_to_xdp_frame in xdp_convert_buff_to_frame 2020-06-01 15:02:53 -07:00
virtio_net.c xdp: Rename convert_to_xdp_frame in xdp_convert_buff_to_frame 2020-06-01 15:02:53 -07:00
vrf.c net: partially revert dynamic lockdep key changes 2020-05-04 12:05:56 -07:00
vsockmon.c
vxlan.c vxlan: Remove access to nexthop group struct 2020-06-10 13:20:20 -07:00
xen-netfront.c