net: stmmac: ensure that the device has released ownership before reading data
authorNiklas Cassel <niklas.cassel@axis.com>
Mon, 26 Feb 2018 21:47:08 +0000 (22:47 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 27 Feb 2018 19:28:10 +0000 (14:28 -0500)
According to Documentation/memory-barriers.txt, we need to use a
dma_rmb() after reading the status/own bit, to ensure that all
descriptor fields are read after reading the own bit.

This way, we ensure that the DMA engine is done with the DMA
descriptor before we read the other descriptor fields, e.g. reading
the tx hardware timestamp (if PTP is enabled).

Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index 6dd04f237b2aa973016ea612a5fcbb514342011f..a9856a8bf8ad28e5e00caa898c5fbeb5c57a9b64 100644 (file)
@@ -1844,6 +1844,11 @@ static void stmmac_tx_clean(struct stmmac_priv *priv, u32 queue)
                if (unlikely(status & tx_dma_own))
                        break;
 
+               /* Make sure descriptor fields are read after reading
+                * the own bit.
+                */
+               dma_rmb();
+
                /* Just consider the last segment and ...*/
                if (likely(!(status & tx_not_ls))) {
                        /* ... verify the status error condition */