Commit e57b8bdb4833 ("igb: Add 1588 support to I210/I211.") enables
per-packet Rx timestamping by setting RXPBS.CFG_TS_EN with Rx queues
running. On i210/i211, CFG_TS_EN makes the DMA engine prepend a 16-byte
timestamp header to every Rx packet buffer and sets RXDADV_STAT_TSIP in the
Rx descriptor so igb_clean_rx_irq() strips it.

Setting CFG_TS_EN changes the buffer layout of already-armed descriptors.
Without a pipeline handshake, descriptor status and packet buffer layout
disagree for in-flight packets:

  header inserted, no TSIP -> unstripped, frame shifted 16 bytes right
  TSIP set, no header      -> 16 bytes stripped, buffer tail appended

In both cases the Ethernet header is corrupted, causing protocol demux to
drop the frame silently. Because igb_alloc_mapped_page() allocates pages
without __GFP_ZERO, the second case appends uninitialized memory.

This occurs reliably on i210/i211 under traffic when requesting hardware
timestamps at runtime, yielding corrupt frames on off-to-on transitions.

Fix by bracketing the CFG_TS_EN transition with igb_down() and igb_up()
when the interface is running, ensuring the bit is only toggled with Rx
queues stopped.

Fixes: e57b8bdb4833 ("igb: Add 1588 support to I210/I211.")
Signed-off-by: Pascal Kneuper <[email protected]>
---
 drivers/net/ethernet/intel/igb/igb_ptp.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c 
b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 638d8242b66bb..4da26e997f92c 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -1283,9 +1283,26 @@ int igb_ptp_hwtstamp_set(struct net_device *netdev,
                         struct netlink_ext_ack *extack)
 {
        struct igb_adapter *adapter = netdev_priv(netdev);
+       struct e1000_hw *hw = &adapter->hw;
+       bool quiesce = false;
        int err;
 
+       /* CFG_TS_EN changes the Rx buffer layout, so flipping it on a live
+        * queue leaves the descriptor and the data disagreeing about the
+        * 16 byte timestamp header for one window, mangling a frame.
+        */
+       if ((hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) &&
+           netif_running(netdev) &&
+           !(rd32(E1000_RXPBS) & E1000_RXPBS_CFG_TS_EN)) {
+               quiesce = true;
+               igb_down(adapter);
+       }
+
        err = igb_ptp_set_timestamp_mode(adapter, config);
+
+       if (quiesce)
+               igb_up(adapter);
+
        if (err)
                return err;
 
-- 
2.47.3

Reply via email to