alistair23-linux/drivers/net/dsa
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
..
b53 net: dsa: b53: remove redundant premature assignment to new_pvid 2020-05-27 11:28:23 -07:00
microchip net: dsa: ksz: Select KSZ protocol tag 2020-03-31 10:04:40 -07:00
mv88e6xxx net: dsa: permit cross-chip bridging between all trees in the system 2020-05-10 19:52:33 -07:00
ocelot Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-05-31 17:48:46 -07:00
qca treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
sja1105 net: dsa: sja1105: fix PTP timestamping with large tc-taprio cycles 2020-06-15 13:45:59 -07:00
bcm_sf2.c net: dsa: bcm_sf2: Ensure correct sub-node is parsed 2020-04-06 10:22:58 -07:00
bcm_sf2.h net: dsa: bcm_sf2: Add support for optional reset controller line 2019-11-05 18:06:38 -08:00
bcm_sf2_cfp.c net: dsa: bcm_sf2: Support specifying VLAN tag egress rule 2020-03-30 19:55:42 -07:00
bcm_sf2_regs.h Revert "net: dsa: bcm_sf2: Also configure Port 5 for 2Gb/sec on 7278" 2020-02-26 16:33:35 -08:00
dsa_loop.c net: dsa: loop: Add module soft dependency 2020-05-10 11:24:20 -07:00
dsa_loop.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
dsa_loop_bdinfo.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
Kconfig treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
lan9303-core.c net: dsa: Get information about stacked DSA protocol 2020-01-08 16:01:13 -08:00
lan9303.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-11-04 09:26:51 +09:00
lan9303_i2c.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
lan9303_mdio.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
lantiq_gswip.c net: dsa: lantiq_gswip: fix and improve the unsupported interface error 2020-06-07 17:09:46 -07:00
lantiq_pce.h net: dsa: Use the correct style for SPDX License Identifier 2019-09-22 15:25:08 -07:00
Makefile net: dsa: add support for Atheros AR9331 built-in switch 2019-12-20 17:05:47 -08:00
mt7530.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-05-24 13:47:27 -07:00
mt7530.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-05-24 13:47:27 -07:00
mv88e6060.c net: dsa: Get information about stacked DSA protocol 2020-01-08 16:01:13 -08:00
mv88e6060.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
qca8k.c net: dsa: qca8k: Fix "Unexpected gfp" kernel exception 2020-06-04 15:47:10 -07:00
qca8k.h net: dsa: qca8k: introduce reset via gpio feature 2019-06-27 11:17:30 -07:00
realtek-smi-core.c net: dsa: remove dsa_switch_alloc helper 2019-10-22 12:37:07 -07:00
realtek-smi-core.h net: dsa: fix warning same module names 2019-06-14 19:28:54 -07:00
rtl8366.c net: dsa: rtl8366: Check VLAN ID and not ports 2019-10-02 12:09:23 -04:00
rtl8366rb.c net: dsa: Get information about stacked DSA protocol 2020-01-08 16:01:13 -08:00
vitesse-vsc73xx-core.c net: dsa: vsc73xx: make the MTU configurable 2020-03-27 16:07:25 -07:00
vitesse-vsc73xx-platform.c net: dsa: vsc73xx: convert to devm_platform_ioremap_resource 2020-05-08 22:28:24 -07:00
vitesse-vsc73xx-spi.c net: dsa: vsc73xx: Split vsc73xx driver 2019-07-07 14:16:32 -07:00
vitesse-vsc73xx.h net: dsa: vsc73xx: Split vsc73xx driver 2019-07-07 14:16:32 -07:00