The TRM's procedure for reading the CPTS event FIFO says that after a
write to EVENT_POP, TS_PEND is not valid until four CPTS_RFT_CLK periods
plus four CPPI_ICLK periods have passed. am65_cpts_fifo_pop_event() does
not wait, so the next read of TS_PEND in __am65_cpts_fifo_read() can
come before it is valid.
After each pop, read a register so that the pop has reached the CPTS,
then wait 100 ns, which is enough for clocks of 80 MHz or more. This
adds about 300 ns per event, with cpts->lock held.
Signed-off-by: James Clark <j…@jclark.com>
---
drivers/net/ethernet/ti/am65-cpts.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c
index 3ce3b2245efb..d5c0a6a07965 100644
--- a/drivers/net/ethernet/ti/am65-cpts.c
+++ b/drivers/net/ethernet/ti/am65-cpts.c
@@ -7,6 +7,7 @@
#include <linux/clk.h>
#include <linux/clk-provider.h>
+#include <linux/delay.h>
#include <linux/err.h>
#include <linux/if_vlan.h>
#include <linux/interrupt.h>
@@ -285,6 +286,14 @@ static bool am65_cpts_fifo_pop_event(struct am65_cpts *cpts,
event->event2 = am65_cpts_read32(cpts, event_2);
event->timestamp |= (u64)am65_cpts_read32(cpts, event_3) << 32;
am65_cpts_write32(cpts, AM65_CPTS_EVENT_POP, event_pop);
+ /*
+ * TS_PEND is valid only once four CPTS_RFT_CLK periods plus
+ * four CPPI_ICLK periods have passed since a pop. Read a
+ * register so that the pop has reached the CPTS, then wait.
+ * 100 ns is enough for clocks of 80 MHz or more.
+ */
+ am65_cpts_read32(cpts, intstat_raw);
+ ndelay(100);
return false;
}
return true;
--
2.56.1